use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class AtlasServiceTest method testJarUpload.
@Test
public void testJarUpload() 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());
String responseJson = new String((byte[]) resFA.getEntity());
assertTrue(responseJson.contains("myCustomFieldAction"));
Response resMB = service.listMappingBuilderClasses(null);
assertEquals(200, resMB.getStatus());
ArrayNode builders = (ArrayNode) new ObjectMapper().readTree((byte[]) resMB.getEntity()).get("ArrayList");
assertEquals(1, builders.size());
assertEquals("io.atlasmap.service.my.MyCustomMappingBuilder", builders.get(0).asText());
BufferedInputStream in = new BufferedInputStream(new FileInputStream("src/test/resources/mappings/atlasmapping-custom-action.json"));
Response resVD = service.validateMappingRequest(in, 0, null);
assertEquals(200, resVD.getStatus());
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class AtlasService method processMappingRequest.
/**
* Processes mapping by feeding input data.
* @param request request
* @param uriInfo URI info
* @return {@link ProcessMappingResponse} which holds the result of the mappings
*/
@PUT
@Path("/mapping/process")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Process Mapping", description = "Process Mapping by feeding input data")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ProcessMappingResponse.class)), description = "Return a mapping result"), @ApiResponse(responseCode = "204", description = "Skipped empty mapping execution") })
public Response processMappingRequest(InputStream request, @Context UriInfo uriInfo) {
ProcessMappingRequest pmr = fromJson(request, ProcessMappingRequest.class);
if (pmr.getAtlasMapping() != null) {
throw new WebApplicationException("Whole mapping execution is not yet supported");
}
Mapping mapping = pmr.getMapping();
if (mapping == null) {
return Response.noContent().build();
}
Audits audits = null;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Preview request: {}", new String(toJson(mapping)));
}
audits = previewContext.processPreview(mapping);
} catch (AtlasException e) {
throw new WebApplicationException("Unable to process mapping preview", e);
}
ProcessMappingResponse response = new ProcessMappingResponse();
response.setMapping(mapping);
if (audits != null) {
response.setAudits(audits);
}
byte[] serialized = toJson(response);
if (LOG.isDebugEnabled()) {
LOG.debug("Preview outcome: {}", new String(serialized));
}
return Response.ok().entity(serialized).build();
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class AtlasTestData method generateAtlasSession.
public static AtlasSession generateAtlasSession() throws Exception {
AtlasMapping mappings = generateAtlasMapping();
Map<String, Object> runtimeProperties = generateRuntimeProperties();
return new DefaultAtlasSession(new DefaultAtlasContext(null)) {
@Override
public Map<String, Object> getSourceProperties() {
return runtimeProperties;
}
@Override
public AtlasMapping getMapping() {
return mappings;
}
};
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class BaseMarshallerTest method generateCollectionMapping.
protected AtlasMapping generateCollectionMapping() {
AtlasMapping innerMapping1 = generateAtlasMapping();
AtlasMapping innerMapping2 = generateAtlasMapping();
Collection cMapping = (Collection) AtlasModelFactory.createMapping(MappingType.COLLECTION);
cMapping.setMappings(new Mappings());
cMapping.getMappings().getMapping().addAll(innerMapping1.getMappings().getMapping());
cMapping.getMappings().getMapping().addAll(innerMapping2.getMappings().getMapping());
cMapping.setCollectionType(CollectionType.LIST);
cMapping.setCollectionSize(new BigInteger("2"));
cMapping.setAlias("alias");
cMapping.setDescription("description");
AtlasMapping mapping = generateAtlasMapping();
mapping.getMappings().getMapping().clear();
mapping.getMappings().getMapping().add(cMapping);
return mapping;
}
use of io.atlasmap.v2.Mappings in project atlasmap by atlasmap.
the class JavaValidationServiceTest method testValidateMappingSourceToTargetFormatConcerns.
@Test
public void testValidateMappingSourceToTargetFormatConcerns() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.json");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
JavaField in = (JavaField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.STRING);
in.setClassName("java.lang.String");
JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.LONG);
out.setClassName("java.lang.Long");
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
if (LOG.isDebugEnabled()) {
debugErrors(validations);
}
assertFalse(validationHelper.hasErrors());
assertTrue(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(3, validationHelper.getCount());
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("format")));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("fractional part")));
}
Aggregations