release version 1.10.0

This commit is contained in:
2024-12-14 04:07:49 +03:00
parent a5088587f7
commit c6b3d793c4
1916 changed files with 254306 additions and 0 deletions

View File

@ -0,0 +1,304 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-parent</artifactId>
<version>2.2.3</version>
<!-- relativePath>../parent</relativePath -->
</parent>
<artifactId>camel3-atlasmap-entaxy</artifactId>
<packaging>bundle</packaging>
<version>2.5.2</version>
<name>camel3-atlasmap</name>
<description>Camel component to perform AtlasMap data mapping as a part of Camel route</description>
<properties>
<entaxy.version>1.10.0</entaxy.version>
<osgi.export.pkg>org.apache.camel.component.atlasmap</osgi.export.pkg>
<osgi.export.service>org.apache.camel.spi.ComponentResolver;component=atlas</osgi.export.service>
<camel3.version>3.4.5</camel3.version>
<atlas.version>2.5.2</atlas.version>
<checkstyle.skip>true</checkstyle.skip>
<jackson.version>2.12.3</jackson.version>
</properties>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
<version>${camel3.version}</version>
</dependency>
<dependency>
<groupId>ru.entaxy.esb.platform.runtime.modules.atlasmap</groupId>
<artifactId>atlasmap-entaxy-libs</artifactId>
<version>${entaxy.version}</version>
</dependency>
<!-- for testing -->
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-java-test-model</artifactId>
<version>${atlas.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-xml-test-model</artifactId>
<version>${atlas.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.atlasmap</groupId>
<artifactId>atlas-xml-core</artifactId>
<version>${atlas.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>${camel3.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-xml</artifactId>
<version>${camel3.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-javaconfig</artifactId>
<version>${camel3.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${camel3-spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>jacoco</id>
<properties>
<sonar.language>java</sonar.language>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>public-deploy</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<distributionManagement>
<repository>
<id>entaxy-public-entaxy</id>
<name>entaxy-public-entaxy</name>
<uniqueVersion>false</uniqueVersion>
<layout>default</layout>
<!-- url>http://localhost:8981/repository/entaxy-public-entaxy/</url -->
<url>https://nexus.entaxy.ru/nexus/repository/entaxy-public-entaxy/</url>
</repository>
<!-- we don't publish snapshots -->
<!-- snapshotRepository>
<id>entaxy-private-snapshots</id>
<name>entaxy-private-snapshots</name>
<uniqueVersion>false</uniqueVersion>
<layout>default</layout>
<url>http://localhost:8981/repository/entaxy-private-snapshots/</url>
</snapshotRepository -->
</distributionManagement>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.camel</groupId>
<artifactId>camel-package-maven-plugin</artifactId>
<versionRange>[2.19.0.fuse-000035,)</versionRange>
<goals>
<goal>prepare-components</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filter</id>
<phase>generate-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- ENTAXY: set to false -->
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>entaxy-private-releases</id>
<name>entaxy-private-releases</name>
<url>https://nexus.entaxy.ru/nexus/repository/entaxy-private-releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>entaxy-private-snapshots</id>
<name>entaxy-private-snapshots</name>
<url>https://nexus.entaxy.ru/nexus/repository/entaxy-private-snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@ -0,0 +1,75 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.component.atlasmap.AtlasEndpoint.TargetMapMode;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.DefaultComponent;
import org.apache.camel.support.ResourceHelper;
import io.atlasmap.api.AtlasContextFactory;
/**
* @version
*/
public class AtlasComponent extends DefaultComponent {
@Metadata(label = "advanced")
private AtlasContextFactory atlasContextFactory;
public AtlasContextFactory getAtlasContextFactory() {
return atlasContextFactory;
}
/**
* To use the {@link AtlasContextFactory} otherwise a new engine is created.
* @param atlasContextFactory {@link AtlasContextFactory}
*/
public void setAtlasContextFactory(AtlasContextFactory atlasContextFactory) {
this.atlasContextFactory = atlasContextFactory;
}
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);
String sourceMapName = getAndRemoveParameter(parameters, "sourceMapName", String.class);
String targetMapName = getAndRemoveParameter(parameters, "targetMapName", String.class);
TargetMapMode targetMapMode = getAndRemoveParameter(parameters, "targetMapMode", TargetMapMode.class);
AtlasEndpoint endpoint = new AtlasEndpoint(uri, this, remaining);
setProperties(endpoint, parameters);
endpoint.setContentCache(cache);
endpoint.setSourceMapName(sourceMapName);
endpoint.setTargetMapName(targetMapName);
endpoint.setAtlasContextFactory(getAtlasContextFactory());
if (targetMapMode != null) {
endpoint.setTargetMapMode(targetMapMode);
}
// if its a http resource then append any remaining parameters and update the
// resource uri
if (ResourceHelper.isHttpUri(remaining)) {
String remainingAndParameters = ResourceHelper.appendParameters(remaining, parameters);
endpoint.setResourceUri(remainingAndParameters);
}
return endpoint;
}
}

View File

@ -0,0 +1,32 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
/**
* Atlas Constants.
*/
public final class AtlasConstants {
public static final String ATLAS_RESOURCE_URI = "CamelAtlasResourceUri";
public static final String ATLAS_MAPPING = "CamelAtlasMapping";
public static final String ATLAS_SOURCE_MAP = "CamelAtlasSourceMap";
public static final String ATLAS_TARGET_MAP = "CamelAtlasTargetMap";
private AtlasConstants() {
}
}

View File

@ -0,0 +1,460 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import static io.atlasmap.api.AtlasContextFactory.Format.ADM;
import static io.atlasmap.api.AtlasContextFactory.Format.JSON;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.component.ResourceEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.support.MessageHelper;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.atlasmap.api.AtlasContext;
import io.atlasmap.api.AtlasContextFactory;
import io.atlasmap.api.AtlasException;
import io.atlasmap.api.AtlasSession;
import io.atlasmap.core.DefaultAtlasContextFactory;
import io.atlasmap.v2.Audit;
import io.atlasmap.v2.DataSource;
import io.atlasmap.v2.DataSourceType;
/**
* Transforms the message using an AtlasMap transformation.
*/
@UriEndpoint(firstVersion = "2.19.0", scheme = "atlas", title = "AtlasMap", syntax = "atlas:resourceUri", producerOnly = true, label = "transformation")
public class AtlasEndpoint extends ResourceEndpoint {
public static final String CONTENT_TYPE_JSON = "application/json";
public static final String CONTENT_TYPE_XML = "application/xml";
private static final Logger LOG = LoggerFactory.getLogger(AtlasEndpoint.class);
private AtlasContextFactory atlasContextFactory;
private AtlasContext atlasContext;
@UriParam(defaultValue = "true")
private boolean loaderCache = true;
@UriParam
private String encoding;
@UriParam
private String propertiesFile;
@UriParam
private String sourceMapName;
@UriParam
private String targetMapName;
@UriParam(defaultValue = "MAP")
private TargetMapMode targetMapMode = TargetMapMode.MAP;
public enum TargetMapMode {
MAP, MESSAGE_HEADER, EXCHANGE_PROPERTY;
}
public AtlasEndpoint(String uri, AtlasComponent component, String resourceUri) {
super(uri, component, resourceUri);
}
@Override
public boolean isSingleton() {
return true;
}
@Override
public ExchangePattern getExchangePattern() {
return ExchangePattern.InOut;
}
@Override
protected String createEndpointUri() {
return "atlas:" + getResourceUri();
}
public AtlasContextFactory getAtlasContextFactory() {
return this.atlasContextFactory;
}
public void setAtlasContextFactory(AtlasContextFactory atlasContextFactory) {
this.atlasContextFactory = atlasContextFactory;
}
public AtlasContext getAtlasContext() {
return this.atlasContext;
}
public void setAtlasContext(AtlasContext atlasContext) {
this.atlasContext = atlasContext;
}
public boolean isLoaderCache() {
return loaderCache;
}
/**
* Enables / disables the atlas map resource loader cache which is enabled by
* default.
* @param loaderCache true to enable loader cache
*/
public void setLoaderCache(boolean loaderCache) {
this.loaderCache = loaderCache;
}
/**
* Character encoding of the resource content.
* @param encoding encoding
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
}
public String getEncoding() {
return encoding;
}
/**
* The URI of the properties file which is used for AtlasContextFactory
* initialization.
* @param file property file path
*/
public void setPropertiesFile(String file) {
propertiesFile = file;
}
public String getPropertiesFile() {
return propertiesFile;
}
/**
* The Exchange property name for a source message map which hold
* <code>java.util.Map&lt;String, Message&gt;</code> where the key is AtlasMap Document ID.
* AtlasMap consumes Message bodies as source documents.
* @param name Exchange property name for source map
*/
public void setSourceMapName(String name) {
this.sourceMapName = name;
}
public String getSourceMapName() {
return this.sourceMapName;
}
/**
* The Exchange property name for a target document map which hold
* <code>java.util.Map&lt;String, Object&gt;</code> where the key is AtlasMap Document ID.
* AtlasMap populates multiple target documents into this map.
* @param name Exchange property name for target map
*/
public void setTargetMapName(String name) {
this.targetMapName = name;
}
public String getTargetMapName() {
return this.targetMapName;
}
/**
* {@link TargetMapMode} enum value to specify how multiple documents are delivered.
* @param mode {@link TargetMapMode}
*/
public void setTargetMapMode(TargetMapMode mode) {
this.targetMapMode = mode;
}
public TargetMapMode getTargetMapMode() {
return this.targetMapMode;
}
public AtlasEndpoint findOrCreateEndpoint(String uri, String newResourceUri) {
String newUri = uri.replace(getResourceUri(), newResourceUri);
log.debug("Getting endpoint with URI: {}", newUri);
return getCamelContext().getEndpoint(newUri, AtlasEndpoint.class);
}
@Override
protected void onExchange(Exchange exchange) throws Exception {
Message incomingMessage = exchange.getIn();
String newResourceUri = incomingMessage.getHeader(AtlasConstants.ATLAS_RESOURCE_URI, String.class);
if (newResourceUri != null) {
incomingMessage.removeHeader(AtlasConstants.ATLAS_RESOURCE_URI);
log.debug("{} set to {} creating new endpoint to handle exchange", AtlasConstants.ATLAS_RESOURCE_URI,
newResourceUri);
AtlasEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
newEndpoint.onExchange(exchange);
return;
}
AtlasSession atlasSession = getOrCreateAtlasContext(incomingMessage).createSession();
populateSourceDocuments(exchange, atlasSession);
atlasSession.getAtlasContext().process(atlasSession);
List<Audit> errors = new ArrayList<>();
for (Audit audit : atlasSession.getAudits().getAudit()) {
switch (audit.getStatus()) {
case ERROR:
errors.add(audit);
break;
case WARN:
LOG.warn("{}: Document='{}(ID:{})', path='{}'",
audit.getMessage(), audit.getDocName(), audit.getDocId(), audit.getPath());
break;
default:
LOG.info("{}: Document='{}(ID:{})', path='{}'",
audit.getMessage(), audit.getDocName(), audit.getDocId(), audit.getPath());
}
}
if (!errors.isEmpty()) {
StringBuilder buf = new StringBuilder("Errors: ");
errors.stream().forEach(a -> buf.append(
String.format("[%s: Document='%s(ID:%s)', path='%s'], ",
a.getMessage(), a.getDocName(), a.getDocId(), a.getPath())));
throw new AtlasException(buf.toString());
}
populateTargetDocuments(atlasSession, exchange);
}
private AtlasContext getOrCreateAtlasContext(Message incomingMessage) throws Exception {
String path = getResourceUri();
ObjectHelper.notNull(path, "mappingUri");
String content = incomingMessage.getHeader(AtlasConstants.ATLAS_MAPPING, String.class);
if (content != null) {
// use content from header
InputStream is = new ByteArrayInputStream(content.getBytes());
if (log.isDebugEnabled()) {
log.debug("Atlas mapping content read from header {} for endpoint {}", AtlasConstants.ATLAS_MAPPING,
getEndpointUri());
}
// remove the header to avoid it being propagated in the routing
incomingMessage.removeHeader(AtlasConstants.ATLAS_MAPPING);
return getOrCreateAtlasContextFactory().createContext(JSON, is);
} else if (getAtlasContext() != null) {
// no mapping specified in header, and found an existing context
return getAtlasContext();
}
// No mapping in header, and no existing context. Create new one from resourceUri
if (log.isDebugEnabled()) {
log.debug("Atlas mapping content read from resourceUri: {} for endpoint {}",
new Object[] { path, getEndpointUri() });
}
atlasContext = getOrCreateAtlasContextFactory().createContext(
path.toLowerCase().endsWith("adm") ? ADM : JSON, getResourceAsInputStream());
return atlasContext;
}
private synchronized AtlasContextFactory getOrCreateAtlasContextFactory() throws Exception {
if (atlasContextFactory != null) {
return atlasContextFactory;
}
atlasContextFactory = DefaultAtlasContextFactory.getInstance();
atlasContextFactory.addClassLoader(getCamelContext().getApplicationContextClassLoader());
// load the properties from property file which may overrides the default ones
if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
Properties properties = new Properties();
InputStream reader = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(),
getPropertiesFile());
try {
properties.load(reader);
log.info("Loaded the Atlas properties file " + getPropertiesFile());
} finally {
IOHelper.close(reader, getPropertiesFile(), log);
}
log.debug("Initializing AtlasContextFactory with properties {}", properties);
atlasContextFactory.setProperties(properties);
}
return atlasContextFactory;
}
private void populateSourceDocuments(Exchange exchange, AtlasSession session) {
if (session.getMapping().getDataSource() == null) {
return;
}
Message inMessage = exchange.getIn();
CamelAtlasPropertyStrategy propertyStrategy = new CamelAtlasPropertyStrategy();
propertyStrategy.setCurrentSourceMessage(inMessage);
propertyStrategy.setTargetMessage(exchange.getMessage());
propertyStrategy.setExchange(exchange);
session.setAtlasPropertyStrategy(propertyStrategy);
DataSource[] sourceDataSources = session.getMapping().getDataSource().stream()
.filter(ds -> ds.getDataSourceType() == DataSourceType.SOURCE)
.toArray(DataSource[]::new);
if (sourceDataSources.length == 0) {
session.setDefaultSourceDocument(inMessage.getBody());
return;
}
if (sourceDataSources.length == 1) {
String docId = sourceDataSources[0].getId();
Object payload = extractPayload(sourceDataSources[0], inMessage);
if (docId == null || docId.isEmpty()) {
session.setDefaultSourceDocument(payload);
} else {
session.setSourceDocument(docId, payload);
propertyStrategy.setSourceMessage(docId, inMessage);
}
return;
}
Map<String, Message> sourceMessages = null;
Map<String, Object> sourceDocuments = null;
if (sourceMapName != null) {
sourceMessages = exchange.getProperty(sourceMapName, Map.class);
}
if (sourceMessages == null) {
Object body = inMessage.getBody();
if (body instanceof Map) {
sourceDocuments = (Map<String, Object>)body;
} else {
session.setDefaultSourceDocument(body);
}
}
for (DataSource ds : sourceDataSources) {
String docId = ds.getId();
if (docId == null || docId.isEmpty()) {
Object payload = extractPayload(ds, inMessage);
session.setDefaultSourceDocument(payload);
} else if (sourceMessages != null) {
Object payload = extractPayload(ds, sourceMessages.get(docId));
session.setSourceDocument(docId, payload);
propertyStrategy.setSourceMessage(docId, sourceMessages.get(docId));
} else if (sourceDocuments != null) {
Object payload = sourceDocuments.get(docId);
session.setSourceDocument(docId, payload);
} else if (inMessage.getHeaders().containsKey(docId)) {
Object payload = inMessage.getHeader(docId);
session.setSourceDocument(docId, payload);
} else if (exchange.getProperties().containsKey(docId)) {
Object payload = exchange.getProperty(docId);
session.setSourceDocument(docId, payload);
} else {
LOG.warn("Ignoring missing source document: '{}(ID:{})'", ds.getName(), ds.getId());
}
}
}
private Object extractPayload(final DataSource dataSource, Message message) {
if (dataSource == null || message == null) {
return null;
}
Object body = null;
if (dataSource != null && dataSource.getUri() != null
&& !(dataSource.getUri().startsWith("atlas:core")
|| dataSource.getUri().startsWith("atlas:java"))) {
body = message.getBody(String.class);
} else {
body = message.getBody();
}
//Just in case, prepare for future calls
MessageHelper.resetStreamCache(message);
return body;
}
private void populateTargetDocuments(AtlasSession session, Exchange exchange) {
Message message = exchange.getMessage();
if (session.getMapping().getDataSource() == null) {
return;
}
DataSource[] targetDataSources = session.getMapping().getDataSource().stream()
.filter(ds -> ds.getDataSourceType() == DataSourceType.TARGET)
.toArray(DataSource[]::new);
if (targetDataSources.length == 0) {
Object newBody = session.getDefaultTargetDocument();
message.setBody(newBody);
return;
}
if (targetDataSources.length == 1) {
String docId = targetDataSources[0].getId();
if (docId == null || docId.isEmpty()) {
Object newBody = session.getDefaultTargetDocument();
message.setBody(newBody);
} else {
Object newBody = session.getTargetDocument(docId);
message.setBody(newBody);
}
setContentType(targetDataSources[0], message);
return;
}
Map<String, Object> targetDocuments = new HashMap<>();
for (DataSource ds : targetDataSources) {
String docId = ds.getId();
if (docId == null || docId.isEmpty()) {
targetDocuments.put(io.atlasmap.api.AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID,
session.getDefaultTargetDocument());
Object newBody = session.getDefaultTargetDocument();
message.setBody(newBody);
setContentType(ds, message);
} else {
targetDocuments.put(docId, session.getTargetDocument(docId));
}
}
switch (targetMapMode) {
case MAP:
if (targetMapName != null) {
exchange.setProperty(targetMapName, targetDocuments);
} else {
message.setBody(targetDocuments);
}
break;
case MESSAGE_HEADER:
targetDocuments.remove(io.atlasmap.api.AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID);
message.getHeaders().putAll(targetDocuments);
break;
case EXCHANGE_PROPERTY:
targetDocuments.remove(io.atlasmap.api.AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID);
exchange.getProperties().putAll(targetDocuments);
break;
}
}
private void setContentType(DataSource ds, Message message) {
if (ds.getUri() == null) {
return;
}
if (ds.getUri().startsWith("atlas:json")) {
message.setHeader(Exchange.CONTENT_TYPE, CONTENT_TYPE_JSON);
} else if (ds.getUri().startsWith("atlas:xml")) {
message.setHeader(Exchange.CONTENT_TYPE, CONTENT_TYPE_XML);
}
}
}

View File

@ -0,0 +1,93 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import java.util.HashMap;
import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import io.atlasmap.api.AtlasConversionException;
import io.atlasmap.api.AtlasSession;
import io.atlasmap.api.AtlasUnsupportedException;
import io.atlasmap.core.DefaultAtlasPropertyStrategy;
import io.atlasmap.v2.PropertyField;
/**
* AtlasMap property strategy to map Camel message headers and exchange properties to/from
* AtlasMap properties.
*
*/
public class CamelAtlasPropertyStrategy extends DefaultAtlasPropertyStrategy {
public static final String SCOPE_EXCHANGE_PROPERTY = "camelExchangeProperty";
public static final String SCOPE_CURRENT_MESSAGE_HEADER = "current";
private Exchange camelExchange;
private Map<String, Message> sourceMessageMap = new HashMap<>();
private Message camelTargetMessage;
@Override
public void readProperty(AtlasSession session, PropertyField propertyField)
throws AtlasUnsupportedException, AtlasConversionException {
String scope = propertyField.getScope();
String key = propertyField.getName();
Map<String, Object> target = null;
if (scope == null && sourceMessageMap.containsKey(SCOPE_CURRENT_MESSAGE_HEADER)) {
target = sourceMessageMap.get(SCOPE_CURRENT_MESSAGE_HEADER).getHeaders();
} else if (SCOPE_EXCHANGE_PROPERTY.equals(scope)) {
target = this.camelExchange.getProperties();
} else if (sourceMessageMap.containsKey(scope)) {
target = sourceMessageMap.get(scope).getHeaders();
}
if (target != null && target.containsKey(key)) {
propertyField.setValue(target.get(key));
} else {
super.readProperty(session, propertyField);
}
}
@Override
public void writeProperty(AtlasSession session, PropertyField propertyField) {
String scope = propertyField.getScope();
String key = propertyField.getName();
Object value = propertyField.getValue();
if (SCOPE_EXCHANGE_PROPERTY.equals(scope)) {
this.camelExchange.setProperty(key, value);
} else {
this.camelTargetMessage.setHeader(key, value);
}
}
public void setExchange(Exchange ex) {
this.camelExchange = ex;
}
public void setSourceMessage(String documentId, Message msg) {
sourceMessageMap.put(documentId, msg);
}
public void setCurrentSourceMessage(Message msg) {
sourceMessageMap.put(SCOPE_CURRENT_MESSAGE_HEADER, msg);
}
public void setTargetMessage(Message msg) {
this.camelTargetMessage = msg;
}
}

View File

@ -0,0 +1,11 @@
=========================================================================
== NOTICE file corresponding to the section 4 d of ==
== the Apache License, Version 2.0, ==
== in this case for the Apache Camel distribution. ==
=========================================================================
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
Please read the different LICENSE files present in the licenses directory of
this distribution.

View File

@ -0,0 +1,18 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
class=org.apache.camel.component.atlasmap.AtlasComponent

View File

@ -0,0 +1,175 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.ComparisonFailure;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.atlasmap.api.AtlasContext;
import io.atlasmap.api.AtlasSession;
import io.atlasmap.v2.AtlasMapping;
import io.atlasmap.v2.Audits;
import io.atlasmap.v2.DataSource;
import io.atlasmap.v2.DataSourceType;
public class AtlasEndpointTest {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEndpointTest.class);
@Test
public void testNoDataSource() throws Exception {
perform(new ArrayList<>(), null, null, false);
}
@Test
public void testDocId() throws Exception {
List<DataSource> ds = new ArrayList<>();
DataSource source = new DataSource();
source.setDataSourceType(DataSourceType.SOURCE);
source.setId("my-source-doc");
ds.add(source);
DataSource target = new DataSource();
target.setDataSourceType(DataSourceType.TARGET);
target.setId("my-target-doc");
ds.add(target);
perform(ds, "my-source-doc", "my-target-doc", false);
}
@Test(expected = ComparisonFailure.class)
public void noConversionIfNoDataSource() throws Exception {
perform(new ArrayList<>(), null, null, true);
}
@Test(expected = ComparisonFailure.class)
public void noConversionIfJavaDataSource() throws Exception {
final List<DataSource> dataSources = new ArrayList<>();
final DataSource dataSource = new DataSource();
dataSource.setDataSourceType(DataSourceType.SOURCE);
dataSource.setUri("atlas:java:some.Type");
dataSources.add(dataSource);
perform(dataSources, null, null, true);
}
@Test
public void doConversionIfJsonDataSource() throws Exception {
final List<DataSource> dataSources = new ArrayList<>();
final DataSource dataSource = new DataSource();
dataSource.setDataSourceType(DataSourceType.SOURCE);
dataSource.setUri("atlas:json:SomeType");
dataSources.add(dataSource);
perform(dataSources, null, null, true);
}
@Test(expected = ComparisonFailure.class)
public void noConversionIfJsonTargetDataSource() throws Exception {
final List<DataSource> dataSources = new ArrayList<>();
final DataSource dataSource = new DataSource();
dataSource.setDataSourceType(DataSourceType.TARGET);
dataSource.setUri("atlas:json:SomeType");
dataSources.add(dataSource);
perform(dataSources, null, null, true);
}
@Test
public void doConversionIfXmlDataSource() throws Exception {
final List<DataSource> dataSources = new ArrayList<>();
final DataSource dataSource = new DataSource();
dataSource.setDataSourceType(DataSourceType.SOURCE);
dataSource.setUri("atlas:xml:SomeType");
dataSources.add(dataSource);
perform(dataSources, null, null, true);
}
@Test(expected = ComparisonFailure.class)
public void noConversionIfXmlTargetDataSource() throws Exception {
final List<DataSource> dataSources = new ArrayList<>();
final DataSource dataSource = new DataSource();
dataSource.setDataSourceType(DataSourceType.TARGET);
dataSource.setUri("atlas:xml:SomeType");
dataSources.add(dataSource);
perform(dataSources, null, null, true);
}
private void perform(List<DataSource> dataSources, String sourceDocId, String targetDocId, boolean fromStream) throws Exception {
final AtlasMapping mapping = new AtlasMapping();
mapping.getDataSource().addAll(dataSources);
final AtlasContext context = spy(AtlasContext.class);
final AtlasSession session = spy(AtlasSession.class);
when(context.createSession()).thenReturn(session);
when(session.getAtlasContext()).thenReturn(context);
when(session.getMapping()).thenReturn(mapping);
when(session.getAudits()).thenReturn(new Audits());
final AtlasEndpoint endpoint = new AtlasEndpoint("atlas:test.xml", new AtlasComponent(), "test.xml");
endpoint.setAtlasContext(context);
final Exchange exchange = spy(Exchange.class);
final Message inMessage = spy(Message.class);
when(inMessage.getBody()).thenReturn(fromStream ? new ByteArrayInputStream("{test}".getBytes()) : "{test}");
when(inMessage.getBody(String.class)).thenReturn("{test}");
when(exchange.getIn()).thenReturn(inMessage);
if (sourceDocId == null) {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
LOG.debug("setDefaultSourceDocument({})", invocation.getArgument(0).toString());
assertEquals("{test}", invocation.getArgument(0).toString());
return null;
}
}).when(session).setDefaultSourceDocument(any());
} else {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
LOG.debug("setSourceDocument({}, {})", invocation.getArgument(0), invocation.getArgument(1));
assertEquals(sourceDocId, invocation.getArgument(0));
assertEquals("{test}", invocation.getArgument(1));
return null;
}
}).when(session).setSourceDocument(any(), any());
}
final Message outMessage = spy(Message.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
LOG.debug("setBody({})", invocation.getArgument(0).toString());
assertEquals("<target/>", invocation.getArgument(0));
return null;
}
}).when(outMessage).setBody(any());
doNothing().when(outMessage).setHeaders(any());
if (targetDocId == null) {
when(session.getDefaultTargetDocument()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
LOG.debug("getDefaultTargetDocument()");
return "<target/>";
}
});
} else {
when(session.getTargetDocument(any())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
LOG.debug("getTargetDocument({})", invocation.getArgument(0).toString());
assertEquals(targetDocId, invocation.getArgument(0));
return "<target/>";
}
});
}
when(exchange.getMessage()).thenReturn(outMessage);
endpoint.onExchange(exchange);
}
}

