[wise-commits] wise SVN: r534 - in core/trunk: core/src/test/java/org/jboss/wise/tree and 1 other directories.

wise-commits at lists.jboss.org wise-commits at lists.jboss.org
Tue Feb 26 18:43:25 EST 2013


Author: alessio.soldano at jboss.com
Date: 2013-02-26 18:43:25 -0500 (Tue, 26 Feb 2013)
New Revision: 534

Modified:
   core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java
   core/trunk/core/src/test/java/org/jboss/wise/tree/ElementTest.java
   core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/tree/WiseIntegrationTreeTest.java
Log:
[WISE-195] Adding ElementBuilder interface


Modified: core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java	2013-02-25 10:00:50 UTC (rev 533)
+++ core/trunk/core/src/main/java/org/jboss/wise/tree/impl/ElementBuilderImpl.java	2013-02-26 23:43:25 UTC (rev 534)
@@ -38,25 +38,45 @@
 import org.jboss.wise.core.utils.JavaUtils;
 import org.jboss.wise.core.utils.ReflectionUtils;
 import org.jboss.wise.tree.Element;
+import org.jboss.wise.tree.ElementBuilder;
 
 
 /**
  * @author alessio.soldano at jboss.com
  * 
  */
-public class ElementBuilderImpl {
+public class ElementBuilderImpl implements ElementBuilder {
     
     private WSDynamicClient client;
-    private final boolean request;
-    private final boolean useDefautValuesForNullLeaves;
+    private boolean request = true;
+    private boolean useDefautValuesForNullLeaves = true;
     
-    public ElementBuilderImpl(WSDynamicClient client, boolean request, boolean useDefautValuesForNullLeaves) {
+    public ElementBuilderImpl() {
+    }
+    
+    @Override
+    public ElementBuilder client(WSDynamicClient client) {
 	this.client = client;
+	return this;
+    }
+
+    @Override
+    public ElementBuilder request(boolean request) {
 	this.request = request;
+	return this;
+    }
+
+    @Override
+    public ElementBuilder useDefautValuesForNullLeaves(boolean useDefautValuesForNullLeaves) {
 	this.useDefautValuesForNullLeaves = useDefautValuesForNullLeaves;
+	return this;
     }
     
+    @Override
     public Element buildTree(Type type, String name, Object value, boolean nillable) {
+	if (client == null) {
+	    throw new IllegalStateException("WSDynamicClient reference is not set!");
+	}
 	return buildTree(type, name, value, nillable, null, null, Collections.synchronizedMap(new HashMap<Type, ElementImpl>()), new HashSet<Type>());
     }
 
@@ -249,4 +269,7 @@
     protected String generateNewID() {
 	return IDGenerator.nextVal();
     }
+
+
+
 }

Modified: core/trunk/core/src/test/java/org/jboss/wise/tree/ElementTest.java
===================================================================
--- core/trunk/core/src/test/java/org/jboss/wise/tree/ElementTest.java	2013-02-25 10:00:50 UTC (rev 533)
+++ core/trunk/core/src/test/java/org/jboss/wise/tree/ElementTest.java	2013-02-26 23:43:25 UTC (rev 534)
@@ -62,7 +62,7 @@
     
     @Test
     public void shouldBuildTreeOfStringElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	final String name = "myString";
 	final String value = "foo";
 	
@@ -133,7 +133,7 @@
     
     @Test
     public void shouldBuildTreeOfQNameElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	final String name = "myQName";
 	final String value = "{org.jboss.wise}foo";
 	
@@ -188,7 +188,7 @@
     
     @Test
     public void shouldBuildTreeOfDurationElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	final String name = "myDuration";
 	final long longVal = 345678;
 	final String value = String.valueOf(DatatypeFactory.newInstance().newDuration(longVal).getTimeInMillis(new GregorianCalendar()));
@@ -240,7 +240,7 @@
     
     @Test
     public void shouldBuildTreeOfXMLGregorianCalendarElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	final String name = "myXMLGregorianCalendar";
 	final String value = "2013-02-13T12:12:10.000Z";
 	final String refCal = "1970-01-01T00:00:00.000Z";
@@ -291,7 +291,7 @@
     }
     
     private static <T> void shouldBuildTreeOfNumberElement(Class<T> clazz, String name, String value, String expDefValue, T expObj, T expDefObj) throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(clazz, name, null, true);
 	assertElementProps(el, true, false, false, true, true, false, false, 0);
 	assertEquals(clazz, el.getClassType());
@@ -338,7 +338,7 @@
     }
     
     private static <T> void shouldBuildTreeOfPrimitiveNumberElement(Class<T> clazz, String name, String value, String expDefValue, T expObj, T expDefObj) throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(clazz, name, null, true);
 	assertElementProps(el, true, false, false, false, false, false, false, 0);
 	assertEquals(clazz, el.getClassType());
@@ -382,7 +382,7 @@
     
     @Test
     public void shouldBuildTreeOfComplexElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(MyTest.class, "myTest", null, true);
 	assertElementProps(el, false, false, false, false, true, false, false, 1);
 	assertEquals(MyTest.class, el.getClassType());
@@ -429,7 +429,7 @@
     @SuppressWarnings("unchecked")
     @Test
     public void shouldBuildTreeOfGroupElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	ParameterizedType type = getTestCollectionType();
 	
 	Element el = builder.buildTree(type, "myTests", null, true);
