Author: objectiser
Date: 2010-07-07 17:30:30 -0400 (Wed, 07 Jul 2010)
New Revision: 316
Added:
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospector.java
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/ContractGeneratorTest.java
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospectorTest.java
Removed:
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/tests/ContractGeneratorTest.java
Modified:
trunk/tools/plugins/org.jboss.savara.protocol.contract/META-INF/MANIFEST.MF
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractGeneratorImpl.java
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/META-INF/MANIFEST.MF
Log:
Update uses of the contract model based on changes from list to set, and implemented abit
more of contract generator.
Modified: trunk/tools/plugins/org.jboss.savara.protocol.contract/META-INF/MANIFEST.MF
===================================================================
--- trunk/tools/plugins/org.jboss.savara.protocol.contract/META-INF/MANIFEST.MF 2010-07-07
21:27:59 UTC (rev 315)
+++ trunk/tools/plugins/org.jboss.savara.protocol.contract/META-INF/MANIFEST.MF 2010-07-07
21:30:30 UTC (rev 316)
@@ -10,4 +10,5 @@
Require-Bundle: org.scribble.core,
org.scribble.conversation.model,
org.jboss.savara.contract.model
-Export-Package: org.jboss.savara.protocol.contract
+Export-Package: org.jboss.savara.protocol.contract,
+ org.jboss.savara.protocol.contract.impl
Modified:
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractGeneratorImpl.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractGeneratorImpl.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractGeneratorImpl.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -54,7 +54,12 @@
getString("SAVARAPC-00002"), (Object)null));
}
- return(null);
+ ContractIntrospector introspector=new ContractIntrospector(new Contract(),
+ new java.util.HashSet<Conversation>());
+
+ introspector.process(cm);
+
+ return(introspector.getContract());
}
}
Added:
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospector.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospector.java
(rev 0)
+++
trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospector.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -0,0 +1,134 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.savara.protocol.contract.impl;
+
+import java.util.logging.Logger;
+
+import org.jboss.savara.contract.model.Contract;
+import org.jboss.savara.contract.model.Interface;
+import org.scribble.conversation.model.Conversation;
+import org.scribble.conversation.model.ConversationInteraction;
+import org.scribble.conversation.model.Run;
+import org.scribble.model.ModelObject;
+import org.scribble.model.Role;
+
+/**
+ * This class examines a protocol to determine the contract that represents
+ * the static functional interface to the role's behaviour.
+ *
+ */
+public class ContractIntrospector implements org.scribble.model.Visitor {
+
+ private Contract m_contract=new Contract();
+ private java.util.Set<Conversation> m_processedProtocols=new
java.util.HashSet<Conversation>();
+ private Role m_role=null;
+ private Conversation m_protocol=null;
+
+ private static Logger logger = Logger.getLogger(ContractIntrospector.class.getName());
+
+ /**
+ * Default constructor for the contract introspector.
+ */
+ protected ContractIntrospector(Contract contract, java.util.Set<Conversation>
processed) {
+ m_contract = contract;
+ m_processedProtocols = processed;
+ }
+
+ /**
+ * This method returns the contract being derived.
+ *
+ * @return The contract
+ */
+ public Contract getContract() {
+ return(m_contract);
+ }
+
+ /**
+ * This method returns the set of processed protocols.
+ *
+ * @return The processed protocols
+ */
+ protected java.util.Set<Conversation> getProcessedProtocols() {
+ return(m_processedProtocols);
+ }
+
+ /**
+ * This method introspects the supplied protocol to derive information
+ * that can be used to define the functional contract for the role
+ * associated with the protocol.
+ *
+ * @param conv The located protocol
+ */
+ public void process(Conversation conv) throws IllegalArgumentException {
+ m_protocol = conv;
+ m_role = conv.getLocatedName().getRole();
+
+ // Find or create an interface associated with the role
+ Interface intf=getContract().getInterface(m_role.getName());
+
+ conv.visit(this);
+ }
+
+ @Override
+ public boolean visit(ModelObject obj) {
+ boolean f_visitChildren=true;
+
+ if (obj.getClass() == Conversation.class) {
+
+ // Only visit children if same protocol that is being visited
+ f_visitChildren = (obj == m_protocol);
+
+ } else if (obj.getClass() == Run.class) {
+ Run run=(Run)obj;
+
+ Conversation toProtocol=run.getDefinition();
+
+ // Check if protocol already processed to avoid stack overflow
+ if (m_processedProtocols.contains(toProtocol) == false) {
+ m_processedProtocols.add(toProtocol);
+
+ process(run.getDefinition());
+ }
+ } else if (obj.getClass() == ConversationInteraction.class) {
+ visitInteraction((ConversationInteraction)obj);
+ }
+
+ return(f_visitChildren);
+ }
+
+ protected void visitInteraction(ConversationInteraction interaction) {
+
+ // Check if the interacton is a request or response
+ if (interaction.getFromRole() != null &&
+ interaction.getFromRole().equals(m_role) == false) {
+
+ // Received by the role, but need to check if its replyTo
+ // has been set, indicating it is receiving a response
+ if (interaction.getReplyToLabel() == null ||
+ interaction.getReplyToLabel().trim().length() == 0) {
+
+ // Receiving a request - so record this in the contract
+
+ }
+ }
+ }
+}
Modified:
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -304,8 +304,10 @@
// Check if contract has atleast one message exchange pattern
boolean f_hasMEP=false;
- for (int i=0; f_hasMEP == false && i < contract.getInterfaces().size();
i++) {
- Interface intf=contract.getInterfaces().get(i);
+ java.util.Iterator<Interface> iter=contract.getInterfaces().iterator();
+
+ while (f_hasMEP == false && iter.hasNext()) {
+ Interface intf=iter.next();
f_hasMEP = (intf.getMessageExchangePatterns().size() > 0);
}
@@ -475,8 +477,12 @@
boolean gen=false;
- for (int i=0; gen == false && i < contract.getInterfaces().size(); i++) {
- if (contract.getInterfaces().get(i).getMessageExchangePatterns().size() > 0) {
+ java.util.Iterator<Interface> iter=contract.getInterfaces().iterator();
+
+ while (gen == false && iter.hasNext()) {
+ Interface intf=iter.next();
+
+ if (intf.getMessageExchangePatterns().size() > 0) {
gen = true;
}
}
@@ -522,7 +528,7 @@
Contract contract=(Contract)useRole.getAnnotations().get(Contract.class.getName());
if (contract.getInterfaces().size() > 0) {
- Interface intf=contract.getInterfaces().get(0);
+ Interface intf=contract.getInterfaces().iterator().next();
String prefix=null;
String portType=intf.getName();
@@ -549,7 +555,7 @@
Contract contract=(Contract)role.getAnnotations().get(Contract.class.getName());
if (contract.getInterfaces().size() > 0) {
- Interface intf=contract.getInterfaces().get(0);
+ Interface intf=contract.getInterfaces().iterator().next();
String prefix=null;
String portType=intf.getName();
Modified:
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationChangeRule.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -24,6 +24,7 @@
import org.scribble.model.*;
import org.scribble.model.change.*;
import org.jboss.savara.contract.model.Contract;
+import org.jboss.savara.contract.model.Interface;
import org.scribble.conversation.model.*;
import org.scribble.extensions.RegistryInfo;
@@ -219,8 +220,12 @@
boolean gen=false;
- for (int i=0; gen == false && i < contract.getInterfaces().size(); i++) {
- if (contract.getInterfaces().get(i).getMessageExchangePatterns().size() > 0) {
+ java.util.Iterator<Interface> iter=contract.getInterfaces().iterator();
+
+ while (gen == false && iter.hasNext()) {
+ Interface intf=iter.next();
+
+ if (intf.getMessageExchangePatterns().size() > 0) {
gen = true;
}
}
Modified:
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/ConversationInteractionModelChangeRule.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -135,7 +135,7 @@
// Assume that contract only has one interface for now
if (contract != null && contract.getInterfaces().size() > 0) {
- intf = contract.getInterfaces().get(0);
+ intf = contract.getInterfaces().iterator().next();
}
}
Modified:
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/model/change/IfModelChangeRule.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -260,7 +260,7 @@
contract = ModelChangeUtils.getContract(context, role.getName());
if (contract != null && contract.getInterfaces().size() > 0) {
- Interface intf = contract.getInterfaces().get(0);
+ Interface intf = contract.getInterfaces().iterator().next();
portType = intf.getName();
@@ -288,7 +288,7 @@
contract = ModelChangeUtils.getContract(context, recv.getFromRole().getName());
if (contract != null && contract.getInterfaces().size() > 0) {
- Interface intf = contract.getInterfaces().get(0);
+ Interface intf = contract.getInterfaces().iterator().next();
portType = intf.getName();
Modified:
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -150,8 +150,10 @@
// Check if contract has atleast one message exchange pattern
boolean f_hasMEP=false;
- for (int i=0; f_hasMEP == false && i < contract.getInterfaces().size();
i++) {
- Interface intf=contract.getInterfaces().get(i);
+ java.util.Iterator<Interface> iter=contract.getInterfaces().iterator();
+
+ while (f_hasMEP == false && iter.hasNext()) {
+ Interface intf=iter.next();
f_hasMEP = (intf.getMessageExchangePatterns().size() > 0);
}
Modified:
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java
===================================================================
---
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -23,6 +23,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.savara.contract.model.FaultDetails;
+import org.jboss.savara.contract.model.Interface;
import org.jboss.savara.contract.model.Namespace;
import org.jboss.savara.contract.model.RequestResponseMEP;
import org.scribble.model.TypeReference;
@@ -68,19 +69,21 @@
main.addService(service);
// Define a port type per interface
- for (int i=0; i < contract.getInterfaces().size(); i++) {
+ java.util.Iterator<Interface> iter=contract.getInterfaces().iterator();
+
+ while (iter.hasNext()) {
+ Interface intf=iter.next();
+
javax.wsdl.PortType portType=
- createPortType(ret, contract, contract.getInterfaces().get(i),
- wsdlBinding);
+ createPortType(ret, contract, intf, wsdlBinding);
javax.wsdl.Binding binding=
- createBinding(ret, contract, contract.getInterfaces().get(i),
- portType, wsdlBinding);
+ createBinding(ret, contract, intf, portType, wsdlBinding);
// Create service port for interface
javax.wsdl.Port port=main.createPort();
- port.setName(contract.getInterfaces().get(i).getName()+"Port");
+ port.setName(intf.getName()+"Port");
port.setBinding(binding);
service.addPort(port);
@@ -164,8 +167,10 @@
ret.setTargetNamespace(targetNamespace);
// Set up namespace mappings
- for (int i=0; i < contract.getNamespaces().size(); i++) {
- Namespace ns=contract.getNamespaces().get(i);
+ java.util.Iterator<Namespace> iter=contract.getNamespaces().iterator();
+
+ while (iter.hasNext()) {
+ Namespace ns=iter.next();
ret.addNamespace(ns.getPrefix(), ns.getURI());
}
Modified: trunk/tools/tests/org.jboss.savara.protocol.contract.tests/META-INF/MANIFEST.MF
===================================================================
---
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/META-INF/MANIFEST.MF 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/META-INF/MANIFEST.MF 2010-07-07
21:30:30 UTC (rev 316)
@@ -12,4 +12,4 @@
org.jboss.savara.contract.model,
org.jboss.savara.protocol.contract,
org.junit
-Export-Package: org.jboss.savara.protocol.contract.tests
+Export-Package: org.jboss.savara.protocol.contract
Added:
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/ContractGeneratorTest.java
===================================================================
---
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/ContractGeneratorTest.java
(rev 0)
+++
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/ContractGeneratorTest.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -0,0 +1,66 @@
+package org.jboss.savara.protocol.contract;
+
+import static org.junit.Assert.*;
+
+import org.jboss.savara.protocol.contract.ContractGenerator;
+import org.jboss.savara.protocol.contract.ContractGeneratorFactory;
+import org.scribble.conversation.model.Conversation;
+import org.scribble.model.LocatedName;
+import org.scribble.model.Role;
+
+public class ContractGeneratorTest {
+
+ @org.junit.Test
+ public void testGenerateProtocolNull() {
+
+ ContractGenerator generator=ContractGeneratorFactory.getContractGenerator();
+
+ try {
+ Conversation conv=null;
+
+ generator.generate(conv);
+
+ fail("Should have thrown IllegalArgumentException");
+
+ } catch(IllegalArgumentException iae) {
+ // Test worked
+ }
+ }
+
+ @org.junit.Test
+ public void testGenerateProtocolNotLocated() {
+
+ ContractGenerator generator=ContractGeneratorFactory.getContractGenerator();
+
+ try {
+ Conversation conv=new Conversation();
+ LocatedName ln=new LocatedName();
+ conv.setLocatedName(ln);
+
+ generator.generate(conv);
+
+ fail("Should have thrown IllegalArgumentException");
+
+ } catch(IllegalArgumentException iae) {
+ // Test worked
+ }
+ }
+
+ @org.junit.Test
+ public void testGenerateConversationAndRoleNotNull2() {
+
+ ContractGenerator generator=ContractGeneratorFactory.getContractGenerator();
+
+ try {
+ Conversation conv=new Conversation();
+ LocatedName ln=new LocatedName();
+ ln.setRole(new Role());
+ conv.setLocatedName(ln);
+
+ generator.generate(conv);
+
+ } catch(IllegalArgumentException iae) {
+ fail("Should NOT have thrown IllegalArgumentException");
+ }
+ }
+}
Added:
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospectorTest.java
===================================================================
---
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospectorTest.java
(rev 0)
+++
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospectorTest.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.savara.protocol.contract.impl;
+
+import org.jboss.savara.contract.model.Contract;
+import org.scribble.conversation.model.Conversation;
+import org.scribble.conversation.model.ConversationReference;
+import org.scribble.conversation.model.Run;
+import org.scribble.model.LocatedName;
+import org.scribble.model.Role;
+
+import static org.junit.Assert.*;
+
+public class ContractIntrospectorTest {
+
+ @org.junit.Test
+ public void testNoSubProtocolWithoutRun() {
+ Role r=new Role();
+ r.setName("role");
+
+ LocatedName ln1=new LocatedName();
+ ln1.setName("top");
+ ln1.setRole(r);
+ LocatedName ln2=new LocatedName();
+ ln2.setName("mid");
+ ln2.setRole(r);
+ LocatedName ln3=new LocatedName();
+ ln3.setName("sub");
+ ln3.setRole(r);
+
+ Conversation top=new Conversation();
+ top.setLocatedName(ln1);
+
+ Conversation mid=new Conversation();
+ mid.setLocatedName(ln2);
+
+ Conversation sub=new Conversation();
+ sub.setLocatedName(ln3);
+
+ ConversationReference ref=new ConversationReference();
+ ref.setLocalpart("sub");
+ ref.setLocatedRole(r.getName());
+
+ Run run=new Run();
+ run.setReference(ref);
+
+ top.getBlock().getContents().add(mid);
+
+ mid.getBlock().getContents().add(run);
+ mid.getBlock().getContents().add(sub);
+
+ Contract contract=new Contract();
+ java.util.Set<Conversation> processed=new
java.util.HashSet<Conversation>();
+
+ ContractIntrospector introspector=new ContractIntrospector(contract, processed);
+
+ introspector.process(top);
+
+ if (processed.size() != 0) {
+ fail("Expecting 0 processed protocol, but got: "+processed.size());
+ }
+ }
+
+ @org.junit.Test
+ public void testSubProtocolWithRun() {
+ Role r=new Role();
+ r.setName("role");
+
+ LocatedName ln1=new LocatedName();
+ ln1.setName("top");
+ ln1.setRole(r);
+ LocatedName ln2=new LocatedName();
+ ln2.setName("mid");
+ ln2.setRole(r);
+ LocatedName ln3=new LocatedName();
+ ln3.setName("sub");
+ ln3.setRole(r);
+
+ Conversation top=new Conversation();
+ top.setLocatedName(ln1);
+
+ Conversation mid=new Conversation();
+ mid.setLocatedName(ln2);
+
+ Conversation sub=new Conversation();
+ sub.setLocatedName(ln3);
+
+ ConversationReference ref1=new ConversationReference();
+ ref1.setLocalpart("mid");
+ ref1.setLocatedRole(r.getName());
+ ref1.setInner(true);
+
+ Run run1=new Run();
+ run1.setReference(ref1);
+
+ top.getBlock().getContents().add(run1);
+ top.getBlock().getContents().add(mid);
+
+ ConversationReference ref2=new ConversationReference();
+ ref2.setLocalpart("sub");
+ ref2.setLocatedRole(r.getName());
+ ref2.setInner(true);
+
+ Run run2=new Run();
+ run2.setReference(ref2);
+
+ mid.getBlock().getContents().add(run2);
+ mid.getBlock().getContents().add(sub);
+
+ Contract contract=new Contract();
+ java.util.Set<Conversation> processed=new
java.util.HashSet<Conversation>();
+
+ ContractIntrospector introspector=new ContractIntrospector(contract, processed);
+
+ introspector.process(top);
+
+ if (processed.size() != 2) {
+ fail("Expecting 2 processed protocol, but got: "+processed.size());
+ }
+
+ if (processed.contains(mid) == false) {
+ fail("Should contain mid");
+ }
+
+ if (processed.contains(sub) == false) {
+ fail("Should contain sub");
+ }
+ }
+}
Deleted:
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/tests/ContractGeneratorTest.java
===================================================================
---
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/tests/ContractGeneratorTest.java 2010-07-07
21:27:59 UTC (rev 315)
+++
trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/tests/ContractGeneratorTest.java 2010-07-07
21:30:30 UTC (rev 316)
@@ -1,66 +0,0 @@
-package org.jboss.savara.protocol.contract.tests;
-
-import static org.junit.Assert.*;
-
-import org.jboss.savara.protocol.contract.ContractGenerator;
-import org.jboss.savara.protocol.contract.ContractGeneratorFactory;
-import org.scribble.conversation.model.Conversation;
-import org.scribble.model.LocatedName;
-import org.scribble.model.Role;
-
-public class ContractGeneratorTest {
-
- @org.junit.Test
- public void testGenerateProtocolNull() {
-
- ContractGenerator generator=ContractGeneratorFactory.getContractGenerator();
-
- try {
- Conversation conv=null;
-
- generator.generate(conv);
-
- fail("Should have thrown IllegalArgumentException");
-
- } catch(IllegalArgumentException iae) {
- // Test worked
- }
- }
-
- @org.junit.Test
- public void testGenerateProtocolNotLocated() {
-
- ContractGenerator generator=ContractGeneratorFactory.getContractGenerator();
-
- try {
- Conversation conv=new Conversation();
- LocatedName ln=new LocatedName();
- conv.setLocatedName(ln);
-
- generator.generate(conv);
-
- fail("Should have thrown IllegalArgumentException");
-
- } catch(IllegalArgumentException iae) {
- // Test worked
- }
- }
-
- @org.junit.Test
- public void testGenerateConversationAndRoleNotNull2() {
-
- ContractGenerator generator=ContractGeneratorFactory.getContractGenerator();
-
- try {
- Conversation conv=new Conversation();
- LocatedName ln=new LocatedName();
- ln.setRole(new Role());
- conv.setLocatedName(ln);
-
- generator.generate(conv);
-
- } catch(IllegalArgumentException iae) {
- fail("Should NOT have thrown IllegalArgumentException");
- }
- }
-}