View File

@ -0,0 +1,70 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapComponentJavaToJsonTest {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@Ignore
@DirtiesContext
public void testMocksAreValid() throws Exception {
result.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());
MockEndpoint.assertIsSatisfied(camelContext);
Message msg = result.getExchanges().get(0).getIn();
assertEquals("application/json", msg.getHeader(Exchange.CONTENT_TYPE));
Object body = msg.getBody();
assertEquals(String.class, body.getClass());
ObjectMapper mapper = new ObjectMapper();
JsonNode sfJson = mapper.readTree((String)body);
assertNotNull(sfJson.get("TwitterScreenName__c"));
assertEquals("bobvila1982", sfJson.get("TwitterScreenName__c").asText());
}
}

View File

@ -0,0 +1,52 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapComponentJsonTest {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@Ignore
@DirtiesContext
public void testMocksAreValid() throws Exception {
result.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());
MockEndpoint.assertIsSatisfied(camelContext);
Object body = result.getExchanges().get(0).getIn().getBody();
assertEquals(String.class, body.getClass());
ObjectMapper mapper = new ObjectMapper();
JsonNode outJson = mapper.readTree((String)body);
assertEquals("Bob", outJson.get("FirstName").asText());
assertEquals("Vila", outJson.get("LastName").asText());
assertEquals("bobvila1982", outJson.get("Title").asText());
assertEquals("Let's build a house!", outJson.get("Description").asText());
}
}

