Skip to content
Browse files

SWITCHYARD-1953 Add a Dozer transformer to SwitchYard

Thanks to parsek-doo for contributions related to this feature
  • Loading branch information...
1 parent c2775b7 commit 9de1c3a6292736827ecf6fd320377e5cac70d5d7 @igarashitm igarashitm committed with rcernich Feb 23, 2014
Showing with 768 additions and 4 deletions.
  1. +4 −0 transform/pom.xml
  2. +15 −4 transform/src/main/java/org/switchyard/transform/TransformMessages.java
  3. +43 −0 transform/src/main/java/org/switchyard/transform/config/model/DozerFileEntryModel.java
  4. +42 −0 transform/src/main/java/org/switchyard/transform/config/model/DozerMappingFilesModel.java
  5. +37 −0 transform/src/main/java/org/switchyard/transform/config/model/DozerTransformModel.java
  6. +56 −0 transform/src/main/java/org/switchyard/transform/config/model/v1/V1DozerFileEntryModel.java
  7. +76 −0 transform/src/main/java/org/switchyard/transform/config/model/v1/V1DozerMappingFilesModel.java
  8. +74 −0 transform/src/main/java/org/switchyard/transform/config/model/v1/V1DozerTransformModel.java
  9. +10 −0 transform/src/main/java/org/switchyard/transform/config/model/v1/V1TransformMarshaller.java
  10. +63 −0 transform/src/main/java/org/switchyard/transform/dozer/internal/DozerTransformFactory.java
  11. +56 −0 transform/src/main/java/org/switchyard/transform/dozer/internal/DozerTransformer.java
  12. +28 −0 transform/src/main/resources/org/switchyard/transform/config/model/v1/transform_1_1.xsd
  13. +19 −0 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassA.java
  14. +19 −0 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassB.java
  15. +19 −0 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassC.java
  16. +19 −0 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassD.java
  17. +84 −0 transform/src/test/java/org/switchyard/transform/dozer/internal/DozerTransformerTest.java
  18. +14 −0 transform/src/test/resources/org/switchyard/transform/dozer/internal/mapping-A-B.xml
  19. +18 −0 transform/src/test/resources/org/switchyard/transform/dozer/internal/mapping-C-D.xml
  20. +25 −0 transform/src/test/resources/org/switchyard/transform/dozer/internal/sw-config-file.xml
  21. +26 −0 transform/src/test/resources/org/switchyard/transform/dozer/internal/sw-config-multi-file.xml
  22. +21 −0 transform/src/test/resources/org/switchyard/transform/dozer/internal/sw-config-nofile.xml
