Search in sources :

Example 96 with Action

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());
}
Also used : Action(io.atlasmap.v2.Action) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Method(java.lang.reflect.Method) FileInputStream(java.io.FileInputStream) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Response(javax.ws.rs.core.Response) Field(io.atlasmap.v2.Field) Audit(io.atlasmap.v2.Audit) AtlasMapping(io.atlasmap.v2.AtlasMapping) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessMappingRequest(io.atlasmap.v2.ProcessMappingRequest) Test(org.junit.jupiter.api.Test)

Example 97 with Action

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());
}
Also used : ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Response(javax.ws.rs.core.Response) Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) Action(io.atlasmap.v2.Action) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Method(java.lang.reflect.Method) FileInputStream(java.io.FileInputStream) ProcessMappingRequest(io.atlasmap.v2.ProcessMappingRequest) Test(org.junit.jupiter.api.Test)

Example 98 with Action

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());
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Action(io.atlasmap.v2.Action) FieldGroup(io.atlasmap.v2.FieldGroup) Expression(io.atlasmap.v2.Expression) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 99 with Action

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);
}
Also used : Prepend(io.atlasmap.v2.Prepend) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) IndexOf(io.atlasmap.v2.IndexOf) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 100 with Action

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));
}
Also used : Action(io.atlasmap.v2.Action) AbsoluteValue(io.atlasmap.v2.AbsoluteValue) ActionProcessor(io.atlasmap.spi.ActionProcessor) Test(org.junit.jupiter.api.Test)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)61 List (java.util.List)40 Action (io.atlasmap.v2.Action)35 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)16 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)14 SimpleField (io.atlasmap.v2.SimpleField)13 Field (io.atlasmap.v2.Field)12 Mapping (io.atlasmap.v2.Mapping)11 ActionContext (com.opensymphony.xwork2.ActionContext)9 AtlasMapping (io.atlasmap.v2.AtlasMapping)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 SettableApiFuture (com.google.api.core.SettableApiFuture)8 ServiceOptions (com.google.cloud.ServiceOptions)8 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)8 Subscriber (com.google.cloud.pubsub.v1.Subscriber)8 Action (com.google.privacy.dlp.v2.Action)8 BigQueryTable (com.google.privacy.dlp.v2.BigQueryTable)8 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)8