View File

@ -0,0 +1,61 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapComponentJsonToJavaTest {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@Ignore
@DirtiesContext
public void testMocksAreValid() throws Exception {
result.setExpectedCount(1);
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", new ByteArrayInputStream("{\"field1\":\"value1\"}".getBytes()));
MockEndpoint.assertIsSatisfied(camelContext);
final Object body = result.getExchanges().get(0).getIn().getBody();
assertEquals(Pojo.class, body.getClass());
assertEquals("value1", ((Pojo) body).getField1());
}
}

View File

@ -0,0 +1,78 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import twitter4j.Status;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapComponentTest {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@Ignore
@DirtiesContext
public void testMocksAreValid() throws Exception {
result.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());
MockEndpoint.assertIsSatisfied(camelContext);
Object body = result.getExchanges().get(0).getIn().getBody();
assertEquals(String.class, body.getClass());
ObjectMapper mapper = new ObjectMapper();
JsonNode outJson = mapper.readTree((String)body);
assertEquals("Bob", outJson.get("FirstName").asText());
assertEquals("Vila", outJson.get("LastName").asText());
assertEquals("bobvila1982", outJson.get("Title").asText());
assertEquals("Let's build a house!", outJson.get("Description").asText());
assertEquals("const foobar", outJson.get("Constant").asText());
}
@Test
@Ignore
@DirtiesContext
public void testSeparateNotSucceed() throws Exception {
result.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
Status s = Util.generateMockTwitterStatus();
when(s.getUser().getName()).thenReturn("BobVila");
producerTemplate.sendBody("direct:start", s);
MockEndpoint.assertIsSatisfied(camelContext);
Object body = result.getExchanges().get(0).getIn().getBody();
assertEquals(String.class, body.getClass());
ObjectMapper mapper = new ObjectMapper();
JsonNode outJson = mapper.readTree((String)body);
assertEquals("BobVila", outJson.get("FirstName").asText());
assertNull(outJson.get("LastName"));
assertEquals("bobvila1982", outJson.get("Title").asText());
assertEquals("Let's build a house!", outJson.get("Description").asText());
}
}

