[overlord-commits] Overlord SVN: r577 - in cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src: test/org/jboss/tools/overlord/cdl/bpel/model/component and 1 other directory.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Fri Apr 10 13:13:57 EDT 2009


Author: objectiser
Date: 2009-04-10 13:13:57 -0400 (Fri, 10 Apr 2009)
New Revision: 577

Added:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractCondition.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/For.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Until.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/PickTest.java
Modified:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Condition.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarm.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Pick.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarmTest.java
Log:
Refactored conditions into an abstract class with three concrete representations - the condition used by if activity, and for/until used by onAlarm element. Finished onAlarm and pick tests.

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractCondition.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractCondition.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractCondition.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others 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.
+ */
+package org.jboss.tools.overlord.cdl.bpel.model.component;
+
+import java.util.List;
+
+import org.jboss.tools.overlord.cdl.bpel.model.BPELLanguageModel;
+import org.jboss.tools.overlord.cdl.bpel.model.ConversionContext;
+import org.scribble.model.Activity;
+
+/**
+ * This class represents the BPEL condition element.
+ */
+public abstract class AbstractCondition extends BPELElement {
+
+	private static final long serialVersionUID = 178873060670041144L;
+
+	private static final String EXPRESSION_LANGUAGE = "expressionLanguage";
+
+	/**
+	 * The constructor for the element.
+	 * 
+	 * @param model The BPEL model
+	 * @param elem The XML configuration details for the element
+	 */
+	public AbstractCondition(BPELLanguageModel model,
+					org.w3c.dom.Element elem) {
+		super(model, elem);
+	}
+
+	/**
+	 * The constructor for the element.
+	 * 
+	 * @param model The BPEL model
+	 * @param elemName The condition's element name
+	 */
+	public AbstractCondition(BPELLanguageModel model, String elemName) {
+		super(model, elemName);
+	}
+
+	/**
+	 * This method returns the expression associated
+	 * with the condition.
+	 * 
+	 * @return The expression
+	 */
+	public String getExpression() {
+		String ret=null;
+		
+		getDOMElement().normalize();
+		
+		if (getDOMElement().getFirstChild() instanceof org.w3c.dom.Text) {
+			org.w3c.dom.Text text=(org.w3c.dom.Text)
+							getDOMElement().getFirstChild();
+			
+			ret = text.getNodeValue();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method sets the expression.
+	 * 
+	 * @param expr The expression
+	 */
+	public void setExpression(String expr) {
+		
+		getDOMElement().normalize();
+		
+		if (getDOMElement().getFirstChild() == null) {
+			org.w3c.dom.Text text=
+				getDOMElement().getOwnerDocument().createTextNode(expr);
+			
+			getDOMElement().appendChild(text);
+			
+		} else if (getDOMElement().getFirstChild() instanceof org.w3c.dom.Text) {
+			org.w3c.dom.Text text=(org.w3c.dom.Text)
+							getDOMElement().getFirstChild();
+			
+			text.setNodeValue(expr);
+		}
+	}
+	
+	/**
+	 * This method returns the expression language associated
+	 * with the condition.
+	 * 
+	 * @return The expression language
+	 */
+	public String getExpressionLanguage() {
+		return(getDOMElement().getAttribute(EXPRESSION_LANGUAGE));
+	}
+	
+	/**
+	 * This method sets the expression language.
+	 * 
+	 * @param lang The expression language
+	 */
+	public void setExpressionLanguage(String lang) {
+		getDOMElement().setAttribute(EXPRESSION_LANGUAGE, lang);
+	}
+	
+	@Override
+	public void convert(List<Activity> activities, ConversionContext context) {
+		// TODO Auto-generated method stub
+		
+	}
+
+
+}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Condition.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Condition.java	2009-04-08 21:57:45 UTC (rev 576)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Condition.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -17,19 +17,13 @@
  */
 package org.jboss.tools.overlord.cdl.bpel.model.component;
 
-import java.util.List;
-
 import org.jboss.tools.overlord.cdl.bpel.model.BPELLanguageModel;
-import org.jboss.tools.overlord.cdl.bpel.model.ConversionContext;
-import org.scribble.model.Activity;
 
 /**
  * This class represents the BPEL condition element.
  */
-public class Condition extends BPELElement {
+public class Condition extends AbstractCondition {
 
-	private static final String EXPRESSION_LANGUAGE = "expressionLanguage";
-
 	private static final long serialVersionUID = 8666349106632652777L;
 
 	public static final String CONDITION="condition";
@@ -54,74 +48,4 @@
 		super(model, CONDITION);
 	}
 
-	/**
-	 * This method returns the expression associated
-	 * with the condition.
-	 * 
-	 * @return The expression
-	 */
-	public String getExpression() {
-		String ret=null;
-		
-		getDOMElement().normalize();
-		
-		if (getDOMElement().getFirstChild() instanceof org.w3c.dom.Text) {
-			org.w3c.dom.Text text=(org.w3c.dom.Text)
-							getDOMElement().getFirstChild();
-			
-			ret = text.getNodeValue();
-		}
-		
-		return(ret);
-	}
-	
-	/**
-	 * This method sets the expression.
-	 * 
-	 * @param expr The expression
-	 */
-	public void setExpression(String expr) {
-		
-		getDOMElement().normalize();
-		
-		if (getDOMElement().getFirstChild() == null) {
-			org.w3c.dom.Text text=
-				getDOMElement().getOwnerDocument().createTextNode(expr);
-			
-			getDOMElement().appendChild(text);
-			
-		} else if (getDOMElement().getFirstChild() instanceof org.w3c.dom.Text) {
-			org.w3c.dom.Text text=(org.w3c.dom.Text)
-							getDOMElement().getFirstChild();
-			
-			text.setNodeValue(expr);
-		}
-	}
-	
-	/**
-	 * This method returns the expression language associated
-	 * with the condition.
-	 * 
-	 * @return The expression language
-	 */
-	public String getExpressionLanguage() {
-		return(getDOMElement().getAttribute(EXPRESSION_LANGUAGE));
-	}
-	
-	/**
-	 * This method sets the expression language.
-	 * 
-	 * @param lang The expression language
-	 */
-	public void setExpressionLanguage(String lang) {
-		getDOMElement().setAttribute(EXPRESSION_LANGUAGE, lang);
-	}
-	
-	@Override
-	public void convert(List<Activity> activities, ConversionContext context) {
-		// TODO Auto-generated method stub
-		
-	}
-
-
 }

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/For.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/For.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/For.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others 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.
+ */
+package org.jboss.tools.overlord.cdl.bpel.model.component;
+
+import org.jboss.tools.overlord.cdl.bpel.model.BPELLanguageModel;
+
+/**
+ * This class represents the BPEL 'for' element.
+ */
+public class For extends AbstractCondition {
+
+	private static final long serialVersionUID = -3123540793706121742L;
+
+	public static final String FOR="for";
+	
+	/**
+	 * The constructor for the element.
+	 * 
+	 * @param model The BPEL model
+	 * @param elem The XML configuration details for the element
+	 */
+	public For(BPELLanguageModel model,
+					org.w3c.dom.Element elem) {
+		super(model, elem);
+	}
+
+	/**
+	 * The constructor for the element.
+	 * 
+	 * @param model The BPEL model
+	 */
+	public For(BPELLanguageModel model) {
+		super(model, FOR);
+	}
+}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarm.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarm.java	2009-04-08 21:57:45 UTC (rev 576)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarm.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -31,9 +31,6 @@
 
 	private static final long serialVersionUID = 271323368015539L;
 
-	public static final String FOR = "for";
-	public static final String UNTIL = "until";
-
 	public static final String ONALARM="onAlarm";
 	
 	/**
@@ -69,11 +66,17 @@
 	 * 
 	 * @param cond The 'until' condition
 	 */
-	public void setUntil(Condition cond) {
-		setChildElement(findChildElement(UNTIL),
-				cond, null);
+	public void setUntil(Until cond) {
+		org.w3c.dom.Element insertBefore=null;
 		
-		org.w3c.dom.Element elem=findChildElement(FOR);
+		if (m_activity != null) {
+			insertBefore = m_activity.getDOMElement();
+		}
+		
+		setChildElement(findChildElement(Until.UNTIL),
+				cond, insertBefore);
+		
+		org.w3c.dom.Element elem=findChildElement(For.FOR);
 		if (elem != null) {
 			getDOMElement().removeChild(elem);
 		}
@@ -84,12 +87,12 @@
 	 * 
 	 * @return The 'until' condition
 	 */
-	public Condition getUntil() {
-		Condition ret=null;
+	public Until getUntil() {
+		Until ret=null;
 		
-		org.w3c.dom.Element elem=findChildElement(UNTIL);
+		org.w3c.dom.Element elem=findChildElement(Until.UNTIL);
 		if (elem != null) {
-			ret = new Condition(getModel(), elem);
+			ret = new Until(getModel(), elem);
 		}
 		
 		return(ret);
@@ -100,11 +103,17 @@
 	 * 
 	 * @param cond The 'for' condition
 	 */
-	public void setFor(Condition cond) {
-		setChildElement(findChildElement(FOR),
-				cond, null);
+	public void setFor(For cond) {	
+		org.w3c.dom.Element insertBefore=null;
 		
-		org.w3c.dom.Element elem=findChildElement(UNTIL);
+		if (m_activity != null) {
+			insertBefore = m_activity.getDOMElement();
+		}
+		
+		setChildElement(findChildElement(For.FOR),
+				cond, insertBefore);
+		
+		org.w3c.dom.Element elem=findChildElement(Until.UNTIL);
 		if (elem != null) {
 			getDOMElement().removeChild(elem);
 		}
@@ -115,12 +124,12 @@
 	 * 
 	 * @return The 'for' condition
 	 */
-	public Condition getFor() {
-		Condition ret=null;
+	public For getFor() {
+		For ret=null;
 		
-		org.w3c.dom.Element elem=findChildElement(FOR);
+		org.w3c.dom.Element elem=findChildElement(For.FOR);
 		if (elem != null) {
-			ret = new Condition(getModel(), elem);
+			ret = new For(getModel(), elem);
 		}
 		
 		return(ret);

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Pick.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Pick.java	2009-04-08 21:57:45 UTC (rev 576)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Pick.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -77,10 +77,16 @@
 	 * @param pos The position to add, or -1 if at the end
 	 */
 	public void addOnMessage(OnMessage on, int pos) {
-		if (pos == -1 && pos < m_onMessages.size()) {
+		if (pos == -1 || pos >= m_onMessages.size()) {
 			m_onMessages.add(on);
 			
-			setChildElement(null, on, null);
+			org.w3c.dom.Element insertBefore=null;
+			
+			if (m_onAlarms.size() > 0) {
+				insertBefore = m_onAlarms.get(0).getDOMElement();
+			}
+			
+			setChildElement(null, on, insertBefore);
 		} else {
 			
 			OnMessage cur=m_onMessages.get(pos);
@@ -91,7 +97,13 @@
 				setChildElement(null, on,
 							cur.getDOMElement());
 			} else {
-				setChildElement(null, on, null);
+				org.w3c.dom.Element insertBefore=null;
+				
+				if (m_onAlarms.size() > 0) {
+					insertBefore = m_onAlarms.get(0).getDOMElement();
+				}
+				
+				setChildElement(null, on, insertBefore);
 			}
 		}
 	}
@@ -130,7 +142,7 @@
 	 * @param pos The position to add, or -1 if at the end
 	 */
 	public void addOnAlarm(OnAlarm on, int pos) {
-		if (pos == -1 && pos < m_onAlarms.size()) {
+		if (pos == -1 || pos >= m_onAlarms.size()) {
 			m_onAlarms.add(on);
 			
 			setChildElement(null, on, null);

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Until.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Until.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Until.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others 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.
+ */
+package org.jboss.tools.overlord.cdl.bpel.model.component;
+
+import org.jboss.tools.overlord.cdl.bpel.model.BPELLanguageModel;
+
+/**
+ * This class represents the BPEL 'until' element.
+ */
+public class Until extends AbstractCondition {
+
+	private static final long serialVersionUID = 5398291987513467996L;
+
+	public static final String UNTIL="until";
+	
+	/**
+	 * The constructor for the element.
+	 * 
+	 * @param model The BPEL model
+	 * @param elem The XML configuration details for the element
+	 */
+	public Until(BPELLanguageModel model,
+					org.w3c.dom.Element elem) {
+		super(model, elem);
+	}
+
+	/**
+	 * The constructor for the element.
+	 * 
+	 * @param model The BPEL model
+	 */
+	public Until(BPELLanguageModel model) {
+		super(model, UNTIL);
+	}
+}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarmTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarmTest.java	2009-04-08 21:57:45 UTC (rev 576)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/OnAlarmTest.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -184,7 +184,7 @@
 			fail("Failed to convert to doc");
 		}
 		
-		Condition condition=new Condition(model, elem);
+		Until condition=new Until(model, elem);
 		
 		OnAlarm component=new OnAlarm(model);
 		
@@ -253,7 +253,7 @@
 			fail("Failed to convert to doc");
 		}
 		
-		Condition condition1=new Condition(model, elem1);
+		Until condition1=new Until(model, elem1);
 		
 		OnAlarm component=new OnAlarm(model);
 		
@@ -278,7 +278,7 @@
 					expr1+"' but got '"+result+"'");
 		}
 
-		Condition condition2=new Condition(model, elem2);
+		Until condition2=new Until(model, elem2);
 		
 		component.setUntil(condition2);
 		
@@ -332,7 +332,7 @@
 			fail("Failed to convert to doc");
 		}
 		
-		Condition condition=new Condition(model, elem);
+		For condition=new For(model, elem);
 		
 		OnAlarm component=new OnAlarm(model);
 		
@@ -401,7 +401,7 @@
 			fail("Failed to convert to doc");
 		}
 		
-		Condition condition1=new Condition(model, elem1);
+		For condition1=new For(model, elem1);
 		
 		OnAlarm component=new OnAlarm(model);
 		
@@ -426,7 +426,7 @@
 					expr1+"' but got '"+result+"'");
 		}
 
-		Condition condition2=new Condition(model, elem2);
+		For condition2=new For(model, elem2);
 		
 		component.setFor(condition2);
 		
@@ -493,7 +493,7 @@
 			fail("Failed to convert to doc");
 		}
 		
-		Condition condition1=new Condition(model, elem1);
+		For condition1=new For(model, elem1);
 		
 		OnAlarm component=new OnAlarm(model);
 		
@@ -518,7 +518,7 @@
 					expr1+"' but got '"+result+"'");
 		}
 
-		Condition condition2=new Condition(model, elem2);
+		Until condition2=new Until(model, elem2);
 		
 		component.setUntil(condition2);
 		
@@ -585,7 +585,7 @@
 			fail("Failed to convert to doc");
 		}
 		
-		Condition condition1=new Condition(model, elem1);
+		Until condition1=new Until(model, elem1);
 		
 		OnAlarm component=new OnAlarm(model);
 		
@@ -610,7 +610,7 @@
 					expr1+"' but got '"+result+"'");
 		}
 
