[savara-commits] savara SVN: r319 - in trunk/tools: plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Jul 8 10:49:53 EDT 2010
Author: objectiser
Date: 2010-07-08 10:49:52 -0400 (Thu, 08 Jul 2010)
New Revision: 319
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.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/impl/ContractIntrospectorTest.java
Log:
Added more tests, and changed way introspector is used slightly.
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-08 13:22:47 UTC (rev 318)
+++ trunk/tools/plugins/org.jboss.savara.protocol.contract/META-INF/MANIFEST.MF 2010-07-08 14:49:52 UTC (rev 319)
@@ -11,4 +11,4 @@
org.scribble.conversation.model,
org.jboss.savara.contract.model
Export-Package: org.jboss.savara.protocol.contract,
- org.jboss.savara.protocol.contract.impl
+ org.jboss.savara.protocol.contract.impl;x-friends:="org.jboss.savara.protocol.contract.tests"
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-08 13:22:47 UTC (rev 318)
+++ trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractGeneratorImpl.java 2010-07-08 14:49:52 UTC (rev 319)
@@ -22,7 +22,6 @@
import org.jboss.savara.contract.model.Contract;
import org.jboss.savara.protocol.contract.ContractGenerator;
import org.scribble.conversation.model.Conversation;
-import org.scribble.model.Role;
/**
* This class generates a contract from a protocol defining the behaviour of
@@ -54,10 +53,9 @@
getString("SAVARAPC-00002"), (Object)null));
}
- ContractIntrospector introspector=new ContractIntrospector(new Contract(),
- new java.util.HashSet<Conversation>());
+ ContractIntrospector introspector=new ContractIntrospector(cm);
- introspector.process(cm);
+ introspector.process();
return(introspector.getContract());
}
Modified: 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 2010-07-08 13:22:47 UTC (rev 318)
+++ trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospector.java 2010-07-08 14:49:52 UTC (rev 319)
@@ -21,6 +21,7 @@
*/
package org.jboss.savara.protocol.contract.impl;
+import java.text.MessageFormat;
import java.util.logging.Logger;
import org.jboss.savara.contract.model.Contract;
@@ -39,18 +40,47 @@
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 java.util.Set<Conversation> m_processedProtocols=null;
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.
+ * Constructor for the contract introspector.
+ *
+ * @param protocol The protocol to introspect
*/
- protected ContractIntrospector(Contract contract, java.util.Set<Conversation> processed) {
+ public ContractIntrospector(Conversation protocol) {
+ this(protocol, null, null);
+ }
+
+ /**
+ * Constructor for the contract introspector.
+ *
+ * @param protocol The protocol being introspected
+ * @param contract The optional contract being derived
+ * @param processed The optional set of protocols currently processed
+ */
+ public ContractIntrospector(Conversation protocol, Contract contract,
+ java.util.Set<Conversation> processed) {
m_contract = contract;
- m_processedProtocols = processed;
+
+ if (m_contract == null) {
+ m_contract = new Contract();
+ }
+
+ if (processed != null) {
+ m_processedProtocols = processed;
+ } else {
+ m_processedProtocols = new java.util.HashSet<Conversation>();
+ }
+
+ m_protocol = protocol;
+
+ if (protocol != null) {
+ m_role = protocol.getLocatedName().getRole();
+ }
}
/**
@@ -63,11 +93,30 @@
}
/**
+ * This method returns the interface.
+ *
+ * @return The interface
+ */
+ public Interface getInterface() {
+ Interface ret=getContract().getInterface(m_role.getName());
+
+ if (ret == null) {
+ // Create interface for the role
+ ret = new Interface();
+ ret.setName(m_role.getName());
+
+ getContract().getInterfaces().add(ret);
+ }
+
+ return(ret);
+ }
+
+ /**
* This method returns the set of processed protocols.
*
* @return The processed protocols
*/
- protected java.util.Set<Conversation> getProcessedProtocols() {
+ public java.util.Set<Conversation> getProcessedProtocols() {
return(m_processedProtocols);
}
@@ -78,14 +127,16 @@
*
* @param conv The located protocol
*/
- public void process(Conversation conv) throws IllegalArgumentException {
- m_protocol = conv;
- m_role = conv.getLocatedName().getRole();
+ public void process() throws IllegalStateException {
- // Find or create an interface associated with the role
- Interface intf=getContract().getInterface(m_role.getName());
+ if (m_protocol == null) {
+ throw new IllegalStateException(MessageFormat.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.savara.protocol.contract.Messages").
+ getString("SAVARAPC-00001"), (Object)null));
+ }
- conv.visit(this);
+ m_protocol.visit(this);
}
@Override
@@ -106,7 +157,12 @@
if (m_processedProtocols.contains(toProtocol) == false) {
m_processedProtocols.add(toProtocol);
- process(run.getDefinition());
+ ContractIntrospector ci=new ContractIntrospector(toProtocol,
+ getContract(), getProcessedProtocols());
+
+ ci.process();
+ } else {
+ logger.fine("Invoked definition not found for "+run.getReference());
}
} else if (obj.getClass() == ConversationInteraction.class) {
visitInteraction((ConversationInteraction)obj);
@@ -115,9 +171,15 @@
return(f_visitChildren);
}
- protected void visitInteraction(ConversationInteraction interaction) {
+ /**
+ * This method introspects the supplied interaction to generate Message Exchange
+ * Patterns on the contract interface.
+ *
+ * @param interaction The interaction
+ */
+ public void visitInteraction(ConversationInteraction interaction) {
- // Check if the interacton is a request or response
+ // Check if the interacton is being received
if (interaction.getFromRole() != null &&
interaction.getFromRole().equals(m_role) == false) {
@@ -127,7 +189,11 @@
interaction.getReplyToLabel().trim().length() == 0) {
// Receiving a request - so record this in the contract
+ Interface intf=getContract().getInterface(m_role.getName());
+
+ } else {
+
}
}
}
Modified: 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 2010-07-08 13:22:47 UTC (rev 318)
+++ trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospectorTest.java 2010-07-08 14:49:52 UTC (rev 319)
@@ -21,17 +21,24 @@
*/
package org.jboss.savara.protocol.contract.impl;
-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.ConversationReference;
import org.scribble.conversation.model.Run;
import org.scribble.model.LocatedName;
+import org.scribble.model.MessageSignature;
import org.scribble.model.Role;
+import org.scribble.model.TypeReference;
import static org.junit.Assert.*;
public class ContractIntrospectorTest {
+ private static final String TYPE_NS = "typeNS";
+ private static final String TYPE_LP = "typeLP";
+ private static final String OP_NAME = "opName";
+
@org.junit.Test
public void testNoSubProtocolWithoutRun() {
Role r=new Role();
@@ -68,15 +75,12 @@
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(top);
- ContractIntrospector introspector=new ContractIntrospector(contract, processed);
+ introspector.process();
- introspector.process(top);
-
- if (processed.size() != 0) {
- fail("Expecting 0 processed protocol, but got: "+processed.size());
+ if (introspector.getProcessedProtocols().size() != 0) {
+ fail("Expecting 0 processed protocol, but got: "+introspector.getProcessedProtocols().size());
}
}
@@ -126,23 +130,76 @@
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(top);
- ContractIntrospector introspector=new ContractIntrospector(contract, processed);
+ introspector.process();
- introspector.process(top);
-
- if (processed.size() != 2) {
- fail("Expecting 2 processed protocol, but got: "+processed.size());
+ if (introspector.getProcessedProtocols().size() != 2) {
+ fail("Expecting 2 processed protocol, but got: "+introspector.getProcessedProtocols().size());
}
- if (processed.contains(mid) == false) {
+ if (introspector.getProcessedProtocols().contains(mid) == false) {
fail("Should contain mid");
}
- if (processed.contains(sub) == false) {
+ if (introspector.getProcessedProtocols().contains(sub) == false) {
fail("Should contain sub");
}
}
+
+ @org.junit.Test
+ public void testCreateSingleInterface() {
+ Conversation protocol=new Conversation();
+ Role role=new Role();
+ role.setName("myRole");
+ LocatedName ln=new LocatedName();
+ ln.setRole(role);
+ protocol.setLocatedName(ln);
+
+ ContractIntrospector introspector=new ContractIntrospector(protocol);
+
+ if (introspector.getContract().getInterfaces().size() != 0) {
+ fail("Should be 0 interfaces: "+introspector.getContract().getInterfaces().size());
+ }
+
+ Interface intf=introspector.getInterface();
+
+ if (intf == null) {
+ fail("Interface not created");
+ }
+
+ if (introspector.getContract().getInterfaces().size() != 1) {
+ fail("Should be 1 interface: "+introspector.getContract().getInterfaces().size());
+ }
+
+ Interface intf2=introspector.getInterface();
+
+ if (intf2 != intf) {
+ fail("Interfaces are different");
+ }
+
+ if (introspector.getContract().getInterfaces().size() != 1) {
+ fail("Should still only be 1 interface: "+introspector.getContract().getInterfaces().size());
+ }
+ }
+
+ @org.junit.Test
+ public void testVisitInteractionRequestRPC() {
+ ContractIntrospector introspector=new ContractIntrospector(null);
+
+ ConversationInteraction interaction=new ConversationInteraction();
+
+ MessageSignature msig=new MessageSignature();
+ msig.setOperation(OP_NAME);
+
+ TypeReference tref=new TypeReference();
+ tref.setLocalpart(TYPE_LP);
+ tref.setNamespace(TYPE_NS);
+ msig.getTypes().add(tref);
+
+ interaction.setMessageSignature(msig);
+
+ introspector.visitInteraction(interaction);
+ }
+
}
More information about the savara-commits
mailing list