Search in sources :

Example 11 with JoltSpecificationDTO

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

the class TestTransformJSONResource method testValidateWithCustomSpec.

@Test
public void testValidateWithCustomSpec() {
    final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
    final Map<String, String> properties = new HashMap<>();
    properties.put("jolt-transform", "jolt-transform-custom");
    final ComponentDetails componentDetails = new ComponentDetails.Builder().properties(properties).build();
    Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
    Mockito.when(niFiWebConfigurationContext.getComponentDetails(any(NiFiWebRequestContext.class))).thenReturn(componentDetails);
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-custom", "[{ \"operation\": \"default\", \"spec\":{ \"custom-id\" :4 }}]");
    joltSpecificationDTO.setCustomClass("TestCustomJoltTransform");
    joltSpecificationDTO.setModules("src/test/resources/TestTransformJSONResource/TestCustomJoltTransform.jar");
    ValidationDTO validate = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
    assertNotNull(validate);
    assertTrue(validate.isValid());
}
Also used : HashMap(java.util.HashMap) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) ValidationDTO(org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) NiFiWebRequestContext(org.apache.nifi.web.NiFiWebRequestContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 12 with JoltSpecificationDTO

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

the class TestTransformJSONResource method testValidateWithInvalidSpec.

@Test
public void testValidateWithInvalidSpec() {
    final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
    final Map<String, String> properties = new HashMap<>();
    properties.put("jolt-transform", "jolt-transform-chain");
    final ComponentDetails componentDetails = new ComponentDetails.Builder().properties(properties).build();
    Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
    Mockito.when(niFiWebConfigurationContext.getComponentDetails(any(NiFiWebRequestContext.class))).thenReturn(componentDetails);
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-chain", "[]");
    ValidationDTO validate = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
    assertNotNull(validate);
    assertTrue(!validate.isValid());
}
Also used : HashMap(java.util.HashMap) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) ValidationDTO(org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) NiFiWebRequestContext(org.apache.nifi.web.NiFiWebRequestContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 13 with JoltSpecificationDTO

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

the class TestTransformJSONResource method testValidateWithInvalidEmptySpec.

@Test
public void testValidateWithInvalidEmptySpec() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove", "");
    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 14 with JoltSpecificationDTO

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

the class TestTransformJSONResource method testValidateWithCustomInvalidSpec.

@Test
public void testValidateWithCustomInvalidSpec() {
    final NiFiWebConfigurationContext niFiWebConfigurationContext = mock(NiFiWebConfigurationContext.class);
    final Map<String, String> properties = new HashMap<>();
    properties.put("jolt-transform", "jolt-transform-custom");
    final ComponentDetails componentDetails = new ComponentDetails.Builder().properties(properties).build();
    Mockito.when(servletContext.getAttribute(Mockito.anyString())).thenReturn(niFiWebConfigurationContext);
    Mockito.when(niFiWebConfigurationContext.getComponentDetails(any(NiFiWebRequestContext.class))).thenReturn(componentDetails);
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-custom", "{ \"operation\": \"default\", \"spec\":{ \"custom-id\" :4 }}");
    joltSpecificationDTO.setCustomClass("TestCustomJoltTransform");
    joltSpecificationDTO.setModules("src/test/resources/TestTransformJSONResource/TestCustomJoltTransform.jar");
    ValidationDTO validate = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
    assertNotNull(validate);
    assertTrue(!validate.isValid());
}
Also used : HashMap(java.util.HashMap) JoltSpecificationDTO(org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO) ValidationDTO(org.apache.nifi.web.standard.api.transformjson.dto.ValidationDTO) NiFiWebConfigurationContext(org.apache.nifi.web.NiFiWebConfigurationContext) ComponentDetails(org.apache.nifi.web.ComponentDetails) NiFiWebRequestContext(org.apache.nifi.web.NiFiWebRequestContext) 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