View File

@ -0,0 +1,70 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import java.io.ByteArrayInputStream;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.diff.Diff;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(value = {"AtlasMapComponentXmlToXmlTest-context.xml"})
public class AtlasMapComponentXmlToXmlDefaultNsTest {
private static final String XML_EXPECTED = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><tns:Patient xmlns:tns=\"http://hl7.org/fhir\"><tns:id value=\"101138\"/></tns:Patient>";
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
result.setExpectedCount(1);
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", new ByteArrayInputStream("<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"101138\"></id></Patient>".getBytes()));
MockEndpoint.assertIsSatisfied(camelContext);
final String body = result.getExchanges().get(0).getIn().getBody(String.class);
Assert.assertNotNull(body);
Diff d = DiffBuilder.compare(Input.fromString(XML_EXPECTED).build())
.withTest(Input.fromString(body).build())
.ignoreWhitespace().build();
Assert.assertFalse(d.toString() + ": " + body, d.hasDifferences());
}
}

View File

@ -0,0 +1,69 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
import java.io.ByteArrayInputStream;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.diff.Diff;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapComponentXmlToXmlTest {
private static final String XML_EXPECTED = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><tns:Patient xmlns:tns=\"http://hl7.org/fhir\"><tns:id value=\"101138\"/></tns:Patient>";
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
result.setExpectedCount(1);
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", new ByteArrayInputStream("<tns:Patient xmlns:tns=\"http://hl7.org/fhir\"><tns:id value=\"101138\"></tns:id></tns:Patient>".getBytes()));
MockEndpoint.assertIsSatisfied(camelContext);
final String body = result.getExchanges().get(0).getIn().getBody(String.class);
Assert.assertNotNull(body);
Diff d = DiffBuilder.compare(Input.fromString(XML_EXPECTED).build())
.withTest(Input.fromString(body).build())
.ignoreWhitespace().build();
Assert.assertFalse(d.toString() + ": " + body, d.hasDifferences());
}
}

View File

@ -0,0 +1,65 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapExtractMappingsTest {
private static final String EXPECTED_BODY = "{\"order\":{\"orderId\":\"A123\"}}";
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@EndpointInject(uri = "mock:result-n")
protected MockEndpoint resultN;
@Test
@DirtiesContext
public void testXMLMappingsExtraction() throws Exception {
result.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start",
new ByteArrayInputStream("{ \"order\": { \"orderId\": \"A123\" }}".getBytes()));
MockEndpoint.assertIsSatisfied(camelContext);
final Object body = result.getExchanges().get(0).getIn().getBody();
assertEquals(EXPECTED_BODY, body);
}
@Test
@DirtiesContext
public void testXMLMappingsExtractionNumberedMappingFile() throws Exception {
resultN.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start-n",
new ByteArrayInputStream("{ \"order\": { \"orderId\": \"A123\" }}".getBytes()));
MockEndpoint.assertIsSatisfied(camelContext);
final Object body = resultN.getExchanges().get(0).getIn().getBody();
assertEquals(EXPECTED_BODY, body);
}
}

View File

@ -0,0 +1,68 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
import java.io.StringReader;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Validator;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import io.atlasmap.xml.core.schema.AtlasXmlSchemaSetParser;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapJsonToXmlSchemaTest {
private static final Logger LOG = LoggerFactory.getLogger(AtlasMapJsonToXmlSchemaTest.class);
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@After
public void after() {
result.reset();
}
@Test
@DirtiesContext
public void test() throws Exception {
result.setExpectedCount(1);
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
InputStream payloadIs = tccl.getResourceAsStream("json-source.json");
producerTemplate.sendBody("direct:start", payloadIs);
MockEndpoint.assertIsSatisfied(camelContext);
final String body = result.getExchanges().get(0).getIn().getBody(String.class);
assertNotNull(body);
LOG.debug(">>>>> {}", body);
InputStream schemaIs = tccl.getResourceAsStream("xml-target-schemaset.xml");
AtlasXmlSchemaSetParser schemaParser = new AtlasXmlSchemaSetParser(tccl);
Validator validator = schemaParser.createSchema(schemaIs).newValidator();
StreamSource source = new StreamSource(new StringReader(body));
validator.validate(source);
}
}

