Author: DartPeng
Date: 2009-01-14 21:16:32 -0500 (Wed, 14 Jan 2009)
New Revision: 13048
Added:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/SelectorTester.java
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/JavaSelectorTestCase.java
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java2java/NormalJ2JConfigFileAnalyzerTester.java
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/AbstractXML2JavaTestCase.java
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/order/ClassicX2JTestCase.java
Log:
JBIDE-3479
Add a new test case for testing local the Javabean with "selector"
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/JavaSelectorTestCase.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/JavaSelectorTestCase.java 2009-01-14
21:45:43 UTC (rev 13047)
+++
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/JavaSelectorTestCase.java 2009-01-15
02:16:32 UTC (rev 13048)
@@ -6,9 +6,10 @@
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer;
import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
import org.jboss.tools.smooks.javabean.model.JavaBeanModelFactory;
+import org.jboss.tools.smooks.ui.IXMLStructuredObject;
+import org.jboss.tools.smooks.utils.UIUtils;
/**
* @author Dart
@@ -23,19 +24,16 @@
JavaBeanModel model = JavaBeanModelFactory
.getJavaBeanModelWithLazyLoad(A.class);
- JavaBeanModel aModel = JavaBeanAnalyzer.localJavaBeanModelWithSelector(
- "a", model);
+ IXMLStructuredObject aModel = UIUtils.localXMLNodeWithPath("a", model);
Assert.assertNotNull(aModel);
- Assert.assertEquals(aModel.getBeanClass(), A.class);
+ Assert.assertEquals(((JavaBeanModel) aModel).getBeanClass(), A.class);
- JavaBeanModel nullModel = JavaBeanAnalyzer
- .localJavaBeanModelWithSelectorWithoutException("a" + sperator
- + "null", model);
+ IXMLStructuredObject nullModel = UIUtils.localXMLNodeWithPath("a" + sperator
+ + "null", model, null, false);
Assert.assertNull(nullModel);
// avoid died loop
- nullModel = JavaBeanAnalyzer
- .localJavaBeanModelWithSelectorWithoutException("null", model);
+ nullModel = UIUtils.localXMLNodeWithPath("null", model, null, false);
Assert.assertNull(nullModel);
}
}
Added:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/SelectorTester.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/SelectorTester.java
(rev 0)
+++
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/SelectorTester.java 2009-01-15
02:16:32 UTC (rev 13048)
@@ -0,0 +1,85 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.test.java;
+
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.emf.ecore.xml.type.AnyType;
+import org.jboss.tools.smooks.javabean.analyzer.JavaBeanAnalyzer;
+import org.jboss.tools.smooks.model.AbstractResourceConfig;
+import org.jboss.tools.smooks.model.ResourceConfigType;
+import org.jboss.tools.smooks.model.ResourceType;
+import org.jboss.tools.smooks.model.SmooksResourceListType;
+import org.jboss.tools.smooks.model.util.SmooksModelUtils;
+import org.jboss.tools.smooks.ui.IXMLStructuredObject;
+import org.jboss.tools.smooks.utils.UIUtils;
+
+/**
+ * @author Dart
+ *
+ */
+public class SelectorTester {
+
+ /**
+ *
+ * @param list
+ * @param source
+ * @param target
+ */
+ public void validSmooksConfigFile(SmooksResourceListType list,
+ IXMLStructuredObject source, IXMLStructuredObject target) {
+ List<AbstractResourceConfig> resourceList = list
+ .getAbstractResourceConfig();
+ for (Iterator<AbstractResourceConfig> iterator = resourceList
+ .iterator(); iterator.hasNext();) {
+ AbstractResourceConfig abstractResourceConfig = (AbstractResourceConfig) iterator
+ .next();
+ if (abstractResourceConfig instanceof ResourceConfigType) {
+ ResourceConfigType config = (ResourceConfigType) abstractResourceConfig;
+ ResourceType resource = config.getResource();
+ if (resource != null) {
+ if (JavaBeanAnalyzer.BEANPOPULATOR.equals(resource
+ .getStringValue())) {
+ IXMLStructuredObject model = UIUtils
+ .localXMLNodeWithPath(config.getSelector(),
+ source);
+ Assert.assertNotNull(model);
+
+ List bindingList = SmooksModelUtils
+ .getBindingListFromResourceConfigType(config);
+
+ for (Iterator iterator2 = bindingList.iterator(); iterator2
+ .hasNext();) {
+ AnyType binding = (AnyType) iterator2.next();
+ String property = SmooksModelUtils
+ .getAttributeValueFromAnyType(binding,
+ SmooksModelUtils.ATTRIBUTE_PROPERTY);
+ if (property != null) {
+ property = property.trim();
+ }
+ String selector = SmooksModelUtils
+ .getAttributeValueFromAnyType(binding,
+ SmooksModelUtils.ATTRIBUTE_SELECTOR);
+ if (selector != null) {
+ selector = selector.trim();
+ }
+
+ if (selector.startsWith("${")) {
+ continue;
+ }
+
+ IXMLStructuredObject childModel = UIUtils
+ .localXMLNodeWithPath(config.getSelector(),
+ source);
+ Assert.assertNotNull(childModel);
+ }
+ }
+ }
+ }
+ }
+ }
+}
Property changes on:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java/SelectorTester.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java2java/NormalJ2JConfigFileAnalyzerTester.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java2java/NormalJ2JConfigFileAnalyzerTester.java 2009-01-14
21:45:43 UTC (rev 13047)
+++
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/java2java/NormalJ2JConfigFileAnalyzerTester.java 2009-01-15
02:16:32 UTC (rev 13048)
@@ -30,6 +30,7 @@
import org.jboss.tools.smooks.javabean.model.JavaBeanModel;
import org.jboss.tools.smooks.model.DocumentRoot;
import org.jboss.tools.smooks.model.SmooksResourceListType;
+import org.jboss.tools.smooks.test.java.SelectorTester;
/**
* @author Dart Peng Date : 2008-9-1
@@ -51,6 +52,11 @@
listType, null, null);
Object target = targetModelAnalyzer.buildTargetInputObjects(graph,
listType, null, null);
+
+ SelectorTester tester = new SelectorTester();
+ tester.validSmooksConfigFile(listType, (JavaBeanModel) ((List) source)
+ .get(0), (JavaBeanModel) ((List) target).get(0));
+
MappingResourceConfigList configList = connectionsAnalyzer
.analyzeMappingSmooksModel(listType, source, target);
List connections = configList.getMappingModelList();
@@ -67,18 +73,23 @@
MappingModel connectionModels = (MappingModel) iterator.next();
Assert.assertNotNull(connectionModels.getSource());
Assert.assertNotNull(connectionModels.getTarget());
- JavaBeanModel sourceModel = (JavaBeanModel)connectionModels.getSource();
- JavaBeanModel targetModel = (JavaBeanModel)connectionModels.getSource();
- if(targetModel.isPrimitive()){
+ JavaBeanModel sourceModel = (JavaBeanModel) connectionModels
+ .getSource();
+ JavaBeanModel targetModel = (JavaBeanModel) connectionModels
+ .getSource();
+ if (targetModel.isPrimitive()) {
// check the connection model properties
- if(targetModel.getName().equals("productCode")){
- Assert.assertTrue(connectionModels.getProperties().size() > 0);
+ if (targetModel.getName().equals("productCode")) {
+ Assert
+ .assertTrue(connectionModels.getProperties().size() > 0);
}
- if(targetModel.getName().equals("unitPrice")){
- Assert.assertTrue(connectionModels.getProperties().size() > 0);
+ if (targetModel.getName().equals("unitPrice")) {
+ Assert
+ .assertTrue(connectionModels.getProperties().size() > 0);
}
- if(targetModel.getName().equals("unitQuantity")){
- Assert.assertTrue(connectionModels.getProperties().size() > 0);
+ if (targetModel.getName().equals("unitQuantity")) {
+ Assert
+ .assertTrue(connectionModels.getProperties().size() > 0);
}
}
}
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/AbstractXML2JavaTestCase.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/AbstractXML2JavaTestCase.java 2009-01-14
21:45:43 UTC (rev 13047)
+++
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/AbstractXML2JavaTestCase.java 2009-01-15
02:16:32 UTC (rev 13048)
@@ -22,7 +22,9 @@
import org.jboss.tools.smooks.model.DocumentRoot;
import org.jboss.tools.smooks.model.SmooksResourceListType;
import org.jboss.tools.smooks.test.AbstractModelTestCase;
+import org.jboss.tools.smooks.test.java.SelectorTester;
import org.jboss.tools.smooks.test.java2java.NormalJ2JConfigFileAnalyzerTester;
+import org.jboss.tools.smooks.ui.IXMLStructuredObject;
import org.jboss.tools.smooks.xml.model.AbstractXMLObject;
import org.jboss.tools.smooks.xml.model.TagList;
import org.jboss.tools.smooks.xml.model.TagObject;
@@ -35,11 +37,11 @@
*
*/
public abstract class AbstractXML2JavaTestCase extends AbstractModelTestCase {
-
+
protected Object source;
protected Object target;
protected MappingResourceConfigList mappingResourceConfigList;
-
+
public Object getSource() {
return source;
}
@@ -65,6 +67,14 @@
this.mappingResourceConfigList = mappingResourceConfigList;
}
+ public void checkSelectors() {
+ SelectorTester tester = new SelectorTester();
+ SmooksResourceListType listType = ((DocumentRoot) smooksResource
+ .getContents().get(0)).getSmooksResourceList();
+ tester.validSmooksConfigFile(listType, (IXMLStructuredObject) source,
+ (IXMLStructuredObject) ((List) target).get(0));
+ }
+
/*
* (non-Javadoc)
*
@@ -110,12 +120,13 @@
listType, null, null);
return source;
}
-
+
/*
* (non-Javadoc)
+ *
* @see junit.framework.TestCase#setUp()
*/
- public void setUp() throws Exception{
+ public void setUp() throws Exception {
super.setUp();
setSource(loadSource());
setTarget(loadTarget());
@@ -173,7 +184,7 @@
protected ITargetModelAnalyzer newTargetModelAnalyzer() {
return new JavaBeanAnalyzer();
}
-
+
protected void checkTargetConnectionCount(
List<MappingModel> mappingModelList) throws Exception {
HashMap map = new HashMap();
@@ -187,7 +198,7 @@
map.put(mappingModel.getTarget(), "Exist");
}
}
-
+
public void checkXMLNodeModelValue(AbstractXMLObject tag) {
Assert.assertNotNull(tag.getName());
if (!(tag instanceof TagList))
@@ -195,7 +206,8 @@
else
Assert.assertNull(tag.getParent());
if (tag instanceof TagObject) {
- List<AbstractXMLObject> children = ((TagObject) tag).getChildren();
+ List<AbstractXMLObject> children = ((TagObject) tag)
+ .getXMLNodeChildren();
for (Iterator iterator = children.iterator(); iterator.hasNext();) {
AbstractXMLObject abstractXMLObject = (AbstractXMLObject) iterator
.next();
@@ -225,7 +237,7 @@
if (name.equalsIgnoreCase(tag.getName())) {
return tag;
}
- List list = tag.getChildren();
+ List list = tag.getXMLNodeChildren();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
Object object = (Object) iterator.next();
if (object instanceof TagObject) {
@@ -237,5 +249,4 @@
return null;
}
-
}
Modified:
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/order/ClassicX2JTestCase.java
===================================================================
---
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/order/ClassicX2JTestCase.java 2009-01-14
21:45:43 UTC (rev 13047)
+++
trunk/smooks/tests/org.jboss.tools.smooks.test/src/org/jboss/tools/smooks/test/xml2java/order/ClassicX2JTestCase.java 2009-01-15
02:16:32 UTC (rev 13048)
@@ -47,6 +47,9 @@
}
public void testGraph() throws Exception {
+
+ checkSelectors();
+
MappingResourceConfigList configList = getMappingResourceConfigList();
List<MappingModel> mappingModelList = configList.getMappingModelList();
// there are 9 connections
@@ -84,7 +87,7 @@
}
}
Assert.assertEquals(equalsUrl, tag.getNamespaceURL());
- List<AbstractXMLObject> children = tag.getChildren();
+ List<AbstractXMLObject> children = tag.getXMLNodeChildren();
for (Iterator<AbstractXMLObject> iterator = children.iterator(); iterator
.hasNext();) {
AbstractXMLObject abstractXMLObject = (AbstractXMLObject) iterator