Search in sources :

Example 6 with JoltSpecificationDTO

use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.

the class TestTransformJSONResource method testExecuteWithValidSpec.

@Test
public void testExecuteWithValidSpec() {
    final Diffy diffy = new Diffy();
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove", "{\"rating\": {\"quality\": \"\"} }");
    String inputJson = "{\"rating\":{\"quality\":2,\"count\":1}}";
    joltSpecificationDTO.setInput(inputJson);
    String responseString = client().target(getBaseUri()).path("/standard/transformjson/execute").request().post(Entity.json(joltSpecificationDTO), String.class);
    Object transformedJson = JsonUtils.jsonToObject(responseString);
    Object compareJson = JsonUtils.jsonToObject("{\"rating\":{\"count\":1}}");
    assertNotNull(transformedJson);
    assertTrue(diffy.diff(compareJson, transformedJson).isEmpty());
}
Also used : Diffy(com.bazaarvoice.jolt.Diffy) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 7 with JoltSpecificationDTO

use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.

the class TestTransformJSONResource method testExecuteWithValidCustomSpec.

@Test
public void testExecuteWithValidCustomSpec() {
    final Diffy diffy = new Diffy();
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-custom", "[{ \"operation\": \"default\", \"spec\":{ \"custom-id\" :4 }}]");
    String inputJson = "{\"rating\":{\"quality\":2,\"count\":1}}";
    joltSpecificationDTO.setInput(inputJson);
    joltSpecificationDTO.setCustomClass("TestCustomJoltTransform");
    joltSpecificationDTO.setModules("src/test/resources/TestTransformJSONResource/TestCustomJoltTransform.jar");
    String responseString = client().target(getBaseUri()).path("/standard/transformjson/execute").request().post(Entity.json(joltSpecificationDTO), String.class);
    Object transformedJson = JsonUtils.jsonToObject(responseString);
    Object compareJson = JsonUtils.jsonToObject("{\"rating\":{\"quality\":2,\"count\":1}, \"custom-id\": 4}");
    assertNotNull(transformedJson);
    assertTrue(diffy.diff(compareJson, transformedJson).isEmpty());
}
Also used : Diffy(com.bazaarvoice.jolt.Diffy) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 8 with JoltSpecificationDTO

use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.

the class TestTransformJSONResource method testValidateWithValidNullSpec.

@Test
public void testValidateWithValidNullSpec() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-sort", null);
    ValidationDTO validation = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
    TestCase.assertNotNull(validation);
    assertTrue(validation.isValid());
}
Also used : JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) ValidationDTO(org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 9 with JoltSpecificationDTO

use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.

the class TestTransformJSONResource method testExecuteWithValidCustomSpecEmptyModule.

@Test
public void testExecuteWithValidCustomSpecEmptyModule() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-custom", "[{ \"operation\": \"default\", \"spec\":{ \"custom-id\" :4 }}]");
    String inputJson = "{\"rating\":{\"quality\":2,\"count\":1}}";
    joltSpecificationDTO.setInput(inputJson);
    joltSpecificationDTO.setCustomClass("TestCustomJoltTransform");
    final Response response = client().target(getBaseUri()).path("/standard/transformjson/execute").request().post(Entity.json(joltSpecificationDTO));
    assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 10 with JoltSpecificationDTO

use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.

the class TestTransformJSONResource method testValidateWithValidSpec.

@Test
public void testValidateWithValidSpec() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove", "{\"rating\": {\"quality\": \"\"} }");
    ValidationDTO validation = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
    TestCase.assertNotNull(validation);
    assertTrue(validation.isValid());
}
Also used : JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) ValidationDTO(org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

JoltSpecificationDTO (org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO)14 JerseyTest (org.glassfish.jersey.test.JerseyTest)14 Test (org.junit.Test)14 ValidationDTO (org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO)9 HashMap (java.util.HashMap)5 ComponentDetails (org.apache.nifi.web.ComponentDetails)4 NiFiWebConfigurationContext (org.apache.nifi.web.NiFiWebConfigurationContext)4 NiFiWebRequestContext (org.apache.nifi.web.NiFiWebRequestContext)4 Diffy (com.bazaarvoice.jolt.Diffy)3 Response (javax.ws.rs.core.Response)2