简体   繁体   English

我需要运行jsonschema2pojo的单元测试的帮助

[英]I need help running a unit test for jsonschema2pojo

I have a question regarding unit testing of jsonschema2pojo. 我对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. 我想做的是在https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/json/RealJsonExamplesIT中使用样本单元测试.java来设置我自己的测试,但是我发现没有可用的测试库。 I tried to set up the sources in my project, but I am not using Maven, but Gradle. 我试图在我的项目中设置源,但是我没有使用Maven,而是使用Gradle。 For the lack of Maven, the class or.jsonschema2pojo.integration.util.JsonSchema2PojoRule class does not want to compile without Maven in my project. 由于缺少Maven,因此在我的项目中,如果没有Maven,则类or.jsonschema2pojo.integration.util.JsonSchema2PojoRule类不希望进行编译。 In our team we do not use maven in our build server. 在我们的团队中,我们不在构建服务器中使用maven。

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"));

}
}

You need add the dependecies in gradle: 您需要在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. 如果Maven中存在,它也可以存在于Gradle中。 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. 签入MavenRepository并选择所需的依赖关系,并且对于所有Java Build Toll都将存在,只需选择Gradle选项卡,您就会看到所需的依赖关系。 org.jsonschema2pojo org.jsonschema2pojo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM