Skip to content
Browse files

SWITCHYARD-365: targetNamespace is being ignored by NamedModel.getQNa…

…me()
  • Loading branch information...
1 parent 841490c commit b54c2320773828df08e2bea86513e89ff9cfa00b @errantepiphany errantepiphany committed Jul 28, 2011
Showing with 557 additions and 134 deletions.
  1. +0 −1 README.txt
  2. +49 −0 common/src/main/java/org/switchyard/common/lang/Strings.java
  3. +11 −19 config/src/main/java/org/switchyard/config/BaseConfiguration.java
  4. +29 −0 config/src/main/java/org/switchyard/config/Configuration.java
  5. +4 −2 config/src/main/java/org/switchyard/config/Configurations.java
  6. +99 −18 config/src/main/java/org/switchyard/config/DOMConfiguration.java
  7. +6 −0 config/src/main/java/org/switchyard/config/OutputKey.java
  8. +25 −0 config/src/main/java/org/switchyard/config/model/BaseModel.java
  9. +25 −5 config/src/main/java/org/switchyard/config/model/BaseNamedModel.java
  10. +6 −0 config/src/main/java/org/switchyard/config/model/Model.java
  11. +2 −0 config/src/main/java/org/switchyard/config/model/Models.java
  12. +14 −7 config/src/main/java/org/switchyard/config/model/NamedModel.java
  13. +2 −2 config/src/main/java/org/switchyard/config/model/composite/v1/V1ComponentModel.java
  14. +5 −2 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeReferenceModel.java
  15. +5 −2 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeServiceModel.java
  16. +18 −0 config/src/test/java/org/switchyard/config/ConfigurationTests.java
  17. +26 −0 config/src/test/java/org/switchyard/config/model/switchyard/SwitchYardModelTests.java
  18. +1 −1 config/src/test/resources/org/switchyard/config/ConfigurationTests-Namespaces.xml
  19. +35 −0 config/src/test/resources/org/switchyard/config/ConfigurationTests-OrderChildren-Ordered.xml
  20. +35 −0 config/src/test/resources/org/switchyard/config/ConfigurationTests-OrderChildren-Unordered.xml
  21. +4 −3 config/src/test/resources/org/switchyard/config/model/switchyard/SwitchYardModelTests-Complete.xml
  22. +2 −1 config/src/test/resources/org/switchyard/config/model/switchyard/SwitchYardModelTests-Fragment.xml
  23. +3 −2 config/src/test/resources/org/switchyard/config/model/switchyard/SwitchYardModelTests-Incomplete.xml
  24. +2 −3 deploy/base/src/test/java/org/switchyard/deploy/internal/DeploymentTest.java
  25. +14 −0 pom.xml
  26. +39 −25 test/pom.xml
  27. +11 −11 test/src/main/java/org/switchyard/test/Invoker.java
  28. +83 −29 test/src/main/java/org/switchyard/test/SwitchYardTestKit.java
  29. +2 −1 transform/src/main/java/org/switchyard/transform/ootb/xml/AbstractDOMTransformer.java
View
1 README.txt
@@ -19,7 +19,6 @@ the tested version specified above
- 'mvn install checkstyle:checkstyle' to enable checkstyle
- 'mvn javadoc:aggregate' to just run javadoc (see target/site/apidocs/index.html)
-
Eclipse:
--------
- Tested version = JBoss Developer Studio 3.0.0
View
49 common/src/main/java/org/switchyard/common/lang/Strings.java
@@ -113,4 +113,53 @@ public static String trimToNull(String str) {
return set.toArray(new String[set.size()]);
}
+ /**
+ * Concatenates Strings using no delimiter, trimming each to null. Nulls are not concatenated.
+ * @param str the original Strings
+ * @return the concatenated String
+ * @see #trimToNull(String)
+ */
+ public static String concat(String... str) {
+ return concat(null, str);
+ }
+
+ /**
+ * Concatenates Strings using the specified delimiter, trimming each to null. Nulls are not concatenated.
+ * @param delim the delimiter
+ * @param str the original Strings
+ * @return the concatenated String
+ * @see #trimToNull(String)
+ */
+ public static String concat(String delim, String... str) {
+ return concat(delim, true, str);
+ }
+
+ /**
+ * Concatenates Strings using the specified delimiter, possibly trimming each to null. Nulls are not concatenated.
+ * @param delim the delimiter
+ * @param trimToNull should each String be trimmed to null first?
+ * @param str the original Strings
+ * @return the concatenated String
+ * @see #trimToNull(String)
+ */
+ public static String concat(String delim, boolean trimToNull, String... str) {
+ if (str != null && str.length > 0) {
+ StringBuilder sb = new StringBuilder();
+ for (int i=0; i < str.length; i++) {
+ String s = str[i];
+ if (trimToNull) {
+ s = trimToNull(s);
+ }
+ if (s != null) {
+ sb.append(s);
+ if (i < str.length-1) {
+ sb.append(delim);
+ }
+ }
+ }
+ return sb.toString();
+ }
+ return null;
+ }
+
}
View
30 config/src/main/java/org/switchyard/config/BaseConfiguration.java
@@ -45,8 +45,6 @@
protected static final String DEFAULT_XMLNS_PFX = "ns0";
protected static final String NULL_NS_URI = XMLConstants.NULL_NS_URI;
- private String[] _childrenOrder = new String[0];
-
/**
* {@inheritDoc}
*/
@@ -113,41 +111,29 @@
* {@inheritDoc}
*/
@Override
- public String[] getChildrenOrder() {
- int length = _childrenOrder.length;
- String[] copy = new String[length];
- System.arraycopy(_childrenOrder, 0, copy, 0, length);
- return copy;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Configuration setChildrenOrder(String... childrenOrder) {
- _childrenOrder = childrenOrder;
- return this;
+ public Configuration orderChildren() {
+ return orderChildren(true);
}
/**
* {@inheritDoc}
*/
@Override
- public Configuration orderChildren() {
+ public Configuration orderChildren(boolean recursive) {
String[] childrenGroups = getChildrenOrder();
if (childrenGroups != null && childrenGroups.length > 0) {
Map<String,List<Configuration>> config_map = new LinkedHashMap<String,List<Configuration>>();
for (String childrenGroup : childrenGroups) {
List<Configuration> config_list;
- for (Configuration selected_config : getChildren(childrenGroup)) {
+ for (Configuration selected_config : getChildrenMatches(childrenGroup)) {
config_list = config_map.get(childrenGroup);
if (config_list == null) {
config_list = new ArrayList<Configuration>();
config_map.put(childrenGroup, config_list);
}
config_list.add(selected_config);
- removeChildren(childrenGroup);
}
+ removeChildrenMatches(childrenGroup);
}
List<Configuration> config_remainder_list = new ArrayList<Configuration>();
for (Configuration config_remainder : getChildren()) {
@@ -156,10 +142,16 @@ public Configuration orderChildren() {
removeChildren();
for (List<Configuration> config_list : config_map.values()) {
for (Configuration selected_config : config_list) {
+ if (recursive) {
+ selected_config.orderChildren(recursive);
+ }
addChild(selected_config);
}
}
for (Configuration config_remainder : config_remainder_list) {
+ if (recursive) {
+ config_remainder.orderChildren(recursive);
+ }
addChild(config_remainder);
}
}
View
29 config/src/main/java/org/switchyard/config/Configuration.java
@@ -194,6 +194,13 @@
public List<Configuration> getChildrenStartsWith(String name);
/**
+ * Gets all children configs of this config with a name that matches the specified regexp.
+ * @param regexp the regexp to match against
+ * @return all children configs with a matching name
+ */
+ public List<Configuration> getChildrenMatches(String regexp);
+
+ /**
* Gets all children configs of this config with the specified qualified name.
* @param qname the qualified name of the children configs
* @return all children configs with the specified qualified name
@@ -242,6 +249,20 @@
public Configuration removeChildren(String name);
/**
+ * Removes all children configs of this config with a name that starts with the specified prefix.
+ * @param name the prefix to match against
+ * @return this config (useful for chaining)
+ */
+ public Configuration removeChildrenStartsWith(String name);
+
+ /**
+ * Removes all children configs of this config with a name that matches the specified regexp.
+ * @param regexp the regexp to match against
+ * @return this config (useful for chaining)
+ */
+ public Configuration removeChildrenMatches(String regexp);
+
+ /**
* Removes all children configs with the specified qualified name.
* @param qname the qualified name of the child configs to remove
* @return this config (useful for chaining)
@@ -263,11 +284,19 @@
/**
* Orders the child configs based on {@link #getChildrenOrder()}.
+ * Same as {@link #orderChildren(boolean)} with recursive as true.
* @return this config (useful for chaining)
*/
public Configuration orderChildren();
/**
+ * Orders the child configs based on {@link #getChildrenOrder()}.
+ * @param recursive whether the children/grandchildren/great-grandchildren/etc should also be ordered
+ * @return this config (useful for chaining)
+ */
+ public Configuration orderChildren(boolean recursive);
+
+ /**
* Copies this config.
* @return a copy of this config
*/
View
6 config/src/main/java/org/switchyard/config/Configurations.java
@@ -46,6 +46,7 @@ private Configurations() {}
/**
* Merges two configs into a new config.
+ * Note: The act of merging results in fromConfig and toConfig to be normalized and their children ordered!
* @param fromConfig merge from this config, overriding anything in toConfig
* @param toConfig merge into a copy of this config
* @return the newly merged config
@@ -56,6 +57,7 @@ public static Configuration merge(Configuration fromConfig, Configuration toConf
/**
* Merges two configs into a new config.
+ * Note: The act of merging results in fromConfig and toConfig to be normalized and their children ordered!
* @param fromConfig merge from this config, optionally overriding anything in toConfig
* @param toConfig merge into a copy of this config
* @param fromOverridesTo whether fromConfig attributes/values should override those in toConfig
@@ -67,9 +69,10 @@ public static Configuration merge(Configuration fromConfig, Configuration toConf
if (!fromConfigQName.equals(toConfigQName)) {
throw new IllegalArgumentException(fromConfigQName + " != " + toConfigQName);
}
+ fromConfig.normalize().orderChildren();
+ toConfig.normalize().orderChildren();
Configuration mergedConfig = toConfig.copy();
recursiveMerge(fromConfig.copy(), mergedConfig, fromOverridesTo);
- mergedConfig.normalize();
return mergedConfig;
}
@@ -138,7 +141,6 @@ private static void recursiveMerge(Configuration from_config, Configuration merg
for (Configuration merged_config_orphan : merged_config_orphans.values()) {
merged_config.addChild(merged_config_orphan);
}
- merged_config.orderChildren();
}
private static final class Key {
View
117 config/src/main/java/org/switchyard/config/DOMConfiguration.java
@@ -38,6 +38,7 @@
import org.switchyard.common.io.pull.ElementPuller;
import org.switchyard.common.io.pull.StringPuller;
+import org.switchyard.common.lang.Strings;
import org.switchyard.common.xml.XMLHelper;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -53,24 +54,31 @@
*/
public class DOMConfiguration extends BaseConfiguration {
+ private static final String CHILDREN_ORDER_KEY = "childrenOrder";
+ private static final String CHILDREN_ORDER_DELIM = ",";
+
private Element _element;
private Element _parent_element;
private DOMConfiguration _parent_config;
DOMConfiguration(Document document) {
_element = new ElementPuller().pull(document);
+ getParent(); // initializes parent
}
DOMConfiguration(Element element) {
- this(element, true);
+ _element = new ElementPuller().pull(element);
+ getParent(); // initializes parent
}
private DOMConfiguration(Element element, boolean normalize) {
_element = new ElementPuller().pull(element, normalize);
+ getParent(); // initializes parent
}
DOMConfiguration(QName qname) {
_element = new ElementPuller().pull(qname);
+ getParent(); // initializes parent
}
DOMConfiguration(Configuration from) {
@@ -88,6 +96,7 @@ private DOMConfiguration(Element element, boolean normalize) {
}
}
_element = config._element;
+ getParent(); // initializes parent
}
/**
@@ -406,9 +415,8 @@ public boolean hasChildren(QName qname) {
for (int i=0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element)node;
- if (XMLHelper.nameOf(element).equals(name)) {
- configs.add(new DOMConfiguration(element));
+ if (XMLHelper.nameOf(node).equals(name)) {
+ configs.add(new DOMConfiguration((Element)node));
}
}
}
@@ -425,9 +433,26 @@ public boolean hasChildren(QName qname) {
for (int i=0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element)node;
- if (XMLHelper.nameOf(element).startsWith(name)) {
- configs.add(new DOMConfiguration(element));
+ if (XMLHelper.nameOf(node).startsWith(name)) {
+ configs.add(new DOMConfiguration((Element)node));
+ }
+ }
+ }
+ return configs;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Configuration> getChildrenMatches(String regexp) {
+ List<Configuration> configs = new ArrayList<Configuration>();
+ NodeList nodes = _element.getChildNodes();
+ for (int i=0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ if (XMLHelper.nameOf(node).matches(regexp)) {
+ configs.add(new DOMConfiguration((Element)node));
}
}
}
@@ -456,9 +481,8 @@ public Configuration getFirstChild(String name) {
for (int i=0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element)node;
- if (XMLHelper.nameOf(element).equals(name)) {
- return new DOMConfiguration(element);
+ if (XMLHelper.nameOf(node).equals(name)) {
+ return new DOMConfiguration((Element)node);
}
}
}
@@ -474,9 +498,8 @@ public Configuration getFirstChildStartsWith(String name) {
for (int i=0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element)node;
- if (XMLHelper.nameOf(element).startsWith(name)) {
- return new DOMConfiguration(element);
+ if (XMLHelper.nameOf(node).startsWith(name)) {
+ return new DOMConfiguration((Element)node);
}
}
}
@@ -530,9 +553,42 @@ public Configuration removeChildren(String name) {
for (int i=0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element)node;
- if (XMLHelper.nameOf(element).equals(name)) {
- _element.removeChild(element);
+ if (XMLHelper.nameOf(node).equals(name)) {
+ _element.removeChild(node);
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Configuration removeChildrenStartsWith(String name) {
+ NodeList nodes = _element.getChildNodes();
+ for (int i=0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ if (XMLHelper.nameOf(node).startsWith(name)) {
+ _element.removeChild(node);
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Configuration removeChildrenMatches(String regexp) {
+ NodeList nodes = _element.getChildNodes();
+ for (int i=0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ if (XMLHelper.nameOf(node).matches(regexp)) {
+ _element.removeChild(node);
}
}
}
@@ -550,13 +606,33 @@ public Configuration removeChildren(QName qname) {
}
return this;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String[] getChildrenOrder() {
+ String co = (String)_element.getUserData(CHILDREN_ORDER_KEY);
+ return Strings.splitTrimToNullArray(co, CHILDREN_ORDER_DELIM);
+ }
/**
* {@inheritDoc}
*/
@Override
+ public Configuration setChildrenOrder(String... childrenOrder) {
+ String co = Strings.concat(CHILDREN_ORDER_DELIM, childrenOrder);
+ _element.setUserData(CHILDREN_ORDER_KEY, co, null);
+ return this;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Configuration copy() {
- return new DOMConfiguration((Element)_element.cloneNode(true), false);
+ Element clone = (Element)_element.cloneNode(true);
+ DOMConfiguration copy = new DOMConfiguration(clone, false);
+ copy.setChildrenOrder(getChildrenOrder());
+ return copy;
}
/**
@@ -581,12 +657,17 @@ public Source getSource() {
*/
@Override
public void write(Writer writer, OutputKey... keys) throws IOException {
- orderChildren();
try {
TransformerFactory tf = TransformerFactory.newInstance();
String xsl = new StringPuller().pull("/org/switchyard/config/pretty-print.xsl", getClass());
Transformer t = tf.newTransformer(new StreamSource(new StringReader(xsl)));
List<OutputKey> key_list = Arrays.asList(keys);
+ if (!key_list.contains(OutputKey.OMIT_NORMALIZATION)) {
+ normalize();
+ }
+ if (!key_list.contains(OutputKey.OMIT_ORDERING)) {
+ orderChildren();
+ }
if (key_list.contains(OutputKey.OMIT_XML_DECLARATION)) {
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
}
View
6 config/src/main/java/org/switchyard/config/OutputKey.java
@@ -25,6 +25,12 @@
*/
public enum OutputKey {
+ /** The omit-normalization hint. */
+ OMIT_NORMALIZATION,
+
+ /** The omit-ordering hint. */
+ OMIT_ORDERING,
+
/** The omit-xml-declaration hint. */
OMIT_XML_DECLARATION
View
25 config/src/main/java/org/switchyard/config/model/BaseModel.java
@@ -299,6 +299,31 @@ protected final Model setModelChildrenOrder(String... childrenOrder) {
* {@inheritDoc}
*/
@Override
+ public Model orderModelChildren() {
+ primeModelChildren();
+ getModelConfiguration().orderChildren();
+ return this;
+ }
+
+ /**
+ * Recursively iterates over the children, which will force instantiation of a Model for every child Configuration.
+ * @return this model (useful for chaining)
+ */
+ protected final Model primeModelChildren() {
+ primeModelChildren(this);
+ return this;
+ }
+
+ private final void primeModelChildren(Model model) {
+ for (Model child : model.getModelChildren()) {
+ primeModelChildren(child);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void write(OutputStream out, OutputKey... keys) throws IOException {
getModelConfiguration().write(out, keys);
}
View
30 config/src/main/java/org/switchyard/config/model/BaseNamedModel.java
@@ -18,8 +18,11 @@
*/
package org.switchyard.config.model;
+import java.net.URI;
+
import javax.xml.namespace.QName;
+import org.switchyard.common.lang.Strings;
import org.switchyard.common.xml.XMLHelper;
import org.switchyard.config.Configuration;
@@ -63,17 +66,34 @@ public NamedModel setName(String name) {
* {@inheritDoc}
*/
@Override
- public QName getQName() {
- return XMLHelper.createQName(getName());
+ public String getTargetNamespace() {
+ String tns = null;
+ Model model = this;
+ while (model instanceof BaseModel) {
+ tns = Strings.trimToNull(((BaseModel)model).getModelAttribute("targetNamespace"));
+ if (tns != null) {
+ break;
+ }
+ model = model.getModelParent();
+ }
+ return tns;
}
/**
* {@inheritDoc}
*/
@Override
- public NamedModel setQName(QName qname) {
- setName(qname != null ? qname.toString() : null);
- return this;
+ public URI getTargetNamespaceURI() {
+ String tns = getTargetNamespace();
+ return tns != null ? URI.create(tns) : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public QName getQName() {
+ return XMLHelper.createQName(getTargetNamespace(), getName());
}
}
View
6 config/src/main/java/org/switchyard/config/model/Model.java
@@ -58,6 +58,12 @@
public List<Model> getModelChildren();
/**
+ * Orders the children based on what was set via {@link #setModelChildrenOrder(String...)}.
+ * @return this model (useful for chaining)
+ */
+ public Model orderModelChildren();
+
+ /**
* Validates this model against schema(s) defined in this model's descriptor.
* @return the result of the validation
*/
View
2 config/src/main/java/org/switchyard/config/model/Models.java
@@ -32,6 +32,7 @@ private Models() {}
/**
* Merges two models into a new model.
+ * Note: The act of merging results in fromModel and toModel to have their configurations normalized and children ordered!
* @param <M> the type of Model being merged
* @param fromModel merge from this model, overriding anything in toModel
* @param toModel merge into a copy of this model
@@ -43,6 +44,7 @@ private Models() {}
/**
* Merges two models into a new model.
+ * Note: The act of merging results in fromModel and toModel to have their configurations normalized and children ordered!
* @param <M> the type of Model being merged
* @param fromModel merge from this model, optionally overriding anything in toModel
* @param toModel merge into a copy of this model
View
21 config/src/main/java/org/switchyard/config/model/NamedModel.java
@@ -18,6 +18,8 @@
*/
package org.switchyard.config.model;
+import java.net.URI;
+
import javax.xml.namespace.QName;
/**
@@ -41,16 +43,21 @@
public NamedModel setName(String name);
/**
- * Gets the qualified name <b>attribute</b> of this Model (<i>not</i> the qualified name of the wrapped Configuration).
- * @return the qualified name
+ * Gets the targetNamespace of this Model from the wrapped Configuration.
+ * @return the targetNamespace
*/
- public QName getQName();
+ public String getTargetNamespace();
/**
- * Sets the qualified name <b>attribute</b> of this Model (<i>not</i> the qualified name of the wrapped Configuration).
- * @param qname the qualified name
- * @return this NamedModel (useful for chaining)
+ * Gets the targetNamespace URI of this Model from the wrapped Configuration.
+ * @return the targetNamespace URI
*/
- public NamedModel setQName(QName qname);
+ public URI getTargetNamespaceURI();
+
+ /**
+ * Gets the qualified name <b>attribute</b> of this Model (<i>not</i> the qualified name of the wrapped Configuration).
+ * @return the qualified name
+ */
+ public QName getQName();
}
View
4 config/src/main/java/org/switchyard/config/model/composite/v1/V1ComponentModel.java
@@ -50,7 +50,7 @@
*/
public V1ComponentModel() {
super(new QName(CompositeModel.DEFAULT_NAMESPACE, ComponentModel.COMPONENT));
- setModelChildrenOrder(ComponentImplementationModel.IMPLEMENTATION, ComponentServiceModel.SERVICE, ComponentReferenceModel.REFERENCE);
+ setModelChildrenOrder(ComponentImplementationModel.IMPLEMENTATION + ".*", ComponentServiceModel.SERVICE, ComponentReferenceModel.REFERENCE);
}
/**
@@ -72,7 +72,7 @@ public V1ComponentModel(Configuration config, Descriptor desc) {
_references.add(reference);
}
}
- setModelChildrenOrder(ComponentImplementationModel.IMPLEMENTATION, ComponentServiceModel.SERVICE, ComponentReferenceModel.REFERENCE);
+ setModelChildrenOrder(ComponentImplementationModel.IMPLEMENTATION + ".*", ComponentServiceModel.SERVICE, ComponentReferenceModel.REFERENCE);
}
/**
View
7 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeReferenceModel.java
@@ -25,6 +25,7 @@
import javax.xml.namespace.QName;
+import org.apache.log4j.Logger;
import org.switchyard.common.lang.Strings;
import org.switchyard.config.Configuration;
import org.switchyard.config.model.BaseNamedModel;
@@ -43,6 +44,8 @@
*/
public class V1CompositeReferenceModel extends BaseNamedModel implements CompositeReferenceModel {
+ private static final Logger LOGGER = Logger.getLogger(V1CompositeReferenceModel.class);
+
private List<BindingModel> _bindings = new ArrayList<BindingModel>();
private InterfaceModel _interface;
@@ -124,11 +127,11 @@ public ComponentReferenceModel getComponentReference() {
return reference;
}
}
- throw new IllegalArgumentException("missing component reference [" + componentReferenceName + "] for component [" + componentName + "]");
+ LOGGER.warn("missing component reference [" + componentReferenceName + "] for component [" + componentName + "]");
}
}
}
- throw new IllegalArgumentException("missing component reference for " + (missingComponent ? "missing " : "") + "component [" + componentName + "]");
+ LOGGER.warn("missing component reference for " + (missingComponent ? "missing " : "") + "component [" + componentName + "]");
}
}
return null;
View
7 config/src/main/java/org/switchyard/config/model/composite/v1/V1CompositeServiceModel.java
@@ -25,6 +25,7 @@
import javax.xml.namespace.QName;
+import org.apache.log4j.Logger;
import org.switchyard.common.lang.Strings;
import org.switchyard.config.Configuration;
import org.switchyard.config.model.BaseNamedModel;
@@ -43,6 +44,8 @@
*/
public class V1CompositeServiceModel extends BaseNamedModel implements CompositeServiceModel {
+ private static final Logger LOGGER = Logger.getLogger(V1CompositeServiceModel.class);
+
private List<BindingModel> _bindings = new ArrayList<BindingModel>();
private InterfaceModel _interface;
@@ -124,11 +127,11 @@ public ComponentServiceModel getComponentService() {
return service;
}
}
- throw new IllegalArgumentException("missing component service [" + componentServiceName + "] for component [" + componentName + "]");
+ LOGGER.warn("missing component service [" + componentServiceName + "] for component [" + componentName + "]");
}
}
}
- throw new IllegalArgumentException("missing component service for " + (missingComponent ? "missing " : "") + "component [" + componentName + "]");
+ LOGGER.warn("missing component service for " + (missingComponent ? "missing " : "") + "component [" + componentName + "]");
}
}
return null;
View
18 config/src/test/java/org/switchyard/config/ConfigurationTests.java
@@ -44,6 +44,8 @@
private static final String FROM_OVERRIDES_TO_XML = "/org/switchyard/config/ConfigurationTests-FromOverridesTo.xml";
private static final String FROM_DOESNT_OVERRIDE_TO_XML = "/org/switchyard/config/ConfigurationTests-FromDoesntOverrideTo.xml";
private static final String NAMESPACES_XML = "/org/switchyard/config/ConfigurationTests-Namespaces.xml";
+ private static final String ORDER_CHILDREN_UNORDERED_XML = "/org/switchyard/config/ConfigurationTests-OrderChildren-Unordered.xml";
+ private static final String ORDER_CHILDREN_ORDERED_XML = "/org/switchyard/config/ConfigurationTests-OrderChildren-Ordered.xml";
private ConfigurationPuller _cfg_puller;
private StringPuller _str_puller;
@@ -123,6 +125,7 @@ public void testNamespaceCollections() throws Exception {
@Test
public void testNamespacesValues() throws Exception {
Configuration config = _cfg_puller.pull(NAMESPACES_XML, getClass());
+ Assert.assertEquals("urn:test", config.getAttribute("targetNamespace"));
Assert.assertEquals("http://a.org/a.xsd", config.getQName().getNamespaceURI());
Assert.assertEquals("bar", config.getAttribute("foo"));
Assert.assertEquals("stuff", config.getFirstChild("two").getValue());
@@ -134,4 +137,19 @@ public void testNamespacesValues() throws Exception {
Assert.assertEquals("robot", config.getChildren().get(1).getAttribute("toy"));
}
+ @Test
+ public void testOrderChildren() throws Exception {
+ Configuration root = _cfg_puller.pull(ORDER_CHILDREN_UNORDERED_XML, getClass());
+ root.setChildrenOrder("one", "two", "three", "four");
+ Configuration one = root.getFirstChild("one");
+ one.setChildrenOrder("a", "b", "c");
+ Configuration three = root.getFirstChild("three");
+ three.setChildrenOrder("c", "b", "a");
+ String actual_xml = root.toString(); // toString() orders the children by default (but can be overridden by OutputKey.OMIT_ORDERING)
+ String expected_xml = _str_puller.pull(ORDER_CHILDREN_ORDERED_XML, getClass());
+ XMLUnit.setIgnoreWhitespace(true);
+ Diff diff = XMLUnit.compareXML(expected_xml, actual_xml);
+ Assert.assertTrue(diff.toString(), diff.identical());
+ }
+
}
View
26 config/src/test/java/org/switchyard/config/model/switchyard/SwitchYardModelTests.java
@@ -33,6 +33,9 @@
import org.switchyard.config.model.Model;
import org.switchyard.config.model.ModelPuller;
import org.switchyard.config.model.Models;
+import org.switchyard.config.model.composite.ComponentModel;
+import org.switchyard.config.model.composite.ComponentReferenceModel;
+import org.switchyard.config.model.composite.ComponentServiceModel;
import org.switchyard.config.model.composite.CompositeModel;
import org.switchyard.config.model.composite.CompositeServiceModel;
import org.switchyard.config.model.composite.test.soap.PortModel;
@@ -136,4 +139,27 @@ public void testValidation() throws Exception {
Assert.assertTrue(switchyard.isModelValid());
}
+ @Test
+ public void testTargetNamespace() throws Exception {
+ SwitchYardModel switchyard = _puller.pull(COMPLETE_XML, getClass());
+ Assert.assertEquals("m1app", switchyard.getName());
+ Assert.assertEquals(new QName("m1app"), switchyard.getQName());
+ final String tns = "urn:m1app:example:1.0";
+ CompositeModel composite = switchyard.getComposite();
+ Assert.assertEquals("m1app", composite.getName());
+ Assert.assertEquals(new QName(tns, "m1app"), composite.getQName());
+ CompositeServiceModel compositeService = composite.getServices().iterator().next();
+ Assert.assertEquals("M1AppService", compositeService.getName());
+ Assert.assertEquals(new QName(tns, "M1AppService"), compositeService.getQName());
+ ComponentModel component = composite.getComponents().iterator().next();
+ Assert.assertEquals("SimpleService", component.getName());
+ Assert.assertEquals(new QName(tns, "SimpleService"), component.getQName());
+ ComponentServiceModel componentService = component.getServices().iterator().next();
+ Assert.assertEquals("SimpleService", componentService.getName());
+ Assert.assertEquals(new QName(tns, "SimpleService"), componentService.getQName());
+ ComponentReferenceModel componentReference = component.getReferences().iterator().next();
+ Assert.assertEquals("anotherService", componentReference.getName());
+ Assert.assertEquals(new QName(tns, "anotherService"), componentReference.getQName());
+ }
+
}
View
2 config/src/test/resources/org/switchyard/config/ConfigurationTests-Namespaces.xml
@@ -17,7 +17,7 @@ v.2.1 along with this distribution; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
-->
-<one xmlns='http://a.org/a.xsd' xmlns:b='http://b.org/b.xsd' xmlns:c='http://c.org/c.xsd' foo='bar'>
+<one xmlns='http://a.org/a.xsd' xmlns:b='http://b.org/b.xsd' xmlns:c='http://c.org/c.xsd' foo='bar' targetNamespace='urn:test'>
<b:two baz='whiz' c:boy='girl'>stuff</b:two>
<three toy='robot' b:man='woman'>junk</three>
</one>
View
35 config/src/test/resources/org/switchyard/config/ConfigurationTests-OrderChildren-Ordered.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+as indicated by the @authors tag. All rights reserved.
+See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This copyrighted material is made available to anyone wishing to use,
+modify, copy, or redistribute it subject to the terms and conditions
+of the GNU Lesser General Public License, v. 2.1.
+This program is distributed in the hope that it will be useful, but WITHOUT A
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+You should have received a copy of the GNU Lesser General Public License,
+v.2.1 along with this distribution; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+MA 02110-1301, USA.
+-->
+<root>
+ <one>
+ <a>a</a>
+ <b>b</b>
+ <c>c</c>
+ </one>
+ <two>2</two>
+ <three>
+ <c>c</c>
+ <b>b</b>
+ <a>a</a>
+ </three>
+ <four>4</four>
+ <foo>foo</foo>
+ <bar>bar</bar>
+</root>
View
35 ...g/src/test/resources/org/switchyard/config/ConfigurationTests-OrderChildren-Unordered.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+as indicated by the @authors tag. All rights reserved.
+See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This copyrighted material is made available to anyone wishing to use,
+modify, copy, or redistribute it subject to the terms and conditions
+of the GNU Lesser General Public License, v. 2.1.
+This program is distributed in the hope that it will be useful, but WITHOUT A
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+You should have received a copy of the GNU Lesser General Public License,
+v.2.1 along with this distribution; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+MA 02110-1301, USA.
+-->
+<root>
+ <two>2</two>
+ <one>
+ <b>b</b>
+ <a>a</a>
+ <c>c</c>
+ </one>
+ <foo>foo</foo>
+ <four>4</four>
+ <three>
+ <b>b</b>
+ <a>a</a>
+ <c>c</c>
+ </three>
+ <bar>bar</bar>
+</root>
View
7 ...c/test/resources/org/switchyard/config/model/switchyard/SwitchYardModelTests-Complete.xml
@@ -22,7 +22,8 @@ MA 02110-1301, USA.
xmlns:soap="urn:switchyard-config:test-soap:1.0"
xmlns:bean="urn:switchyard-config:test-bean:1.0"
xmlns:java="urn:switchyard-config:test-java:1.0"
- xmlns:smooks="urn:switchyard-config:test-smooks:1.0">
+ xmlns:smooks="urn:switchyard-config:test-smooks:1.0"
+ name="m1app">
<sca:composite name="m1app" targetNamespace="urn:m1app:example:1.0">
<sca:service name="M1AppService" promote="SimpleService">
<soap:binding.soap>
@@ -57,8 +58,8 @@ MA 02110-1301, USA.
<java:transform.java from="msgD" to="msgA" class="org.examples.transform.DtoATransform"/>
</transforms>
<properties>
- <property name="foo" value="bar"/>
- <property name="tuna" value="fish"/>
+ <property name="foo" value="bar"/>
+ <property name="tuna" value="fish"/>
</properties>
<handlers>
<handler name="handler1" class="org.switchyard.handlers.TestHandler"/>
View
3 ...c/test/resources/org/switchyard/config/model/switchyard/SwitchYardModelTests-Fragment.xml
@@ -19,7 +19,8 @@ MA 02110-1301, USA.
-->
<switchyard xmlns="urn:switchyard-config:switchyard:1.0"
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
- xmlns:soap="urn:switchyard-config:test-soap:1.0">
+ xmlns:soap="urn:switchyard-config:test-soap:1.0"
+ name="m1app">
<sca:composite name="m1app" targetNamespace="urn:m1app:example:1.0">
<sca:service name="M1AppService" promote="SimpleService">
<soap:binding.soap>
View
5 ...test/resources/org/switchyard/config/model/switchyard/SwitchYardModelTests-Incomplete.xml
@@ -21,8 +21,9 @@ MA 02110-1301, USA.
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:bean="urn:switchyard-config:test-bean:1.0"
xmlns:java="urn:switchyard-config:test-java:1.0"
- xmlns:smooks="urn:switchyard-config:test-smooks:1.0">
- <sca:composite name="m1app" targetNamespace="urn:m1app:example:1.0">
+ xmlns:smooks="urn:switchyard-config:test-smooks:1.0"
+ name="m1app">
+ <sca:composite name="m1app" targetNamespace="urn:m1app:example:1.0">
<sca:component name="SimpleService">
<bean:implementation.bean class="org.switchyard.example.m1app.SimpleBean"/>
<sca:service name="SimpleService">
View
5 deploy/base/src/test/java/org/switchyard/deploy/internal/DeploymentTest.java
@@ -107,8 +107,7 @@ public void interfaceWSDL() throws Exception {
deployment.init(ServiceDomainManager.createDomain());
deployment.start();
- // FIXME: new QName("urn:switchyard-interface-wsdl", "HelloService") does not work
- ServiceReference service = deployment.getDomain().getService(new QName("HelloService"));
+ ServiceReference service = deployment.getDomain().getService(new QName("urn:switchyard-interface-wsdl", "HelloService"));
Assert.assertNotNull(service);
ServiceInterface iface = service.getInterface();
Assert.assertEquals(WSDLService.TYPE, iface.getType());
@@ -135,7 +134,7 @@ public void nonExistentActivatorThrowsException() throws Exception {
deployment.start();
} catch (SwitchYardException sye) {
exception = sye;
- System.out.println(sye.toString());
+ System.err.println(sye.toString());
} finally {
if (swConfigStream != null) {
swConfigStream.close();
View
14 pom.xml
@@ -159,6 +159,20 @@
<groupId>org.milyn</groupId>
<artifactId>milyn-smooks-all</artifactId>
<version>${version.milyn}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xmlParserAPIs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
View
64 test/pom.xml
@@ -22,25 +22,25 @@
-->
<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">
+ 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>org.switchyard</groupId>
- <artifactId>switchyard-core-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>switchyard-test</artifactId>
-
- <packaging>jar</packaging>
- <name>SwitchYard: Test Utilities</name>
- <version>${project.parent.version}</version>
- <description>Test Utility classes.</description>
- <url>http://switchyard.org/</url>
+ <parent>
+ <groupId>org.switchyard</groupId>
+ <artifactId>switchyard-core-parent</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>switchyard-test</artifactId>
+
+ <packaging>jar</packaging>
+ <name>SwitchYard: Test Utilities</name>
+ <version>${project.parent.version}</version>
+ <description>Test Utility classes.</description>
+ <url>http://switchyard.org/</url>
<properties>
<weld.version>1.1.0.Final</weld.version>
@@ -50,8 +50,8 @@
<shrinkwrap.version>1.0.0-alpha-12</shrinkwrap.version>
</properties>
- <dependencies>
- <!-- internal dependencies -->
+ <dependencies>
+ <!-- internal dependencies -->
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-runtime</artifactId>
@@ -60,8 +60,8 @@
<groupId>org.switchyard</groupId>
<artifactId>switchyard-deploy</artifactId>
</dependency>
- <!-- N/A -->
- <!-- external dependencies -->
+ <!-- N/A -->
+ <!-- external dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@@ -88,10 +88,10 @@
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.6.1</version>
- <scope>runtime</scope>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.6.1</version>
+ <scope>runtime</scope>
</dependency>
<dependency>
@@ -128,6 +128,20 @@
<groupId>org.jbpm</groupId>
<artifactId>jbpm-human-task</artifactId>
<version>${jbpm.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xmlParserAPIs</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
View
22 test/src/main/java/org/switchyard/test/Invoker.java
@@ -33,6 +33,7 @@
import org.switchyard.Message;
import org.switchyard.ServiceDomain;
import org.switchyard.ServiceReference;
+import org.switchyard.common.xml.XMLHelper;
import org.switchyard.metadata.BaseExchangeContract;
import org.switchyard.metadata.ExchangeContract;
import org.switchyard.metadata.InOnlyOperation;
@@ -64,16 +65,7 @@
* @param serviceName The Service name.
*/
protected Invoker(ServiceDomain domain, String serviceName) {
- _domain = domain;
-
- String[] serviceNameTokens = serviceName.split("\\.");
-
- if (serviceNameTokens.length == 1) {
- _serviceName = QName.valueOf(serviceName);
- } else if (serviceNameTokens.length == 2) {
- _serviceName = QName.valueOf(serviceNameTokens[0]);
- _operationName = serviceNameTokens[1];
- }
+ this(domain, XMLHelper.createQName(domain.getName().getNamespaceURI(), serviceName));
}
/**
@@ -83,7 +75,15 @@ protected Invoker(ServiceDomain domain, String serviceName) {
*/
public Invoker(ServiceDomain domain, QName serviceName) {
_domain = domain;
- _serviceName = serviceName;
+
+ String[] serviceNameTokens = serviceName.getLocalPart().split("\\.");
+
+ if (serviceNameTokens.length == 1) {
+ _serviceName = serviceName;
+ } else if (serviceNameTokens.length == 2) {
+ _serviceName = XMLHelper.createQName(serviceName.getNamespaceURI(), serviceNameTokens[0]);
+ _operationName = serviceNameTokens[1];
+ }
}
/**
View
112 test/src/main/java/org/switchyard/test/SwitchYardTestKit.java
@@ -16,9 +16,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
-
package org.switchyard.test;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.apache.log4j.Logger;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
@@ -27,6 +42,7 @@
import org.switchyard.ServiceDomain;
import org.switchyard.common.type.Classes;
import org.switchyard.common.type.classpath.ClasspathScanner;
+import org.switchyard.common.xml.XMLHelper;
import org.switchyard.config.model.MergeScanner;
import org.switchyard.config.model.Model;
import org.switchyard.config.model.ModelPuller;
@@ -35,6 +51,8 @@
import org.switchyard.config.model.Scanner;
import org.switchyard.config.model.ScannerInput;
import org.switchyard.config.model.ScannerOutput;
+import org.switchyard.config.model.Validation;
+import org.switchyard.config.model.composite.CompositeModel;
import org.switchyard.config.model.switchyard.SwitchYardModel;
import org.switchyard.config.model.switchyard.v1.V1SwitchYardModel;
import org.switchyard.config.model.transform.TransformModel;
@@ -51,21 +69,6 @@
import org.switchyard.transform.TransformerUtil;
import org.w3c.dom.Document;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
@@ -231,6 +234,22 @@ public ServiceDomain getServiceDomain() {
}
/**
+ * Creates a QName given this test kit's config model's targetNamespace + the specified localPart.
+ * @param localPart the specified localPart
+ * @return the QName
+ */
+ public QName createQName(String localPart) {
+ final String tns;
+ if (_configModel != null) {
+ CompositeModel composite = _configModel.getComposite();
+ tns = composite != null ? composite.getTargetNamespace() : _configModel.getTargetNamespace();
+ } else {
+ tns = null;
+ }
+ return XMLHelper.createQName(tns, localPart);
+ }
+
+ /**
* Register an IN_OUT Service.
* <p/>
* Registers a {@link MockHandler} as the service handler.
@@ -240,7 +259,7 @@ public ServiceDomain getServiceDomain() {
*/
public MockHandler registerInOutService(String serviceName) {
MockHandler handler = new MockHandler();
- getServiceDomain().registerService(QName.valueOf(serviceName), handler, new InOutService());
+ getServiceDomain().registerService(createQName(serviceName), handler, new InOutService());
return handler;
}
@@ -251,7 +270,7 @@ public MockHandler registerInOutService(String serviceName) {
* @param serviceHandler The service handler.
*/
public void registerInOutService(String serviceName, ExchangeHandler serviceHandler) {
- getServiceDomain().registerService(QName.valueOf(serviceName), serviceHandler, new InOutService());
+ getServiceDomain().registerService(createQName(serviceName), serviceHandler, new InOutService());
}
/**
@@ -262,7 +281,7 @@ public void registerInOutService(String serviceName, ExchangeHandler serviceHand
* @param metadata Service interface.
*/
public void registerInOutService(String serviceName, ExchangeHandler serviceHandler, ServiceInterface metadata) {
- getServiceDomain().registerService(QName.valueOf(serviceName), serviceHandler, metadata);
+ getServiceDomain().registerService(createQName(serviceName), serviceHandler, metadata);
}
/**
@@ -275,7 +294,7 @@ public void registerInOutService(String serviceName, ExchangeHandler serviceHand
*/
public MockHandler registerInOnlyService(String serviceName) {
MockHandler handler = new MockHandler();
- getServiceDomain().registerService(QName.valueOf(serviceName), handler, new InOnlyService());
+ getServiceDomain().registerService(createQName(serviceName), handler, new InOnlyService());
return handler;
}
@@ -286,7 +305,7 @@ public MockHandler registerInOnlyService(String serviceName) {
* @param serviceHandler The service handler.
*/
public void registerInOnlyService(String serviceName, ExchangeHandler serviceHandler) {
- getServiceDomain().registerService(QName.valueOf(serviceName), serviceHandler, new InOnlyService());
+ getServiceDomain().registerService(createQName(serviceName), serviceHandler, new InOnlyService());
}
/**
@@ -313,7 +332,7 @@ public Invoker newInvoker(QName serviceName) {
* @return The invoker instance.
*/
public Invoker newInvoker(String serviceName) {
- return new Invoker(getServiceDomain(), serviceName);
+ return newInvoker(createQName(serviceName));
}
/**
@@ -473,22 +492,51 @@ public Document readResourceDocument(String path) {
* @return The SwitchYard config model.
*/
public SwitchYardModel loadSwitchYardModel(InputStream configModel) {
- return loadConfigModel(configModel, SwitchYardModel.class);
+ return loadSwitchYardModel(configModel, true);
}
/**
* Load the SwitchYard configuration model specified by the configModel stream.
+ * @param configModel The config model stream.
+ * @param validate Validate the model?
+ * @return The SwitchYard config model.
+ */
+ public SwitchYardModel loadSwitchYardModel(InputStream configModel, boolean validate) {
+ return loadConfigModel(configModel, SwitchYardModel.class, validate);
+ }
+
+ /**
+ * Load the configuration model specified by the configModel stream.
* @param <M> Model type.
* @param configModel The config model stream.
* @param modelType Model type.
- * @return The SwitchYard config model.
+ * @return The config model.
*/
public <M extends Model> M loadConfigModel(InputStream configModel, Class<M> modelType) {
+ return loadConfigModel(configModel, modelType, true);
+ }
+
+ /**
+ * Load the SwitchYard configuration model specified by the configModel stream.
+ * @param <M> Model type.
+ * @param configModel The config model stream.
+ * @param modelType Model type.
+ * @param validate Validate the model?
+ * @return The SwitchYard config model.
+ */
+ public <M extends Model> M loadConfigModel(InputStream configModel, Class<M> modelType, boolean validate) {
if (configModel == null) {
throw new IllegalArgumentException("null 'configModel' arg.");
}
try {
- return new ModelPuller<M>().pull(configModel);
+ M pulledModel = new ModelPuller<M>().pull(configModel);
+ if (validate) {
+ Validation v = pulledModel.validateModel();
+ if (!v.isValid()) {
+ Assert.fail("Error validating " + modelType.getSimpleName() + ": " + v.getMessage());
+ }
+ }
+ return pulledModel;
} catch (IOException e) {
Assert.fail("Unexpected error building " + modelType.getSimpleName() + ": " + e.getMessage());
} finally {
@@ -582,21 +630,27 @@ private void createMixInInstances() {
private SwitchYardModel createSwitchYardModel(InputStream configModel, List<Scanner<V1SwitchYardModel>> scanners) {
Assert.assertNotNull("Test 'configModel' is null.", configModel);
+ final SwitchYardModel returnModel;
try {
- SwitchYardModel model = loadSwitchYardModel(configModel);
+ SwitchYardModel model = loadSwitchYardModel(configModel, false);
ClassLoader classLoader = _testInstance.getClass().getClassLoader();
if (scanners != null && !scanners.isEmpty() && classLoader instanceof URLClassLoader) {
MergeScanner<V1SwitchYardModel> merge_scanner = new MergeScanner<V1SwitchYardModel>(V1SwitchYardModel.class, true, scanners);
List<URL> scanURLs = getScanURLs((URLClassLoader)classLoader);
- ScannerInput<V1SwitchYardModel> scanner_input = new ScannerInput<V1SwitchYardModel>().setName("").setURLs(scanURLs);
+ ScannerInput<V1SwitchYardModel> scanner_input = new ScannerInput<V1SwitchYardModel>().setName(model.getName()).setURLs(scanURLs);
V1SwitchYardModel scannedModel = merge_scanner.scan(scanner_input).getModel();
- return Models.merge(scannedModel, model, false);
+ returnModel = Models.merge(scannedModel, model, false);
} else {
- return model;
+ returnModel = model;
+ }
+ Validation v = returnModel.validateModel();
+ if (!v.isValid()) {
+ Assert.fail("Error validating " + SwitchYardModel.class.getSimpleName() + ": " + v.getMessage());
}
+ return returnModel;
} catch (java.io.IOException ioEx) {
throw new SwitchYardException("Failed to read switchyard config.", ioEx);
}
View
3 transform/src/main/java/org/switchyard/transform/ootb/xml/AbstractDOMTransformer.java
@@ -52,6 +52,7 @@
*/
public abstract class AbstractDOMTransformer<F, T> extends BaseTransformer<F, T> {
+ private static final Logger LOGGER = Logger.getLogger(AbstractDOMTransformer.class);
private Logger _log;
private static DocumentBuilderFactory _docBuilderFactory;
@@ -119,7 +120,7 @@ public static Document parse(InputSource source) {
}
}
} catch (IOException e) {
- System.out.println("Exception while closing DOM InputSource: " + e.getMessage());
+ LOGGER.error("Exception while closing DOM InputSource: " + e.getMessage());
}
}
}

0 comments on commit b54c232

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