@@ -506,7 +506,7 @@
     
     @Test
     public void shouldBuildTreeOfLazyElement() throws Exception {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(MyLazyTest.class, "myLazyTest", null, true);
 	assertElementProps(el, false, false, false, false, true, false, false, 2);
 	assertEquals(MyLazyTest.class, el.getClassType());
@@ -564,14 +564,14 @@
     
     @Test(expected = UnsupportedOperationException.class)
     public void incrementChildOperationOnNotGroupElementShouldCauseExceptionThrown() {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(MyTest.class, "myTest", null, true);
 	el.incrementChildren();
     }
     
     @Test(expected = WiseRuntimeException.class)
     public void removeChildOperationOfUnremovableElementShouldCauseExceptionThrown() {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(MyTest.class, "myTest", null, true);
 	Element child = el.getChildren().next();
 	el.removeChild(child.getId());
@@ -579,23 +579,23 @@
     
     @Test(expected = UnsupportedOperationException.class)
     public void incrementChildOperationOnLeafElementShouldCauseExceptionThrown() {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(String.class, "myString", null, true);
 	el.incrementChildren();
     }
     
     @Test(expected = UnsupportedOperationException.class)
     public void setValueOperationsOnNotLeafElementShouldCauseExceptionThrown() {
-	ElementBuilderImpl builder = getElementBuilder(true, false);
+	ElementBuilder builder = getElementBuilder(true, false);
 	Element el = builder.buildTree(MyTest.class, "myTest", null, true);
 	el.setValue("Foo");
     }
     
-    private static ElementBuilderImpl getElementBuilder(boolean request, boolean useDefaults) {
+    private static ElementBuilder getElementBuilder(boolean request, boolean useDefaults) {
 	WSDynamicClientImpl mock = mock(WSDynamicClientImpl.class);
 	mock.setClassLoader(ElementTest.class.getClassLoader());
 //	when(mock.getClassLoaderInternal()).thenReturn();
-	return new TestElementBuilder(mock, request, useDefaults);
+	return new TestElementBuilder().client(mock).request(request).useDefautValuesForNullLeaves(useDefaults);
     }
     
     private static void assertElementProps(Element el, boolean leaf, boolean group, boolean lazy, boolean nil, boolean nillable, boolean removable, boolean resolved, int childrenCount) {
@@ -614,10 +614,6 @@
     
     private static class TestElementBuilder extends ElementBuilderImpl {
 	
-	public TestElementBuilder(WSDynamicClient client, boolean request, boolean useDefautValuesForNulls) {
-	    super(client, request, useDefautValuesForNulls);
-	}
-
 	protected boolean isSimpleType(Class<?> cl, WSDynamicClient client) {
 	    if (cl.isEnum() || cl.isPrimitive()) {
 		return true;

Modified: core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/tree/WiseIntegrationTreeTest.java
===================================================================
--- core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/tree/WiseIntegrationTreeTest.java	2013-02-25 10:00:50 UTC (rev 533)
+++ core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/tree/WiseIntegrationTreeTest.java	2013-02-26 23:43:25 UTC (rev 534)
@@ -36,7 +36,8 @@
 import org.jboss.wise.core.client.factories.WSDynamicClientFactory;
 import org.jboss.wise.core.test.WiseTest;
 import org.jboss.wise.tree.Element;
-import org.jboss.wise.tree.impl.ElementBuilderImpl;
+import org.jboss.wise.tree.ElementBuilder;
+import org.jboss.wise.tree.ElementBuilderFactory;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -70,7 +71,8 @@
 	Map<String, ? extends WebParameter> pars = method.getWebParams();
 	WebParameter customerPar = pars.get("Customer");
 	
-	Element customerElement = new ElementBuilderImpl(client, true, true).buildTree(customerPar.getType(), customerPar.getName(), null, true);
+	ElementBuilder builder = ElementBuilderFactory.getElementBuilder().client(client).request(true).useDefautValuesForNullLeaves(true);
+	Element customerElement = builder.buildTree(customerPar.getType(), customerPar.getName(), null, true);
 	customerElement.getChildByName("id").setValue("1234");
 	customerElement.getChildByName("name").getChildByName("firstName").setValue("Foo");
 	customerElement.getChildByName("name").getChildByName("lastName").setValue("Bar");
@@ -96,7 +98,8 @@
 	WebParameter customerPar = pars.get("Customer");
 	Assert.assertEquals(WebParam.Mode.INOUT, customerPar.getMode());
 	
-	Element element = new ElementBuilderImpl(client, true, true).buildTree(customerPar.getType(), customerPar.getName(), null, true);
+	ElementBuilder builder = ElementBuilderFactory.getElementBuilder().client(client).request(true).useDefautValuesForNullLeaves(true);
+	Element element = builder.buildTree(customerPar.getType(), customerPar.getName(), null, true);
 	Element customerElement = element.getChildren().next();
 	customerElement.getChildByName("id").setValue("1235");
 	customerElement.getChildByName("name").getChildByName("firstName").setValue("Foo");
@@ -114,7 +117,7 @@
 	Assert.assertEquals(void.class, test.get("type.result"));
 
 	final String key = "Customer";
-	Element returnElement = new ElementBuilderImpl(client, false, false).buildTree((Type)test.get("type." + key), key, test.get(key), true);
+	Element returnElement = builder.request(false).useDefautValuesForNullLeaves(false).buildTree((Type)test.get("type." + key), key, test.get(key), true);
 	Element returnCustomerElement = returnElement.getChildren().next();
 	Assert.assertEquals("1235", returnCustomerElement.getChildByName("id").getValue());
 	Assert.assertEquals("Foo", returnCustomerElement.getChildByName("name").getChildByName("firstName").getValue());



More information about the wise-commits mailing list