[savara-commits] savara SVN: r320 - 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 12:56:25 EDT 2010
Author: objectiser
Date: 2010-07-08 12:56:24 -0400 (Thu, 08 Jul 2010)
New Revision: 320
Modified:
trunk/tools/plugins/org.jboss.savara.contract.model/src/java/org/jboss/savara/contract/model/Interface.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 code and tests for creating a request.
Modified: trunk/tools/plugins/org.jboss.savara.contract.model/src/java/org/jboss/savara/contract/model/Interface.java
===================================================================
--- trunk/tools/plugins/org.jboss.savara.contract.model/src/java/org/jboss/savara/contract/model/Interface.java 2010-07-08 14:49:52 UTC (rev 319)
+++ trunk/tools/plugins/org.jboss.savara.contract.model/src/java/org/jboss/savara/contract/model/Interface.java 2010-07-08 16:56:24 UTC (rev 320)
@@ -80,4 +80,27 @@
public java.util.List<MessageExchangePattern> getMessageExchangePatterns() {
return(m_messageExchangePatterns);
}
+
+ /**
+ * This method retrieves an existing message exchange pattern,
+ * associated with the supplied operation name, if one exists.
+ *
+ * @param op The operation
+ * @return The message exchange pattern, or null if not found
+ */
+ public MessageExchangePattern getMessageExchangePatternForOperation(String op) {
+ MessageExchangePattern ret=null;
+
+ java.util.Iterator<MessageExchangePattern> iter=getMessageExchangePatterns().iterator();
+
+ while (ret == null && iter.hasNext()) {
+ ret = iter.next();
+
+ if (op.equals(ret.getOperation()) == false) {
+ ret = null;
+ }
+ }
+
+ return(ret);
+ }
}
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 14:49:52 UTC (rev 319)
+++ trunk/tools/plugins/org.jboss.savara.protocol.contract/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospector.java 2010-07-08 16:56:24 UTC (rev 320)
@@ -26,11 +26,17 @@
import org.jboss.savara.contract.model.Contract;
import org.jboss.savara.contract.model.Interface;
+import org.jboss.savara.contract.model.MessageExchangePattern;
+import org.jboss.savara.contract.model.OneWayRequestMEP;
+import org.jboss.savara.contract.model.RequestResponseMEP;
+import org.jboss.savara.contract.model.Type;
+import org.jboss.savara.contract.model.TypeDefinition;
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;
+import org.scribble.model.TypeReference;
/**
* This class examines a protocol to determine the contract that represents
@@ -189,12 +195,55 @@
interaction.getReplyToLabel().trim().length() == 0) {
// Receiving a request - so record this in the contract
- Interface intf=getContract().getInterface(m_role.getName());
+ Interface intf=getInterface();
-
+ if (interaction.getMessageSignature().getOperation() != null) {
+
+ // Check if message exchange pattern exists for operation
+ MessageExchangePattern mep=intf.getMessageExchangePatternForOperation(
+ interaction.getMessageSignature().getOperation());
+
+ if (mep == null) {
+ // Create new MEP
+ if (interaction.getRequestLabel() != null) {
+ mep = new RequestResponseMEP();
+ } else {
+ mep = new OneWayRequestMEP();
+ }
+
+ mep.setOperation(interaction.getMessageSignature().getOperation());
+
+ for (int i=0; i < interaction.getMessageSignature().getTypes().size(); i++) {
+ mep.getTypes().add(convertType(interaction.getMessageSignature().getTypes().get(i)));
+ }
+
+ intf.getMessageExchangePatterns().add(mep);
+ }
+ }
+
} else {
}
}
}
+
+ /**
+ * This method converts a protocol type reference into a contract model type.
+ *
+ * @param tref The protocol type reference
+ * @return The type
+ */
+ public Type convertType(TypeReference tref) {
+ Type ret=new Type();
+
+ TypeDefinition td=new TypeDefinition();
+ td.setName(tref.getLocalpart());
+ td.setNamespace(tref.getNamespace());
+ //td.setTypeSystem(typeSystem);
+
+ ret.getTypeDefinitions().add(td);
+ ret.setName(td.getName());
+
+ return(ret);
+ }
}
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 14:49:52 UTC (rev 319)
+++ trunk/tools/tests/org.jboss.savara.protocol.contract.tests/src/java/org/jboss/savara/protocol/contract/impl/ContractIntrospectorTest.java 2010-07-08 16:56:24 UTC (rev 320)
@@ -21,7 +21,12 @@
*/
package org.jboss.savara.protocol.contract.impl;
+import org.jboss.savara.contract.model.Contract;
import org.jboss.savara.contract.model.Interface;
+import org.jboss.savara.contract.model.MessageExchangePattern;
+import org.jboss.savara.contract.model.OneWayRequestMEP;
+import org.jboss.savara.contract.model.RequestResponseMEP;
+import org.jboss.savara.contract.model.Type;
import org.scribble.conversation.model.Conversation;
import org.scribble.conversation.model.ConversationInteraction;
import org.scribble.conversation.model.ConversationReference;
@@ -35,6 +40,7 @@
public class ContractIntrospectorTest {
+ private static final String MY_ROLE = "myRole";
private static final String TYPE_NS = "typeNS";
private static final String TYPE_LP = "typeLP";
private static final String OP_NAME = "opName";
@@ -151,7 +157,7 @@
public void testCreateSingleInterface() {
Conversation protocol=new Conversation();
Role role=new Role();
- role.setName("myRole");
+ role.setName(MY_ROLE);
LocatedName ln=new LocatedName();
ln.setRole(role);
protocol.setLocatedName(ln);
@@ -184,9 +190,16 @@
}
@org.junit.Test
- public void testVisitInteractionRequestRPC() {
- ContractIntrospector introspector=new ContractIntrospector(null);
+ public void testVisitInteractionOneWayRequestRPC() {
+ Conversation protocol=new Conversation();
+ Role role=new Role();
+ role.setName(MY_ROLE);
+ LocatedName ln=new LocatedName();
+ ln.setRole(role);
+ protocol.setLocatedName(ln);
+ ContractIntrospector introspector=new ContractIntrospector(protocol);
+
ConversationInteraction interaction=new ConversationInteraction();
MessageSignature msig=new MessageSignature();
@@ -198,8 +211,93 @@
msig.getTypes().add(tref);
interaction.setMessageSignature(msig);
+ interaction.setFromRole(new Role());
introspector.visitInteraction(interaction);
+
+ Contract contract=introspector.getContract();
+
+ Interface intf=contract.getInterface(role.getName());
+
+ if (intf == null) {
+ fail("Interface '"+role.getName()+"' not found");
+ }
+
+ MessageExchangePattern mep=intf.getMessageExchangePatternForOperation(OP_NAME);
+
+ if (mep == null) {
+ fail("Operation '"+OP_NAME+"' not found");
+ }
+
+ if ((mep instanceof OneWayRequestMEP) == false) {
+ fail("Not a oneway request");
+ }
+
+ if (mep.getTypes().size() != 1) {
+ fail("One type expected, but got: "+mep.getTypes().size());
+ }
+
+ Type t=mep.getTypes().get(0);
+
+ if (t.getName().equals(TYPE_LP) == false) {
+ fail("Type name not correct: "+t.getName());
+ }
}
+
+ @org.junit.Test
+ public void testVisitInteractionRequestResponseRPCOnlyRequest() {
+ Conversation protocol=new Conversation();
+ Role role=new Role();
+ role.setName(MY_ROLE);
+ LocatedName ln=new LocatedName();
+ ln.setRole(role);
+ protocol.setLocatedName(ln);
+
+ ContractIntrospector introspector=new ContractIntrospector(protocol);
+
+ 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);
+ interaction.setFromRole(new Role());
+ interaction.setRequestLabel("label");
+
+ introspector.visitInteraction(interaction);
+
+ Contract contract=introspector.getContract();
+
+ Interface intf=contract.getInterface(role.getName());
+
+ if (intf == null) {
+ fail("Interface '"+role.getName()+"' not found");
+ }
+
+ MessageExchangePattern mep=intf.getMessageExchangePatternForOperation(OP_NAME);
+
+ if (mep == null) {
+ fail("Operation '"+OP_NAME+"' not found");
+ }
+
+ if ((mep instanceof RequestResponseMEP) == false) {
+ fail("Not a request/response MEP");
+ }
+
+ if (mep.getTypes().size() != 1) {
+ fail("One type expected, but got: "+mep.getTypes().size());
+ }
+
+ Type t=mep.getTypes().get(0);
+
+ if (t.getName().equals(TYPE_LP) == false) {
+ fail("Type name not correct: "+t.getName());
+ }
+ }
}
More information about the savara-commits
mailing list