View File

@ -0,0 +1,201 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import static org.xmlunit.assertj.XmlAssert.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.support.DefaultMessage;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.atlasmap.java.test.SourceContact;
import io.atlasmap.java.test.TargetContact;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapMultiDocsTest {
private static final String JSON_SOURCE =
"{" +
"\"firstName\": \"JsonFirstName\"," +
"\"lastName\": \"JsonLastName\"," +
"\"phoneNumber\": \"JsonPhoneNumber\"," +
"\"zipCode\": \"JsonZipCode\"" +
"}";
private static final String XML_SOURCE =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<ns:Contact xmlns:ns=\"http://atlasmap.io/xml/test/v2\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" firstName=\"XmlFirstName\" lastName=\"XmlLastName\"\n" +
" phoneNumber=\"XmlPhoneNumber\" zipCode=\"XmlZipCode\" />\n";
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@EndpointInject(uri = "mock:result-body")
protected MockEndpoint resultBody;
@After
public void after() {
result.reset();
resultBody.reset();
}
@Test
@Ignore
@DirtiesContext
public void test() throws Exception {
result.setExpectedCount(1);
Map<String, Message> sourceMap = new HashMap<>();
SourceContact javaSource = new SourceContact();
javaSource.setFirstName("JavaFirstName");
javaSource.setLastName("JavaLastName");
javaSource.setPhoneNumber("JavaPhoneNumber");
javaSource.setZipCode("JavaZipCode");
Message msg = new DefaultMessage(camelContext);
msg.setBody(javaSource);
msg.setHeader("testProp", "java-source-header");
sourceMap.put("DOCID-JAVA-CONTACT-S", msg);
msg = new DefaultMessage(camelContext);
msg.setBody(JSON_SOURCE);
msg.setHeader("testProp", "json-source-header");
sourceMap.put("DOCID-JSON-CONTACT-S", msg);
msg = new DefaultMessage(camelContext);
msg.setBody(XML_SOURCE);
msg.setHeader("testProp", "xml-source-header");
sourceMap.put("DOCID-XML-CONTACT-S", msg);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBodyAndProperty("direct:start", null, "CAPTURED_OUT_MESSAGES_MAP", sourceMap);
MockEndpoint.assertIsSatisfied(camelContext);
Exchange exchange = result.getExchanges().get(0);
Map<?, ?> targetMap = exchange.getProperty("TARGET_MESSAGES_MAP", Map.class);
verifyTargetDocs(targetMap);
assertEquals("java-source-header", exchange.getProperty("target-exchange"));
assertEquals("json-source-header", exchange.getProperty("testProp"));
assertEquals("xml-source-header", exchange.getIn().getHeader("testProp"));
assertEquals("java-source-headerjson-source-headerxml-source-header"
, exchange.getIn().getHeader("testPropExpression"));
}
@Test
@Ignore
public void testBody() throws Exception {
resultBody.setExpectedCount(1);
Map<String, Object> sourceMap = new HashMap<>();
SourceContact javaSource = new SourceContact();
javaSource.setFirstName("JavaFirstName");
javaSource.setLastName("JavaLastName");
javaSource.setPhoneNumber("JavaPhoneNumber");
javaSource.setZipCode("JavaZipCode");
sourceMap.put("DOCID-JAVA-CONTACT-S", javaSource);
sourceMap.put("DOCID-JSON-CONTACT-S", JSON_SOURCE);
sourceMap.put("DOCID-XML-CONTACT-S", XML_SOURCE);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start-body", sourceMap);
MockEndpoint.assertIsSatisfied(camelContext);
Exchange exchange = resultBody.getExchanges().get(0);
Map<?, ?> targetMap = exchange.getIn().getBody(Map.class);
verifyTargetDocs(targetMap);
}
@Test
@Ignore
public void testHeaderDocs() throws Exception {
resultBody.setExpectedCount(1);
Map<String, Object> sourceMap = new HashMap<>();
SourceContact javaSource = new SourceContact();
javaSource.setFirstName("JavaFirstName");
javaSource.setLastName("JavaLastName");
javaSource.setPhoneNumber("JavaPhoneNumber");
javaSource.setZipCode("JavaZipCode");
sourceMap.put("DOCID-JAVA-CONTACT-S", javaSource);
sourceMap.put("DOCID-JSON-CONTACT-S", JSON_SOURCE);
sourceMap.put("DOCID-XML-CONTACT-S", XML_SOURCE);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBodyAndHeaders("direct:start-header", null, sourceMap);
MockEndpoint.assertIsSatisfied(camelContext);
Exchange exchange = resultBody.getExchanges().get(0);
verifyTargetDocs(exchange.getIn().getHeaders());
}
@Test
@Ignore
public void testExchangePropertyDocs() throws Exception {
resultBody.setExpectedCount(1);
Map<String, Object> sourceMap = new HashMap<>();
SourceContact javaSource = new SourceContact();
javaSource.setFirstName("JavaFirstName");
javaSource.setLastName("JavaLastName");
javaSource.setPhoneNumber("JavaPhoneNumber");
javaSource.setZipCode("JavaZipCode");
sourceMap.put("DOCID-JAVA-CONTACT-S", javaSource);
sourceMap.put("DOCID-JSON-CONTACT-S", JSON_SOURCE);
sourceMap.put("DOCID-XML-CONTACT-S", XML_SOURCE);
Endpoint ep = camelContext.getEndpoint("direct:start-exchange-property");
Exchange ex = ep.createExchange();
ex.getProperties().putAll(sourceMap);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.send(ep, ex);
MockEndpoint.assertIsSatisfied(camelContext);
Exchange exchange = resultBody.getExchanges().get(0);
verifyTargetDocs(exchange.getProperties());
}
private void verifyTargetDocs(Map<?, ?> targetMap) throws Exception {
String jsonTarget = (String) targetMap.get("DOCID-JSON-CONTACT-T");
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonTargetNode = mapper.readTree(jsonTarget);
assertEquals("JsonFirstName", jsonTargetNode.get("firstName").asText());
assertEquals("JavaLastName", jsonTargetNode.get("lastName").asText());
assertEquals("XmlPhoneNumber", jsonTargetNode.get("phoneNumber").asText());
String xmlTarget = (String) targetMap.get("DOCID-XML-CONTACT-T");
HashMap<String,String> ns = new HashMap<>();
ns.put("ns", "http://atlasmap.io/xml/test/v2");
assertThat(xmlTarget).withNamespaceContext(ns).valueByXPath("/Contact/@firstName").isEqualTo("XmlFirstName");
assertThat(xmlTarget).withNamespaceContext(ns).valueByXPath("/Contact/@lastName").isEqualTo("JsonLastName");
assertThat(xmlTarget).withNamespaceContext(ns).valueByXPath("/Contact/@phoneNumber").isEqualTo("JavaPhoneNumber");
}
}

View File

@ -0,0 +1,68 @@
package org.apache.camel.component.atlasmap;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.diff.Diff;
import io.atlasmap.java.test.SourceContact;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapMultiNSTest {
private static final String XML_EXPECTED =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<tns:request xmlns:tns=\"http://syndesis.io/v1/swagger-connector-template/request\">\n" +
" <tns:body>\n" +
" <Pet>\n" +
" <name>Jackson</name>\n" +
" </Pet>\n" +
" </tns:body>\n" +
"</tns:request>";
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@Ignore
@DirtiesContext
public void test() throws Exception {
result.setExpectedCount(1);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
SourceContact c = new SourceContact();
c.setFirstName("Jackson");
producerTemplate.sendBody("direct:start", c);
MockEndpoint.assertIsSatisfied(camelContext);
Message message = result.getExchanges().get(0).getIn();
Assert.assertEquals("application/xml", message.getHeader(Exchange.CONTENT_TYPE));
String out = message.getBody(String.class);
Assert.assertNotNull(out);
Diff d = DiffBuilder.compare(Input.fromString(XML_EXPECTED).build())
.withTest(Input.fromString(out).build())
.ignoreWhitespace().build();
Assert.assertFalse(d.toString() + ": " + out, d.hasDifferences());
}
}

View File

