0

I have a question regarding unit testing of jsonschema2pojo.

What I am trying to do is use the sample unit test in https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/json/RealJsonExamplesIT.java to set up my own test, however I find that there is no test library available. I tried to set up the sources in my project, but I am not using Maven, but Gradle. For the lack of Maven, the class or.jsonschema2pojo.integration.util.JsonSchema2PojoRule class does not want to compile without Maven in my project. In our team we do not use maven in our build server.

I hope that someone can help me point in the direction of how I would unit test my implementation method.

This is the unit test I am trying to run:

public class AnalyticsGeneratorImplTest extends AbstractGoogleAnalyticsTest {

// Set a logger
private static Logger log = LoggerFactory.getLogger(AnalyticsGeneratorImplTest.class);

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

@Rule
public JsonSchema2PojoRule schemaRule = new JsonSchema2PojoRule();

@Test
public void getTitleFromGeneratedJson() throws Exception {
    //verify that the incoming Json has been transformed

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/assets/generated-list/google-analytics.json", "uk.ac.soton.generators.analytics.target",
            config("sourceType", "json",
                    "useLongIntegers", true));

    Class<?> googleAnalyticsJsonObject = resultsClassLoader.loadClass("uk.ac.soton.generators.analytics.serialised.GoogleAnalyticsJsonObject");

    Object gaJsonObj = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/assets/generated-list/google-analytics.json"), googleAnalyticsJsonObject);
    Object result = googleAnalyticsJsonObject.getMethod("getResult").invoke(gaJsonObj);
    Object data = result.getClass().getMethod("getData").invoke(result);
    Object title = data.getClass().getMethod("getTitle").invoke(data);

    assertThat(title.getClass().getMethod("getTitle").invoke(title).toString(), is("blue"));

}
}
Arnout Cator
  • 81
  • 1
  • 1
  • 7

1 Answers1

0

You need add the dependecies in gradle:

compile group: 'org.jsonschema2pojo', name: 'jsonschema2pojo-gradle-plugin', version: '0.4.29'

And the others one. If there exist in Maven, it can exist in Gradle too. Check in MavenRepository and select the dependecie you want and Will be exist for all Java Build Toll just select the Gradle Tab and you see the dependecie you need. org.jsonschema2pojo

Gatusko
  • 2,503
  • 1
  • 17
  • 25