use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.
the class TestTransformJSONResource method testValidateWithValidEmptySpec.
@Test
public void testValidateWithValidEmptySpec() {
JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-sort", "");
ValidationDTO validation = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
TestCase.assertNotNull(validation);
assertTrue(validation.isValid());
}
use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.
the class TestTransformJSONResource method testValidateWithCustomSpecEmptyModule.
@Test
public void testValidateWithCustomSpecEmptyModule() {
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");
ValidationDTO validate = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
assertNotNull(validate);
assertTrue(!validate.isValid());
}
use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.
the class TestTransformJSONResource method testExecuteWithValidExpressionLanguageSpec.
@Test
public void testExecuteWithValidExpressionLanguageSpec() {
final Diffy diffy = new Diffy();
JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-shift", "{ \"rating\" : {\"quality\": \"${qual_var}\"} }");
String inputJson = "{\"rating\":{\"quality\":2,\"count\":1}}";
joltSpecificationDTO.setInput(inputJson);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("qual_var", "qa");
joltSpecificationDTO.setExpressionLanguageAttributes(attributes);
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("{\"qa\":2}}");
assertNotNull(transformedJson);
assertTrue(diffy.diff(compareJson, transformedJson).isEmpty());
}
use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.
the class TestTransformJSONResource method testValidateWithValidExpressionLanguageSpec.
@Test
public void testValidateWithValidExpressionLanguageSpec() {
JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove", "{\"rating\": {\"${filename}\": \"\"} }");
ValidationDTO validation = client().target(getBaseUri()).path("/standard/transformjson/validate").request().post(Entity.json(joltSpecificationDTO), ValidationDTO.class);
TestCase.assertNotNull(validation);
assertTrue(validation.isValid());
}
use of org.apache.nifi.web.standard.api.transformjson.dto.JoltSpecificationDTO in project nifi by apache.
the class TestTransformJSONResource method testExecuteWithInvalidSpec.
@Test
public void testExecuteWithInvalidSpec() {
JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove", "{\"rating\": {\"quality\": \"\"} }");
final Response response = client().target(getBaseUri()).path("/standard/transformjson/execute").request().post(Entity.json(joltSpecificationDTO));
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
Aggregations