@ -0,0 +1,75 @@
package org.apache.camel.component.atlasmap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.DefaultExchange;
import org.apache.camel.support.DefaultMessage;
import org.junit.Test;
import io.atlasmap.api.AtlasSession;
import io.atlasmap.core.DefaultAtlasSession;
import io.atlasmap.v2.PropertyField;
public class CamelAtlasPropertyStrategyTest {
@Test
public void testRead() throws Exception {
CamelAtlasPropertyStrategy strategy = new CamelAtlasPropertyStrategy();
DefaultCamelContext context = new DefaultCamelContext();
DefaultExchange exchange = new DefaultExchange(context);
exchange.setProperty("testProp", "testProp-exchangeProperty");
strategy.setExchange(exchange);
DefaultMessage currentMessage = new DefaultMessage(exchange);
currentMessage.setHeader("testProp", "testProp-currentMessage");
strategy.setCurrentSourceMessage(currentMessage);
DefaultMessage message1 = new DefaultMessage(exchange);
message1.setHeader("testProp", "testProp-message1");
strategy.setSourceMessage("Doc1", message1);
DefaultMessage message2 = new DefaultMessage(exchange);
message2.setHeader("testProp", "testProp-message2");
strategy.setSourceMessage("Doc2", message2);
AtlasSession session = mock(AtlasSession.class);
when(session.getAtlasPropertyStrategy()).thenReturn(strategy);
PropertyField propertyField = new PropertyField();
propertyField.setName("testProp");
strategy.readProperty(session, propertyField);
assertEquals("testProp-currentMessage", propertyField.getValue());
propertyField.setScope(CamelAtlasPropertyStrategy.SCOPE_EXCHANGE_PROPERTY);
strategy.readProperty(session, propertyField);
assertEquals("testProp-exchangeProperty", propertyField.getValue());
propertyField.setScope("Doc1");
strategy.readProperty(session, propertyField);
assertEquals("testProp-message1", propertyField.getValue());
propertyField.setScope("Doc2");
strategy.readProperty(session, propertyField);
assertEquals("testProp-message2", propertyField.getValue());
}
@Test
public void testWrite() throws Exception {
CamelAtlasPropertyStrategy strategy = new CamelAtlasPropertyStrategy();
DefaultCamelContext context = new DefaultCamelContext();
DefaultExchange exchange = new DefaultExchange(context);
strategy.setExchange(exchange);
DefaultMessage message = new DefaultMessage(exchange);
strategy.setTargetMessage(message);
PropertyField propertyField = new PropertyField();
propertyField.setName("testProp-message");
propertyField.setValue("testValue");
AtlasSession session = mock(DefaultAtlasSession.class);
when(session.getAtlasPropertyStrategy()).thenReturn(strategy);
strategy.writeProperty(session, propertyField);
propertyField.setName("testProp-exchange");
propertyField.setScope(CamelAtlasPropertyStrategy.SCOPE_EXCHANGE_PROPERTY);
strategy.writeProperty(session, propertyField);
assertEquals("testValue", message.getHeader("testProp-message"));
assertNull(message.getHeader("testProp-exchange"));
assertNull(exchange.getProperty("testProp-message"));
assertEquals("testValue", exchange.getProperty("testProp-exchange"));
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright (C) 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.atlasmap;
public class Pojo {
private String field1;
public String getField1() {
return field1;
}
public void setField1(final String field1) {
this.field1 = field1;
}
}

View File

@ -0,0 +1,21 @@
package org.apache.camel.component.atlasmap;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import twitter4j.Status;
import twitter4j.User;
public class Util {
public static Status generateMockTwitterStatus() {
Status status = mock(Status.class);
User user = mock(User.class);
when(user.getName()).thenReturn("Bob Vila");
when(user.getScreenName()).thenReturn("bobvila1982");
when(status.getUser()).thenReturn(user);
when(status.getText()).thenReturn("Let's build a house!");
return status;
}
}

View File

@ -0,0 +1,92 @@
package org.apache.camel.component.atlasmap.issue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapIssue2552Test {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result-old")
protected MockEndpoint resultOld;
@EndpointInject(uri = "mock:result-new")
protected MockEndpoint resultNew;
@Test
public void testOld() throws Exception {
String jsonSource = new String(Files.readAllBytes(Paths.get(
this.getClass().getClassLoader().getResource(
"org/apache/camel/component/atlasmap/issue/2552-input.json").toURI())));
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start-old", jsonSource);
MockEndpoint.assertIsSatisfied(camelContext);
ObjectMapper om = new ObjectMapper();
Exchange exchange = resultOld.getExchanges().get(0);
String target = exchange.getIn().getBody(String.class);
JsonNode targetJsonOld = om.readTree(target);
assertTarget(targetJsonOld);
}
@Test
public void testNew() throws Exception {
String jsonSource = new String(Files.readAllBytes(Paths.get(
this.getClass().getClassLoader().getResource(
"org/apache/camel/component/atlasmap/issue/2552-input.json").toURI())));
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start-new", jsonSource);
MockEndpoint.assertIsSatisfied(camelContext);
ObjectMapper om = new ObjectMapper();
Exchange exchange = resultNew.getExchanges().get(0);
String target = exchange.getIn().getBody(String.class);
JsonNode targetJsonNew = om.readTree(target);
assertTarget(targetJsonNew);
}
private void assertTarget(JsonNode root) {
ArrayNode bodyArray = (ArrayNode) root.get("body");
assertEquals(3, bodyArray.size());
ObjectNode body1 = (ObjectNode) bodyArray.get(0);
ObjectNode body2 = (ObjectNode) bodyArray.get(1);
ObjectNode body3 = (ObjectNode) bodyArray.get(2);
assertEquals(1111, body1.get("id").asInt());
assertEquals(1, body1.get("completed").asInt());
assertEquals("task1", body1.get("task").asText());
assertEquals(2222, body2.get("id").asInt());
assertTrue(body2.get("completed").isNull());
assertEquals("task2", body2.get("task").asText());
assertEquals(3333, body3.get("id").asInt());
assertEquals(3, body3.get("completed").asInt());
assertEquals("task3", body3.get("task").asText());
}
}

View File

@ -0,0 +1,54 @@
package org.apache.camel.component.atlasmap.issue;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.BootstrapWith;
import org.springframework.test.context.ContextConfiguration;
import io.atlasmap.java.test.SourceContact;
import io.atlasmap.java.test.TargetContact;
@RunWith(CamelSpringRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration
public class AtlasMapIssue729Test {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
@Test
@Ignore
public void test() throws Exception {
SourceContact javaSource = new SourceContact();
javaSource.setFirstName("JavaFirstName");
javaSource.setLastName("JavaLastName");
javaSource.setPhoneNumber("JavaPhoneNumber");
javaSource.setZipCode("JavaZipCode");
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody("direct:start", javaSource);
MockEndpoint.assertIsSatisfied(camelContext);
Exchange exchange = result.getExchanges().get(0);
Map<?, ?> targetMap = exchange.getIn().getBody(Map.class);
TargetContact javaTarget = (TargetContact) targetMap.get("DOCID:JAVA:CONTACT:T");
assertEquals("JavaFirstName", javaTarget.getFirstName());
}
}

View File

@ -0,0 +1,56 @@
{
"AtlasMapping": {
"jsonType": "io.atlasmap.v2.AtlasMapping",
"dataSource": [
{
"jsonType": "io.atlasmap.v2.DataSource",
"id": "twitter4j.Status",
"uri": "atlas:java?className=twitter4j.Status",
"dataSourceType": "SOURCE"
},
{
"jsonType": "io.atlasmap.json.v2.JsonDataSource",
"id": "Contact",
"uri": "atlas:json:Contact",
"dataSourceType": "TARGET",
"template": null
}
],
"mappings": {
"mapping": [
{
"jsonType": "io.atlasmap.v2.Mapping",
"mappingType": "MAP",
"inputField": [
{
"jsonType": "io.atlasmap.java.v2.JavaField",
"name": "screenName",
"path": "/user/screenName",
"fieldType": "STRING",
"docId": "twitter4j.Status"
}
],
"outputField": [
{
"jsonType": "io.atlasmap.json.v2.JsonComplexType",
"name": "TwitterScreenName__c",
"path": "/TwitterScreenName__c",
"fieldType": "STRING",
"docId": "Contact",
"userCreated": false
}
]
}
]
},
"name": "UI.246440",
"lookupTables": {
"lookupTable": [
]
},
"properties": {
"property": [
]
}
}
}

View File

@ -0,0 +1,56 @@
{
"AtlasMapping": {
"jsonType": "io.atlasmap.v2.AtlasMapping",
"dataSource": [
{
"jsonType": "io.atlasmap.json.v2.JsonDataSource",
"id": "Contact",
"uri": "atlas:json:Json",
"dataSourceType": "SOURCE",
"template": null
},
{
"jsonType": "io.atlasmap.v2.DataSource",
"id": "twitter4j.Status",
"uri": "atlas:java?className=org.apache.camel.component.atlasmap.Pojo",
"dataSourceType": "TARGET"
}
],
"mappings": {
"mapping": [
{
"jsonType": "io.atlasmap.v2.Mapping",
"mappingType": "MAP",
"inputField": [
{
"jsonType": "io.atlasmap.json.v2.JsonComplexType",
"name": "field1",
"path": "/field1",
"fieldType": "STRING",
"docId": "Contact",
"userCreated": false
}
],
"outputField": [
{
"jsonType": "io.atlasmap.java.v2.JavaField",
"name": "field1",
"path": "/field1",
"fieldType": "STRING",
"docId": "twitter4j.Status"
}
]
}
]
},
"name": "UI.246440",
"lookupTables": {
"lookupTable": [
]
},
"properties": {
"property": [
]
}
}
}

View File

@ -0,0 +1,289 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID-JAVA-CONTACT-S",
"uri" : "atlas:java?className=io.atlasmap.java.test.SourceContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID-JSON-CONTACT-S",
"uri" : "atlas:json:JSONContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID-XML-CONTACT-S",
"uri" : "atlas:xml:XMLContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID-JAVA-CONTACT-T",
"uri" : "atlas:java?className=io.atlasmap.java.test.TargetContact",
"dataSourceType" : "TARGET"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID-JSON-CONTACT-T",
"uri" : "atlas:json:JSONContact",
"dataSourceType" : "TARGET"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID-XML-CONTACT-T",
"uri" : "atlas:xml:XMLContact",
"dataSourceType" : "TARGET"
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID-JAVA-CONTACT-S",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName",
"getMethod" : "getFirstName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID-JAVA-CONTACT-T",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName",
"setMethod" : "setFirstName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID-JAVA-CONTACT-S",
"path" : "/lastName",
"fieldType" : "STRING",
"name" : "lastName",
"getMethod" : "getLastName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"docId" : "DOCID-JSON-CONTACT-T",
"path" : "/lastName",
"fieldType" : "STRING",
"name" : "lastName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID-JAVA-CONTACT-S",
"path" : "/phoneNumber",
"fieldType" : "STRING",
"name" : "phoneNumber",
"getMethod" : "getPhoneNumber"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "DOCID-XML-CONTACT-T",
"path" : "/Contact/@phoneNumber",
"fieldType" : "STRING",
"name" : "phoneNumber"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"docId" : "DOCID-JSON-CONTACT-S",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"docId" : "DOCID-JSON-CONTACT-T",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"docId" : "DOCID-JSON-CONTACT-S",
"path" : "/lastName",
"fieldType" : "STRING",
"name" : "lastName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "DOCID-XML-CONTACT-T",
"path" : "/Contact/@lastName",
"fieldType" : "STRING",
"name" : "lastName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"docId" : "DOCID-JSON-CONTACT-S",
"path" : "/phoneNumber",
"fieldType" : "STRING",
"name" : "phoneNumber"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID-JAVA-CONTACT-T",
"path" : "/phoneNumber",
"fieldType" : "STRING",
"name" : "phoneNumber",
"setMethod" : "setPhoneNumber"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "DOCID-XML-CONTACT-S",
"path" : "/Contact/@firstName",
"fieldType" : "STRING",
"name" : "firstName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "DOCID-XML-CONTACT-T",
"path" : "/Contact/@firstName",
"fieldType" : "STRING",
"name" : "firstName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "DOCID-XML-CONTACT-S",
"path" : "/Contact/@lastName",
"fieldType" : "STRING",
"name" : "lastName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID-JAVA-CONTACT-T",
"path" : "/lastName",
"fieldType" : "STRING",
"name" : "lastName",
"setMethod" : "setLastName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "DOCID-XML-CONTACT-S",
"path" : "/Contact/@phoneNumber",
"fieldType" : "STRING",
"name" : "phoneNumber"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"docId" : "DOCID-JSON-CONTACT-T",
"path" : "/phoneNumber",
"fieldType" : "STRING",
"name" : "phoneNumber"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"path" : "/testProp",
"fieldType" : "STRING",
"scope" : "DOCID-JAVA-CONTACT-S",
"name" : "testProp"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"path" : "/target-exchange",
"fieldType" : "STRING",
"scope" : "camelExchangeProperty",
"name" : "target-exchange"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"path" : "/testProp",
"fieldType" : "STRING",
"scope" : "DOCID-JSON-CONTACT-S",
"name" : "testProp"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"path" : "/testProp",
"fieldType" : "STRING",
"scope" : "camelExchangeProperty",
"name" : "testProp"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"path" : "/testProp",
"fieldType" : "STRING",
"scope" : "DOCID-XML-CONTACT-S",
"name" : "testProp"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"path" : "/testProp",
"fieldType" : "STRING",
"name" : "testProp"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"expression" : "${PROP:/DOCID-JAVA-CONTACT-S/testProp} + ${PROP:/DOCID-JSON-CONTACT-S/testProp} + ${PROP:/DOCID-XML-CONTACT-S/testProp}",
"inputFieldGroup" : {
"jsonType" : "io.atlasmap.v2.FieldGroup",
"field" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"docId" : "PROP",
"path" : "/DOCID-JAVA-CONTACT-S/testProp",
"fieldType" : "STRING",
"scope" : "DOCID-JAVA-CONTACT-S",
"name" : "testProp"
}, {
"jsonType" : "io.atlasmap.v2.PropertyField",
"docId" : "PROP",
"path" : "/DOCID-JSON-CONTACT-S/testProp",
"fieldType" : "STRING",
"scope" : "DOCID-JSON-CONTACT-S",
"name" : "testProp"
}, {
"jsonType" : "io.atlasmap.v2.PropertyField",
"docId" : "PROP",
"path" : "/DOCID-XML-CONTACT-S/testProp",
"fieldType" : "STRING",
"scope" : "DOCID-XML-CONTACT-S",
"name" : "testProp"
} ] },
"outputField" : [ {
"jsonType" : "io.atlasmap.v2.PropertyField",
"docId" : "PROP",
"path" : "/testPropExpression",
"fieldType" : "STRING",
"name" : "testPropExpression"
} ]
} ]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "mockMapping"
}
}