-		Condition condition2=new Condition(model, elem2);
+		For condition2=new For(model, elem2);
 		
 		component.setFor(condition2);
 		
@@ -822,12 +822,11 @@
 			fail("Activity is not a sequence");
 		}
 
-		Condition cond=new Condition(model);
+		For cond=new For(model);
 		cond.setExpression(expr1);
 		
 		component.setFor(cond);
 		
-		/*
 		String result=component.getFor().getExpression();
 		
 		if (result == null) {
@@ -840,7 +839,7 @@
 		}
 		
 		if (component.getDOMElement().getChildNodes().item(0).
-				getLocalName().equals(OnAlarm.FOR) == false) {
+				getLocalName().equals(For.FOR) == false) {
 			fail("First element was not a 'for': "+
 					component.getDOMElement().getChildNodes().item(0).
 									getLocalName());
@@ -852,6 +851,84 @@
 					component.getDOMElement().getChildNodes().item(1).
 									getLocalName());
 		}
-	*/
 	}
+
+	public void testAddUntilOnAlarm() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String expr1="Test Expression 1";
+		
+		String xml="<onAlarm xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">" +
+				"<sequence/>"+
+				"</onAlarm>";
+		org.w3c.dom.Element elem=null;
+		
+		try {
+			javax.xml.parsers.DocumentBuilderFactory factory=
+				javax.xml.parsers.DocumentBuilderFactory.newInstance();
+			
+			factory.setNamespaceAware(true);
+			
+			javax.xml.parsers.DocumentBuilder builder=
+						factory.newDocumentBuilder();
+			
+			java.io.InputStream is=new java.io.ByteArrayInputStream(xml.getBytes());
+			
+			org.w3c.dom.Document doc=builder.parse(is);
+			elem = doc.getDocumentElement();
+			
+			is.close();
+			
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		OnAlarm component=new OnAlarm(model, elem);		
+		
+		if (component.getFor() != null) {
+			fail("For condition should not be set");
+		}
+		
+		if (component.getUntil() != null) {
+			fail("Until condition should not be set");
+		}
+		
+		if (component.getActivity() == null) {
+			fail("No activity");
+		}
+		
+		if ((component.getActivity() instanceof Sequence) == false) {
+			fail("Activity is not a sequence");
+		}
+
+		Until cond=new Until(model);
+		cond.setExpression(expr1);
+		
+		component.setUntil(cond);
+		
+		String result=component.getUntil().getExpression();
+		
+		if (result == null) {
+			fail("Expression is null");
+		}
+		
+		if (result.equals(expr1) == false) {
+			fail("Expression is not valid: expecting '"+
+					expr1+"' but got '"+result+"'");
+		}
+		
+		if (component.getDOMElement().getChildNodes().item(0).
+				getLocalName().equals(Until.UNTIL) == false) {
+			fail("First element was not a 'until': "+
+					component.getDOMElement().getChildNodes().item(0).
+									getLocalName());
+		}
+		
+		if (component.getDOMElement().getChildNodes().item(1).
+				getLocalName().equals(Sequence.SEQUENCE) == false) {
+			fail("Second element was not a sequence: "+
+					component.getDOMElement().getChildNodes().item(1).
+									getLocalName());
+		}
+	}
 }

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/PickTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/PickTest.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/PickTest.java	2009-04-10 17:13:57 UTC (rev 577)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others 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.
+ */
+package org.jboss.tools.overlord.cdl.bpel.model.component;
+
+import org.jboss.tools.overlord.cdl.bpel.model.BPELLanguageModel;
+import org.jboss.tools.overlord.cdl.bpel.model.DefaultBPELLanguageModel;
+
+import junit.framework.TestCase;
+
+public class PickTest extends TestCase {
+
+	public void testIsActivity() {
+		Pick act=new Pick(new DefaultBPELLanguageModel(null));
+		
+		if (act.isActivity() == false) {
+			fail("Should be an activity");
+		}
+	}
+	
+	public void testPickFromDOM() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String xml="<pick xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+		       "<onMessage/>"+
+		       "<onMessage/>"+
+		       "<onAlarm/>"+
+		       "</pick>";
+		
+		org.w3c.dom.Element elem=null;
+		
+		try {
+			javax.xml.parsers.DocumentBuilderFactory factory=
+				javax.xml.parsers.DocumentBuilderFactory.newInstance();
+			
+			factory.setNamespaceAware(true);
+			
+			javax.xml.parsers.DocumentBuilder builder=
+						factory.newDocumentBuilder();
+			
+			java.io.InputStream is=new java.io.ByteArrayInputStream(xml.getBytes());
+			
+			org.w3c.dom.Document doc=builder.parse(is);
+			elem = doc.getDocumentElement();
+			
+			is.close();
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		Pick component=new Pick(model, elem);		
+		
+		if (component.getOnMessages().size() != 2) {
+			fail("Expecting 2 onMessage: "+
+							component.getOnMessages().size());
+		}
+		
+		if (component.getOnAlarms().size() != 1) {
+			fail("Expecting 1 onAlarm: "+
+							component.getOnAlarms().size());
+		}
+	}
+
+	public void testAddOnMessageToPickInitFromDOM() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String xml="<pick xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+	       		"<targets/>"+
+	       		"<onAlarm/>"+
+	       		"<onAlarm/>"+
+	       		"</pick>";
+		
+		org.w3c.dom.Element elem=null;
+		
+		try {
+			javax.xml.parsers.DocumentBuilderFactory factory=
+				javax.xml.parsers.DocumentBuilderFactory.newInstance();
+			
+			factory.setNamespaceAware(true);
+			
+			javax.xml.parsers.DocumentBuilder builder=
+						factory.newDocumentBuilder();
+			
+			java.io.InputStream is=new java.io.ByteArrayInputStream(xml.getBytes());
+			
+			org.w3c.dom.Document doc=builder.parse(is);
+			elem = doc.getDocumentElement();
+			
+			is.close();
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		Pick component=new Pick(model, elem);		
+		
+		if (component.getOnAlarms().size() != 2) {
+			fail("Expecting 2 onAlarms: "+
+							component.getOnAlarms().size());
+		}
+		
+		if (component.getOnMessages().size() != 0) {
+			fail("Expecting 0 onMessages: "+
+							component.getOnMessages().size());
+		}
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 3) {
+			fail("Three child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+
+		OnMessage sub=new OnMessage(model);
+		
+		component.addOnMessage(sub, 0);
+		
+		if (component.getOnMessages().size() != 1) {
+			fail("Expecting 1 onMessage: "+
+							component.getOnMessages().size());
+		}
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 4) {
+			fail("Four child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+
+		if (component.getDOMElement().getChildNodes().item(1).
+				getLocalName().equals(OnMessage.ONMESSAGE) == false) {
+			fail("Second element was not a 'onMessage': "+
+					component.getDOMElement().getChildNodes().item(1).
+									getLocalName());
+		}
+	}
+
+
+	public void testAddOnAlarmToPickInitFromDOM() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String xml="<pick xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+	       		"<targets/>"+
+	       		"<onMessage/>"+
+	       		"<onMessage/>"+
+	       		"</pick>";
+		
+		org.w3c.dom.Element elem=null;
+		
+		try {
+			javax.xml.parsers.DocumentBuilderFactory factory=
+				javax.xml.parsers.DocumentBuilderFactory.newInstance();
+			
+			factory.setNamespaceAware(true);
+			
+			javax.xml.parsers.DocumentBuilder builder=
+						factory.newDocumentBuilder();
+			
+			java.io.InputStream is=new java.io.ByteArrayInputStream(xml.getBytes());
+			
+			org.w3c.dom.Document doc=builder.parse(is);
+			elem = doc.getDocumentElement();
+			
+			is.close();
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		Pick component=new Pick(model, elem);		
+		
+		if (component.getOnMessages().size() != 2) {
+			fail("Expecting 2 onMessages: "+
+							component.getOnMessages().size());
+		}
+		
+		if (component.getOnAlarms().size() != 0) {
+			fail("Expecting 0 onAlarms: "+
+							component.getOnAlarms().size());
+		}
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 3) {
+			fail("Three child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+
+		OnAlarm sub=new OnAlarm(model);
+		
+		component.addOnAlarm(sub, 0);
+		
+		if (component.getOnAlarms().size() != 1) {
+			fail("Expecting 1 onAlarm: "+
+							component.getOnAlarms().size());
+		}
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 4) {
+			fail("Four child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+
+		if (component.getDOMElement().getChildNodes().item(3).
+				getLocalName().equals(OnAlarm.ONALARM) == false) {
+			fail("Second element was not a 'onAlarm': "+
+					component.getDOMElement().getChildNodes().item(3).
+									getLocalName());
+		}
+	}
+}




More information about the overlord-commits mailing list