Skip to content

Commit

Permalink
[RESTEASY-2347] added property check and related unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rsearls authored and asoldano committed Nov 12, 2019
1 parent e490913 commit ad89f72
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Expand Up @@ -49,8 +49,12 @@ public class JsonBindingProvider extends AbstractJsonBindingProvider
public JsonBindingProvider() {
super();
ResteasyConfiguration context = ResteasyProviderFactory.getContextData(ResteasyConfiguration.class);
disabled = (context != null && (Boolean.parseBoolean(context.getParameter(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB))
|| Boolean.parseBoolean(context.getParameter("resteasy.jsonp.enable"))));
if (context == null) {
disabled = Boolean.getBoolean(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB);
} else {
disabled = (Boolean.parseBoolean(context.getParameter(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB))
|| Boolean.parseBoolean(context.getParameter("resteasy.jsonp.enable")));
}
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions testsuite/unit-tests/pom.xml
Expand Up @@ -88,6 +88,12 @@
<version>${version.resteasy.testsuite}</version>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-json-binding-provider</artifactId>
<version>${version.resteasy.testsuite}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
@@ -0,0 +1,43 @@
package org.jboss.resteasy.test.providers;

import org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

/**
* Check when ResteasyConfiguration.class is null in JsonBindingProvider
* system property is checked and the property is set accordingly.
* There are integration tests that check the properly setting when
* a ResteasyConfiguration.class is provided.
*/
public class JsonBindingTest {
private MediaType mediaType = new MediaType("application", "json");

@Test
public void testUseJSONB() throws Exception
{
String origValue = System.getProperty(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB);

System.setProperty(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, "true");
JsonBindingProvider jbp = new JsonBindingProvider();
boolean result = jbp.isReadable(null, null, null, mediaType);

if (origValue == null) {
System.setProperty(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, "");
} else {
System.setProperty(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, origValue);
}
assertFalse(result);
}

@Test
public void testUseJACKSON() throws Exception
{
JsonBindingProvider jbp = new JsonBindingProvider();
boolean result = jbp.isReadable(null, null, null, mediaType);
assertTrue(result);
}
}

0 comments on commit ad89f72

Please sign in to comment.