View File

@ -0,0 +1,52 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "SourceContact",
"uri" : "atlas:java:SourceContact?className=io.atlasmap.java.test.SourceContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.xml.v2.XmlDataSource",
"id" : "XMLSchemaTarget",
"uri" : "atlas:xml:XMLSchemaTarget",
"dataSourceType" : "TARGET",
"xmlNamespaces" : {
"xmlNamespace" : [ {
"alias" : "tns",
"uri" : "http://syndesis.io/v1/swagger-connector-template/request"
} ]
}
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "SourceContact",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName",
"getMethod" : "getFirstName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.xml.v2.XmlField",
"docId" : "XMLSchemaTarget",
"path" : "/tns:request/tns:body/Pet/name",
"fieldType" : "STRING",
"name" : "name",
"userCreated" : false
} ],
"id" : "mapping.222691"
} ]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "UI.860284"
}
}

View File

@ -0,0 +1,66 @@
{
"AtlasMapping": {
"dataSource": [
{
"dataSourceType": "SOURCE",
"id": "-LO2lWtkzmk816-JEluS",
"jsonType": "io.atlasmap.xml.v2.XmlDataSource",
"uri": "atlas:xml:-LO2lWtkzmk816-JEluS",
"xmlNamespaces": {
"xmlNamespace": [
{
"alias": "tns",
"uri": "http://hl7.org/fhir"
}
]
}
},
{
"dataSourceType": "TARGET",
"id": "-LO2lU-dzmk816-JEluS",
"jsonType": "io.atlasmap.xml.v2.XmlDataSource",
"uri": "atlas:xml:-LO2lU-dzmk816-JEluS",
"xmlNamespaces": {
"xmlNamespace": [
{
"alias": "tns",
"targetNamespace": true,
"uri": "http://hl7.org/fhir"
}
]
}
}
],
"jsonType": "io.atlasmap.v2.AtlasMapping",
"mappings": {
"mapping": [
{
"id": "mapping.431884",
"inputField": [
{
"docId": "-LO2lWtkzmk816-JEluS",
"fieldType": "STRING",
"jsonType": "io.atlasmap.xml.v2.XmlField",
"name": "value",
"path": "/tns:Patient/tns:id/@value",
"userCreated": false
}
],
"jsonType": "io.atlasmap.v2.Mapping",
"mappingType": "MAP",
"outputField": [
{
"docId": "-LO2lU-dzmk816-JEluS",
"fieldType": "STRING",
"jsonType": "io.atlasmap.xml.v2.XmlField",
"name": "value",
"path": "/tns:Patient/tns:id/@value",
"userCreated": false
}
]
}
]
},
"name": "UI.266964"
}
}

View File