View
4 transform/pom.xml
@@ -68,6 +68,10 @@
</dependency>
<!-- external dependencies -->
<dependency>
+ <groupId>net.sf.dozer</groupId>
+ <artifactId>dozer</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-runtime</artifactId>
<scope>test</scope>
View
19 transform/src/main/java/org/switchyard/transform/TransformMessages.java
@@ -1,24 +1,21 @@
package org.switchyard.transform;
import java.beans.IntrospectionException;
-
import java.io.IOException;
import javax.xml.bind.JAXBException;
-
+import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonMappingException;
-
import org.jboss.logging.Messages;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageBundle;
-
import org.switchyard.SwitchYardException;
import org.xml.sax.SAXException;
@@ -529,5 +526,19 @@
@Message(id=16858, value = "Invalid @Transformer method '%s' on class '%s'. Must return a result.")
SwitchYardException invalidTransformerMethodResult(String methodName, String className);
+ /**
+ * invalidFromTypeForDozerTransformer method definition.
+ * @param from 'from' QName
+ * @return SwitchYardException
+ */
+ @Message(id=16859, value = "Invalid 'from' type '%s' for Dozer transformer")
+ SwitchYardException invalidFromTypeForDozerTransformer(QName from);
+ /**
+ * invalidToTypeForDozerTransformer method definition.
+ * @param to 'to' QName
+ * @return SwitchYardException
+ */
+ @Message(id=16860, value = "Invalid 'to' type '%s' for Dozer transformer")
+ SwitchYardException invalidToTypeForDozerTransformer(QName to);
}
View
43 transform/src/main/java/org/switchyard/transform/config/model/DozerFileEntryModel.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.config.model;
+
+import org.switchyard.config.model.Model;
+
+/**
+ * A "entry" configuration model.
+ */
+public interface DozerFileEntryModel extends Model {
+
+ /** entry. */
+ public static final String ENTRY = "entry";
+
+ /** file. */
+ public static final String FILE = "file";
+
+ /**
+ * Get file.
+ * @return file
+ */
+ String getFile();
+
+ /**
+ * Set file.
+ * @param file file
+ * @return model representation
+ */
+ DozerFileEntryModel setFile(String file);
+
+}
View
42 transform/src/main/java/org/switchyard/transform/config/model/DozerMappingFilesModel.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.config.model;
+
+import java.util.List;
+
+import org.switchyard.config.model.Model;
+
+/**
+ * A "mappingFiles" configuration model for dozer transformer.
+ */
+public interface DozerMappingFilesModel extends Model {
+
+ /** mapping files. */
+ public static final String MAPPING_FILES = "mappingFiles";
+
+ /**
+ * Get file entries.
+ * @return file entries
+ */
+ List<DozerFileEntryModel> getEntries();
+
+ /**
+ * Set a file entry.
+ * @param entry file entry
+ * @return model representation
+ */
+ DozerMappingFilesModel addEntry(DozerFileEntryModel entry);
+
+}
View
37 transform/src/main/java/org/switchyard/transform/config/model/DozerTransformModel.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.config.model;
+
+import org.switchyard.config.model.transform.TransformModel;
+
+/**
+ * A "transform.dozer" configuration model.
+ */
+public interface DozerTransformModel extends TransformModel {
+
+ /** The "dozer" name. */
+ String DOZER = "dozer";
+
+ /**
+ * @return get a DozerMappingFiles model.
+ */
+ DozerMappingFilesModel getDozerMappingFiles();
+
+ /** Set a DozerMappingFiles model.
+ * @param model MappingFiles Model
+ * @return model representation
+ */
+ DozerTransformModel setDozerMappingFiles(DozerMappingFilesModel model);
+}
View
56 transform/src/main/java/org/switchyard/transform/config/model/v1/V1DozerFileEntryModel.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.config.model.v1;
+
+import javax.xml.namespace.QName;
+
+import org.switchyard.config.Configuration;
+import org.switchyard.config.model.BaseModel;
+import org.switchyard.config.model.Descriptor;
+import org.switchyard.transform.config.model.DozerFileEntryModel;
+
+/**
+ * A version 1 DozerFileEntryModel.
+ */
+public class V1DozerFileEntryModel extends BaseModel implements DozerFileEntryModel {
+
+ /**
+ * Constructs a new V1DozerFileEntryModel.
+ * @param namespace namespace
+ */
+ public V1DozerFileEntryModel(String namespace) {
+ super(new QName(namespace, DozerFileEntryModel.ENTRY));
+ }
+
+ /**
+ * Constructs a new V1DozerFileEntryModel with the specified Configuration and Descriptor.
+ * @param config the Configuration
+ * @param desc the Descriptor
+ */
+ public V1DozerFileEntryModel(Configuration config, Descriptor desc) {
+ super(config, desc);
+ }
+
+ @Override
+ public String getFile() {
+ return getModelAttribute(DozerFileEntryModel.FILE);
+ }
+
+ @Override
+ public DozerFileEntryModel setFile(String file) {
+ setModelAttribute(DozerFileEntryModel.FILE, file);
+ return this;
+ }
+}
View
76 ...form/src/main/java/org/switchyard/transform/config/model/v1/V1DozerMappingFilesModel.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.config.model.v1;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.switchyard.config.Configuration;
+import org.switchyard.config.model.BaseModel;
+import org.switchyard.config.model.Descriptor;
+import org.switchyard.transform.config.model.DozerFileEntryModel;
+import org.switchyard.transform.config.model.DozerMappingFilesModel;
+
+/**
+ * A version 1 DozerMappingFilesModel.
+ */
+public class V1DozerMappingFilesModel extends BaseModel implements DozerMappingFilesModel {
+
+ private List<DozerFileEntryModel> _entries = new ArrayList<DozerFileEntryModel>();
+
+ /**
+ * Constructs a new V1DozerMappingFilesModel.
+ * @param namespace namespace
+ */
+ public V1DozerMappingFilesModel(String namespace) {
+ super(new QName(namespace, DozerMappingFilesModel.MAPPING_FILES));
+ }
+
+ /**
+ * Constructs a new V1DozerMappingFilesModel with the specified Configuration and Descriptor.
+ * @param config the Configuration
+ * @param desc the Descriptor
+ */
+ public V1DozerMappingFilesModel(Configuration config, Descriptor desc) {
+ super(config, desc);
+ for (Configuration entryConfig : config.getChildrenStartsWith(DozerFileEntryModel.ENTRY)) {
+ DozerFileEntryModel entry = (DozerFileEntryModel)readModel(entryConfig);
+ if (entry != null) {
+ _entries.add(entry);
+ }
+ }
+ setModelChildrenOrder(DozerFileEntryModel.ENTRY);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<DozerFileEntryModel> getEntries() {
+ return _entries;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public DozerMappingFilesModel addEntry(DozerFileEntryModel entry) {
+ addChildModel(entry);
+ _entries.add(entry);
+ return this;
+ }
+}
View
74 transform/src/main/java/org/switchyard/transform/config/model/v1/V1DozerTransformModel.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.config.model.v1;
+
+import javax.xml.namespace.QName;
+
+import org.switchyard.config.Configuration;
+import org.switchyard.config.model.Descriptor;
+import org.switchyard.config.model.transform.TransformModel;
+import org.switchyard.config.model.transform.v1.V1BaseTransformModel;
+import org.switchyard.transform.config.model.DozerMappingFilesModel;
+import org.switchyard.transform.config.model.DozerTransformModel;
+import org.switchyard.transform.internal.TransformerFactoryClass;
+import org.switchyard.transform.dozer.internal.DozerTransformFactory;
+
+/**
+ * A version 1 DozerTransformModel.
+ */
+@TransformerFactoryClass(DozerTransformFactory.class)
+public class V1DozerTransformModel extends V1BaseTransformModel implements DozerTransformModel {
+
+ private DozerMappingFilesModel _mappingFilesModel;
+
+ /**
+ * Constructs a new V1DozerTransformModel.
+ * @param namespace namespace
+ */
+ public V1DozerTransformModel(String namespace) {
+ super(new QName(namespace, TransformModel.TRANSFORM + '.' + DOZER));
+ }
+
+ /**
+ * Constructs a new V1DozerTransformModel with the specified Configuration and Descriptor.
+ * @param config the Configuration
+ * @param desc the Descriptor
+ */
+ public V1DozerTransformModel(Configuration config, Descriptor desc) {
+ super(config, desc);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public DozerMappingFilesModel getDozerMappingFiles() {
+ if (_mappingFilesModel == null) {
+ _mappingFilesModel = (DozerMappingFilesModel)getFirstChildModelStartsWith(DozerMappingFilesModel.MAPPING_FILES);
+ }
+ return _mappingFilesModel;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V1DozerTransformModel setDozerMappingFiles(DozerMappingFilesModel model) {
+ setChildModel(model);
+ _mappingFilesModel = model;
+ return this;
+ }
+
+}
View
10 transform/src/main/java/org/switchyard/transform/config/model/v1/V1TransformMarshaller.java
@@ -19,6 +19,9 @@
import org.switchyard.config.model.Descriptor;
import org.switchyard.config.model.Model;
import org.switchyard.config.model.transform.TransformModel;
+import org.switchyard.transform.config.model.DozerFileEntryModel;
+import org.switchyard.transform.config.model.DozerMappingFilesModel;
+import org.switchyard.transform.config.model.DozerTransformModel;
import org.switchyard.transform.config.model.JAXBTransformModel;
import org.switchyard.transform.config.model.JSONTransformModel;
import org.switchyard.transform.config.model.JavaTransformModel;
@@ -37,6 +40,7 @@
private static final String TRANSFORM_JSON = TransformModel.TRANSFORM + "." + JSONTransformModel.JSON;
private static final String TRANSFORM_XSLT = TransformModel.TRANSFORM + "." + XsltTransformModel.XSLT;
private static final String TRANSFORM_JAXB = TransformModel.TRANSFORM + "." + JAXBTransformModel.JAXB;
+ private static final String TRANSFORM_DOZER = TransformModel.TRANSFORM + "." + DozerTransformModel.DOZER;
/**
* Constructs a new V1TransformMarshaller with the specified Descriptor.
@@ -64,6 +68,12 @@ public Model read(Configuration config) {
return new V1XsltTransformModel(config, desc);
} else if (name.equals(TRANSFORM_JAXB)) {
return new V1JAXBTransformModel(config, desc);
+ } else if (name.equals(TRANSFORM_DOZER)) {
+ return new V1DozerTransformModel(config, desc);
+ } else if (name.equals(DozerMappingFilesModel.MAPPING_FILES)) {
+ return new V1DozerMappingFilesModel(config, desc);
+ } else if (name.equals(DozerFileEntryModel.ENTRY)) {
+ return new V1DozerFileEntryModel(config, desc);
}
return null;
View
63 transform/src/main/java/org/switchyard/transform/dozer/internal/DozerTransformFactory.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.dozer.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.switchyard.common.xml.QNameUtil;
+import org.switchyard.transform.TransformMessages;
+import org.switchyard.transform.Transformer;
+import org.switchyard.transform.config.model.DozerFileEntryModel;
+import org.switchyard.transform.config.model.DozerMappingFilesModel;
+import org.switchyard.transform.config.model.DozerTransformModel;
+import org.switchyard.transform.internal.TransformerFactory;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Dozer Transformer factory.
+ */
+public class DozerTransformFactory implements TransformerFactory<DozerTransformModel> {
+
+ /**
+ * Create a {@link Transformer} instance from the supplied {@link DozerTransformModel}.
+ * @param model The model.
+ * @return The Transformer instance.
+ */
+ public Transformer<?,?> newTransformer(DozerTransformModel model) {
+ QName from = model.getFrom();
+ QName to = model.getTo();
+ if (from == null || !QNameUtil.isJavaMessageType(from)) {
+ throw TransformMessages.MESSAGES.invalidFromTypeForDozerTransformer(from);
+ }
+ if (to == null || !QNameUtil.isJavaMessageType(to)) {
+ throw TransformMessages.MESSAGES.invalidToTypeForDozerTransformer(to);
+ }
+
+ List<String> mappingFiles = new ArrayList<String>();
+ DozerMappingFilesModel files = model.getDozerMappingFiles();
+ if (files != null) {
+ for (DozerFileEntryModel entry : files.getEntries()) {
+ String filename = entry.getFile();
+ if (filename != null && !filename.isEmpty()) {
+ mappingFiles.add(filename);
+ }
+ }
+ }
+
+ return new DozerTransformer(from, to, mappingFiles);
+ }
+}
View
56 transform/src/main/java/org/switchyard/transform/dozer/internal/DozerTransformer.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.dozer.internal;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.dozer.DozerBeanMapper;
+import org.switchyard.Message;
+import org.switchyard.common.xml.QNameUtil;
+import org.switchyard.config.model.Scannable;
+import org.switchyard.transform.BaseTransformer;
+
+/**
+ * Dozer {@link org.switchyard.transform.Transformer}.
+ */
+@Scannable(false)
+public class DozerTransformer extends BaseTransformer<Message,Message> {
+
+ private DozerBeanMapper _dozerBeanMapper;
+
+ /**
+ * Constructor.
+ * @param from From type.
+ * @param to To type.
+ * @param config config.
+ */
+ protected DozerTransformer(final QName from, final QName to, List<String> configs) {
+ super(from, to);
+ _dozerBeanMapper = new DozerBeanMapper();
+ if (configs != null && !configs.isEmpty()) {
+ _dozerBeanMapper.setMappingFiles(configs);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Message transform(Message message) {
+ Object result = _dozerBeanMapper.map(message.getContent(), QNameUtil.toJavaMessageType(getTo()));
+ return message.setContent(result);
+ }
+}
View
28 transform/src/main/resources/org/switchyard/transform/config/model/v1/transform_1_1.xsd
@@ -201,4 +201,32 @@
</complexContent>
</complexType>
+ <element name="transform.dozer" type="trfm:DozerTransformType" substitutionGroup="swyd:transform" />
+ <complexType name="DozerTransformType">
+ <annotation>
+ <documentation xml:lang="en">
+ Dozer Transformer Configuration.
+ </documentation>
+ </annotation>
+ <complexContent>
+ <extension base="swyd:TransformType">
+ <sequence>
+ <element name="mappingFiles" type="trfm:dozerMappingFilesType" minOccurs="0" maxOccurs="1"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ <complexType name="dozerMappingFilesType">
+ <annotation>
+ <documentation xml:lang="en">
+ Dozer mapping file configuration.
+ </documentation>
+ </annotation>
+ <sequence>
+ <element name="entry" type="trfm:dozerFileEntryType" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+ <complexType name="dozerFileEntryType">
+ <attribute name="file" type="string" use="required"/>
+ </complexType>
</schema>
View
19 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassA.java
@@ -0,0 +1,19 @@
+package org.switchyard.transform.dozer.internal;
+
+public class ClassA {
+ private String fieldA;
+ private String fieldB;
+
+ public String getFieldA() {
+ return fieldA;
+ }
+ public void setFieldA(String fieldA) {
+ this.fieldA = fieldA;
+ }
+ public String getFieldB() {
+ return fieldB;
+ }
+ public void setFieldB(String fieldB) {
+ this.fieldB = fieldB;
+ }
+}
View
19 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassB.java
@@ -0,0 +1,19 @@
+package org.switchyard.transform.dozer.internal;
+
+public class ClassB {
+ private String fieldA;
+ private String fieldB_mod;
+
+ public String getFieldA() {
+ return fieldA;
+ }
+ public void setFieldA(String fieldA) {
+ this.fieldA = fieldA;
+ }
+ public String getFieldB_mod() {
+ return fieldB_mod;
+ }
+ public void setFieldB_mod(String fieldB_mod) {
+ this.fieldB_mod = fieldB_mod;
+ }
+}
View
19 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassC.java
@@ -0,0 +1,19 @@
+package org.switchyard.transform.dozer.internal;
+
+public class ClassC {
+ private ClassA fieldA;
+ private String fieldC;
+
+ public ClassA getFieldA() {
+ return fieldA;
+ }
+ public void setFieldA(ClassA fieldA) {
+ this.fieldA = fieldA;
+ }
+ public String getFieldC() {
+ return fieldC;
+ }
+ public void setFieldC(String fieldC) {
+ this.fieldC = fieldC;
+ }
+}
View
19 transform/src/test/java/org/switchyard/transform/dozer/internal/ClassD.java
@@ -0,0 +1,19 @@
+package org.switchyard.transform.dozer.internal;
+
+public class ClassD {
+ private ClassB fieldB;
+ private String fieldD;
+
+ public ClassB getFieldB() {
+ return fieldB;
+ }
+ public void setFieldB(ClassB fieldB) {
+ this.fieldB = fieldB;
+ }
+ public String getFieldD() {
+ return fieldD;
+ }
+ public void setFieldD(String fieldD) {
+ this.fieldD = fieldD;
+ }
+}
View
84 transform/src/test/java/org/switchyard/transform/dozer/internal/DozerTransformerTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * 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.switchyard.transform.dozer.internal;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.switchyard.Message;
+import org.switchyard.internal.DefaultMessage;
+import org.switchyard.transform.AbstractTransformerTestCase;
+import org.switchyard.transform.Transformer;
+
+/**
+ * Dozer transformer tests.
+ */
+public class DozerTransformerTest extends AbstractTransformerTestCase {
+
+ @Test
+ public void test_no_mapping_file() throws IOException {
+ Transformer<?,?> transformer = getTransformer("sw-config-nofile.xml");
+ Assert.assertTrue(transformer instanceof DozerTransformer);
+ DozerTransformer dozer = DozerTransformer.class.cast(transformer);
+ ClassA a = new ClassA();
+ a.setFieldA("testa");
+ a.setFieldB("testb");
+ Message msg = dozer.transform(new DefaultMessage().setContent(a));
+ Object result = msg.getContent();
+ Assert.assertTrue(result instanceof ClassB);
+ ClassB b = ClassB.class.cast(result);
+ Assert.assertEquals("testa", b.getFieldA());
+ Assert.assertNull(b.getFieldB_mod());
+ }
+
+ @Test
+ public void test_mapping_file() throws IOException {
+ Transformer<?,?> transformer = getTransformer("sw-config-file.xml");
+ Assert.assertTrue(transformer instanceof DozerTransformer);
+ DozerTransformer dozer = DozerTransformer.class.cast(transformer);
+ ClassA a = new ClassA();
+ a.setFieldA("testa");
+ a.setFieldB("testb");
+ Message msg = dozer.transform(new DefaultMessage().setContent(a));
+ Object result = msg.getContent();
+ Assert.assertTrue(result instanceof ClassB);
+ ClassB b = ClassB.class.cast(result);
+ Assert.assertEquals("testa", b.getFieldA());
+ Assert.assertEquals("testb", b.getFieldB_mod());
+ }
+
+ @Test
+ public void test_multi_mapping_file() throws IOException {
+ Transformer<?,?> transformer = getTransformer("sw-config-multi-file.xml");
+ Assert.assertTrue(transformer instanceof DozerTransformer);
+ DozerTransformer dozer = DozerTransformer.class.cast(transformer);
+ ClassA a = new ClassA();
+ a.setFieldA("testa");
+ a.setFieldB("testb");
+ ClassC c = new ClassC();
+ c.setFieldA(a);
+ c.setFieldC("testc");
+ Message msg = dozer.transform(new DefaultMessage().setContent(c));
+ Object result = msg.getContent();
+ Assert.assertTrue(result instanceof ClassD);
+ ClassD d = ClassD.class.cast(result);
+ ClassB b = d.getFieldB();
+ Assert.assertEquals("testa", b.getFieldA());
+ Assert.assertEquals("testb", b.getFieldB_mod());
+ Assert.assertEquals("testc", d.getFieldD());
+ }
+}
View
14 transform/src/test/resources/org/switchyard/transform/dozer/internal/mapping-A-B.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mappings xmlns="http://dozer.sourceforge.net"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://dozer.sourceforge.net
+ http://dozer.sourceforge.net/schema/beanmapping.xsd">
+ <mapping>
+ <class-a>org.switchyard.transform.dozer.internal.ClassA</class-a>
+ <class-b>org.switchyard.transform.dozer.internal.ClassB</class-b>
+ <field>
+ <a>fieldB</a>
+ <b>fieldB_mod</b>
+ </field>
+ </mapping>
+</mappings>
View
18 transform/src/test/resources/org/switchyard/transform/dozer/internal/mapping-C-D.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mappings xmlns="http://dozer.sourceforge.net"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://dozer.sourceforge.net
+ http://dozer.sourceforge.net/schema/beanmapping.xsd">
+ <mapping>
+ <class-a>org.switchyard.transform.dozer.internal.ClassC</class-a>
+ <class-b>org.switchyard.transform.dozer.internal.ClassD</class-b>
+ <field>
+ <a>fieldA</a>
+ <b>fieldB</b>
+ </field>
+ <field>
+ <a>fieldC</a>
+ <b>fieldD</b>
+ </field>
+ </mapping>
+</mappings>
View
25 transform/src/test/resources/org/switchyard/transform/dozer/internal/sw-config-file.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ - Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ -
+ - 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.
+ -->
+<switchyard xmlns="urn:switchyard-config:switchyard:1.1">
+ <transforms>
+ <transform.dozer xmlns="urn:switchyard-config:transform:1.0"
+ from="java:org.switchyard.transform.dozer.internal.ClassA"
+ to="java:org.switchyard.transform.dozer.internal.ClassB">
+ <mappingFiles>
+ <entry file="org/switchyard/transform/dozer/internal/mapping-A-B.xml"/>
+ </mappingFiles>
+ </transform.dozer>
+ </transforms>
+</switchyard>
View
26 ...sform/src/test/resources/org/switchyard/transform/dozer/internal/sw-config-multi-file.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ - Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ -
+ - 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.
+ -->
+<switchyard xmlns="urn:switchyard-config:switchyard:1.1">
+ <transforms>
+ <transform.dozer xmlns="urn:switchyard-config:transform:1.0"
+ from="java:org.switchyard.transform.dozer.internal.ClassC"
+ to="java:org.switchyard.transform.dozer.internal.ClassD">
+ <mappingFiles>
+ <entry file="org/switchyard/transform/dozer/internal/mapping-A-B.xml"/>
+ <entry file="org/switchyard/transform/dozer/internal/mapping-C-D.xml"/>
+ </mappingFiles>
+ </transform.dozer>
+ </transforms>
+</switchyard>
View
21 transform/src/test/resources/org/switchyard/transform/dozer/internal/sw-config-nofile.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ - Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
+ -
+ - 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.
+ -->
+<switchyard xmlns="urn:switchyard-config:switchyard:1.1">
+ <transforms>
+ <transform.dozer xmlns="urn:switchyard-config:transform:1.0"
+ from="java:org.switchyard.transform.dozer.internal.ClassA"
+ to="java:org.switchyard.transform.dozer.internal.ClassB" />
+ </transforms>
+</switchyard>

0 comments on commit 9de1c3a

Please sign in to comment.
Something went wrong with that request. Please try again.