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();
}
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());
}
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());
}
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());
}
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)));
}
Aggregations