@ -0,0 +1,95 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"uri" : "atlas:java?className=twitter4j.Status",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"uri" : "atlas:json:JSONContact",
"dataSourceType" : "TARGET"
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "SEPARATE",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"path" : "/User/name",
"fieldType" : "STRING",
"name" : "Name",
"getMethod" : "getName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"index" : 0,
"path" : "/FirstName",
"fieldType" : "STRING",
"name" : "FirstName"
}, {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"index" : 1,
"path" : "/LastName",
"fieldType" : "STRING",
"name" : "LastName"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"path" : "/Text",
"fieldType" : "STRING",
"name" : "Text",
"getMethod" : "getText"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"path" : "/Description",
"fieldType" : "STRING",
"name" : "Description"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"path" : "/User/screenName",
"fieldType" : "STRING",
"name" : "ScreenName",
"getMethod" : "getScreenName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"path" : "/Title",
"fieldType" : "STRING",
"name" : "Title"
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.v2.ConstantField",
"value" : "const foobar",
"docId" : "DOC.Constants.973849",
"path" : "/foobar",
"fieldType" : "STRING"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.json.v2.JsonField",
"path" : "/Constant",
"fieldType" : "STRING",
"name" : "Constant"
} ]
} ]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "mockMapping"
}
}

View File

@ -0,0 +1,47 @@
{
"order": {
"address": {
"street": "123 any st",
"city": "Austin",
"state": "TX",
"zip": "78626"
},
"contact": {
"firstName": "james",
"lastName": "smith",
"phone": "512-123-1234"
},
"orderId": "123"
},
"primitives": {
"stringPrimitive": "some value",
"booleanPrimitive": true,
"numberPrimitive": 24
},
"addressList": [
{
"street": "123 any st",
"city": "Austin",
"state": "TX",
"zip": "78626"
},
{
"street": "123 any st",
"city": "Austin",
"state": "TX",
"zip": "78626"
},
{
"street": "123 any st",
"city": "Austin",
"state": "TX",
"zip": "78626"
},
{
"street": "123 any st",
"city": "Austin",
"state": "TX",
"zip": "78626"
}
]
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="File" fileName="target/camel-atlasmap.log">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="File" />
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping-java-to-json.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping-json-to-java.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping-xml-to-xml.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmap-mapping.adm" />
<to uri="mock:result" />
</route>
<route>
<from uri="direct:start-n" />
<to uri="atlas:atlasmap-mapping-n.adm" />
<to uri="mock:result-n" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:json-schema-source-to-xml-schema-target.adm" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping-multidocs.json?sourceMapName=CAPTURED_OUT_MESSAGES_MAP&amp;targetMapName=TARGET_MESSAGES_MAP" />
<to uri="mock:result" />
</route>
<route>
<from uri="direct:start-body" />
<to uri="atlas:atlasmapping-multidocs.json" />
<to uri="mock:result-body" />
</route>
<route>
<from uri="direct:start-header" />
<to uri="atlas:atlasmapping-multidocs.json?targetMapMode=MESSAGE_HEADER" />
<to uri="mock:result-body" />
</route>
<route>
<from uri="direct:start-exchange-property" />
<to uri="atlas:atlasmapping-multidocs.json?targetMapMode=EXCHANGE_PROPERTY" />
<to uri="mock:result-body" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:atlasmapping-multins.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,17 @@
[
{
"id" : 1111,
"completed" : 1,
"task" : "task1"
},
{
"id" : 2222,
"completed" : null,
"task" : "task2"
},
{
"id" : 3333,
"completed" : 3,
"task" : "task3"
}
]

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start-old" />
<to uri="atlas:org/apache/camel/component/atlasmap/issue/atlasmapping-2552-old.json" />
<to uri="mock:result-old" />
</route>
<route>
<from uri="direct:start-new" />
<to uri="atlas:org/apache/camel/component/atlasmap/issue/atlasmapping-2552-new.json" />
<to uri="mock:result-new" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<to uri="atlas:org/apache/camel/component/atlasmap/issue/atlasmapping-issue-729.json" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,83 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "JsonSource",
"uri" : "atlas:json:JsonSource",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "JsonTarget",
"uri" : "atlas:json:JsonTarget",
"dataSourceType" : "TARGET"
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"id": "mapping.459765",
"inputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "id",
"path": "/<>/id",
"fieldType": "BIG_INTEGER",
"docId": "JsonSource",
"userCreated": false
} ],
"outputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "id",
"path": "/body<>/id",
"fieldType": "BIG_INTEGER",
"docId": "JsonTarget",
"userCreated": false
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"id": "mapping.352061",
"inputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "completed",
"path": "/<>/completed",
"fieldType": "BIG_INTEGER",
"docId": "JsonSource",
"userCreated": false
} ],
"outputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "completed",
"path": "/body<>/completed",
"fieldType": "BIG_INTEGER",
"docId": "JsonTarget",
"userCreated": false
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"id": "mapping.252216",
"inputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "task",
"path": "/<>/task",
"fieldType": "STRING",
"docId": "JsonSource",
"userCreated": false
} ],
"outputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "completed",
"path": "/body<>/task",
"fieldType": "STRING",
"docId": "JsonTarget",
"userCreated": false
} ]
} ]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "mockMapping"
}
}

View File

@ -0,0 +1,83 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "JsonSource",
"uri" : "atlas:json:JsonSource",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "JsonTarget",
"uri" : "atlas:json:JsonTarget",
"dataSourceType" : "TARGET"
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"id": "mapping.459765",
"inputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "id",
"path": "/<>/id",
"fieldType": "INTEGER",
"docId": "JsonSource",
"userCreated": false
} ],
"outputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "id",
"path": "/body<>/id",
"fieldType": "INTEGER",
"docId": "JsonTarget",
"userCreated": false
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"id": "mapping.352061",
"inputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "completed",
"path": "/<>/completed",
"fieldType": "INTEGER",
"docId": "JsonSource",
"userCreated": false
} ],
"outputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "completed",
"path": "/body<>/completed",
"fieldType": "INTEGER",
"docId": "JsonTarget",
"userCreated": false
} ]
}, {
"jsonType" : "io.atlasmap.v2.Mapping",
"id": "mapping.252216",
"inputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "task",
"path": "/<>/task",
"fieldType": "STRING",
"docId": "JsonSource",
"userCreated": false
} ],
"outputField" : [ {
"jsonType": "io.atlasmap.json.v2.JsonField",
"name": "completed",
"path": "/body<>/task",
"fieldType": "STRING",
"docId": "JsonTarget",
"userCreated": false
} ]
} ]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "mockMapping"
}
}

View File

@ -0,0 +1,65 @@
{
"AtlasMapping" : {
"jsonType" : "io.atlasmap.v2.AtlasMapping",
"dataSource" : [ {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID:JAVA:CONTACT:S",
"uri" : "atlas:java?className=io.atlasmap.java.test.SourceContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID:JSON:CONTACT:S",
"uri" : "atlas:json:JSONContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID:XML:CONTACT:S",
"uri" : "atlas:xml:XMLContact",
"dataSourceType" : "SOURCE"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID:JAVA:CONTACT:T",
"uri" : "atlas:java?className=io.atlasmap.java.test.TargetContact",
"dataSourceType" : "TARGET"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID:JSON:CONTACT:T",
"uri" : "atlas:json:JSONContact",
"dataSourceType" : "TARGET"
}, {
"jsonType" : "io.atlasmap.v2.DataSource",
"id" : "DOCID:XML:CONTACT:T",
"uri" : "atlas:xml:XMLContact",
"dataSourceType" : "TARGET"
} ],
"mappings" : {
"mapping" : [ {
"jsonType" : "io.atlasmap.v2.Mapping",
"mappingType" : "MAP",
"inputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID:JAVA:CONTACT:S",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName",
"getMethod" : "getFirstName"
} ],
"outputField" : [ {
"jsonType" : "io.atlasmap.java.v2.JavaField",
"docId" : "DOCID:JAVA:CONTACT:T",
"path" : "/firstName",
"fieldType" : "STRING",
"name" : "firstName",
"setMethod" : "setFirstName"
} ]
} ]
},
"lookupTables" : {
"lookupTable" : [ ]
},
"properties" : {
"property" : [ ]
},
"name" : "mockMapping"
}
}

View File

@ -0,0 +1,59 @@
<d:SchemaSet xmlns:d="http://atlasmap.io/xml/schemaset/v2" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:schema targetNamespace="http://syndesis.io/v1/swagger-connector-template/request" elementFormDefault="qualified">
<xsd:element name="request">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="body">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Pet" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<d:AdditionalSchemas>
<xsd:schema>
<xsd:element name="Pet">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:decimal" minOccurs="0" />
<xsd:element name="Category">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:decimal" minOccurs="0" />
<xsd:element name="name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="photoUrl" minOccurs="0" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="photoUrl" type="xsd:string" maxOccurs="unbounded" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="tag" minOccurs="0" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Tag" maxOccurs="unbounded" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:decimal" />
<xsd:element name="name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="status" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</d:AdditionalSchemas>
</d:SchemaSet>