Search in sources :

Example 1 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class AtlasService method validateMapping.

protected Response validateMapping(AtlasMapping mapping, UriInfo uriInfo) throws IOException, AtlasException {
    File temporaryMappingFile = File.createTempFile("atlas-mapping", "xml");
    temporaryMappingFile.deleteOnExit();
    atlasContextFactory.getMappingService().saveMappingAsFile(mapping, temporaryMappingFile);
    AtlasContext context = atlasContextFactory.createContext(temporaryMappingFile.toURI());
    AtlasSession session = context.createSession();
    context.processValidation(session);
    Validations validations = session.getValidations();
    if (session.getValidations() == null) {
        validations = new Validations();
    }
    if (temporaryMappingFile.exists() && !temporaryMappingFile.delete()) {
        LOG.warn("Failed to deleting temporary file: " + (temporaryMappingFile != null ? temporaryMappingFile.toString() : null));
    }
    return Response.ok().entity(toJson(validations)).build();
}
Also used : Validations(io.atlasmap.v2.Validations) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession)

Example 2 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class Atlasmap233Test method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/atlasmap-233-mapping.xml");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    session.setSourceDocument("io.atlasmap.core.issue.SourceClass", new SourceClass().setSourceInteger(-1));
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    Object output = session.getTargetDocument("io.atlasmap.core.issue.TargetClass");
    assertEquals(TargetClass.class, output.getClass());
    assertEquals(1, ((TargetClass) output).getTargetInteger());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) Test(org.junit.Test)

Example 3 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class CombineSeparateChangeDelimiterTest method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/combine-separate-change-delimiter-mapping.xml");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    SourceClass source = new SourceClass().setSourceFirstName("Manjiro").setSourceLastName("Nakahama").setSourceName("Manjiro,Nakahama");
    session.setSourceDocument("io.atlasmap.core.issue.SourceClass", source);
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    assertFalse(TestHelper.printAudit(session), session.hasWarns());
    Object output = session.getTargetDocument("io.atlasmap.core.issue.TargetClass");
    assertEquals(TargetClass.class, output.getClass());
    TargetClass target = TargetClass.class.cast(output);
    assertEquals("Manjiro", target.getTargetFirstName());
    assertEquals("Nakahama", target.getTargetLastName());
    assertEquals("Manjiro,Nakahama", target.getTargetName());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) Test(org.junit.Test)

Example 4 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class OverloadedFieldActionsTest method testMappingDayOfWeekInteger.

@Test
public void testMappingDayOfWeekInteger() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(generateMappingDayOfWeek(Integer.class));
    AtlasSession session = context.createSession();
    SourceFlatPrimitiveClass src = new SourceFlatPrimitiveClass();
    src.setIntField(1);
    session.setInput(src);
    context.process(session);
    Object tgt = session.getOutput();
    assertNotNull(tgt);
    assertTrue(tgt.getClass().isAssignableFrom(TargetFlatPrimitiveClass.class));
    System.out.println(((TargetFlatPrimitiveClass) tgt).getBoxedStringField());
}
Also used : TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) SourceFlatPrimitiveClass(io.atlasmap.java.test.SourceFlatPrimitiveClass) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 5 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class ConcurrencyChaosMonkeyTest method chaosMonkeyTestManyThreads.

// many threads, one context
@Test
public void chaosMonkeyTestManyThreads() throws Exception {
    long startTime = System.nanoTime();
    URI mappingURI = generateMappingURI();
    Status twitterStatus = generateTwitterStatus();
    AtlasContext context = atlasContextFactory.createContext(mappingURI);
    for (int i = 0; i < 256; i++) {
        Thread chaosMonkeyThread = new Thread("ChaosMonkeyThread-" + i) {

            public void run() {
                LOG.info(this.getName() + " starting.");
                for (int j = 0; j < 100000; j++) {
                    try {
                        AtlasSession session = context.createSession();
                        session.setDefaultSourceDocument(twitterStatus);
                        context.process(session);
                        Random rand = new Random(System.currentTimeMillis() % 13);
                        int randSleep;
                        randSleep = rand.nextInt(20000);
                        Thread.sleep(randSleep);
                        context.process(session);
                        Thread.sleep(randSleep);
                    } catch (Throwable e) {
                        LOG.error("ERROR", e);
                    }
                }
                LOG.info(this.getName() + " thread completed.");
            }
        };
        chaosMonkeyThread.start();
    }
    Thread.sleep(600000L);
    long difference = System.nanoTime() - startTime;
    LOG.info(String.format("Total time: %d minutes to process 100000 mappings with one context shared with 256 threads", TimeUnit.NANOSECONDS.toMinutes(difference)));
}
Also used : Status(twitter4j.Status) Random(java.util.Random) AtlasContext(io.atlasmap.api.AtlasContext) URI(java.net.URI) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)138 AtlasSession (io.atlasmap.api.AtlasSession)138 File (java.io.File)128 Test (org.junit.Test)119 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)111 BaseContact (io.atlasmap.java.test.BaseContact)25 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)25 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)24 TargetContact (io.atlasmap.java.test.TargetContact)19 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)13 BaseOrder (io.atlasmap.java.test.BaseOrder)12 TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetTestClass (io.atlasmap.java.test.TargetTestClass)11 XmlContactAttribute (io.atlasmap.xml.test.v2.XmlContactAttribute)9 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)8 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)7 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)7 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 TargetOrder (io.atlasmap.json.test.TargetOrder)4 XmlFlatPrimitiveElement (io.atlasmap.xml.test.v2.XmlFlatPrimitiveElement)4