use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class AtlasServiceTest method testJarUploadNoProcessorLoader.
@Test
public void testJarUploadNoProcessorLoader() throws Exception {
assumeFalse(isWindowsJDK8());
createJarFile(false, true);
FileInputStream jarIn = new FileInputStream(TEST_JAR_PATH);
Response resUL = service.uploadLibrary(jarIn);
assertEquals(200, resUL.getStatus());
Response resFA = service.listFieldActions(null);
assertEquals(200, resFA.getStatus());
String responseJson = new String((byte[]) resFA.getEntity());
assertFalse(responseJson.contains("myCustomFieldAction"));
BufferedInputStream in = new BufferedInputStream(new FileInputStream("src/test/resources/mappings/atlasmapping-custom-action.json"));
AtlasMapping am = mapper.readValue(in, AtlasMapping.class);
Mapping m = (Mapping) am.getMappings().getMapping().get(0);
Field f = m.getInputField().get(0);
f.setValue("foo");
Action action = f.getActions().get(0);
Method method = action.getClass().getDeclaredMethod("setParam", new Class[] { String.class });
method.invoke(action, "param");
ProcessMappingRequest request = new ProcessMappingRequest();
request.setMapping(m);
Response resMR = service.processMappingRequest(new ByteArrayInputStream(mapper.writeValueAsBytes(request)), null);
assertEquals(200, resMR.getStatus());
ProcessMappingResponse pmr = Json.mapper().readValue((byte[]) resMR.getEntity(), ProcessMappingResponse.class);
assertEquals(1, pmr.getAudits().getAudit().size(), printAudit(pmr.getAudits()));
Audit audit = pmr.getAudits().getAudit().get(0);
assertEquals(AuditStatus.WARN, audit.getStatus());
assertTrue(audit.getMessage().contains("Couldn't find metadata for a FieldAction 'MyFieldActionsModel'"));
assertEquals("foo", pmr.getMapping().getOutputField().get(0).getValue());
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class AtlasServiceTest method testProcessMappingCustomAction.
@Test
public void testProcessMappingCustomAction() throws Exception {
createJarFile(false, false);
FileInputStream jarIn = new FileInputStream(TEST_JAR_PATH);
Response resUL = service.uploadLibrary(jarIn);
assertEquals(200, resUL.getStatus());
Response resFA = service.listFieldActions(null);
assertEquals(200, resFA.getStatus());
BufferedInputStream in = new BufferedInputStream(new FileInputStream("src/test/resources/mappings/atlasmapping-custom-action.json"));
AtlasMapping am = mapper.readValue(in, AtlasMapping.class);
Mapping m = (Mapping) am.getMappings().getMapping().get(0);
Field f = m.getInputField().get(0);
f.setValue("foo");
Action action = f.getActions().get(0);
Method method = action.getClass().getDeclaredMethod("setParam", new Class[] { String.class });
method.invoke(action, "param");
ProcessMappingRequest request = new ProcessMappingRequest();
request.setMapping(m);
Response resMR = service.processMappingRequest(new ByteArrayInputStream(mapper.writeValueAsBytes(request)), null);
assertEquals(200, resMR.getStatus());
ProcessMappingResponse pmr = Json.mapper().readValue((byte[]) resMR.getEntity(), ProcessMappingResponse.class);
assertEquals(0, pmr.getAudits().getAudit().size(), printAudit(pmr.getAudits()));
assertEquals("param foo", pmr.getMapping().getOutputField().get(0).getValue());
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionWithoutRoot.
@Test
public void testProcessOldExpressionActionWithoutRoot() throws Exception {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
FieldGroup fieldGroup = new FieldGroup();
fieldGroup.setPath("/fields<>");
fieldGroup.setCollectionType(CollectionType.LIST);
Field field1 = new SimpleField();
field1.setPath("/fields<0>");
field1.setValue("one");
fieldGroup.getField().add(field1);
Field field2 = new SimpleField();
field2.setPath("/fields<1>");
field2.setValue("two");
fieldGroup.getField().add(field2);
Field field3 = new SimpleField();
field3.setPath("/fields<3>");
field3.setValue("four");
fieldGroup.getField().add(field3);
Expression action = new Expression();
action.setExpression("capitalize(${0})");
fieldGroup.setActions(new ArrayList<Action>());
fieldGroup.getActions().add(action);
Field answer = fieldActionsService.processActions(session, fieldGroup);
assertEquals(FieldGroup.class, answer.getClass());
FieldGroup answerGroup = (FieldGroup) answer;
assertEquals(3, answerGroup.getField().size());
Field f = answerGroup.getField().get(0);
assertEquals("/$ATLASMAP<0>", f.getPath());
assertEquals("One", f.getValue());
f = answerGroup.getField().get(1);
assertEquals("/$ATLASMAP<1>", f.getPath());
assertEquals("Two", f.getValue());
f = answerGroup.getField().get(2);
assertEquals("/$ATLASMAP<2>", f.getPath());
assertEquals("Four", f.getValue());
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testFindActionDetail.
@Test
public void testFindActionDetail() throws Exception {
ActionDetail actionDetail = fieldActionsService.findActionDetail(new Prepend(), FieldType.STRING);
assertNotNull(actionDetail);
System.out.println(new ObjectMapper().writeValueAsString(actionDetail.getActionSchema()));
actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.STRING);
assertNotNull(actionDetail);
actionDetail = fieldActionsService.findActionDetail(new Action() {
}, FieldType.STRING);
assertNull(actionDetail);
actionDetail = fieldActionsService.findActionDetail(new IndexOf(), null);
assertNotNull(actionDetail);
actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.STRING);
assertNotNull(actionDetail);
actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.ANY);
assertNotNull(actionDetail);
actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.NONE);
assertNotNull(actionDetail);
actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.BOOLEAN);
assertNotNull(actionDetail);
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessActionWithActionActionDetailObjectAssignableType.
@Test
public void testProcessActionWithActionActionDetailObjectAssignableType() throws AtlasException {
Action action = new AbsoluteValue();
Object sourceObject = Integer.valueOf("1");
ActionProcessor processor = fieldActionsService.findActionProcessor(action, FieldType.STRING);
assertEquals(1L, processor.process(action, sourceObject));
}
Aggregations