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

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Tue Mar 31 16:53:18 EDT 2009


Author: objectiser
Date: 2009-03-31 16:53:18 -0400 (Tue, 31 Mar 2009)
New Revision: 563

Added:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/WhileTest.java
Modified:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/ConversationInteractionModelChangeRule.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/WhileModelChangeRule.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractInteractionActivity.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/BPELElement.java
   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/Elseif.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/If.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Receive.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Reply.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/While.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/ConditionTest.java
Log:
Added tests for 'while' and expression language on condition. Moved references to ConversationInteraction out of bpel model components, so only used in the model change rules.

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/ConversationInteractionModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/ConversationInteractionModelChangeRule.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/ConversationInteractionModelChangeRule.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -89,13 +89,17 @@
 		BPELLanguageModel bpelModel=(BPELLanguageModel)model;
 		ConversationInteraction interaction=(ConversationInteraction)mobj;
 		boolean ret=false;
+		AbstractInteractionActivity act=null;
 		
 		// Check if send or receive
 		if (InteractionUtil.isSend(interaction)) {
 			
+			// TODO: Record variables against relevant interaction
+			// based activity - probably only mechanism for
+			// establishing message type
+
 			if (InteractionUtil.isRequest(interaction)) {
-				Invoke act=new Invoke(bpelModel,
-								interaction);
+				act = new Invoke(bpelModel);
 				
 				if (context.getParent() instanceof Sequence) {
 					((Sequence)context.getParent()).addActivity(act, -1);
@@ -110,8 +114,7 @@
 				// possibly wrapped around, or contained within the
 				// invoke.
 			} else {
-				Reply act=new Reply(bpelModel,
-							interaction);
+				act = new Reply(bpelModel);
 		
 				if (context.getParent() instanceof Sequence) {
 					((Sequence)context.getParent()).addActivity(act, -1);
@@ -121,8 +124,7 @@
 			}
 		} else {
 			if (InteractionUtil.isRequest(interaction)) {
-				Receive act=new Receive(bpelModel,
-									interaction);
+				act = new Receive(bpelModel);
 	
 				if (context.getParent() instanceof Sequence) {
 					((Sequence)context.getParent()).addActivity(act, -1);
@@ -131,6 +133,10 @@
 				}	
 			}
 		}
+
+		if (act != null && interaction.getMessageSignature() != null) {
+			act.setOperation(interaction.getMessageSignature().getOperation());
+		}
 		
 		return(ret);
 	}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/WhileModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/WhileModelChangeRule.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/change/WhileModelChangeRule.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -90,7 +90,6 @@
 		While act=new While(bpelModel);
 		
 		Sequence seq=new Sequence(bpelModel);
-		act.setActivity(seq);
 		
 		if (context.getParent() instanceof Sequence) {		
 			((Sequence)context.getParent()).addActivity(act, -1);
@@ -107,6 +106,8 @@
 			context.insert(model, acts.get(i), null);
 		}
 		
+		act.setActivity(seq);
+
 		// Reset old parent
 		context.setParent(parent);
 		

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractInteractionActivity.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractInteractionActivity.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/AbstractInteractionActivity.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -28,6 +28,7 @@
  */
 public abstract class AbstractInteractionActivity extends BPELElement {
 
+	private static final String OPERATION = "operation";
 	private static final long serialVersionUID = -5048477859609625462L;
 
 	/**
@@ -45,25 +46,28 @@
 	 * The constructor for the activity.
 	 * 
 	 * @param model The BPEL model
-	 * @param interaction The conversation
 	 */
 	public AbstractInteractionActivity(BPELLanguageModel model,
-			String name, ConversationInteraction interaction) {
+			String name) {
 		super(model, name);
-		
-		initialize(interaction);
 	}
 	
 	/**
-	 * This method initializes the invoke interaction.
+	 * This method sets the operation.
 	 * 
-	 * @param interaction The invoke interaction
+	 * @param op The operation
 	 */
-	protected void initialize(ConversationInteraction interaction) {
-		
-		getDOMElement().setAttribute("operation",
-				interaction.getMessageSignature().getOperation());
-		
+	public void setOperation(String op) {		
+		getDOMElement().setAttribute(OPERATION, op);
+	}
+	
+	/**
+	 * This method returns the operation.
+	 * 
+	 * @return The operation
+	 */
+	public String getOperation() {
+		return(getDOMElement().getAttribute(OPERATION));
 		// TODO: Record variables against relevant interaction
 		// based activity - probably only mechanism for
 		// establishing message type

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/BPELElement.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/BPELElement.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/BPELElement.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -98,7 +98,7 @@
 	 * @param name The name
 	 * @return The element, or null if not found
 	 */
-	protected org.w3c.dom.Element findElement(String name) {
+	protected org.w3c.dom.Element findChildElement(String name) {
 		org.w3c.dom.Element ret=null;
 		
 		org.w3c.dom.NodeList nl=getDOMElement().getChildNodes();

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-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Condition.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -28,6 +28,8 @@
  */
 public class Condition extends BPELElement {
 
+	private static final String EXPRESSION_LANGUAGE = "expressionLanguage";
+
 	private static final long serialVersionUID = 8666349106632652777L;
 
 	public static final String CONDITION="condition";
@@ -96,6 +98,25 @@
 		}
 	}
 	
+	/**
+	 * 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/Elseif.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Elseif.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Elseif.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -44,7 +44,7 @@
 		super(model, activity);
 
 		org.w3c.dom.Element cond=
-				findElement(Condition.CONDITION);
+				findChildElement(Condition.CONDITION);
 	
 		if (cond == null) {
 			m_condition = new Condition(model);
@@ -78,7 +78,7 @@
 	public void setCondition(Condition cond) {
 		m_condition = cond;
 		
-		setChildElement(findElement(Condition.CONDITION),
+		setChildElement(findChildElement(Condition.CONDITION),
 				cond.getDOMElement(), getDOMElement().getFirstChild());
 	}
 	

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/If.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/If.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/If.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -44,7 +44,7 @@
 		super(model, activity);
 
 		org.w3c.dom.Element cond=
-				findElement(Condition.CONDITION);
+				findChildElement(Condition.CONDITION);
 
 		if (cond == null) {
 			m_condition = new Condition(model);
@@ -122,7 +122,7 @@
 	public void setCondition(Condition cond) {
 		m_condition = cond;
 		
-		setChildElement(findElement(Condition.CONDITION),
+		setChildElement(findChildElement(Condition.CONDITION),
 				cond.getDOMElement(), getDOMElement().getFirstChild());
 	}
 	

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Invoke.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -17,7 +17,6 @@
  */
 package org.jboss.tools.overlord.cdl.bpel.model.component;
 
-import org.scribble.conversation.model.ConversationInteraction;
 import org.scribble.model.*;
 import org.scribble.model.admin.ModelListener;
 import org.jboss.tools.overlord.cdl.bpel.model.*;
@@ -48,11 +47,9 @@
 	 * The constructor for the activity.
 	 * 
 	 * @param model The BPEL model
-	 * @param interaction The conversation
 	 */
-	public Invoke(BPELLanguageModel model,
-				ConversationInteraction interaction) {
-		super(model, INVOKE, interaction);
+	public Invoke(BPELLanguageModel model) {
+		super(model, INVOKE);
 	}
 	
 	/**

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Receive.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Receive.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Receive.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -29,7 +29,8 @@
  */
 public class Receive extends AbstractInteractionActivity {
 
-	private static final String RECEIVE = "receive";
+	public static final String RECEIVE = "receive";
+	
 	private static final long serialVersionUID = -3041725198724191842L;
 
 	/**
@@ -47,11 +48,9 @@
 	 * The constructor for the activity.
 	 * 
 	 * @param model The BPEL model
-	 * @param interaction The conversation
 	 */
-	public Receive(BPELLanguageModel model,
-				ConversationInteraction interaction) {
-		super(model, RECEIVE, interaction);
+	public Receive(BPELLanguageModel model) {
+		super(model, RECEIVE);
 	}
 
 	/**

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Reply.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Reply.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/Reply.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -29,7 +29,8 @@
  */
 public class Reply extends AbstractInteractionActivity {
 
-	private static final String REPLY = "reply";
+	public static final String REPLY = "reply";
+	
 	private static final long serialVersionUID = 8582738107125170604L;
 
 	/**
@@ -47,11 +48,9 @@
 	 * The constructor for the activity.
 	 * 
 	 * @param model The BPEL model
-	 * @param interaction The conversation
 	 */
-	public Reply(BPELLanguageModel model,
-				ConversationInteraction interaction) {
-		super(model, REPLY, interaction);
+	public Reply(BPELLanguageModel model) {
+		super(model, REPLY);
 	}
 
 	/**

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/While.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/While.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/java/org/jboss/tools/overlord/cdl/bpel/model/component/While.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -29,7 +29,8 @@
 public class While extends AbstractGroupingActivity {
 
 	private static final long serialVersionUID = -4173984531470466407L;
-	private static final String WHILE = "while";
+	
+	public static final String WHILE = "while";
 
 	/**
 	 * The constructor for the activity.
@@ -40,6 +41,17 @@
 	public While(BPELLanguageModel model,
 					org.w3c.dom.Element activity) {
 		super(model, activity);
+	
+		org.w3c.dom.Element cond=
+			findChildElement(Condition.CONDITION);
+
+		if (cond == null) {
+			m_condition = new Condition(model);
+		} else {
+			m_condition = new Condition(model, cond);
+		}
+	
+		m_activity = findChildActivity();
 	}
 
 	/**
@@ -73,4 +85,58 @@
 			ConversionContext context) {
 	}
 
+	/**
+	 * This method sets the condition.
+	 * 
+	 * @param cond The condition
+	 */
+	public void setCondition(Condition cond) {
+		m_condition = cond;
+		
+		setChildElement(findChildElement(Condition.CONDITION),
+				cond.getDOMElement(), getDOMElement().getFirstChild());
+	}
+	
+	/**
+	 * This method returns the condition.
+	 * 
+	 * @return The condition
+	 */
+	public Condition getCondition() {
+		return(m_condition);
+	}
+
+	/**
+	 * This method sets the main 'if' activity.
+	 * 
+	 * @param act The activity associated with the 'if'
+	 */
+	public void setActivity(BPELElement act) {
+		m_activity = act;
+		
+		BPELElement existing=findChildActivity();
+		org.w3c.dom.Element existingElem=null;
+		
+		if (existing != null) {
+			existingElem = existing.getDOMElement();
+		}
+
+		org.w3c.dom.Element insertBefore=null;
+		
+		setChildElement(existingElem, act.getDOMElement(),
+						insertBefore);
+	}
+
+	/**
+	 * This method returns the activity associated with
+	 * the 'if' path.
+	 * 
+	 * @return The 'if' activity
+	 */
+	public BPELElement getActivity() {
+		return(m_activity);
+	}
+	
+	private Condition m_condition=null;
+	private BPELElement m_activity=null;
 }

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/ConditionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/ConditionTest.java	2009-03-30 22:30:29 UTC (rev 562)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/ConditionTest.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -93,4 +93,67 @@
 					expr+"' but got '"+result+"'");
 		}		
 	}
+
+	public void testGetExpressionLanguage() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+		Condition condition=new Condition(model);
+		
+		String lang="Test Language";
+		
+		condition.setExpressionLanguage(lang);
+		
+		String result=condition.getExpressionLanguage();
+		
+		if (result == null) {
+			fail("Expression is null");
+		}
+		
+		if (result.equals(lang) == false) {
+			fail("Expression language is not valid: expecting '"+
+					lang+"' but got '"+result+"'");
+		}
+	}
+	
+	public void testGetExpressionLanguageFromDOM() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String lang="TestLanguage";
+		
+		String xml="<condition xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\"" +
+				" expressionLanguage=\""+lang+"\"></condition>";
+		
+		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");
+		}
+		
+		Condition condition=new Condition(model, elem);		
+		
+		String result=condition.getExpressionLanguage();
+		
+		if (result == null) {
+			fail("Expression language is null");
+		}
+		
+		if (result.equals(lang) == false) {
+			fail("Expression language is not valid: expecting '"+
+					lang+"' but got '"+result+"'");
+		}		
+	}
 }

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/WhileTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/WhileTest.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.cdl.bpel/src/test/org/jboss/tools/overlord/cdl/bpel/model/component/WhileTest.java	2009-03-31 20:53:18 UTC (rev 563)
@@ -0,0 +1,336 @@
+/*
+ * 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 WhileTest extends TestCase {
+
+	public void testIsActivity() {
+		While act=new While(new DefaultBPELLanguageModel(null));
+		
+		if (act.isActivity() == false) {
+			fail("Should be an activity");
+		}
+	}
+	
+	public void testIfFromDOM() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String expr1="Test Expression 1";
+		
+		String xml="<while xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+		       "<condition>"+expr1+"</condition>"+
+		       "<sequence/>"+
+		       "</while>";
+		
+		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");
+		}
+		
+		While component=new While(model, elem);		
+		
+		if (component.getCondition() == null) {
+			fail("Condition not set");
+		}
+		
+		String result=component.getCondition().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.getActivity() == null) {
+			fail("Activity not set");
+		}
+		
+		if ((component.getActivity() instanceof Sequence) == false) {
+			fail("Activity not a sequence");
+		}
+	}
+	
+	public void testSetConditionNew() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String expr1="Test Expression 1";
+		
+		String xml="<condition xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+		       expr1+
+		       "</condition>";
+		
+		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");
+		}
+		
+		Condition condition=new Condition(model, elem);
+		
+		While component=new While(model);
+		
+		component.setCondition(condition);
+		
+		if (component.getCondition() == null) {
+			fail("Condition not set");
+		}
+		
+		String result=component.getCondition().getExpression();
+		
+		if (result == null) {
+			fail("Expression is null");
+		}
+		
+		if (result.equals(expr1) == false) {
+			fail("Expression is not valid: expecting '"+
+					expr1+"' but got '"+result+"'");
+		}
+	}	
+	
+	public void testSetConditionReplace() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String expr1="Test Expression 1";
+		String expr2="Test Expression 2";
+		
+		String xml1="<condition xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+	       		expr1+
+	       		"</condition>";
+	
+		String xml2="<condition xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+	       		expr2+
+	       		"</condition>";
+	
+		org.w3c.dom.Element elem1=null;
+		org.w3c.dom.Element elem2=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(xml1.getBytes());
+			
+			org.w3c.dom.Document doc=builder.parse(is);
+			elem1 = doc.getDocumentElement();
+			
+			is.close();
+			
+			is=new java.io.ByteArrayInputStream(xml2.getBytes());
+			
+			doc=builder.parse(is);
+			elem2 = doc.getDocumentElement();
+			
+			is.close();
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		Condition condition1=new Condition(model, elem1);
+		
+		While component=new While(model);
+		
+		component.setCondition(condition1);
+		
+		if (component.getCondition() == null) {
+			fail("Condition not set");
+		}
+		
+		String result=component.getCondition().getExpression();
+		
+		if (result == null) {
+			fail("Expression is null");
+		}
+		
+		if (result.equals(expr1) == false) {
+			fail("Expression1 is not valid: expecting '"+
+					expr1+"' but got '"+result+"'");
+		}
+
+		Condition condition2=new Condition(model, elem2);
+		
+		component.setCondition(condition2);
+		
+		if (component.getCondition() == null) {
+			fail("Condition not set");
+		}
+		
+		result=component.getCondition().getExpression();
+		
+		if (result == null) {
+			fail("Expression is null");
+		}
+		
+		if (result.equals(expr2) == false) {
+			fail("Expression2 is not valid: expecting '"+
+					expr2+"' but got '"+result+"'");
+		}
+	}	
+	
+	public void testSetActivityNew() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String xml="<while xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+		       "<condition/>"+
+		       "</while>";
+		
+		org.w3c.dom.Element ifelem=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);
+			ifelem = doc.getDocumentElement();
+			
+			is.close();
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		While component=new While(model, ifelem);
+
+		if (component.getActivity() != null) {
+			fail("Activity should be null");
+		}
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 1) {
+			fail("One child element expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+		
+		Sequence seq=new Sequence(model);
+		
+		component.setActivity(seq);
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 2) {
+			fail("Two child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+		
+		if (component.getDOMElement().getChildNodes().item(1).
+				getLocalName().equals(Sequence.SEQUENCE) == false) {
+			fail("Second element was not a sequence: "+
+					component.getDOMElement().getChildNodes().item(1).
+									getLocalName());
+		}
+	}	
+	
+	public void testSetActivityReplace() {
+		BPELLanguageModel model=new DefaultBPELLanguageModel(null);
+
+		String xml="<while xmlns=\"http://docs.oasis-open.org/wsbpel/2.0/process/executable\">"+
+		       "<condition/>"+
+		       "<sequence/>"+
+		       "</while>";
+		
+		org.w3c.dom.Element ifelem=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);
+			ifelem = doc.getDocumentElement();
+			
+			is.close();
+		} catch(Exception e) {
+			fail("Failed to convert to doc");
+		}
+		
+		While component=new While(model, ifelem);
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 2) {
+			fail("Two child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+		
+		If sub=new If(model);
+		
+		component.setActivity(sub);
+		
+		if (component.getDOMElement().getChildNodes().getLength() != 2) {
+			fail("Two child elements expected: "+
+					component.getDOMElement().getChildNodes().getLength());
+		}
+		
+		if (component.getDOMElement().getChildNodes().item(1).
+				getLocalName().equals(If.IF) == false) {
+			fail("Second element was not an 'if': "+
+					component.getDOMElement().getChildNodes().item(1).
+									getLocalName());
+		}
+	}	
+}




More information about the overlord-commits mailing list