Work in progress. Fixed implementation of NodeImpl, now working without dependencies on implementations from other bundles (except RuntimeAssemblyFactory, which will need to be cleaned up too). Started to remove dependencies on host-embedded and port code to NodeFactory and Node, as an interim step to bring them up, before porting them to the OSGi-enabled node launcher.

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@703068 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jsdelfino 2008-10-09 06:33:54 +00:00
parent aacabe1650
commit efe3363a81
162 changed files with 3180 additions and 6788 deletions

View file

@ -25,10 +25,10 @@ import java.io.File;
import junit.framework.Assert;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -40,8 +40,8 @@ import org.junit.Test;
*/
public class CallableReferenceRemoteTestCase {
private static SCANode nodeA;
private static SCANode nodeB;
private static Node nodeA;
private static Node nodeB;
private static AComponent acomponent;
@ -52,21 +52,21 @@ public class CallableReferenceRemoteTestCase {
System.out.println("Setting up nodes");
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
nodeA = nodeFactory.createSCANode(new File("src/main/resources/nodeA/CompositeA.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
nodeA = nodeFactory.createNode(new File("src/main/resources/nodeA/CompositeA.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/nodeA").toURL().toString()));
nodeB = nodeFactory.createSCANode(new File("src/main/resources/nodeB/CompositeB.composite").toURL().toString(),
new SCAContribution("TestContribution",
nodeB = nodeFactory.createNode(new File("src/main/resources/nodeB/CompositeB.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/nodeB").toURL().toString()));
nodeA.start();
nodeB.start();
acomponent = ((SCAClient)nodeA).getService(AComponent.class, "AComponent/AComponent");
acomponent = ((Client)nodeA).getService(AComponent.class, "AComponent/AComponent");
} catch (Throwable ex) {
System.out.println(ex.toString());

View file

@ -24,10 +24,10 @@ import java.io.File;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -35,20 +35,20 @@ import org.junit.Test;
public class ConversationWSDLTestCase {
private SCANode node;
private Node node;
private ConversationalClient conversationalStatelessClientStatefulService;
@Before
public void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ConversationalWSDL/conversationalWSDL.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ConversationalWSDL/conversationalWSDL.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ConversationalWSDL").toURL().toString()));
node.start();
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class, "ConversationalStatelessClientStatefulService");
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class, "ConversationalStatelessClientStatefulService");
ConversationalClientStatelessImpl.calls = new StringBuffer();

View file

@ -29,17 +29,17 @@ import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStat
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulNonConversationalCallbackImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class NonConversationalCallbackTestCase {
private static SCANode node;
private static Node node;
private static ConversationalClient conversationalStatelessClientStatelessService;
private static ConversationalClient conversationalStatelessClientStatefulService;
private static ConversationalClient conversationalStatefulClientStatelessService;
@ -50,28 +50,28 @@ public class NonConversationalCallbackTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/Conversational").toURL().toString()));
node.start();
conversationalStatelessClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatelessService");
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatefulService");
conversationalStatefulClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatelessService");
conversationalStatefulClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatefulService");
conversationalStatelessClientRequestService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientRequestService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientRequestService");
conversationalStatefulClientNonConversationalCallbackStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientNonConversationalCallbackStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientNonConversationalCallbackStatefulService");
// reset the place where we record the sequence of calls passing

View file

@ -30,17 +30,17 @@ import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStat
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceRequestImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class RequestScopeTestCase {
private static SCANode node;
private static Node node;
private static ConversationalClient conversationalStatelessClientStatelessService;
private static ConversationalClient conversationalStatelessClientStatefulService;
private static ConversationalClient conversationalStatefulClientStatelessService;
@ -51,28 +51,28 @@ public class RequestScopeTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/Conversational").toURL().toString()));
node.start();
conversationalStatelessClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatelessService");
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatefulService");
conversationalStatefulClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatelessService");
conversationalStatefulClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatefulService");
conversationalStatelessClientRequestService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientRequestService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientRequestService");
conversationalStatefulClientNonConversationalCallbackStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientNonConversationalCallbackStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientNonConversationalCallbackStatefulService");
// reset the place where we record the sequence of calls passing

View file

@ -29,17 +29,17 @@ import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStat
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStatelessImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class StatefulStatefulTestCase {
private static SCANode node;
private static Node node;
private static ConversationalClient conversationalStatelessClientStatelessService;
private static ConversationalClient conversationalStatelessClientStatefulService;
private static ConversationalClient conversationalStatefulClientStatelessService;
@ -50,28 +50,28 @@ public class StatefulStatefulTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/Conversational").toURL().toString()));
node.start();
conversationalStatelessClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatelessService");
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatefulService");
conversationalStatefulClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatelessService");
conversationalStatefulClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatefulService");
conversationalStatelessClientRequestService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientRequestService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientRequestService");
conversationalStatefulClientNonConversationalCallbackStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientNonConversationalCallbackStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientNonConversationalCallbackStatefulService");
// reset the place where we record the sequence of calls passing

View file

@ -29,17 +29,17 @@ import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStat
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStatelessImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class StatefulStatelessTestCase {
private static SCANode node;
private static Node node;
private static ConversationalClient conversationalStatelessClientStatelessService;
private static ConversationalClient conversationalStatelessClientStatefulService;
private static ConversationalClient conversationalStatefulClientStatelessService;
@ -50,28 +50,28 @@ public class StatefulStatelessTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/Conversational").toURL().toString()));
node.start();
conversationalStatelessClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatelessService");
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatefulService");
conversationalStatefulClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatelessService");
conversationalStatefulClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatefulService");
conversationalStatelessClientRequestService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientRequestService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientRequestService");
conversationalStatefulClientNonConversationalCallbackStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientNonConversationalCallbackStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientNonConversationalCallbackStatefulService");
// reset the place where we record the sequence of calls passing

View file

@ -28,17 +28,17 @@ import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStat
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStatelessImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class StatelessStatefulTestCase {
private static SCANode node;
private static Node node;
private static ConversationalClient conversationalStatelessClientStatelessService;
private static ConversationalClient conversationalStatelessClientStatefulService;
private static ConversationalClient conversationalStatefulClientStatelessService;
@ -49,28 +49,28 @@ public class StatelessStatefulTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/Conversational").toURL().toString()));
node.start();
conversationalStatelessClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatelessService");
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatefulService");
conversationalStatefulClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatelessService");
conversationalStatefulClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatefulService");
conversationalStatelessClientRequestService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientRequestService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientRequestService");
conversationalStatefulClientNonConversationalCallbackStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientNonConversationalCallbackStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientNonConversationalCallbackStatefulService");
// reset the place where we record the sequence of calls passing

View file

@ -28,17 +28,17 @@ import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStat
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalClientStatelessImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatefulImpl;
import org.apache.tuscany.sca.itest.conversational.impl.ConversationalServiceStatelessImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class StatelessStatelessTestCase {
private static SCANode node;
private static Node node;
private static ConversationalClient conversationalStatelessClientStatelessService;
private static ConversationalClient conversationalStatelessClientStatefulService;
private static ConversationalClient conversationalStatefulClientStatelessService;
@ -49,28 +49,28 @@ public class StatelessStatelessTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/Conversational/conversational.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/Conversational").toURL().toString()));
node.start();
conversationalStatelessClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatelessService");
conversationalStatelessClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientStatefulService");
conversationalStatefulClientStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatelessService");
conversationalStatefulClientStatefulService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientStatefulService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientStatefulService");
conversationalStatelessClientRequestService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatelessClientRequestService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatelessClientRequestService");
conversationalStatefulClientNonConversationalCallbackStatelessService = ((SCAClient)node).getService(ConversationalClient.class,
conversationalStatefulClientNonConversationalCallbackStatelessService = ((Client)node).getService(ConversationalClient.class,
"ConversationalStatefulClientNonConversationalCallbackStatefulService");
// reset the place where we record the sequence of calls passing

View file

@ -27,9 +27,9 @@ import java.util.Map;
import junit.framework.Assert;
import org.apache.tuscany.sca.itest.databindings.jaxb.HelloServiceClient;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -39,8 +39,8 @@ import org.junit.Test;
*/
public class DatabindingTestCase {
private static SCAClient client;
private static SCANode node;
private static Client client;
private static Node node;
/**
* Runs once before running the tests
@ -48,10 +48,10 @@ public class DatabindingTestCase {
@BeforeClass
public static void setUp() throws Exception {
try {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createSCANodeFromClassLoader("wsdl/wrapped/helloservice.composite", null);
node.start();
client = (SCAClient)node;
client = (Client)node;
}catch(Throwable e) {
e.printStackTrace();
}

View file

@ -22,9 +22,9 @@ package org.apache.tuscany.sca.itest.databindings.jaxb.topdown;
import junit.framework.Assert;
import org.apache.tuscany.sca.itest.databindings.jaxb.PrimitivesServiceClient;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -34,18 +34,18 @@ import org.junit.Test;
*/
public class PrimitivesDatabindingTestCase {
private static SCAClient domain;
private static SCANode node;
private static Client domain;
private static Node node;
/**
* Runs before each test method
*/
@BeforeClass
public static void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createSCANodeFromClassLoader("wsdl/wrapped/primitivesservice.composite", null);
node.start();
domain = (SCAClient)node;
domain = (Client)node;
}
/**

View file

@ -55,9 +55,9 @@ import org.apache.axiom.attachments.ByteArrayDataSource;
import org.apache.tuscany.sca.databinding.xml.String2Node;
import org.apache.tuscany.sca.itest.databindings.jaxb.StandardTypesServiceClient;
import org.apache.tuscany.sca.itest.databindings.jaxb.impl.StandardTypesTransformer;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
@ -69,18 +69,18 @@ import org.xml.sax.InputSource;
*/
public class StandardTypesDatabindingTestCase {
private static SCAClient domain;
private static SCANode node;
private static Client domain;
private static Node node;
/**
* Runs once before the tests
*/
@BeforeClass
public static void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createSCANodeFromClassLoader("wsdl/wrapped/standard-types-service.composite", null);
node.start();
domain = (SCAClient)node;
domain = (Client)node;
}
/**

View file

@ -23,10 +23,10 @@ import java.io.File;
import junit.framework.Assert;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.launcher.DomainManagerLauncher;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -38,9 +38,9 @@ import org.junit.Test;
*/
public class LateReferenceResolutionTestCase {
private static SCANode nodeA;
private static SCANode nodeB;
private static SCANode nodeC;
private static Node nodeA;
private static Node nodeB;
private static Node nodeC;
private static CalculatorService calculatorService;
@ -53,22 +53,22 @@ public class LateReferenceResolutionTestCase {
System.out.println("Setting up domain");
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
nodeC = nodeFactory.createSCANode(new File("src/main/resources/nodeC/Calculator.composite").toURL().toString(),
new SCAContribution("NodeC",
NodeFactory nodeFactory = NodeFactory.newInstance();
nodeC = nodeFactory.createNode(new File("src/main/resources/nodeC/Calculator.composite").toURL().toString(),
new Contribution("NodeC",
new File("src/main/resources/nodeC").toURL().toString()));
nodeB = nodeFactory.createSCANode(new File("src/main/resources/nodeB/Calculator.composite").toURL().toString(),
new SCAContribution("NodeB",
nodeB = nodeFactory.createNode(new File("src/main/resources/nodeB/Calculator.composite").toURL().toString(),
new Contribution("NodeB",
new File("src/main/resources/nodeB").toURL().toString()));
nodeA = nodeFactory.createSCANode(new File("src/main/resources/nodeA/Calculator.composite").toURL().toString(),
new SCAContribution("NodeA",
nodeA = nodeFactory.createNode(new File("src/main/resources/nodeA/Calculator.composite").toURL().toString(),
new Contribution("NodeA",
new File("src/main/resources/nodeA").toURL().toString()));
nodeC.start();
nodeB.start();
nodeA.start();
SCAClient client = (SCAClient)nodeA;
Client client = (Client)nodeA;
calculatorService =
client.getService(CalculatorService.class, "CalculatorServiceComponentA");

View file

@ -30,9 +30,9 @@ import junit.framework.Assert;
import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
import org.apache.tuscany.sca.itest.oneway.impl.OneWayClientImpl;
import org.apache.tuscany.sca.itest.oneway.impl.OneWayServiceImpl;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -49,7 +49,7 @@ public class OneWayTestCase {
*/
private static final int MAX_SLEEP_TIME = 10000;
private SCANode node;
private Node node;
/**
* Initialise the SCADomain.
@ -59,7 +59,7 @@ public class OneWayTestCase {
@Before
public void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createSCANodeFromClassLoader("OneWayContribution/META-INF/sca-deployables/oneWay.composite", null);
node.start();
@ -84,7 +84,7 @@ public class OneWayTestCase {
@Test
public void testOneWay() throws Exception {
OneWayClient client =
((SCAClient)node).getService(OneWayClient.class, "OneWayClientComponent");
((Client)node).getService(OneWayClient.class, "OneWayClientComponent");
int count = 100;
@ -120,7 +120,7 @@ public class OneWayTestCase {
@Test
public void testOneWayUsingNonBlockingInterceptorThrowsAnException() {
OneWayClient client =
((SCAClient)node).getService(OneWayClient.class, "OneWayClientComponentSCABinding");
((Client)node).getService(OneWayClient.class, "OneWayClientComponentSCABinding");
// We need to modify the JDK Logger for the NonBlockingInterceptor so we
// can check that it logs a message for the @OneWay invocation that throws

View file

@ -24,9 +24,9 @@ import java.io.ByteArrayInputStream;
import junit.framework.Assert;
import helloworld.HelloWorldService;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.ws.security.util.Base64;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -39,18 +39,18 @@ import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
public class BasicAuthTestCase {
private static SCANode node;
private static Node node;
private static HelloWorldService service;
@BeforeClass
public static void init() throws Exception {
try {
SCANodeFactory factory = SCANodeFactory.newInstance();
NodeFactory factory = NodeFactory.newInstance();
node = factory.createSCANodeFromClassLoader("helloworld.composite",
BasicAuthTestCase.class.getClassLoader());
node.start();
service = ((SCAClient)node).getService(HelloWorldService.class, "HelloWorldClientComponent");
service = ((Client)node).getService(HelloWorldService.class, "HelloWorldClientComponent");
} catch (Exception ex) {
ex.printStackTrace();
}

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,13 +39,13 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class ComponentReferenceTargetNotFoundTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ComponentReferenceTargetNotFound/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ComponentReferenceTargetNotFound/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ComponentReferenceTargetNotFound").toURL().toString()));
try {
@ -54,7 +54,7 @@ public class ComponentReferenceTargetNotFoundTestCase extends TestCase {
// do nothing - the SCA binding throws and exception here
// because the interface for the reference is not remotable
}
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,22 +27,22 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
* This shows how to test the Calculator service component.
*/
public class DuplicateImplementationPropertyNameTestCase extends TestCase {
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/DuplicateImplementationPropertyName/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/DuplicateImplementationPropertyName/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/DuplicateImplementationPropertyName").toURL().toString()));
}

View file

@ -27,9 +27,9 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -37,13 +37,13 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
*/
public class DuplicateImplementationReferenceNameTestCase extends TestCase {
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/DuplicateImplementationReferenceName/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/DuplicateImplementationReferenceName/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/DuplicateImplementationReferenceName").toURL().toString()));
}

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class DuplicatePropertyNameTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/DuplicatePropertyName/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/DuplicatePropertyName/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/DuplicatePropertyName").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class DuplicateReferenceNameTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/DuplicateReferenceName/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/DuplicateReferenceName/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/DuplicateReferenceName").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class MultipleBindingsForServiceTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/MultipleBindingsForService/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/MultipleBindingsForService/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/MultipleBindingsForService").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,9 +27,9 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -38,13 +38,13 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class NoComponentImplementationTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/NoComponentImplementation/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/NoComponentImplementation/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/NoComponentImplementation").toURL().toString()));
}

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class NoCompositeNamespaceTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/NoCompositeNamespace/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/NoCompositeNamespace/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/NoCompositeNamespace").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,17 +39,17 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class NoMatchingBindingTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
NodeFactory nodeFactory = NodeFactory.newInstance();
node =
nodeFactory.createSCANode("Calculator.composite", new SCAContribution("TestContribution", new File("src/main/resources/NoMatchingBinding")
nodeFactory.createNode("Calculator.composite", new Contribution("TestContribution", new File("src/main/resources/NoMatchingBinding")
.toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class PromotedReferenceNotFoundTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/PromotedReferenceNotFound/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/PromotedReferenceNotFound/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/PromotedReferenceNotFound").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class PromotedServiceNotFoundTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/PromotedServiceNotFound/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/PromotedServiceNotFound/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/PromotedServiceNotFound").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class PropertyAttributeMustSupplyNullTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/PropertyAttribute/CalculatorNullMustSupply.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/PropertyAttribute/CalculatorNullMustSupply.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/PropertyAttribute").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class PropertyAttributeTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/PropertyAttribute/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/PropertyAttribute/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/PropertyAttribute").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class PropertyNotFoundTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/PropertyNotFound/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/PropertyNotFound/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/PropertyNotFound").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class PropertyOverrideManyAttributeTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/PropertyAttribute/CalculatorOverrideManyAttribute.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/PropertyAttribute/CalculatorOverrideManyAttribute.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/PropertyAttribute").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class ReferenceIncompatibleComponentInterfaceTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ReferenceIncompatibleComponentInterface/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ReferenceIncompatibleComponentInterface/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ReferenceIncompatibleComponentInterface").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class ReferenceIncompatibleInterfaceTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ReferenceIncompatibleInterface/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ReferenceIncompatibleInterface/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ReferenceIncompatibleInterface").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class ReferenceIncompatibleMultiplicityTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ReferenceIncompatibleMultiplicity/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ReferenceIncompatibleMultiplicity/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ReferenceIncompatibleMultiplicity").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class ReferenceWithoutTargetsTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ReferenceWithoutTargets/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ReferenceWithoutTargets/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ReferenceWithoutTargets").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,10 +27,10 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -39,16 +39,16 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class ServiceNotFoundForComponentServiceTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/ServiceNotFoundForComponentService/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/ServiceNotFoundForComponentService/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/ServiceNotFoundForComponentService").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
}
@Override

View file

@ -27,9 +27,9 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
/**
@ -38,13 +38,13 @@ import org.apache.tuscany.sca.node.impl.NodeImpl;
public class UnresolvedComponentImplementationTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
node = nodeFactory.createSCANode(new File("src/main/resources/UnresolvedComponentImplementation/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
NodeFactory nodeFactory = NodeFactory.newInstance();
node = nodeFactory.createNode(new File("src/main/resources/UnresolvedComponentImplementation/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/UnresolvedComponentImplementation").toURL().toString()));
}

View file

@ -22,10 +22,10 @@ import java.io.File;
import junit.framework.TestCase;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
/**
* This shows how to test the Calculator service component.
@ -33,18 +33,18 @@ import org.apache.tuscany.sca.node.SCANodeFactory;
public class XSDValidationTestCase extends TestCase {
private CalculatorService calculatorService;
private SCANode node;
private Node node;
private Exception startUpException;
@Override
protected void setUp() throws Exception {
SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
NodeFactory nodeFactory = NodeFactory.newInstance();
try {
node = nodeFactory.createSCANode(new File("src/main/resources/XsdValidation/Calculator.composite").toURL().toString(),
new SCAContribution("TestContribution",
node = nodeFactory.createNode(new File("src/main/resources/XsdValidation/Calculator.composite").toURL().toString(),
new Contribution("TestContribution",
new File("src/main/resources/XsdValidation").toURL().toString()));
node.start();
calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent");
calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");
} catch (Exception ex){
startUpException = ex;
}

View file

@ -162,7 +162,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -8,37 +8,53 @@ import org.apache.abdera.Abdera;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Client;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class AtomDeleteTestCase {
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static Node consumerNode;
protected static Node providerNode;
protected static CustomerClient testService;
protected static Abdera abdera;
@BeforeClass
public static void init() throws Exception {
try{
System.out.println(">>>AtomDeleteTestCase.init entry");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
providerNode.start();
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterClass
public static void destroy() throws Exception {
// System.out.println(">>>AtomDeleteTestCase.destroy entry");
scaConsumerDomain.close();
scaProviderDomain.close();
consumerNode.stop();
consumerNode.destroy();
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull(scaConsumerDomain);
Assert.assertNotNull(providerNode);
Assert.assertNotNull(consumerNode);
Assert.assertNotNull(testService);
Assert.assertNotNull(abdera);
}

View file

@ -6,37 +6,47 @@ import org.apache.abdera.Abdera;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class AtomGetTestCase {
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static Node consumerNode;
protected static Node providerNode;
protected static CustomerClient testService;
protected static Abdera abdera;
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>AtomGetTestCase.init entry");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
providerNode.start();
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
}
@AfterClass
public static void destroy() throws Exception {
// System.out.println(">>>AtomGetTestCase.destroy entry");
scaConsumerDomain.close();
scaProviderDomain.close();
consumerNode.stop();
consumerNode.destroy();
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull(scaConsumerDomain);
Assert.assertNotNull(providerNode);
Assert.assertNotNull(consumerNode);
Assert.assertNotNull(testService);
Assert.assertNotNull(abdera);
}

View file

@ -6,37 +6,47 @@ import org.apache.abdera.Abdera;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class AtomPostTestCase {
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static Node consumerNode;
protected static Node providerNode;
protected static CustomerClient testService;
protected static Abdera abdera;
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>AtomPostTestCase.init entry");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
providerNode.start();
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>AtomPostTestCase.destroy entry");
scaConsumerDomain.close();
scaProviderDomain.close();
consumerNode.stop();
consumerNode.destroy();
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull(scaConsumerDomain);
Assert.assertNotNull(providerNode);
Assert.assertNotNull(consumerNode);
Assert.assertNotNull(testService);
Assert.assertNotNull(abdera);
}

View file

@ -8,37 +8,47 @@ import org.apache.abdera.Abdera;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class AtomPutTestCase {
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static Node consumerNode;
protected static Node providerNode;
protected static CustomerClient testService;
protected static Abdera abdera;
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>AtomPutTestCase.init entry");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
providerNode.start();
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
}
@AfterClass
public static void destroy() throws Exception {
// System.out.println(">>>AtomPutTestCase.destroy entry");
scaConsumerDomain.close();
scaProviderDomain.close();
consumerNode.stop();
consumerNode.destroy();
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull(scaConsumerDomain);
Assert.assertNotNull(providerNode);
Assert.assertNotNull(consumerNode);
Assert.assertNotNull(testService);
Assert.assertNotNull(abdera);
}

View file

@ -19,17 +19,24 @@
package org.apache.tuscany.sca.binding.atom;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Consumer {
public static void main(String[] args) throws Exception {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
node.start();
CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient");
CustomerClient testService = node.getService(CustomerClient.class, "CustomerClient");
testService.testCustomerCollection();
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -27,7 +27,10 @@ import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -37,119 +40,126 @@ import org.junit.Test;
*/
public class ConsumerProviderAtomTestCase {
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static CustomerClient testService;
protected static Abdera abdera;
protected static Node consumerNode;
protected static Node providerNode;
protected static CustomerClient testService;
protected static Abdera abdera;
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>AtomBindingIntegratedTestCase.init entry");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
testService = scaConsumerDomain.getService(CustomerClient.class,"CustomerClient");
abdera = new Abdera();
}
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>AtomBindingIntegratedTestCase.init entry");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
providerNode.start();
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry");
scaConsumerDomain.close();
scaProviderDomain.close();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>AtomBindingIntegratedTestCase.destroy entry");
consumerNode.stop();
consumerNode.destroy();
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull(scaConsumerDomain);
Assert.assertNotNull(testService);
Assert.assertNotNull(abdera);
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(providerNode);
Assert.assertNotNull(consumerNode);
Assert.assertNotNull(testService);
Assert.assertNotNull(abdera);
}
@Test
public void testEntry() throws Exception {
// System.out.println( getClass().getName() + ".testEntry entry" );
Entry entry = abdera.newEntry();
Assert.assertNotNull(entry);
@Test
public void testEntry() throws Exception {
// System.out.println( getClass().getName() + ".testEntry entry" );
Entry entry = abdera.newEntry();
Assert.assertNotNull(entry);
String testTitle = "Sponge Bob";
entry.setTitle(testTitle);
Assert.assertEquals(testTitle, entry.getTitle());
String testTitle = "Sponge Bob";
entry.setTitle(testTitle);
Assert.assertEquals(testTitle, entry.getTitle());
String testContent = "This is the content";
entry.setContent(testContent);
Assert.assertEquals(testContent, entry.getContent());
String testContent = "This is the content";
entry.setContent(testContent);
Assert.assertEquals(testContent, entry.getContent());
Date now = new Date();
entry.setEdited(now);
Assert.assertEquals(now, entry.getEdited());
Date now = new Date();
entry.setEdited(now);
Assert.assertEquals(now, entry.getEdited());
Date later = new Date();
entry.setPublished(later);
Assert.assertEquals(later, entry.getPublished());
Date later = new Date();
entry.setPublished(later);
Assert.assertEquals(later, entry.getPublished());
String testSummary = "This is the summary";
entry.setSummary(testSummary);
Assert.assertEquals(testSummary, entry.getSummary());
}
String testSummary = "This is the summary";
entry.setSummary(testSummary);
Assert.assertEquals(testSummary, entry.getSummary());
}
@Test
public void testCustomerCollection() throws Exception {
System.out.println(getClass().getName() + ".testCustomerCollection entry");
Collection resourceCollection = testService.getCustomerCollection();
Assert.assertNotNull(resourceCollection);
Entry newEntry = newEntry("Sponge Bob");
System.out.println(">>> post entry=" + newEntry.getTitle());
newEntry = resourceCollection.post(newEntry);
System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
@Test
public void testCustomerCollection() throws Exception {
System.out.println(getClass().getName() + ".testCustomerCollection entry");
Collection resourceCollection = testService.getCustomerCollection();
Assert.assertNotNull(resourceCollection);
newEntry = newEntry("Jane Bond");
System.out.println(">>> post entry=" + newEntry.getTitle());
newEntry = resourceCollection.post(newEntry);
System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
Entry newEntry = newEntry("Sponge Bob");
System.out.println(">>> post entry=" + newEntry.getTitle());
newEntry = resourceCollection.post(newEntry);
System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
System.out.println(">>> get id=" + newEntry.getId());
Entry entry = resourceCollection.get(newEntry.getId().toString());
System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle());
newEntry = newEntry("Jane Bond");
System.out.println(">>> post entry=" + newEntry.getTitle());
newEntry = resourceCollection.post(newEntry);
System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle());
System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle());
resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond"));
System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle());
System.out.println(">>> get id=" + newEntry.getId());
Entry entry = resourceCollection.get(newEntry.getId().toString());
System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle());
System.out.println(">>> delete id=" + entry.getId());
resourceCollection.delete(entry.getId().toString());
System.out.println("<<< delete id=" + entry.getId());
System.out.println(">>> get collection");
Feed feed = resourceCollection.getFeed();
System.out.println("<<< get collection");
for (Object o : feed.getEntries()) {
Entry e = (Entry)o;
System.out.println("id = " + e.getId() + " entry = " + e.getTitle());
}
}
System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle());
resourceCollection.put(entry.getId().toString(), updateEntry(entry, "James Bond"));
System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle());
private Entry newEntry(String value) {
Entry entry = abdera.newEntry();
entry.setTitle("customer " + value);
System.out.println(">>> delete id=" + entry.getId());
resourceCollection.delete(entry.getId().toString());
System.out.println("<<< delete id=" + entry.getId());
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(value);
entry.setContentElement(content);
System.out.println(">>> get collection");
Feed feed = resourceCollection.getFeed();
System.out.println("<<< get collection");
for (Object o : feed.getEntries()) {
Entry e = (Entry)o;
System.out.println("id = " + e.getId() + " entry = " + e.getTitle());
}
}
return entry;
}
private Entry newEntry(String value) {
Entry entry = abdera.newEntry();
entry.setTitle("customer " + value);
private Entry updateEntry(Entry entry, String value) {
entry.setTitle("customer " + value);
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(value);
entry.setContentElement(content);
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(value);
entry.setContentElement(content);
return entry;
}
return entry;
}
}
private Entry updateEntry(Entry entry, String value) {
entry.setTitle("customer " + value);
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(value);
entry.setContentElement(content);
return entry;
}
}

View file

@ -20,230 +20,246 @@ package org.apache.tuscany.sca.binding.atom;
import java.io.IOException;
import java.io.Reader;
import java.text.SimpleDateFormat;
import java.util.Date;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Base;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Service;
import org.apache.abdera.parser.Parser;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
import org.apache.abdera.protocol.client.util.BaseRequestEntity;
import org.apache.abdera.util.EntityTag;
import org.apache.abdera.parser.Parser;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Tests use of content negotiation for Atom binding in Tuscany.
* Uses the SCA provided Provider composite to act as a server.
* Uses the Abdera provided Client to act as a client.
* Tests use of content negotiation for Atom binding in Tuscany. Uses the SCA
* provided Provider composite to act as a server. Uses the Abdera provided
* Client to act as a client.
*/
public class ContentNegotiationTest {
public final static String providerURI = "http://localhost:8084/customer";
protected static SCADomain scaProviderDomain;
protected static CustomerClient testService;
public final static String providerURI = "http://localhost:8084/customer";
protected static Node providerNode;
protected static Abdera abdera;
protected static AbderaClient client;
protected static Parser abderaParser;
protected static Parser abderaParser;
protected static String lastId;
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>ContentNegotiationTest.init");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>ContentNegotiationTest.init");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
providerNode.start();
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>ContentNegotiationTest.destroy");
scaProviderDomain.close();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>ContentNegotiationTest.destroy");
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull( client );
}
@Test
public void testPost() throws Exception {
System.out.println(">>>ContentNegotiationTest.testPost");
// Testing of entry creation
Factory factory = abdera.getFactory();
String customerName = "Fred Farkle";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
// ID created by collection.
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
public void testPrelim() throws Exception {
Assert.assertNotNull(providerNode);
Assert.assertNotNull(client);
}
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
// AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts );
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
ClientResponse res = client.post(colUri.toString(), entry, opts);
// Assert response status code is 201-OK.
// Assert response header Content-Type: application/atom+xml; charset=UTF-8
Assert.assertEquals(201, res.getStatus());
String returnedContentType = res.getContentType().toString().trim();
Assert.assertEquals(contentType, returnedContentType );
@Test
public void testPost() throws Exception {
System.out.println(">>>ContentNegotiationTest.testPost");
// Testing of entry creation
Factory factory = abdera.getFactory();
String customerName = "Fred Farkle";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
// ID created by collection.
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
String eTag = res.getHeader( "ETag" );
if ( eTag != null)
lastId = eTag.substring( 1, eTag.length()-1);
// AtomTestCaseUtils.printResponseHeaders( "Entry post response headers:", " ", res );
// System.out.println("Entry post response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
}
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
// AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ",
// opts );
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
ClientResponse res = client.post(colUri.toString(), entry, opts);
@Test
public void testXMLEntryGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testXMLEntryGet");
RequestOptions opts = new RequestOptions();
opts.setHeader( "Accept", "application/atom+xml" );
IRI colUri = new IRI(providerURI).resolve("customer");
ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
Assert.assertEquals(200, res.getStatus());
String returnedContentType = res.getContentType().toString().trim();
// Assert.assertEquals(contentType, returnedContentType );
res.release();
}
// Assert response status code is 201-OK.
// Assert response header Content-Type: application/atom+xml;
// charset=UTF-8
Assert.assertEquals(201, res.getStatus());
String returnedContentType = res.getContentType().toString().trim();
Assert.assertEquals(contentType, returnedContentType);
@Test
public void testJSONEntryGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testJSONEntryGet");
RequestOptions opts = new RequestOptions();
opts.setHeader( "Accept", "application/json" );
IRI colUri = new IRI(providerURI).resolve("customer");
ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
try {
Assert.assertEquals(200, res.getStatus());
// Abdera 0.4 throws exception on getContentType with application/json.
// System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
String contentType = res.getHeader( "Content-Type");
Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
// Following is a poor man's JSONObject test to avoid dependency on JSON libs.
// JSONObject jsonResp = new JSONObject(res.);
// Assert.assertEquals(12345, jsonResp.getInt("result"));
String responseBody = readResponse( res.getReader() );
Assert.assertTrue( responseBody.startsWith( "{") );
Assert.assertTrue( responseBody.endsWith( "}") );
Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
// AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res );
// System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
} finally {
res.release();
}
}
String eTag = res.getHeader("ETag");
if (eTag != null)
lastId = eTag.substring(1, eTag.length() - 1);
@Test
public void testXMLFeedGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testXMLFeedGet");
RequestOptions opts = new RequestOptions();
opts.setHeader( "Accept", "application/atom+xml" );
// Atom feed request
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Asser feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
// AtomTestCaseUtils.printResponseHeaders(
// "Entry post response headers:", " ", res );
// System.out.println("Entry post response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
}
// Perform other tests on feed.
Document<Feed> doc = res.getDocument();
Assert.assertNotNull( doc );
Feed feed = doc.getRoot();
Assert.assertNotNull( feed );
// RFC 4287 requires non-null id, title, updated elements
Assert.assertNotNull( feed.getId() );
Assert.assertNotNull( feed.getTitle() );
Assert.assertNotNull( feed.getUpdated() );
// AtomTestCaseUtils.printFeed( "Feed values", " ", feed );
} finally {
res.release();
}
}
@Test
public void testXMLEntryGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testXMLEntryGet");
RequestOptions opts = new RequestOptions();
opts.setHeader("Accept", "application/atom+xml");
@Test
public void testJSONFeedGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testJSONFeedGet");
RequestOptions opts = new RequestOptions();
opts.setHeader( "Accept", "application/json" );
// JSON feed request
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Assert feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
// Abdera 0.4 throws exception on getContentType with application/json.
// System.out.println( "ContentNegotiationTest.testJSONEntryGet contentType=" + res.getContentType());
String contentType = res.getHeader( "Content-Type");
Assert.assertTrue( -1 < contentType.indexOf( "application/json" ));
// Following is a poor man's JSONObject test to avoid dependency on JSON libs.
// JSONObject jsonResp = new JSONObject(res.);
// Assert.assertEquals(12345, jsonResp.getInt("result"));
String responseBody = readResponse( res.getReader() );
Assert.assertTrue( responseBody.startsWith( "{") );
Assert.assertTrue( responseBody.endsWith( "}") );
Assert.assertTrue( -1 < responseBody.indexOf( "\"id\"" ));
Assert.assertTrue( -1 < responseBody.indexOf( "\"title\"" ));
Assert.assertTrue( -1 < responseBody.indexOf( "\"updated\"" ));
Assert.assertTrue( -1 < responseBody.indexOf( "\"entries\"" ));
// AtomTestCaseUtils.printResponseHeaders( "JSON Entry response headers:", " ", res );
// System.out.println( "ContentNegotiationTest.testJSONEntryGet JSON entry body=" + responseBody );
} finally {
res.release();
}
}
protected String readResponse( Reader responseReader ) {
if ( responseReader == null ) return "";
StringBuffer sb = new StringBuffer(1024);
try {
int charValue = 0;
while ((charValue = responseReader.read()) != -1) {
//result = result + (char) charValue;
sb.append((char)charValue);
}
} catch ( IOException e ) {
}
return sb.toString();
}
IRI colUri = new IRI(providerURI).resolve("customer");
ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
Assert.assertEquals(200, res.getStatus());
String returnedContentType = res.getContentType().toString().trim();
// Assert.assertEquals(contentType, returnedContentType );
res.release();
}
@Test
public void testJSONEntryGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testJSONEntryGet");
RequestOptions opts = new RequestOptions();
opts.setHeader("Accept", "application/json");
IRI colUri = new IRI(providerURI).resolve("customer");
ClientResponse res = client.get(colUri.toString() + "/" + lastId, opts);
try {
Assert.assertEquals(200, res.getStatus());
// Abdera 0.4 throws exception on getContentType with
// application/json.
// System.out.println(
// "ContentNegotiationTest.testJSONEntryGet contentType=" +
// res.getContentType());
String contentType = res.getHeader("Content-Type");
Assert.assertTrue(-1 < contentType.indexOf("application/json"));
// Following is a poor man's JSONObject test to avoid dependency on
// JSON libs.
// JSONObject jsonResp = new JSONObject(res.);
// Assert.assertEquals(12345, jsonResp.getInt("result"));
String responseBody = readResponse(res.getReader());
Assert.assertTrue(responseBody.startsWith("{"));
Assert.assertTrue(responseBody.endsWith("}"));
Assert.assertTrue(-1 < responseBody.indexOf("\"id\""));
Assert.assertTrue(-1 < responseBody.indexOf("\"title\""));
Assert.assertTrue(-1 < responseBody.indexOf("\"updated\""));
// AtomTestCaseUtils.printResponseHeaders(
// "JSON Entry response headers:", " ", res );
// System.out.println(
// "ContentNegotiationTest.testJSONEntryGet JSON entry body=" +
// responseBody );
} finally {
res.release();
}
}
@Test
public void testXMLFeedGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testXMLFeedGet");
RequestOptions opts = new RequestOptions();
opts.setHeader("Accept", "application/atom+xml");
// Atom feed request
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Asser feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
// " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
// Perform other tests on feed.
Document<Feed> doc = res.getDocument();
Assert.assertNotNull(doc);
Feed feed = doc.getRoot();
Assert.assertNotNull(feed);
// RFC 4287 requires non-null id, title, updated elements
Assert.assertNotNull(feed.getId());
Assert.assertNotNull(feed.getTitle());
Assert.assertNotNull(feed.getUpdated());
// AtomTestCaseUtils.printFeed( "Feed values", " ", feed );
} finally {
res.release();
}
}
@Test
public void testJSONFeedGet() throws Exception {
System.out.println(">>>ContentNegotiationTest.testJSONFeedGet");
RequestOptions opts = new RequestOptions();
opts.setHeader("Accept", "application/json");
// JSON feed request
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Assert feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
// Abdera 0.4 throws exception on getContentType with
// application/json.
// System.out.println(
// "ContentNegotiationTest.testJSONEntryGet contentType=" +
// res.getContentType());
String contentType = res.getHeader("Content-Type");
Assert.assertTrue(-1 < contentType.indexOf("application/json"));
// Following is a poor man's JSONObject test to avoid dependency on
// JSON libs.
// JSONObject jsonResp = new JSONObject(res.);
// Assert.assertEquals(12345, jsonResp.getInt("result"));
String responseBody = readResponse(res.getReader());
Assert.assertTrue(responseBody.startsWith("{"));
Assert.assertTrue(responseBody.endsWith("}"));
Assert.assertTrue(-1 < responseBody.indexOf("\"id\""));
Assert.assertTrue(-1 < responseBody.indexOf("\"title\""));
Assert.assertTrue(-1 < responseBody.indexOf("\"updated\""));
Assert.assertTrue(-1 < responseBody.indexOf("\"entries\""));
// AtomTestCaseUtils.printResponseHeaders(
// "JSON Entry response headers:", " ", res );
// System.out.println(
// "ContentNegotiationTest.testJSONEntryGet JSON entry body=" +
// responseBody );
} finally {
res.release();
}
}
protected String readResponse(Reader responseReader) {
if (responseReader == null)
return "";
StringBuffer sb = new StringBuffer(1024);
try {
int charValue = 0;
while ((charValue = responseReader.read()) != -1) {
// result = result + (char) charValue;
sb.append((char)charValue);
}
} catch (IOException e) {
}
return sb.toString();
}
}

View file

@ -21,13 +21,19 @@ package org.apache.tuscany.sca.binding.atom;
import java.io.IOException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Provider {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
node.start();
System.out.println("Provider.composite ready...");
try {
@ -36,6 +42,7 @@ public class Provider {
e.printStackTrace();
}
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -22,415 +22,456 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Base;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Service;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.parser.Parser;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
import org.apache.abdera.protocol.client.util.BaseRequestEntity;
import org.apache.abdera.util.EntityTag;
import org.apache.abdera.parser.Parser;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Tests use of server provided entry entity tags for Atom binding in Tuscany.
* Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match)
* using entity tags or last modified header entries.
* Uses the SCA provided Provider composite to act as a server.
* Uses the Abdera provided Client to act as a client.
* Tests conditional gets (e.g. get if-none-match) or conditional posts (post
* if-match) using entity tags or last modified header entries. Uses the SCA
* provided Provider composite to act as a server. Uses the Abdera provided
* Client to act as a client.
*/
public class ProviderEntryEntityTagsTest {
public final static String providerURI = "http://localhost:8084/customer";
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static CustomerClient testService;
public final static String providerURI = "http://localhost:8084/customer";
protected static Node providerNode;
protected static Abdera abdera;
protected static AbderaClient client;
protected static Parser abderaParser;
protected static Parser abderaParser;
protected static String eTag;
protected static Date lastModified;
protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time
protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); // RFC
// 822
// date
// time
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>ProviderEntryEntityTagsTest.init");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>ProviderEntryEntityTagsTest.init");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
providerNode.start();
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>ProviderEntryEntityTagsTest.destroy");
scaProviderDomain.close();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>ProviderEntryEntityTagsTest.destroy");
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull( client );
}
@Test
public void testEmptyCachePost() throws Exception {
// Pseudo-code
// 1) Example HTTP POST request (new entry put, new etag response)
// User client post request
// POST /myblog/entries HTTP/1.1
// Slug: First Post
//
// <?xml version="1.0" ?>
// <entry xmlns="http://www.w3.org/2005/Atom">
// <title>Atom-Powered Robots Run Amok</title>
// <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
// <updated>2007-02-123T17:09:02Z</updated>
// <author><name>Captain Lansing</name></author>
// <content>It's something moving... solid metal</content>
// </entry>
public void testPrelim() throws Exception {
Assert.assertNotNull(providerNode);
Assert.assertNotNull(client);
}
// Expected Atom server response (note unique ETag)
// HTTP/1.1 201 Created
// Date: Fri, 23 Feb 2007 21:17:11 GMT
// Content-Length: nnn
// Content-Type: application/atom+xml;type=entry
// Location: http://example.org/edit/first-post.atom
// Content-Location: http://example.org/edit/first-post.atom
// ETag: "e180ee84f0671b1"
// Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
//
// <?xml version="1.0" ?>
// <entry xmlns="http://www.w3.org/2005/Atom">
// <title>Atom-Powered Robots Run Amok</title>
// <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
// <updated>2007-02-123T17:09:02Z</updated>
// <author><name>Captain Lansing</name></author>
// <content>It's something moving... solid metal</content>
// </entry>
// Testing of entry creation
Factory factory = abdera.getFactory();
String customerName = "Fred Farkle";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
// ID created by collection.
@Test
public void testEmptyCachePost() throws Exception {
// Pseudo-code
// 1) Example HTTP POST request (new entry put, new etag response)
// User client post request
// POST /myblog/entries HTTP/1.1
// Slug: First Post
//
// <?xml version="1.0" ?>
// <entry xmlns="http://www.w3.org/2005/Atom">
// <title>Atom-Powered Robots Run Amok</title>
// <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
// <updated>2007-02-123T17:09:02Z</updated>
// <author><name>Captain Lansing</name></author>
// <content>It's something moving... solid metal</content>
// </entry>
// Expected Atom server response (note unique ETag)
// HTTP/1.1 201 Created
// Date: Fri, 23 Feb 2007 21:17:11 GMT
// Content-Length: nnn
// Content-Type: application/atom+xml;type=entry
// Location: http://example.org/edit/first-post.atom
// Content-Location: http://example.org/edit/first-post.atom
// ETag: "e180ee84f0671b1"
// Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
//
// <?xml version="1.0" ?>
// <entry xmlns="http://www.w3.org/2005/Atom">
// <title>Atom-Powered Robots Run Amok</title>
// <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
// <updated>2007-02-123T17:09:02Z</updated>
// <author><name>Captain Lansing</name></author>
// <content>It's something moving... solid metal</content>
// </entry>
// Testing of entry creation
Factory factory = abdera.getFactory();
String customerName = "Fred Farkle";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
// ID created by collection.
// entry.setId(id); // auto-provided
// entry.addLink("" + id, "edit"); // auto-provided
// entry.addLink("" + id, "alternate"); // auto-provided
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
// AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ", opts );
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
ClientResponse res = client.post(colUri.toString(), entry, opts);
// Assert response status code is 201-OK.
// Assert response header Content-Type: application/atom+xml; charset=UTF-8
// Assert response header Location: http://example.org/edit/first-post.atom
// Assert response header Content-Location: http://example.org/edit/first-post.atom
// Assert response header ETag: "e180ee84f0671b1"
// Assert response header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
// Assert collection size is 1.
Assert.assertEquals(201, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
// Save eTag for subsequent tests;
eTag = res.getHeader( "ETag" );
Assert.assertNotNull( eTag );
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
}
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
// AtomTestCaseUtils.printRequestHeaders( "Post request headers", " ",
// opts );
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
ClientResponse res = client.post(colUri.toString(), entry, opts);
@Test
public void testDirtyCachePut() throws Exception {
// 2) Conditional PUT request (post with etag. entry provided is stale)
// User client PUT request
// PUT /edit/first-post.atom HTTP/1.1
// > If-Match: "e180ee84f0671b1"
//
// <?xml version="1.0" ?>
// <entry xmlns="http://www.w3.org/2005/Atom">
// <title>Atom-Powered Robots Run Amok</title>
// <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
// <updated>2007-02-24T16:34:06Z</updated>
// <author><name>Captain Lansing</name></author>
// <content>Update: it's a hoax!</content>
// </entry>
// Testing of entry creation
Factory factory = abdera.getFactory();
String customerName = "Molly Ringwald";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated( new Date());
entry.addAuthor("Apache Tuscany");
String id = eTag.substring( 1, eTag.length()-1);
// Assert response status code is 201-OK.
// Assert response header Content-Type: application/atom+xml;
// charset=UTF-8
// Assert response header Location:
// http://example.org/edit/first-post.atom
// Assert response header Content-Location:
// http://example.org/edit/first-post.atom
// Assert response header ETag: "e180ee84f0671b1"
// Assert response header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
// Assert collection size is 1.
Assert.assertEquals(201, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
// Save eTag for subsequent tests;
eTag = res.getHeader("ETag");
Assert.assertNotNull(eTag);
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
}
@Test
public void testDirtyCachePut() throws Exception {
// 2) Conditional PUT request (post with etag. entry provided is stale)
// User client PUT request
// PUT /edit/first-post.atom HTTP/1.1
// > If-Match: "e180ee84f0671b1"
//
// <?xml version="1.0" ?>
// <entry xmlns="http://www.w3.org/2005/Atom">
// <title>Atom-Powered Robots Run Amok</title>
// <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
// <updated>2007-02-24T16:34:06Z</updated>
// <author><name>Captain Lansing</name></author>
// <content>Update: it's a hoax!</content>
// </entry>
// Testing of entry creation
Factory factory = abdera.getFactory();
String customerName = "Molly Ringwald";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
String id = eTag.substring(1, eTag.length() - 1);
entry.setId(id); // auto-provided
// entry.addLink("" + id, "edit"); // auto-provided
// entry.addLink("" + id, "alternate"); // auto-provided
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-None-Match", eTag);
AtomTestCaseUtils.printRequestHeaders( "Put request headers", " ", opts );
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.put(colUri.toString() + "/" + id, new BaseRequestEntity( entry ), opts);
// Expected Atom server response (item was edited by another user)
// > HTTP/1.1 412 Precondition Failed
// Date: Sat, 24 Feb 2007 16:34:11 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-None-Match", eTag);
// If-Match Assert response status code is 412. Precondition failed.
// If-None-Match Assert response status code is 200. OK
Assert.assertEquals(200, res.getStatus());
// Put provides null body and no etags.
res.release();
}
@Test
public void testETagMissGet() throws Exception {
// 4) Conditional GET example (get with etag. etag not in cache)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-None-Match: "e180ee84f0671b1"
AtomTestCaseUtils.printRequestHeaders("Put request headers", " ", opts);
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.put(colUri.toString() + "/" + id, new BaseRequestEntity(entry), opts);
// Expected Atom server response (item was edited by another user)
// > HTTP/1.1 412 Precondition Failed
// Date: Sat, 24 Feb 2007 16:34:11 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-None-Match", "123456");
opts.setHeader( "Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Expected Atom server response (item was edited by another user)
// > HTTP/1.1 412 Precondition Failed
// Date: Sat, 24 Feb 2007 16:34:11 GMT
// If-Match Assert response status code is 412. Precondition failed.
// If-None-Match Assert response status code is 200. OK
Assert.assertEquals(200, res.getStatus());
// Put provides null body and no etags.
res.release();
}
// Atom server response (item was up to date)
// > HTTP/1.1 200 OK
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// > ETag: "bb4f5e86e92ddb8549604a0df0763581"
// > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500
@Test
public void testETagMissGet() throws Exception {
// 4) Conditional GET example (get with etag. etag not in cache)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-None-Match: "e180ee84f0671b1"
// Assert response status code is 200 OK.
// Assert header Content-Type: application/atom+xml;type=entry
// Assert header Location: http://example.org/edit/first-post.atom
// Assert header Content-Location: http://example.org/edit/first-post.atom
// Assert header ETag: "555555" (etag response != etag request)
// Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
Assert.assertNotNull( res.getHeader( "ETag" ) );
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
res.release();
}
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-None-Match", "123456");
opts.setHeader("Pragma", "no-cache"); // turn off client caching
@Test
public void testETagHitGet() throws Exception {
// 3) Conditional GET example (get with etag. etag match)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-None-Match: "e180ee84f0671b1"
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Expected Atom server response (item was edited by another user)
// > HTTP/1.1 412 Precondition Failed
// Date: Sat, 24 Feb 2007 16:34:11 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-None-Match", eTag);
opts.setHeader( "Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Atom server response (item was up to date)
// > HTTP/1.1 304 Not Modified
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// Atom server response (item was up to date)
// > HTTP/1.1 200 OK
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// > ETag: "bb4f5e86e92ddb8549604a0df0763581"
// > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500
// Assert response status code is 304 Not Modified.
// Assert header ETag: "e180ee84f0671b1"
// Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
// Assert.assertEquals(304, res.getStatus());
res.release();
}
// Assert response status code is 200 OK.
// Assert header Content-Type: application/atom+xml;type=entry
// Assert header Location: http://example.org/edit/first-post.atom
// Assert header Content-Location:
// http://example.org/edit/first-post.atom
// Assert header ETag: "555555" (etag response != etag request)
// Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
Assert.assertNotNull(res.getHeader("ETag"));
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
res.release();
}
@Test
public void testETagHitGet() throws Exception {
// 3) Conditional GET example (get with etag. etag match)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-None-Match: "e180ee84f0671b1"
@Test
public void testUpToDateGet() throws Exception {
// 3) Conditional GET example (get with If-Mod. entry is up to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-Modified-Since: Sat, 29 Oct 2025 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 2025 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date
opts.setHeader( "Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
ClientResponse res = client.execute( "GET", colUri.toString(), (BaseRequestEntity)null, opts);
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-None-Match", eTag);
opts.setHeader("Pragma", "no-cache"); // turn off client caching
// Atom server response (item was up to date)
// > HTTP/1.1 304 Not Modified
// Date: Sat, 24 Feb 2007 13:17:11 GMT
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Atom server response (item was up to date)
// > HTTP/1.1 304 Not Modified
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// Assert response status code is 304 Not Modified.
Assert.assertEquals(304, res.getStatus());
res.release();
}
// Assert response status code is 304 Not Modified.
// Assert header ETag: "e180ee84f0671b1"
// Assert header Last-Modified: Fri, 25 Jul 2008 14:36:44 -0500
// Assert.assertEquals(304, res.getStatus());
res.release();
}
@Test
public void testOutOfDateGet() throws Exception {
// 4) Conditional GET example (get with If-Mod. entry is not to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-Modified-Since: Sat, 29 Oct 1844 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-Modified-Since", "Sat, 29 Oct 1844 19:43:31 GMT"); // "EEE, dd MMM yyyy HH:mm:ss Z // RFC 822 Date
opts.setHeader( "Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
@Test
public void testUpToDateGet() throws Exception {
// 3) Conditional GET example (get with If-Mod. entry is up to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-Modified-Since: Sat, 29 Oct 2025 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-Modified-Since", "Sat, 29 Oct 2025 19:43:31 GMT"); // "EEE,
// dd
// MMM
// yyyy
// HH
// :
// mm
// :
// ss
// Z
// /
// /
// RFC
// 822
// Date
opts.setHeader("Pragma", "no-cache"); // turn off client caching
// Atom server response (item was up to date)
// > HTTP/1.1 200 OK
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// > ETag: "bb4f5e86e92ddb8549604a0df0763581"
// > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
ClientResponse res = client.execute("GET", colUri.toString(), (BaseRequestEntity)null, opts);
// Assert response status code is 200 OK.
// Assert header ETag: "e180ee84f0671b1"
// Assert header Last-Modified: Greater than If-Mod
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
Assert.assertNotNull( res.getHeader( "ETag" ) );
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
res.release();
}
@Test
public void testUpToDateUnModGet() throws Exception {
// 3) Conditional GET example (get with If-Unmod. entry is up to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-Unmodified-Since: Sat, 29 Oct 2025 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 2050 19:43:31 GMT" );
opts.setHeader( "Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Atom server response (item was up to date)
// > HTTP/1.1 304 Not Modified
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// Atom server response (item was up to date)
// > HTTP/1.1 304 Not Modified
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// Assert response status code is 304 Not Modified.
Assert.assertEquals(304, res.getStatus());
res.release();
}
// Assert response status code is 304 Not Modified.
// Assert.assertEquals(304, res.getStatus());
// TODO Update when If-Unmodified-Since enabled.
Assert.assertEquals(200, res.getStatus());
res.release();
}
@Test
public void testOutOfDateGet() throws Exception {
// 4) Conditional GET example (get with If-Mod. entry is not to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-Modified-Since: Sat, 29 Oct 1844 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-Modified-Since", "Sat, 29 Oct 1844 19:43:31 GMT"); // "EEE,
// dd
// MMM
// yyyy
// HH
// :
// mm
// :
// ss
// Z
// /
// /
// RFC
// 822
// Date
opts.setHeader("Pragma", "no-cache"); // turn off client caching
@Test
public void testOutOfDateUnModGet() throws Exception {
// 4) Conditional GET example (get with If-Unmod. entry is not to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// Host: example.org
// > If-Unmodified-Since: Sat, 29 Oct 1844 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader( "If-Unmodified-Since", "Sat, 29 Oct 1844 19:43:31 GMT" );
opts.setHeader( "Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring( 1, eTag.length()-1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Atom server response (item was up to date)
// > HTTP/1.1 200 OK
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// > ETag: "bb4f5e86e92ddb8549604a0df0763581"
// > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500
// Atom server response (item was up to date)
// > HTTP/1.1 200 OK
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// > ETag: "bb4f5e86e92ddb8549604a0df0763581"
// > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500
// Assert response status code is 200 OK.
// Assert header Content-Type: application/atom+xml;type=entry
// Assert header Location: http://example.org/edit/first-post.atom
// Assert header Content-Location: http://example.org/edit/first-post.atom
// Assert header ETag: "e180ee84f0671b1"
// Assert header Last-Modified: Less than If-Unmod
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
Assert.assertNotNull( res.getHeader( "ETag" ) );
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
res.release();
}
// Assert response status code is 200 OK.
// Assert header ETag: "e180ee84f0671b1"
// Assert header Last-Modified: Greater than If-Mod
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
Assert.assertNotNull(res.getHeader("ETag"));
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
res.release();
}
@Test
public void testUpToDateUnModGet() throws Exception {
// 3) Conditional GET example (get with If-Unmod. entry is up to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// > If-Unmodified-Since: Sat, 29 Oct 2025 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-Unmodified-Since", "Sat, 29 Oct 2050 19:43:31 GMT");
opts.setHeader("Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Atom server response (item was up to date)
// > HTTP/1.1 304 Not Modified
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// Assert response status code is 304 Not Modified.
// Assert.assertEquals(304, res.getStatus());
// TODO Update when If-Unmodified-Since enabled.
Assert.assertEquals(200, res.getStatus());
res.release();
}
@Test
public void testOutOfDateUnModGet() throws Exception {
// 4) Conditional GET example (get with If-Unmod. entry is not to date)
// User client GET request
// GET /edit/first-post.atom HTTP/1.1
// Host: example.org
// > If-Unmodified-Since: Sat, 29 Oct 1844 19:43:31 GMT
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
opts.setHeader("If-Unmodified-Since", "Sat, 29 Oct 1844 19:43:31 GMT");
opts.setHeader("Pragma", "no-cache"); // turn off client caching
IRI colUri = new IRI(providerURI).resolve("customer");
// res = client.post(colUri.toString() + "?test=foo", entry, opts);
String id = eTag.substring(1, eTag.length() - 1);
// Warning. AbderaClient.put(String uri,Base base,RequestOptions
// options) caches on the client side.
// ClientResponse res = client.put(colUri.toString() + id, entry, opts);
ClientResponse res = client.get(colUri.toString() + "/" + id, opts);
// Atom server response (item was up to date)
// > HTTP/1.1 200 OK
// Date: Sat, 24 Feb 2007 13:17:11 GMT
// > ETag: "bb4f5e86e92ddb8549604a0df0763581"
// > Last-Modified: Mon, 28 Jul 2008 10:25:37 -0500
// Assert response status code is 200 OK.
// Assert header Content-Type: application/atom+xml;type=entry
// Assert header Location: http://example.org/edit/first-post.atom
// Assert header Content-Location:
// http://example.org/edit/first-post.atom
// Assert header ETag: "e180ee84f0671b1"
// Assert header Last-Modified: Less than If-Unmod
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(contentType, res.getContentType().toString().trim());
// Assert.assertNotNull( res.getLocation().toString() );
// Assert.assertEquals( "", res.getContentLocation().toString() );
Assert.assertNotNull(res.getHeader("ETag"));
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
res.release();
}
}

View file

@ -22,335 +22,344 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Base;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Service;
import org.apache.abdera.model.Collection;
import org.apache.abdera.parser.Parser;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
import org.apache.abdera.protocol.client.util.BaseRequestEntity;
import org.apache.abdera.util.EntityTag;
import org.apache.abdera.parser.Parser;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Tests use of server provided feed entity tags for Atom binding in Tuscany.
* Tests conditional gets (e.g. get if-none-match) or conditional posts (post if-match)
* using entity tags and last modified entries in headers.
* Uses the SCA provided Provider composite to act as a server.
* Uses the Abdera provided Client to act as a client.
* Tests conditional gets (e.g. get if-none-match) or conditional posts (post
* if-match) using entity tags and last modified entries in headers. Uses the
* SCA provided Provider composite to act as a server. Uses the Abdera provided
* Client to act as a client.
*/
public class ProviderFeedEntityTagsTest {
public final static String providerURI = "http://localhost:8084/customer";
protected static SCADomain scaConsumerDomain;
protected static SCADomain scaProviderDomain;
protected static CustomerClient testService;
public final static String providerURI = "http://localhost:8084/customer";
protected static Node providerNode;
protected static Abdera abdera;
protected static AbderaClient client;
protected static Parser abderaParser;
protected static Parser abderaParser;
protected static String eTag;
protected static Date lastModified;
protected static final SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time
protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); // RFC
// 822
// date
// time
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.init");
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@BeforeClass
public static void init() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.init");
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
providerNode.start();
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.destroy");
scaProviderDomain.close();
}
@AfterClass
public static void destroy() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.destroy");
providerNode.stop();
providerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull( client );
}
@Test
public void testFeedBasics() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedBasics");
// Normal feed request
ClientResponse res = client.get(providerURI);
Assert.assertNotNull(res);
try {
// Asser feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(providerNode);
Assert.assertNotNull(client);
}
// Perform other tests on feed.
Document<Feed> doc = res.getDocument();
Assert.assertNotNull( doc );
Feed feed = doc.getRoot();
Assert.assertNotNull( feed );
printFeed( "Feed values", " ", feed );
// RFC 4287 requires non-null id, title, updated elements
Assert.assertNotNull( feed.getId() );
Assert.assertNotNull( feed.getTitle() );
Assert.assertNotNull( feed.getUpdated() );
eTag = res.getHeader("ETag");
Assert.assertNotNull( eTag );
lastModified = res.getLastModified();
Assert.assertNotNull( lastModified );
} finally {
res.release();
}
}
@Test
public void testFeedBasics() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedBasics");
// Normal feed request
ClientResponse res = client.get(providerURI);
Assert.assertNotNull(res);
try {
// Asser feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
// " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
@Test
public void testUnmodifiedGetIfMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfMatch");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-Match", eTag);
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
String thisETag = res.getHeader("ETag");
Assert.assertNotNull( thisETag );
Date thisLastModified = res.getLastModified();
Assert.assertNotNull( thisLastModified );
// Should return 200 - Feed provided since it matches etag.
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
} finally {
res.release();
}
}
// Perform other tests on feed.
Document<Feed> doc = res.getDocument();
Assert.assertNotNull(doc);
Feed feed = doc.getRoot();
Assert.assertNotNull(feed);
printFeed("Feed values", " ", feed);
// RFC 4287 requires non-null id, title, updated elements
Assert.assertNotNull(feed.getId());
Assert.assertNotNull(feed.getTitle());
Assert.assertNotNull(feed.getUpdated());
@Test
public void testUnmodifiedGetIfNoneMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfNoneMatch");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-None-Match", eTag);
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 304 - Feed not provided since it matches ETag.
Assert.assertEquals(304, res.getStatus());
} finally {
res.release();
}
}
eTag = res.getHeader("ETag");
Assert.assertNotNull(eTag);
lastModified = res.getLastModified();
Assert.assertNotNull(lastModified);
} finally {
res.release();
}
}
@Test
public void testUnmodifiedGetIfUnModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 304 - Feed not provided since feed is modified since.
Assert.assertEquals(304, res.getStatus());
} finally {
res.release();
}
}
@Test
public void testUnmodifiedGetIfMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfMatch");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-Match", eTag);
@Test
public void testUnmodifiedGetIfModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-Modified-Since", dateFormat.format( new Date( 0 ) ));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 200 - Feed provided since feed is changed.
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
String thisETag = res.getHeader("ETag");
Assert.assertNotNull(thisETag);
Date thisLastModified = res.getLastModified();
Assert.assertNotNull(thisLastModified);
String thisETag = res.getHeader("ETag");
Assert.assertNotNull( thisETag );
Date thisLastModified = res.getLastModified();
Assert.assertNotNull( thisLastModified );
} finally {
res.release();
}
}
// Should return 200 - Feed provided since it matches etag.
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
// " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
} finally {
res.release();
}
}
@Test
public void testModifiedGetIfNoneMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfNoneMatch");
// Post some new content to the feed.
Factory factory = abdera.getFactory();
String customerName = "Fred Farkle";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
@Test
public void testUnmodifiedGetIfNoneMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfNoneMatch");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-None-Match", eTag);
RequestOptions opts = new RequestOptions();
String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
IRI colUri = new IRI(providerURI).resolve("customer");
ClientResponse res = client.post(colUri.toString(), entry, opts);
// Feed request with predicates
opts = new RequestOptions();
contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-None-Match", eTag);
res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
String thisETag = res.getHeader("ETag");
Assert.assertNotNull( thisETag );
Date thisLastModified = res.getLastModified();
Assert.assertNotNull( thisLastModified );
// Should return 200 - value since feed is changed
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed modified if-none-match response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
} finally {
res.release();
}
}
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 304 - Feed not provided since it matches ETag.
Assert.assertEquals(304, res.getStatus());
} finally {
res.release();
}
}
@Test
public void testModifiedGetIfMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfMatch");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-Match", eTag);
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 412 - Precondition failed since feed changed.
Assert.assertEquals(412, res.getStatus());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
} finally {
res.release();
}
}
@Test
public void testUnmodifiedGetIfUnModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-Unmodified-Since", dateFormat.format(new Date()));
@Test
public void testModifiedGetIfUnModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 304 - Feed not provided since feed is modified since.
Assert.assertEquals(304, res.getStatus());
} finally {
res.release();
}
}
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 304 - Feed not provided since feed is modified
// since.
Assert.assertEquals(304, res.getStatus());
} finally {
res.release();
}
}
@Test
public void testModifiedGetIfModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified ));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 200 - Feed provided since feed is changed.
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
@Test
public void testUnmodifiedGetIfModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-Modified-Since", dateFormat.format(new Date(0)));
String thisETag = res.getHeader("ETag");
Assert.assertNotNull( thisETag );
Date thisLastModified = res.getLastModified();
Assert.assertNotNull( thisLastModified );
} finally {
res.release();
}
}
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 200 - Feed provided since feed is changed.
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
String thisETag = res.getHeader("ETag");
Assert.assertNotNull(thisETag);
Date thisLastModified = res.getLastModified();
Assert.assertNotNull(thisLastModified);
} finally {
res.release();
}
}
public static void printFeed( String title, String indent, Feed feed ) {
if ( feed == null ) {
System.out.println( title + " feed is null");
return;
}
System.out.println( title );
System.out.println( indent + "id=" + feed.getId() );
System.out.println( indent + "title=" + feed.getTitle() );
System.out.println( indent + "updated=" + feed.getUpdated() );
System.out.println( indent + "author=" + feed.getAuthor() );
Collection collection = feed.getCollection();
if ( collection == null ) {
System.out.println( indent + "collection=null" );
} else {
System.out.println( indent + "collection=" + collection );
}
// System.out.println( indent + "collection size=" + feed.getCollection() );
// for (Collection collection : workspace.getCollections()) {
// if (collection.getTitle().equals("customers")) {
// String expected = uri + "customers";
// String actual = collection.getResolvedHref().toString();
// assertEquals(expected, actual);
// }
// }
@Test
public void testModifiedGetIfNoneMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfNoneMatch");
// Post some new content to the feed.
Factory factory = abdera.getFactory();
String customerName = "Fred Farkle";
Entry entry = factory.newEntry();
entry.setTitle("customer " + customerName);
entry.setUpdated(new Date());
entry.addAuthor("Apache Tuscany");
Content content = abdera.getFactory().newContent();
content.setContentType(Content.Type.TEXT);
content.setValue(customerName);
entry.setContentElement(content);
}
RequestOptions opts = new RequestOptions();
String contentType = "application/atom+xml; type=entry";
opts.setContentType(contentType);
IRI colUri = new IRI(providerURI).resolve("customer");
ClientResponse res = client.post(colUri.toString(), entry, opts);
// Feed request with predicates
opts = new RequestOptions();
contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-None-Match", eTag);
res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
String thisETag = res.getHeader("ETag");
Assert.assertNotNull(thisETag);
Date thisLastModified = res.getLastModified();
Assert.assertNotNull(thisLastModified);
// Should return 200 - value since feed is changed
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders(
// "Feed modified if-none-match response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
} finally {
res.release();
}
}
@Test
public void testModifiedGetIfMatch() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedModifiedGetIfMatch");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-Match", eTag);
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 412 - Precondition failed since feed changed.
Assert.assertEquals(412, res.getStatus());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
// " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
} finally {
res.release();
}
}
@Test
public void testModifiedGetIfUnModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfUnModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-Unmodified-Since", dateFormat.format(new Date()));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 304 - Feed not provided since feed is modified
// since.
Assert.assertEquals(304, res.getStatus());
} finally {
res.release();
}
}
@Test
public void testModifiedGetIfModified() throws Exception {
System.out.println(">>>ProviderFeedEntityTagsTest.testFeedUnmodifiedGetIfModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
opts.setHeader("If-Modified-Since", dateFormat.format(lastModified));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
// Should return 200 - Feed provided since feed is changed.
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
String thisETag = res.getHeader("ETag");
Assert.assertNotNull(thisETag);
Date thisLastModified = res.getLastModified();
Assert.assertNotNull(thisLastModified);
} finally {
res.release();
}
}
public static void printFeed(String title, String indent, Feed feed) {
if (feed == null) {
System.out.println(title + " feed is null");
return;
}
System.out.println(title);
System.out.println(indent + "id=" + feed.getId());
System.out.println(indent + "title=" + feed.getTitle());
System.out.println(indent + "updated=" + feed.getUpdated());
System.out.println(indent + "author=" + feed.getAuthor());
Collection collection = feed.getCollection();
if (collection == null) {
System.out.println(indent + "collection=null");
} else {
System.out.println(indent + "collection=" + collection);
}
// System.out.println( indent + "collection size=" +
// feed.getCollection() );
// for (Collection collection : workspace.getCollections()) {
// if (collection.getTitle().equals("customers")) {
// String expected = uri + "customers";
// String actual = collection.getResolvedHref().toString();
// assertEquals(expected, actual);
// }
// }
}
}

View file

@ -18,94 +18,98 @@
*/
package org.apache.tuscany.sca.binding.atom;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import junit.framework.Assert;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Service;
import org.apache.abdera.parser.Parser;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.binding.atom.collection.Collection;
import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Service;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
import org.apache.abdera.parser.Parser;
/**
* Tests use of service documents provided by atom binding based collections.
* Uses the SCA provided Provider composite to act as a server.
* Uses the Abdera provided Client to act as a client.
* Uses the SCA provided Provider composite to act as a server. Uses the Abdera
* provided Client to act as a client.
*/
public class ProviderServiceDocumentTest {
public final static String providerURI = "http://localhost:8084/customer";
protected static SCADomain scaProviderDomain;
protected static SCADomain scaConsumerDomain;
public final static String providerURI = "http://localhost:8084/customer";
protected static Node providerNode;
protected static Node consumerNode;
protected static CustomerClient testService;
protected static Abdera abdera;
protected static AbderaClient client;
protected static Parser abderaParser;
protected static Parser abderaParser;
@BeforeClass
public static void init() throws Exception {
scaProviderDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Provider.composite");
scaConsumerDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/atom/Consumer.composite");
testService = scaConsumerDomain.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@BeforeClass
public static void init() throws Exception {
String contribution = ContributionLocationHelper.getContributionLocation(AtomDeleteTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/atom/Consumer.composite", new Contribution("consumer", contribution));
providerNode.start();
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
abdera = new Abdera();
client = new AbderaClient(abdera);
abderaParser = Abdera.getNewParser();
}
@AfterClass
public static void destroy() throws Exception {
scaProviderDomain.close();
}
@AfterClass
public static void destroy() throws Exception {
providerNode.stop();
providerNode.destroy();
consumerNode.stop();
consumerNode.destroy();
}
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(scaProviderDomain);
Assert.assertNotNull( client );
}
@Test
public void testFeedBasics() throws Exception {
// Normal feed request
ClientResponse res = client.get(providerURI);
Assert.assertNotNull(res);
try {
// Assert feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:", " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
@Test
public void testPrelim() throws Exception {
Assert.assertNotNull(providerNode);
Assert.assertNotNull(client);
}
// Perform other tests on feed.
Document<Feed> doc = res.getDocument();
Assert.assertNotNull( doc );
Feed feed = doc.getRoot();
Assert.assertNotNull( feed );
// printFeed( "Feed values", " ", feed );
// RFC 4287 requires non-null id, title, updated elements
Assert.assertNotNull( feed.getId() );
Assert.assertNotNull( feed.getTitle() );
Assert.assertNotNull( feed.getUpdated() );
} finally {
res.release();
}
}
@Test
public void testFeedBasics() throws Exception {
// Normal feed request
ClientResponse res = client.get(providerURI);
Assert.assertNotNull(res);
try {
// Assert feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// AtomTestCaseUtils.printResponseHeaders( "Feed response headers:",
// " ", res );
// System.out.println("Feed response content:");
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
// Perform other tests on feed.
Document<Feed> doc = res.getDocument();
Assert.assertNotNull(doc);
Feed feed = doc.getRoot();
Assert.assertNotNull(feed);
// printFeed( "Feed values", " ", feed );
// RFC 4287 requires non-null id, title, updated elements
Assert.assertNotNull(feed.getId());
Assert.assertNotNull(feed.getTitle());
Assert.assertNotNull(feed.getUpdated());
} finally {
res.release();
}
}
@Test
public void testServiceDocumentGet() throws Exception {
@ -119,56 +123,57 @@ public class ProviderServiceDocumentTest {
postEntry = postEntry("Count Dracula");
newEntry = resourceCollection.post(postEntry);
// Service document
ClientResponse res = client.get(providerURI + "/atomsvc");
Assert.assertNotNull(res);
try {
// Asser feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// Service document
ClientResponse res = client.get(providerURI + "/atomsvc");
Assert.assertNotNull(res);
try {
// Asser feed provided since no predicates
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
// Perform other tests on feed.
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
Document<Service> serviceDoc = res.getDocument();
Service service = serviceDoc.getRoot();
Assert.assertNotNull( service );
org.apache.abdera.model.Collection collection = service.getCollection( "workspace", "customers" );
String title = collection.getTitle();
Assert.assertEquals("customers", title);
String href = collection.getHref().toString();
Assert.assertTrue( href.contains( "customer") );
} finally {
res.release();
}
// Perform other tests on feed.
// AtomTestCaseUtils.prettyPrint(abdera, res.getDocument());
Document<Service> serviceDoc = res.getDocument();
Service service = serviceDoc.getRoot();
Assert.assertNotNull(service);
org.apache.abdera.model.Collection collection = service.getCollection("workspace", "customers");
String title = collection.getTitle();
Assert.assertEquals("customers", title);
String href = collection.getHref().toString();
Assert.assertTrue(href.contains("customer"));
} finally {
res.release();
}
}
public static void printFeed( String title, String indent, Feed feed ) {
if ( feed == null ) {
System.out.println( title + " feed is null");
return;
}
System.out.println( title );
System.out.println( indent + "id=" + feed.getId() );
System.out.println( indent + "title=" + feed.getTitle() );
System.out.println( indent + "updated=" + feed.getUpdated() );
System.out.println( indent + "author=" + feed.getAuthor() );
// Collection collection = feed.getCollection();
// if ( collection == null ) {
// System.out.println( indent + "collection=null" );
// } else {
// System.out.println( indent + "collection=" + collection );
// }
// System.out.println( indent + "collection size=" + feed.getCollection() );
// for (Collection collection : workspace.getCollections()) {
// if (collection.getTitle().equals("customers")) {
// String expected = uri + "customers";
// String actual = collection.getResolvedHref().toString();
// assertEquals(expected, actual);
// }
// }
public static void printFeed(String title, String indent, Feed feed) {
if (feed == null) {
System.out.println(title + " feed is null");
return;
}
}
System.out.println(title);
System.out.println(indent + "id=" + feed.getId());
System.out.println(indent + "title=" + feed.getTitle());
System.out.println(indent + "updated=" + feed.getUpdated());
System.out.println(indent + "author=" + feed.getAuthor());
// Collection collection = feed.getCollection();
// if ( collection == null ) {
// System.out.println( indent + "collection=null" );
// } else {
// System.out.println( indent + "collection=" + collection );
// }
// System.out.println( indent + "collection size=" +
// feed.getCollection() );
// for (Collection collection : workspace.getCollections()) {
// if (collection.getTitle().equals("customers")) {
// String expected = uri + "customers";
// String actual = collection.getResolvedHref().toString();
// assertEquals(expected, actual);
// }
// }
}
private Entry postEntry(String value) {
Entry entry = abdera.newEntry();

View file

@ -73,7 +73,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -20,7 +20,10 @@ package org.apache.tuscany.sca.binding.ejb.tests;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import account.Customer;
@ -31,7 +34,7 @@ import account.Customer;
*/
public class EJBReferenceTestCase extends TestCase {
private static final int MOCK_PORT = 8085;
private SCADomain scaDomain;
private Node node;
@Override
protected void setUp() throws Exception {
@ -39,7 +42,9 @@ public class EJBReferenceTestCase extends TestCase {
System.setProperty("java.naming.provider.url", "ejbd://localhost:" + MOCK_PORT);
System.setProperty("managed", "false");
scaDomain = SCADomain.newInstance("account/account.composite");
String contribution = ContributionLocationHelper.getContributionLocation(EJBReferenceTestCase.class);
node = NodeFactory.newInstance().createNode("account/account.composite", new Contribution("account", contribution));
node.start();
// To capture the network traffic for the MockServer, uncomment the next line
// new Thread(new SocketTracer(MOCK_PORT, OPENEJB_PORT)).start();
@ -53,11 +58,12 @@ public class EJBReferenceTestCase extends TestCase {
@Override
protected void tearDown() throws Exception {
scaDomain.close();
node.stop();
node.destroy();
}
public void testCalculator() throws Exception {
Customer customer = scaDomain.getService(Customer.class, "CustomerComponent");
Customer customer = node.getService(Customer.class, "CustomerComponent");
// This is one of the customer numbers in bank application running on Geronimo
String accountNo = "1234567890";
Double balance = customer.depositAmount(accountNo, new Double(100));

View file

@ -135,12 +135,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>

View file

@ -19,7 +19,10 @@
package org.apache.tuscany.sca.binding.gdata;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
@ -30,8 +33,11 @@ public class Consumer {
public static void main(String[] args) throws Exception {
//Initialize the GData client service (Reference Binding test)
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite");
CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(Consumer.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite", new Contribution("consumer", contribution));
node.start();
CustomerClient testService = node.getService(CustomerClient.class, "CustomerClient");
Feed feed = testService.clientGetFeed();

View file

@ -20,18 +20,23 @@
package org.apache.tuscany.sca.binding.gdata;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
import com.google.gdata.data.PlainTextConstruct;
public class ConsumerProviderTestCase extends TestCase {
private SCADomain scaDomainProvider = null;
private SCADomain scaDomainConsumer = null;
private Node providerNode = null;
private Node consumerNode = null;
private CustomerClient testService = null;
@Before
@ -40,18 +45,26 @@ public class ConsumerProviderTestCase extends TestCase {
System.out.println("Method Test Start-----------------------------------------------------------------------");
// Setup the local GData servlet (Service Binding test)
scaDomainProvider = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite");
String contribution = ContributionLocationHelper.getContributionLocation(ConsumerProviderTestCase.class);
providerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/Provider.composite", new Contribution("provider", contribution));
providerNode.start();
System.out.println("[Debug Info] Provider.composite ready...");
// Initialize the GData client service (Reference Binding test)
scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Consumer.composite");
testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/Consumer.composite", new Contribution("consumer", contribution));
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
}
@After
@Override
public void tearDown() {
scaDomainProvider.close();
providerNode.stop();
providerNode.destroy();
consumerNode.stop();
consumerNode.destroy();
System.out.println("Method Test End------------------------------------------------------------------------");
System.out.println("\n\n");
}

View file

@ -23,7 +23,10 @@ import java.net.URL;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -36,11 +39,10 @@ import com.google.gdata.data.PlainTextConstruct;
public class GoogleBloggerServiceTestCase extends TestCase{
private SCADomain scaDomainConsumer = null;
private Node consumerNode = null;
private CustomerClient testService = null;
public GoogleBloggerServiceTestCase(){
}
@Before
@ -49,8 +51,11 @@ public class GoogleBloggerServiceTestCase extends TestCase{
System.out.println("Method Test Start-----------------------------------------------------------------------");
//Initialize the GData client service (Reference Binding test)
scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite");
testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(GoogleBloggerServiceTestCase.class);
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/ConsumerGoogleBlogger.composite", new Contribution("consumer", contribution));
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
}
@After
@ -58,6 +63,8 @@ public class GoogleBloggerServiceTestCase extends TestCase{
public void tearDown(){
System.out.println("Method Test End------------------------------------------------------------------------");
System.out.println("\n\n");
consumerNode.stop();
consumerNode.destroy();
}
@Test

View file

@ -23,7 +23,10 @@ import java.net.URL;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -36,11 +39,10 @@ import com.google.gdata.data.PlainTextConstruct;
public class GoogleCalendarServiceTestCase extends TestCase{
private SCADomain scaDomainConsumer = null;
private Node consumerNode = null;
private CustomerClient testService = null;
public GoogleCalendarServiceTestCase(){
}
@Before
@ -49,8 +51,11 @@ public class GoogleCalendarServiceTestCase extends TestCase{
System.out.println("Method Test Start-----------------------------------------------------------------------");
//Initialize the GData client service (Reference Binding test)
scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite");
testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(GoogleCalendarServiceTestCase.class);
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/ConsumerGoogleCalendar.composite", new Contribution("consumer", contribution));
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
}
@After
@ -58,6 +63,8 @@ public class GoogleCalendarServiceTestCase extends TestCase{
public void tearDown(){
System.out.println("Method Test End------------------------------------------------------------------------");
System.out.println("\n\n");
consumerNode.stop();
consumerNode.destroy();
}
@Test

View file

@ -23,7 +23,10 @@ import java.net.URL;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -36,7 +39,7 @@ import com.google.gdata.data.PlainTextConstruct;
public class GoogleContactsServiceTestCase extends TestCase{
private SCADomain scaDomainConsumer = null;
private Node consumerNode = null;
private CustomerClient testService = null;
public GoogleContactsServiceTestCase(){
@ -49,8 +52,11 @@ public class GoogleContactsServiceTestCase extends TestCase{
System.out.println("Method Test Start-----------------------------------------------------------------------");
//Initialize the GData client service (Reference Binding test)
scaDomainConsumer = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite");
testService = scaDomainConsumer.getService(CustomerClient.class, "CustomerClient");
String contribution = ContributionLocationHelper.getContributionLocation(GoogleContactsServiceTestCase.class);
consumerNode = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/ConsumerGoogleContacts.composite", new Contribution("consumer", contribution));
consumerNode.start();
testService = consumerNode.getService(CustomerClient.class, "CustomerClient");
}
@After
@ -58,6 +64,8 @@ public class GoogleContactsServiceTestCase extends TestCase{
public void tearDown(){
System.out.println("Method Test End------------------------------------------------------------------------");
System.out.println("\n\n");
consumerNode.stop();
consumerNode.destroy();
}
@Test

View file

@ -21,13 +21,19 @@ package org.apache.tuscany.sca.binding.gdata;
import java.io.IOException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Provider {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite");
String contribution = ContributionLocationHelper.getContributionLocation(Provider.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/Provider.composite", new Contribution("provider", contribution));
node.start();
System.out.println("Provider.composite ready...");
try {
@ -36,6 +42,7 @@ public class Provider {
e.printStackTrace();
}
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -21,13 +21,19 @@ package org.apache.tuscany.sca.binding.gdata;
import java.io.IOException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class StartLocalhostServlet {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite");
String contribution = ContributionLocationHelper.getContributionLocation(Provider.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/Provider.composite", new Contribution("provider", contribution));
node.start();
System.out.println("Provider.composite ready...");
try {
@ -36,6 +42,7 @@ public class StartLocalhostServlet {
e.printStackTrace();
}
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -106,11 +106,11 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>gdata-core</artifactId>

View file

@ -18,6 +18,11 @@
*/
package org.apache.tuscany.sca.binding.gdata.calendarconsumer;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import com.google.gdata.data.BaseEntry;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.Entry;
@ -26,18 +31,20 @@ import com.google.gdata.data.Person;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.extensions.EventEntry;
import com.google.gdata.data.extensions.When;
import org.apache.tuscany.sca.host.embedded.SCADomain;
public class CalendarConsumer {
public static void main(String... args) throws Exception {
SCADomain scaDomain;
Node node;
CalendarConsumerImpl resourceCollection;
//init
scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite");
resourceCollection = scaDomain.getService(CalendarConsumerImpl.class, "CalendarConsumer");
String contribution = ContributionLocationHelper.getContributionLocation(CalendarConsumer.class);
node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite", new Contribution("consumer", contribution));
node.start();
resourceCollection = node.getService(CalendarConsumerImpl.class, "CalendarConsumer");
//test methods
System.out.println(
@ -115,7 +122,8 @@ public class CalendarConsumer {
}
//close
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -18,6 +18,20 @@
*/
package org.apache.tuscany.sca.binding.gdata.calendarconsumer;
import static org.junit.Assert.assertNotNull;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.gdata.data.BaseEntry;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.Feed;
@ -25,20 +39,11 @@ import com.google.gdata.data.Person;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.extensions.EventEntry;
import com.google.gdata.data.extensions.When;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.junit.Test;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import static org.junit.Assert.assertNotNull;
//FIX-ME: the tests are executed in an incorrect order
public class CalendarConsumerTest {
private static SCADomain scaDomain;
private static Node node;
private Feed feed;
private BaseEntry returnedEntry;
private BaseEntry searchedEntry;
@ -47,13 +52,17 @@ public class CalendarConsumerTest {
@BeforeClass
public static void init() {
scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite");
consumer = scaDomain.getService(CalendarConsumerImpl.class, "CalendarConsumer");
String contribution = ContributionLocationHelper.getContributionLocation(CalendarConsumer.class);
node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite", new Contribution("consumer", contribution));
node.start();
consumer = node.getService(CalendarConsumerImpl.class, "CalendarConsumer");
}
@AfterClass
public static void close() {
scaDomain.close();
node.stop();
node.destroy();
}
@Test

View file

@ -19,18 +19,24 @@
package org.apache.tuscany.sca.binding.gdata.consumerprovider;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Consumer {
public static void main(String[] args) throws Exception {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Consumer.composite");
String contribution = ContributionLocationHelper.getContributionLocation(Consumer.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/Consumer.composite", new Contribution("consumer", contribution));
node.start();
CustomerClient testService = node.getService(CustomerClient.class, "CustomerClient");
CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient");
testService.testCustomerCollection();
testService.testCustomerCollection();
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -18,17 +18,23 @@
*/
package org.apache.tuscany.sca.binding.gdata.consumerprovider;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Provider {
public static void main(String[] args) throws Exception {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite");
String contribution = ContributionLocationHelper.getContributionLocation(Provider.class);
Node node = NodeFactory.newInstance().createNode(
"org/apache/tuscany/sca/binding/gdata/Provider.composite", new Contribution("provider", contribution));
node.start();
System.out.println("Ready for consultings...");
System.in.read();
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -56,7 +56,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -25,9 +25,12 @@ import java.io.OutputStream;
import java.net.Socket;
import java.text.MessageFormat;
import junit.framework.TestCase;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import junit.framework.TestCase;
/**
* HTTP binding unit tests.
@ -65,16 +68,19 @@ public class HTTPBindingTestCase extends TestCase {
private static final int HTTP_PORT = 8085;
private SCADomain scaDomain;
private Node node;
@Override
protected void setUp() throws Exception {
scaDomain = SCADomain.newInstance("test.composite");
String contribution = ContributionLocationHelper.getContributionLocation(HTTPBindingCacheTestCase.class);
node = NodeFactory.newInstance().createNode("test.composite", new Contribution("test", contribution));
node.start();
}
@Override
protected void tearDown() throws Exception {
scaDomain.close();
node.stop();
node.destroy();
}
/**

View file

@ -100,7 +100,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -103,14 +103,13 @@
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>

View file

@ -22,11 +22,13 @@ import java.io.ByteArrayInputStream;
import junit.framework.Assert;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import com.meterware.httpunit.PostMethodWebRequest;
@ -39,155 +41,140 @@ import com.meterware.httpunit.WebResponse;
*/
public class JSONRPCDataTypeTestCase {
private static final String SERVICE_PATH = "/EchoService";
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
private SCADomain domain;
private static final String SERVICE_PATH = "/EchoService";
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
private Node node;
@Before
public void setUp() throws Exception {
domain = SCADomain.newInstance("JSONRPCBinding.composite");
}
@Before
public void setUp() throws Exception {
String contribution = ContributionLocationHelper.getContributionLocation(getClass());
node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
node.start();
}
@After
public void tearDown() throws Exception {
domain.close();
}
@After
public void tearDown() throws Exception {
node.stop();
node.destroy();
}
@Test
public void testInt() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{ \"method\": \"echoInt\", \"params\": [12345], \"id\": 4}");
@Test
public void testInt() throws Exception {
JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoInt\", \"params\": [12345], \"id\": 4}");
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(200, response.getResponseCode());
JSONObject jsonResp = new JSONObject(response.getText());
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals(12345, jsonResp.getInt("result"));
}
Assert.assertEquals(12345, jsonResp.getInt("result"));
}
@Test
public void testBoolean() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{ \"method\": \"echoBoolean\", \"params\": [true], \"id\": 5}");
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
@Test
public void testBoolean() throws Exception {
JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoBoolean\", \"params\": [true], \"id\": 5}");
Assert.assertEquals(200, response.getResponseCode());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(true, jsonResp.getBoolean("result"));
}
JSONObject jsonResp = new JSONObject(response.getText());
@Test
public void testMap() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{ \"method\": \"echoMap\", \"params\": [ {\"javaClass\": \"java.util.HashMap\", \"map\": { \"Binding\": \"JSON-RPC\"}}], \"id\": 6}");
Assert.assertEquals(true, jsonResp.getBoolean("result"));
}
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
@Test
public void testMap() throws Exception {
JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoMap\", \"params\": [ {\"javaClass\": \"java.util.HashMap\", \"map\": { \"Binding\": \"JSON-RPC\"}}], \"id\": 6}");
Assert.assertEquals(200, response.getResponseCode());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getJSONObject("map").getString("Binding"));
}
@Test
public void testBean() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{ \"method\": \"echoBean\", \"params\": [ {\"javaClass\": \"bean.TestBean\", \"testString\": \"JSON-RPC\", \"testInt\":1234}], \"id\": 7}");
JSONObject jsonResp = new JSONObject(response.getText());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getJSONObject("map").getString("Binding"));
}
Assert.assertEquals(200, response.getResponseCode());
@Test
public void testBean() throws Exception {
JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoBean\", \"params\": [ {\"javaClass\": \"bean.TestBean\", \"testString\": \"JSON-RPC\", \"testInt\":1234}], \"id\": 7}");
JSONObject jsonResp = new JSONObject(response.getText());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getString("testString"));
}
Assert.assertEquals(200, response.getResponseCode());
@Test
public void testList() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{ \"method\": \"echoList\", \"params\": [ {\"javaClass\": \"java.util.ArrayList\", \"list\": [0,1,2,3,4]}], \"id\": 8}");
JSONObject jsonResp = new JSONObject(response.getText());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getString("testString"));
}
Assert.assertEquals(200, response.getResponseCode());
@Test
public void testList() throws Exception {
JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoList\", \"params\": [ {\"javaClass\": \"java.util.ArrayList\", \"list\": [0,1,2,3,4]}], \"id\": 8}");
JSONObject jsonResp = new JSONObject(response.getText());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0));
}
@Test
public void testArrayString() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}");
Assert.assertEquals(200, response.getResponseCode());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0));
}
JSONObject jsonResp = new JSONObject(response.getText());
@Test
public void testArrayString() throws Exception {
JSONObject jsonRequest = new JSONObject("{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}");
Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0));
}
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
@Test
public void testArrayInt() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{\"params\":[[1,2]],\"method\":\"echoArrayInt\",\"id\":10}");
Assert.assertEquals(200, response.getResponseCode());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0));
}
JSONObject jsonResp = new JSONObject(response.getText());
@Test
public void testArrayInt() throws Exception {
JSONObject jsonRequest = new JSONObject("{\"params\":[[1,2]],\"method\":\"echoArrayInt\",\"id\":10}");
Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0));
}
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
@Test
public void testSet() throws Exception {
JSONObject jsonRequest = new JSONObject(
"{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}");
Assert.assertEquals(200, response.getResponseCode());
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL,
new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0));
}
JSONObject jsonResp = new JSONObject(response.getText());
@Test
public void testSet() throws Exception {
JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}");
Assert.assertEquals("red", jsonResp.getJSONObject("result").getJSONObject("set").getString("red"));
}
}
WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals(200, response.getResponseCode());
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals("red", jsonResp.getJSONObject("result").getJSONObject("set").getString("red"));
}
}

View file

@ -22,7 +22,10 @@ import java.io.ByteArrayInputStream;
import junit.framework.Assert;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
@ -42,16 +45,19 @@ public class JSONRPCExceptionTestCase{
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
private SCADomain domain;
private Node node;
@Before
public void setUp() throws Exception {
domain = SCADomain.newInstance("JSONRPCBinding.composite");
String contribution = ContributionLocationHelper.getContributionLocation(getClass());
node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
node.start();
}
@After
public void tearDown() throws Exception {
domain.close();
node.stop();
node.destroy();
}
@Test

View file

@ -22,7 +22,10 @@ import java.io.ByteArrayInputStream;
import junit.framework.Assert;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
@ -42,16 +45,19 @@ public class JSONRPCServiceTestCase{
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
private SCADomain domain;
private Node node;
@Before
public void setUp() throws Exception {
domain = SCADomain.newInstance("JSONRPCBinding.composite");
String contribution = ContributionLocationHelper.getContributionLocation(getClass());
node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
node.start();
}
@After
public void tearDown() throws Exception {
domain.close();
node.stop();
node.destroy();
}
@Test

View file

@ -63,7 +63,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -22,7 +22,10 @@ import helloworld.HelloException;
import helloworld.HelloWorldRmiService;
import junit.framework.Assert;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -34,7 +37,7 @@ import org.junit.Test;
*/
public class BindingTestCase {
private static HelloWorldRmiService helloWorldRmiService;
private static SCADomain domain;
private static Node node;
@Test
public void testRmiService() {
@ -60,8 +63,10 @@ public class BindingTestCase {
@BeforeClass
public static void init() throws Exception {
try {
domain = SCADomain.newInstance("RMIBindingTest.composite");
helloWorldRmiService = domain.getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent");
String contribution = ContributionLocationHelper.getContributionLocation(BindingTestCase.class);
node = NodeFactory.newInstance().createNode("RMIBindingTest.composite", new Contribution("test", contribution));
node.start();
helloWorldRmiService = node.getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent");
} catch (Exception e) {
e.printStackTrace();
}
@ -69,7 +74,8 @@ public class BindingTestCase {
@AfterClass
public static void destroy() throws Exception {
domain.close();
node.stop();
node.destroy();
}
}

View file

@ -106,7 +106,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -19,17 +19,23 @@
package org.apache.tuscany.sca.binding.rss;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Consumer {
public static void main(String[] args) throws Exception {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Consumer.composite");
String contribution = ContributionLocationHelper.getContributionLocation(Consumer.class);
Node node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/feed/Consumer.composite", new Contribution("test", contribution));
node.start();
CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient");
CustomerClient testService = node.getService(CustomerClient.class, "CustomerClient");
testService.testCustomerCollection();
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -21,13 +21,18 @@ package org.apache.tuscany.sca.binding.rss;
import java.io.IOException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
public class Provider {
public static void main(String[] args) {
SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/feed/Provider.composite");
String contribution = ContributionLocationHelper.getContributionLocation(Consumer.class);
Node node = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/feed/Provider.composite", new Contribution("test", contribution));
node.start();
System.out.println("Provider.composite ready...");
try {
@ -36,6 +41,7 @@ public class Provider {
e.printStackTrace();
}
scaDomain.close();
node.stop();
node.destroy();
}
}

View file

@ -63,7 +63,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -59,9 +59,9 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>

View file

@ -277,7 +277,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>

View file

@ -20,9 +20,12 @@
package org.apache.tuscany.sca.domain.manager.launcher;
import org.apache.tuscany.sca.domain.manager.impl.DomainManagerConfiguration;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
/**
* Bootstrap class for the SCA domain manager.
@ -30,15 +33,15 @@ import org.apache.tuscany.sca.node.SCANodeFactory;
* @version $Rev$ $Date$
*/
public class DomainManagerLauncherBootstrap {
private SCANode node;
private Node node;
/**
* A node wrappering an instance of a domain manager.
*/
public static class NodeFacade implements SCANode {
public static class NodeFacade implements Node {
private ClassLoader threadContextClassLoader;
private ClassLoader runtimeClassLoader;
private SCANode node;
private Node node;
private String rootDirectory;
private NodeFacade(String rootDirectory) {
@ -51,12 +54,13 @@ public class DomainManagerLauncherBootstrap {
boolean started = false;
try {
Thread.currentThread().setContextClassLoader(runtimeClassLoader);
SCANodeFactory factory = SCANodeFactory.newInstance();
node = factory.createSCANodeFromClassLoader("DomainManager.composite", getClass().getClassLoader());
NodeFactory factory = NodeFactory.newInstance();
String contribution = ContributionLocationHelper.getContributionLocation(getClass());
node = factory.createNode("DomainManager.composite", new Contribution("domain-manager", contribution));
node.start();
// Set the domain manager's root directory
DomainManagerConfiguration domainManagerConfiguration = ((SCAClient) node).getService(DomainManagerConfiguration.class, "DomainManagerConfigurationComponent");
DomainManagerConfiguration domainManagerConfiguration = node.getService(DomainManagerConfiguration.class, "DomainManagerConfigurationComponent");
domainManagerConfiguration.setRootDirectory(rootDirectory);
started = true;
@ -75,6 +79,28 @@ public class DomainManagerLauncherBootstrap {
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
}
}
public void destroy() {
try {
Thread.currentThread().setContextClassLoader(runtimeClassLoader);
node.destroy();
} finally {
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
}
}
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
throw new UnsupportedOperationException();
}
public <B> B getService(Class<B> businessInterface, String serviceName) {
throw new UnsupportedOperationException();
}
public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName) {
throw new UnsupportedOperationException();
}
}
/**
@ -88,7 +114,7 @@ public class DomainManagerLauncherBootstrap {
* Returns the node representing the domain manager.
* @return
*/
public SCANode getNode() {
public Node getNode() {
return node;
}

View file

@ -1,205 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -1 +0,0 @@
This directory contains a generated MANIFEST.MF file.

View file

@ -1,6 +0,0 @@
${pom.name}
Copyright (c) 2005 - 2008 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).

View file

@ -1,132 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-modules</artifactId>
<version>1.4-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>tuscany-host-embedded</artifactId>
<name>Apache Tuscany SCA Embedded Host</name>
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-extensibility</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-core</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-definitions</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-definitions-xml</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-assembly-xml</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-sca</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-sca-xml</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-contribution-impl</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-policy-xml</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-core-databinding</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-assembly-xsd</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-endpoint</artifactId>
<version>1.4-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Version>${tuscany.version}</Bundle-Version>
<Bundle-SymbolicName>org.apache.tuscany.sca.host.embedded</Bundle-SymbolicName>
<Bundle-Description>${pom.name}</Bundle-Description>
<Export-Package>org.apache.tuscany.sca.host.embedded*</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,229 +0,0 @@
/*
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded;
import java.lang.reflect.Constructor;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
import org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.ServiceRuntimeException;
/**
* A handle to an SCA domain.
*
* @version $Rev$ $Date$
*/
public abstract class SCADomain {
static final String LOCAL_DOMAIN_URI = "http://localhost";
/**
* Static variable to hold the most recent instance of SCADomain
*/
// TODO: Temporary support for SCADomain.connect() API
protected static SCADomain theDomain;
/**
* Returns a new instance of a local SCA domain.
*
* @return
*/
public static SCADomain newInstance() {
return createNewInstance(LOCAL_DOMAIN_URI, null);
}
/**
* Returns a new instance of a local SCA domain. The specified deployable
* composite will be included in the SCA domain.
*
* @param composite the deployable composite to include in the SCA domain.
* @return
*/
public static SCADomain newInstance(String composite) {
return createNewInstance(LOCAL_DOMAIN_URI, "/", composite);
}
/**
* Returns a new instance of a local SCA domain. The specified deployable
* composites will be included in the SCA domain.
*
* @param domainURI the URI of the SCA domain
* @param contributionLocation the location of an SCA contribution
* @param composites the deployable composites to include in the SCA domain.
* @return
*/
public static SCADomain newInstance(String domainURI, String contributionLocation, String... composites) {
return createNewInstance(domainURI, contributionLocation, composites);
}
/**
* Removes the specified local SCA Domain instance
*
* @param domainInstance the instance to be removed
*/
// FIXME: Adding this as temporary support for the "connect" API
public static void removeInstance(SCADomain domainInstance) {
theDomain = null;
}
/**
* Returns an SCADomain representing a remote SCA domain.
*
* @param domainURI the URI of the SCA domain
* @return
*/
// FIXME : this is a temporary implementation to get the capability working
public static SCADomain connect(String domainURI) {
return theDomain;
}
/**
* Close the SCA domain.
*/
public void close() {
// TODO: temporary to support initial SCADomain.connect capability
SCADomain.removeInstance(this);
}
/**
* Returns the URI of the SCA Domain.
*
* @return the URI of the SCA Domain
*/
public abstract String getURI();
/**
* Cast a type-safe reference to a CallableReference. Converts a type-safe
* reference to an equivalent CallableReference; if the target refers to a
* service then a ServiceReference will be returned, if the target refers to
* a callback then a CallableReference will be returned.
*
* @param target a reference proxy provided by the SCA runtime
* @param <B> the Java type of the business interface for the reference
* @param <R> the type of reference to be returned
* @return a CallableReference equivalent for the proxy
* @throws IllegalArgumentException if the supplied instance is not a
* reference supplied by the SCA runtime
*/
public abstract <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
/**
* Returns a proxy for a service provided by a component in the SCA domain.
*
* @param businessInterface the interface that will be used to invoke the
* service
* @param serviceName the name of the service
* @param <B> the Java type of the business interface for the service
* @return an object that implements the business interface
*/
public abstract <B> B getService(Class<B> businessInterface, String serviceName);
/**
* Returns a ServiceReference for a service provided by a component in the
* SCA domain.
*
* @param businessInterface the interface that will be used to invoke the
* service
* @param serviceName the name of the service
* @param <B> the Java type of the business interface for the service
* @return a ServiceReference for the designated service
*/
public abstract <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName);
/**
* Returns an SCADomain instance. If the system property
* "org.apache.tuscany.sca.host.embedded.SCADomain" is set, its value is used as
* the name of the implementation class. Otherwise, if the resource
* "META-INF/services/org.apache.tuscany.sca.host.embedded.SCADomain" can be
* loaded from the supplied ClassLoader. Otherwise, it will use
* "org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain" as the default.
* The named class is loaded from the supplied ClassLoader.
*
* @param classLoader
* @param domainURI
* @param contributionLocation
* @param composites
* @return
*/
static SCADomain createNewInstance(String domainURI, String contributionLocation, String... composites) {
SCADomain domain = null;
try {
// Determine the runtime and application ClassLoader
final ClassLoader runtimeClassLoader = SCADomain.class.getClassLoader();
final ClassLoader applicationClassLoader = Thread.currentThread().getContextClassLoader();
ServiceDeclaration implDeclaration = ServiceDiscovery.getInstance().getFirstServiceDeclaration(SCADomain.class.getName());
if (implDeclaration == null) {
// Create a default SCA domain implementation
domain =
new DefaultSCADomain(runtimeClassLoader, applicationClassLoader, domainURI, contributionLocation,
composites);
} else {
// Create an instance of the discovered SCA domain implementation
Constructor<?> constructor = null;
try {
Class<?> implClass = implDeclaration.loadClass();
constructor =
implClass.getConstructor(ClassLoader.class,
ClassLoader.class,
String.class,
String.class,
String[].class);
} catch (NoSuchMethodException e) {
}
if (constructor != null) {
domain =
(SCADomain)constructor.newInstance(runtimeClassLoader,
applicationClassLoader,
domainURI,
contributionLocation,
composites);
} else {
Class<?> implClass = implDeclaration.loadClass();
constructor = implClass.getConstructor(ClassLoader.class, String.class);
domain = (SCADomain)constructor.newInstance(runtimeClassLoader, domainURI);
}
}
// FIXME: temporary support for connect() API
theDomain = domain;
return domain;
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
public ComponentManager getComponentManager() {
return null;
}
}

View file

@ -1,125 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
/**
*
* @version $Rev$ $Date$
*/
public class SCADomainBean extends SCADomain {
private SCADomain instance;
private String uri = LOCAL_DOMAIN_URI;
private String location = "/";
private String[] composites;
/**
* Constructs a new SCA domain
*/
public SCADomainBean() {
}
@Override
public String getURI() {
return uri;
}
public void setURI(String uri) {
this.uri = uri;
}
public void setContributionLocation(String contributionLocation) {
this.location = contributionLocation;
}
public String getContributionLocation() {
return location;
}
public void setDeployableComposite(String composite) {
setDeployableComposites(composite);
}
public void setDeployableComposites(String... composites) {
this.composites = composites;
}
public String[] getDeployableComposites() {
return composites;
}
@SuppressWarnings("unchecked")
@Override
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
if (instance == null) {
instance = SCADomain.createNewInstance(uri, location, composites);
}
Object result = instance.cast(target);
return (R) result;
}
@Override
public void close() {
if (instance == null) {
instance = SCADomain.createNewInstance(uri, location, composites);
}
instance.close();
instance = null;
}
@Override
public <B> B getService(Class<B> businessInterface, String serviceName) {
if (instance == null) {
instance = SCADomain.createNewInstance(uri, location, composites);
}
return instance.getService(businessInterface, serviceName);
}
@Override
public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
if (instance == null) {
instance = SCADomain.createNewInstance(uri, location, composites);
}
return instance.getServiceReference(businessInterface, referenceName);
}
@Override
protected void finalize() throws Throwable {
// Make sure that the SCA domain is closed
if (instance != null) {
instance.close();
instance = null;
}
}
@Override
public ComponentManager getComponentManager() {
if (instance == null) {
instance = SCADomain.createNewInstance(uri, location, composites);
}
return instance.getComponentManager();
}
}

View file

@ -1,291 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* A helper class that can be used to run an SCA JUnit test case. The test case will run in an isolated class loader.
*
* @version $Rev$ $Date$
*/
public class SCATestCaseRunner {
private ClassLoader classLoader;
private Class<?> testSuiteClass;
private Object testSuite;
private Class<?> testResultClass;
private Class<?> testCaseClass;
private Object testCase;
private Class<?> beforeAnnotation;
private Class<?> beforeClassAnnotation;
private Class<?> afterAnnotation;
private Class<?> afterClassAnnotation;
private Class<?> junit4AdapterClass;
private Class<?> junit3TestCaseClass;
/**
* Constructs a new TestCase runner.
*
* @param testClass
*/
public SCATestCaseRunner(Class testClass) {
try {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
classLoader = testClass.getClassLoader();
if (classLoader instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader)classLoader).getURLs();
classLoader = new URLClassLoader(urls, classLoader.getParent());
} else if (classLoader == tccl || classLoader.getParent() == tccl) {
classLoader = new URLClassLoader(new URL[0], classLoader);
} else {
classLoader = tccl;
}
try {
// Thread.currentThread().setContextClassLoader(classLoader);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finalClassLoader = classLoader;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finalClassLoader);
return null;
}
});
testCaseClass = Class.forName(testClass.getName(), true, classLoader);
testCase = testCaseClass.newInstance();
ClassLoader testClassLoader = testCaseClass.getClassLoader();
junit3TestCaseClass = Class.forName("junit.framework.TestCase", true, testClassLoader);
testSuiteClass = Class.forName("junit.framework.TestSuite", true, testClassLoader);
Constructor testSuiteConstructor = testSuiteClass.getConstructor(Class.class);
testSuite = testSuiteConstructor.newInstance(testCaseClass);
testResultClass = Class.forName("junit.framework.TestResult", true, testClassLoader);
try {
beforeAnnotation = Class.forName("org.junit.Before", true, testClassLoader);
afterAnnotation = Class.forName("org.junit.After", true, testClassLoader);
beforeClassAnnotation = Class.forName("org.junit.BeforeClass", true, testClassLoader);
afterClassAnnotation = Class.forName("org.junit.AfterClass", true, testClassLoader);
junit4AdapterClass = Class.forName("junit.framework.JUnit4TestAdapter", true, testClassLoader);
} catch (Exception e) {
// Unexpected
throw new AssertionError(e);
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
// Thread.currentThread().setContextClassLoader(tccl);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finaltccl = tccl;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finaltccl);
return null;
}
});
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Run the test case
*/
public void run() {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
// Thread.currentThread().setContextClassLoader(classLoader);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finalClassLoader = classLoader;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finalClassLoader);
return null;
}
});
if (junit3TestCaseClass.isAssignableFrom(testCaseClass)) {
Object testResult = testResultClass.newInstance();
Method runMethod = testSuiteClass.getMethod("run", testResultClass);
runMethod.invoke(testSuite, testResult);
} else {
Object junit4Adapter = junit4AdapterClass.getConstructor(Class.class).newInstance(testCaseClass);
Object testResult = testResultClass.newInstance();
Method runMethod = junit4AdapterClass.getMethod("run", testResultClass);
runMethod.invoke(junit4Adapter, testResult);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// Thread.currentThread().setContextClassLoader(tccl);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finaltccl = tccl;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finaltccl);
return null;
}
});
}
}
/**
* Invoke the setUp method
*/
public void setUp() {
execute("setUp");
}
/**
* Invoke the before methods
*/
public void before() {
execute(beforeAnnotation);
}
/**
* Invoke the beforeClass methods
*/
public void beforeClass() {
execute(beforeClassAnnotation);
}
/**
* Invoke the tearDown method
*/
public void tearDown() {
execute("tearDown");
}
/**
* Invoke the after methods
*/
public void after() {
execute(afterAnnotation);
}
/**
* Invoke the afterClass methods
*/
public void afterClass() {
execute(afterClassAnnotation);
}
/**
* Invoke the specified test method.
*/
public void run(String methodName) {
execute(methodName);
}
/**
* Invoke the methods annotated with the specified annotation.
*/
private void execute(Class<?> annotationClass) {
if (annotationClass == null) {
throw new RuntimeException(new NoSuchMethodException());
}
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
// Thread.currentThread().setContextClassLoader(classLoader);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finalClassLoader = classLoader;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finalClassLoader);
return null;
}
});
for (Method method : testCaseClass.getDeclaredMethods()) {
for (Annotation annotation : method.getAnnotations()) {
if (annotation.annotationType() == annotationClass) {
method.invoke(testCase);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// Thread.currentThread().setContextClassLoader(tccl);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finaltccl = tccl;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finaltccl);
return null;
}
});
}
}
/**
* Invoke the specified method
*/
private void execute(String methodName) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
// Thread.currentThread().setContextClassLoader(classLoader);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finalClassLoader = classLoader;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finalClassLoader);
return null;
}
});
Method setUpMethod = testCaseClass.getDeclaredMethod(methodName);
setUpMethod.setAccessible(true);
setUpMethod.invoke(testCase);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// Thread.currentThread().setContextClassLoader(tccl);
// Allow privileged access to set class loader. Requires RuntimePermission
// setContextClassLoader in security policy.
final ClassLoader finaltccl = tccl;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Thread.currentThread().setContextClassLoader(finaltccl);
return null;
}
});
}
}
}

View file

@ -1,120 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
/**
* Implementation of the ComponentManager.
*
* @version $Rev$ $Date$
*/
public class ComponentManagerImpl implements ComponentManager {
protected List<ComponentListener> listeners = new CopyOnWriteArrayList<ComponentListener>();
protected EmbeddedSCADomain domain;
public ComponentManagerImpl(EmbeddedSCADomain domain) {
this.domain = domain;
}
public void addComponentListener(ComponentListener listener) {
this.listeners.add(listener);
}
public void removeComponentListener(ComponentListener listener) {
this.listeners.remove(listener);
}
public Set<String> getComponentNames() {
Set<String> names = new HashSet<String>();
for (Composite composite: domain.getDomainComposite().getIncludes()) {
for (Component component: composite.getComponents()) {
names.add(component.getName());
}
}
return names;
}
public Component getComponent(String componentName) {
for (Composite composite: domain.getDomainComposite().getIncludes()) {
for (Component component: composite.getComponents()) {
if (component.getName().equals(componentName)) {
return component;
}
}
}
return null;
}
public void startComponent(String componentName) throws ActivationException {
Component component = getComponent(componentName);
if (component == null) {
throw new IllegalArgumentException("no component: " + componentName);
}
domain.getCompositeActivator().start(component);
notifyComponentStarted(componentName);
}
public void stopComponent(String componentName) throws ActivationException {
Component component = getComponent(componentName);
if (component == null) {
throw new IllegalArgumentException("no component: " + componentName);
}
domain.getCompositeActivator().stop(component);
notifyComponentStopped(componentName);
}
public void notifyComponentStarted(String componentName) {
for (ComponentListener listener : listeners) {
try {
listener.componentStarted(componentName);
} catch (Exception e) {
e.printStackTrace(); // TODO: log
}
}
}
public void notifyComponentStopped(String componentName) {
for (ComponentListener listener : listeners) {
try {
listener.componentStopped(componentName);
} catch (Exception e) {
e.printStackTrace(); // TODO: log
}
}
}
public boolean isComponentStarted(String componentName) {
RuntimeComponentImpl runtimeComponent = (RuntimeComponentImpl)getComponent(componentName);
return runtimeComponent.isStarted();
}
}

View file

@ -1,340 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.xml.Constants;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.apache.tuscany.sca.node.SCAClient;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.impl.NodeImpl;
import org.apache.tuscany.sca.node.impl.NodeUtil;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
/**
* A default SCA domain facade implementation.
*
* @version $Rev$ $Date$
*/
public class DefaultSCADomain extends SCADomain {
private String uri;
private String[] composites;
// private Composite domainComposite;
// private List<Contribution> contributions;
private Map<String, Component> components;
private ComponentManager componentManager;
// private ClassLoader runtimeClassLoader;
private ClassLoader applicationClassLoader;
private String domainURI;
private List<String> contributionURLs;
private CompositeActivator compositeActivator;
private SCANode node;
private SCAClient client;
/**
* Constructs a new domain facade.
*
* @param domainURI
* @param contributionLocation
* @param composites
*/
public DefaultSCADomain(ClassLoader runtimeClassLoader,
ClassLoader applicationClassLoader,
String domainURI,
String contributionLocation,
String... composites) {
this.uri = domainURI;
this.composites = composites;
// this.runtimeClassLoader = runtimeClassLoader;
this.applicationClassLoader = applicationClassLoader;
this.domainURI = domainURI;
this.contributionURLs = new ArrayList<String>();
if (contributionLocation != null && !"/".equals(contributionLocation)) {
this.contributionURLs.add(contributionLocation);
}
this.composites = composites;
init();
this.componentManager = new DefaultSCADomainComponentManager(this);
}
/**
* A hack to create an aggregated composite
* @param classLoader
* @param composites
* @return
*/
private String createDeploymentComposite(ClassLoader classLoader, String composites[]) {
try {
StringBuffer xml =
new StringBuffer("<sca:composite xmlns:sca=\"http://www.osoa.org/xmlns/sca/1.0\"")
.append(" targetNamespace=\"http://tempuri.org\" name=\"aggregated\">\n");
XMLInputFactory factory = XMLInputFactory.newInstance();
for (int i = 0; i < composites.length; i++) {
URL url = classLoader.getResource(composites[i]);
if (url == null) {
continue;
}
String location = NodeUtil.getContributionURL(url, composites[i]).toString();
if (!contributionURLs.contains(location)) {
contributionURLs.add(location);
}
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
XMLStreamReader reader = factory.createXMLStreamReader(connection.getInputStream());
reader.nextTag();
assert Constants.COMPOSITE_QNAME.equals(reader.getName());
String ns = reader.getAttributeValue(null, "targetNamespace");
if (ns == null) {
ns = XMLConstants.NULL_NS_URI;
}
String name = reader.getAttributeValue(null, "name");
reader.close();
if (XMLConstants.NULL_NS_URI.equals(ns)) {
xml.append("<sca:include name=\"").append(name).append("\"/>\n");
} else {
xml.append("<sca:include xmlns:ns").append(i).append("=\"").append(ns).append("\"");
xml.append(" name=\"").append("ns").append(i).append(":").append(name).append("\"/>\n");
}
}
xml.append("</sca:composite>");
// System.out.println(xml.toString());
return xml.toString();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
public void init() {
SCANodeFactory factory = SCANodeFactory.newInstance();
List<SCAContribution> contributions = new ArrayList<SCAContribution>();
if (composites != null && composites.length > 1) {
// Create an aggregated composite that includes all the composites as Node API only takes one composite
String content = createDeploymentComposite(applicationClassLoader, composites);
// Create SCA contributions
for (String location : contributionURLs) {
contributions.add(new SCAContribution(location, location));
}
node =
factory.createSCANode("http://tempuri.org/aggregated", content, contributions
.toArray(new SCAContribution[contributions.size()]));
} else {
for (String location : contributionURLs) {
contributions.add(new SCAContribution(location, location));
}
String composite = (composites != null && composites.length >= 1) ? composites[0] : null;
if (!contributions.isEmpty()) {
node =
factory.createSCANode(composite, contributions.toArray(new SCAContribution[contributions.size()]));
} else {
node = factory.createSCANodeFromClassLoader(composite, applicationClassLoader);
}
}
client = (SCAClient)node;
compositeActivator = ((NodeImpl)node).getCompositeActivator();
components = new HashMap<String, Component>();
node.start();
getComponents(compositeActivator.getDomainComposite());
}
private void getComponents(Composite composite) {
for (Component c : composite.getComponents()) {
components.put(c.getName(), c);
}
for (Composite cp : composite.getIncludes()) {
getComponents(cp);
}
}
@Override
public void close() {
super.close();
node.stop();
}
@Override
@SuppressWarnings("unchecked")
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
return (R)client.cast(target);
}
@Override
public <B> B getService(Class<B> businessInterface, String serviceName) {
return client.getService(businessInterface, serviceName);
}
@Override
public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
return client.getServiceReference(businessInterface, name);
}
@Override
public String getURI() {
return uri;
}
@Override
public ComponentManager getComponentManager() {
return componentManager;
}
public Set<String> getComponentNames() {
return components.keySet();
/*
Set<String> componentNames = new HashSet<String>();
for (Contribution contribution : contributions) {
for (Artifact artifact : contribution.getArtifacts()) {
if (artifact.getModel() instanceof Composite) {
for (Component component : ((Composite)artifact.getModel()).getComponents()) {
componentNames.add(component.getName());
}
}
}
}
return componentNames;
*/
}
public Component getComponent(String componentName) {
return components.get(componentName);
/*
for (Contribution contribution : contributions) {
for (Artifact artifact : contribution.getArtifacts()) {
if (artifact.getModel() instanceof Composite) {
for (Component component : ((Composite)artifact.getModel()).getComponents()) {
if (component.getName().equals(componentName)) {
return component;
}
}
}
}
}
return null;
*/
}
public void startComponent(String componentName) throws ActivationException {
Component component = getComponent(componentName);
if (component == null) {
throw new IllegalArgumentException("no component: " + componentName);
}
compositeActivator.start(component);
}
public void stopComponent(String componentName) throws ActivationException {
Component component = getComponent(componentName);
if (component == null) {
throw new IllegalArgumentException("no component: " + componentName);
}
compositeActivator.stop(component);
}
}
class DefaultSCADomainComponentManager implements ComponentManager {
protected DefaultSCADomain scaDomain;
protected List<ComponentListener> listeners = new CopyOnWriteArrayList<ComponentListener>();
public DefaultSCADomainComponentManager(DefaultSCADomain scaDomain) {
this.scaDomain = scaDomain;
}
public void addComponentListener(ComponentListener listener) {
this.listeners.add(listener);
}
public void removeComponentListener(ComponentListener listener) {
this.listeners.remove(listener);
}
public Set<String> getComponentNames() {
return scaDomain.getComponentNames();
}
public Component getComponent(String componentName) {
return scaDomain.getComponent(componentName);
}
public void startComponent(String componentName) throws ActivationException {
scaDomain.startComponent(componentName);
}
public void stopComponent(String componentName) throws ActivationException {
scaDomain.stopComponent(componentName);
}
public void notifyComponentStarted(String componentName) {
for (ComponentListener listener : listeners) {
try {
listener.componentStarted(componentName);
} catch (Exception e) {
e.printStackTrace(); // TODO: log
}
}
}
public void notifyComponentStopped(String componentName) {
for (ComponentListener listener : listeners) {
try {
listener.componentStopped(componentName);
} catch (Exception e) {
e.printStackTrace(); // TODO: log
}
}
}
public boolean isComponentStarted(String componentName) {
RuntimeComponentImpl runtimeComponent = (RuntimeComponentImpl)getComponent(componentName);
return runtimeComponent.isStarted();
}
}

View file

@ -1,235 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
import org.apache.tuscany.sca.assembly.xml.Constants;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.node.impl.RuntimeBootStrapper;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.ServiceRuntimeException;
/**
* An SCA domain facade implementation.
*
* @version $Rev$ $Date$
*/
public class EmbeddedSCADomain extends SCADomain {
private String uri;
private Composite domainComposite;
private RuntimeBootStrapper runtime;
private ComponentManagerImpl componentManager = new ComponentManagerImpl(this);
/**
* Constructs a new domain facade.
*
* @param runtimeClassLoader
* @param domainURI
*/
public EmbeddedSCADomain(ClassLoader runtimeClassLoader,
String domainURI) {
this.uri = domainURI;
// Create a runtime
runtime = new RuntimeBootStrapper(runtimeClassLoader);
}
public void start() throws ActivationException {
// Start the runtime
runtime.start();
// Create an in-memory domain level composite
AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
domainComposite = assemblyFactory.createComposite();
domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
domainComposite.setURI(uri);
getCompositeActivator().setDomainComposite(domainComposite);
}
public void stop() throws ActivationException {
// Stop the runtime
runtime.stop();
// Cleanup
domainComposite = null;
}
public void buildComposite(Composite composite) throws CompositeBuilderException {
runtime.buildComposite(composite);
}
public ContributionService getContributionService() {
return runtime.getContributionService();
}
public CompositeBuilder getCompositeBuilder() {
return runtime.getCompositeBuilder();
}
public CompositeActivator getCompositeActivator() {
return runtime.getCompositeActivator();
}
public Composite getDomainComposite() {
return domainComposite;
}
@Override
public ComponentManager getComponentManager() {
return componentManager;
}
@Override
public void close() {
super.close();
}
@Override
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
return (R)runtime.getProxyFactory().cast(target);
}
@Override
public <B> B getService(Class<B> businessInterface, String serviceName) {
ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
if (serviceReference == null) {
throw new ServiceRuntimeException("Service not found: " + serviceName);
}
return serviceReference.getService();
}
private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
try {
AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
Composite composite = assemblyFactory.createComposite();
composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
component.setName("default");
component.setURI("default");
runtime.getCompositeActivator().configureComponentContext(component);
composite.getComponents().add(component);
RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
reference.setName("default");
FactoryExtensionPoint factories =
runtime.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class);
JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
reference.setInterfaceContract(interfaceContract);
component.getReferences().add(reference);
reference.setComponent(component);
SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
SCABinding binding = scaBindingFactory.createSCABinding();
binding.setURI(targetURI);
reference.getBindings().add(binding);
return new ServiceReferenceImpl<B>(businessInterface, component, reference, binding, runtime
.getProxyFactory(), runtime.getCompositeActivator());
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
@Override
public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
// Extract the component name
String componentName;
String serviceName;
int i = name.indexOf('/');
if (i != -1) {
componentName = name.substring(0, i);
serviceName = name.substring(i + 1);
} else {
componentName = name;
serviceName = null;
}
// Lookup the component in the domain
Component component = componentManager.getComponent(componentName);
if (component == null) {
// The component is not local in the partition, try to create a remote service ref
return createServiceReference(businessInterface, name);
}
RuntimeComponentContext componentContext = null;
// If the component is a composite, then we need to find the
// non-composite component that provides the requested service
if (component.getImplementation() instanceof Composite) {
for (ComponentService componentService : component.getServices()) {
if (serviceName == null || serviceName.equals(componentService.getName())) {
CompositeService compositeService = (CompositeService)componentService.getService();
if (compositeService != null) {
if (serviceName != null) {
serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName;
}
componentContext =
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
return componentContext.createSelfReference(businessInterface, compositeService
.getPromotedService());
}
break;
}
}
// No matching service is found
throw new ServiceRuntimeException("Composite service not found: " + name);
} else {
componentContext = ((RuntimeComponent)component).getComponentContext();
if (serviceName != null) {
return componentContext.createSelfReference(businessInterface, serviceName);
} else {
return componentContext.createSelfReference(businessInterface);
}
}
}
@Override
public String getURI() {
return uri;
}
}

View file

@ -1,389 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.contribution.service.util.FileHelper;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.ServiceRuntimeException;
/**
* An SCADomain that starts a Tuscany runtime supporting multiple
* SCA contribution jars. All contribution jars found in a repository
* directory will be contributed to the SCA domain. Any changes to the
* contributions in that repository will be automatically detected and
* the SCADomain updated accordingly.
*
* TODO: find how to properly add/remove contributions and start/activate the SCADomain
* TODO: support contributions that are folders as well as jar's
* TODO: needs to restart the entire SCADomain when a contribution changes
* as the domain classpath includes all the contribution jar's, would
* be nice to find a way to avoid this
* TODO: hot update requires copying contribution jars to a temp location
* to avoid the classpath lock preventing updating the contribution
* jars, would be nice to find a way to avoid that
*
* @version $Rev$ $Date$
*/
public class HotUpdatableSCADomain extends SCADomain {
private static final Logger logger = Logger.getLogger(HotUpdatableSCADomain.class.getName());
protected String domainURI;
protected File contributionRepository;
protected EmbeddedSCADomain scaDomain;
protected boolean hotUpdateActive;
protected Thread hotUpdateThread;
protected int hotUpdateInterval; // milliseconds, 0 = hotupdate disabled
protected HashMap<URL, Long> existingContributions; // value is last modified time
protected ClassLoader originalCCL;
protected static final String REPOSITORY_FOLDER = "sca-contributions";
public HotUpdatableSCADomain(String domainURI, File contributionRepository, int hotupdateInterval) {
this.domainURI = domainURI;
this.contributionRepository = contributionRepository;
this.hotUpdateInterval = hotupdateInterval;
this.originalCCL = Thread.currentThread().getContextClassLoader();
start();
}
protected void start() {
try {
initEmbeddedSCADomain();
activateHotUpdate();
for (URL url : existingContributions.keySet()) {
File f = new File(url.toURI());
logger.info("added contribution: " + f.getName());
}
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
} catch (URISyntaxException e) {
throw new ServiceRuntimeException(e);
}
}
@Override
public void close() {
try {
hotUpdateActive = false;
scaDomain.stop();
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
}
Thread.currentThread().setContextClassLoader(originalCCL);
super.close();
}
protected SCADomain initEmbeddedSCADomain() throws ActivationException {
URL[] contributionJars = getContributionJarURLs(contributionRepository);
this.existingContributions = getLastModified(contributionJars);
if (hotUpdateInterval > 0) {
contributionJars = copyContributionsToTemp(contributionJars);
}
// Using the CCL as the parent exposes Tuscany to the contributions, want to do this?
URLClassLoader cl = new URLClassLoader(contributionJars, originalCCL);
Thread.currentThread().setContextClassLoader(cl);
scaDomain = new EmbeddedSCADomain(cl, domainURI);
scaDomain.start();
initContributions(scaDomain, cl, contributionJars);
return scaDomain;
}
protected URL[] getContributionJarURLs(File repositoryDir) {
String[] jars = repositoryDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}});
List<URL> contributionJars = new ArrayList<URL>();
if (jars != null) {
for (String jar : jars) {
try {
contributionJars.add(new File(repositoryDir, jar).toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
return contributionJars.toArray(new URL[contributionJars.size()]);
}
/**
* TODO: No idea what the 'correct' way to add/contribute and activate/start things to an scaDomain is
* but this seems to work. Doesn't seem to start <service>s or <reference>s which are outside of
* a <component> so something is missing/wrong. Also this doesn't seem to be picking up composites
* located in META-INF/deployables or specified in the sca-deployables.xml. Maybe the EmbeddedSCADomain
* and ContributionService APIs should make all this easier?
*/
protected void initContributions(EmbeddedSCADomain scaDomain, ClassLoader cl, URL[] contributionJars) {
Contribution contribution = null;
ContributionService contributionService = scaDomain.getContributionService();
for (URL jar : contributionJars) {
InputStream is = null;
try {
is = jar.openStream();
contribution = contributionService.contribute(jar.toString(), jar, is);
} catch (Exception e) {
System.err.println("exception adding contribution: " + jar);
e.printStackTrace();
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
if (contribution != null ) {
try {
for (Composite composite : contribution.getDeployables()) {
scaDomain.getDomainComposite().getIncludes().add(composite);
scaDomain.getCompositeBuilder().build(composite);
scaDomain.getCompositeActivator().activate(composite);
}
for (Composite composite : contribution.getDeployables()) {
scaDomain.getCompositeActivator().start(composite);
}
} catch (ActivationException e) {
throw new RuntimeException(e);
} catch (CompositeBuilderException e) {
throw new RuntimeException(e);
}
}
}
/**
* Copies Files to a temp location returning the URLs of the new temp files.
* For hot update to work need to be able to delete/update the contribution jar's
* but as they're in the classpath the URLClassLoader has an open lock on the jar's
* so you can't update them. This solution copies each contribution to a temp
* location for use on the classpath, nicer would be a ClassLoder impl that doesn't
* lock the jar's.
*/
protected URL[] copyContributionsToTemp(URL[] contributionJars) {
try {
URL[] newURLs = new URL[contributionJars.length];
File tempDir = new File(System.getProperty("java.io.tmpdir"));
for (int i=0; i<contributionJars.length; i++) {
File fin = new File(contributionJars[i].toURI());
File fout = File.createTempFile("tuscany", fin.getName(), tempDir);
fout.deleteOnExit();
FileHelper.copyFile(fin, fout);
fout.setLastModified(System.currentTimeMillis());
newURLs[i] = fout.toURL();
}
return newURLs;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
/**
* Returns the last modified times of the files pointed to by the URLs
*/
protected HashMap<URL, Long> getLastModified(URL[] contrabutions) {
try {
HashMap<URL, Long> contributionLastUpdates = new HashMap<URL, Long>();
for (URL url: contrabutions) {
File f = new File(url.toURI());
contributionLastUpdates.put(url, new Long(f.lastModified()));
}
return contributionLastUpdates;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
protected void activateHotUpdate() {
if (hotUpdateInterval == 0) {
return; // hotUpdateInterval of 0 disables hotupdate
}
Runnable runable = new Runnable() {
public void run() {
logger.info("Tuscany contribution hotupdate running");
while (hotUpdateActive) {
try {
Thread.sleep(hotUpdateInterval);
} catch (InterruptedException e) {
}
if (hotUpdateActive) {
checkForUpdates();
}
}
logger.info("Tuscany contribution hotupdate stopped");
}
};
hotUpdateThread = new Thread(runable, "TuscanyHotUpdate");
hotUpdateActive = true;
hotUpdateThread.start();
}
/**
* Checks if any of the contributions have been updated and if so restarts the SCADomain
* TODO: Ideally just the altered contribution would be restarted but thats not possible
* as the ClassLoader used by the SCADomain includes the old contribution so need
* to restart the entire domain to use a new ClassLoader. Should there be separate
* ClassLoader per contribution? But then have all the issues with sharing classes
* across contributions.
*/
protected void checkForUpdates() {
URL[] currentContributions = getContributionJarURLs(contributionRepository);
if (areContributionsAltered(currentContributions)) {
try {
scaDomain.stop();
} catch (Exception e) {
e.printStackTrace();
}
try {
initEmbeddedSCADomain();
} catch (Exception e) {
e.printStackTrace();
}
}
}
protected boolean areContributionsAltered(URL[] currentContrabutions) {
try {
List addedContributions = getAddedContributions(currentContrabutions);
List removedContributions = getRemovedContributions(currentContrabutions);
List updatedContributions = getUpdatedContributions(currentContrabutions);
return (addedContributions.size() > 0 || removedContributions.size() > 0 || updatedContributions.size() > 0);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
protected List<URL> getUpdatedContributions(URL[] currentContrabutions) throws URISyntaxException {
List<URL> urls = new ArrayList<URL>();
for (URL url : currentContrabutions) {
if (existingContributions.containsKey(url)) {
File curentFile = new File(url.toURI());
if (curentFile.lastModified() != existingContributions.get(url)) {
urls.add(url);
logger.info("updated contribution: " + curentFile.getName());
}
}
}
return urls;
}
protected List getRemovedContributions(URL[] currentContrabutions) throws URISyntaxException {
List<URL> currentUrls = Arrays.asList(currentContrabutions);
List<URL> urls = new ArrayList<URL>();
for (URL url : existingContributions.keySet()) {
if (!currentUrls.contains(url)) {
urls.add(url);
}
}
for (URL url : urls) {
logger.info("removed contributions: " + new File(url.toURI()).getName());
}
return urls;
}
protected List getAddedContributions(URL[] currentContrabutions) throws URISyntaxException {
List<URL> urls = new ArrayList<URL>();
for (URL url : currentContrabutions) {
if (!existingContributions.containsKey(url)) {
urls.add(url);
logger.info("added contribution: " + new File(url.toURI()).getName());
}
}
return urls;
}
@Override
public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
throw new UnsupportedOperationException("not implemented");
}
@Override
public <B> B getService(Class<B> businessInterface, String serviceName) {
return scaDomain.getService(businessInterface, serviceName);
}
@Override
public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
return scaDomain.getServiceReference(businessInterface, referenceName);
}
@Override
public String getURI() {
return domainURI;
}
@Override
public ComponentManager getComponentManager(){
return scaDomain.getComponentManager();
}
}

View file

@ -1,385 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.EndpointFactory;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.ModuleActivator;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
import org.apache.tuscany.sca.core.scope.ScopeRegistry;
import org.apache.tuscany.sca.definitions.SCADefinitions;
import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl;
import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.invocation.MessageFactory;
import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.IntentAttachPointType;
import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.provider.SCADefinitionsProvider;
import org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint;
import org.apache.tuscany.sca.work.WorkScheduler;
/**
*
* @version $Rev$ $Date$
*/
public class ReallySmallRuntime {
private static final Logger logger = Logger.getLogger(ReallySmallRuntime.class.getName());
private List<ModuleActivator> modules;
private ExtensionPointRegistry registry;
private ClassLoader classLoader;
private AssemblyFactory assemblyFactory;
private ContributionService contributionService;
private CompositeActivator compositeActivator;
private CompositeBuilder compositeBuilder;
// private DomainBuilder domainBuilder;
private WorkScheduler workScheduler;
private ScopeRegistry scopeRegistry;
private ProxyFactory proxyFactory;
private List<SCADefinitions> policyDefinitions;
private ModelResolver policyDefinitionsResolver;
private Monitor monitor;
public ReallySmallRuntime(ClassLoader classLoader) {
this.classLoader = classLoader;
}
public void start() throws ActivationException {
long start = System.currentTimeMillis();
// Create our extension point registry
registry = new DefaultExtensionPointRegistry();
UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
// Get work scheduler
workScheduler = utilities.getUtility(WorkScheduler.class);
// Create an interface contract mapper
InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
// Get factory extension point
FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
// Get Message factory
MessageFactory messageFactory = factories.getFactory(MessageFactory.class);
// Get proxy factory
ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
proxyFactory = new ExtensibleProxyFactory(proxyFactories);
// Create model factories
assemblyFactory = new RuntimeAssemblyFactory();
factories.addFactory(assemblyFactory);
PolicyFactory policyFactory = new DefaultPolicyFactory();
factories.addFactory(policyFactory);
// Load the runtime modules
modules = loadModules(registry);
// Start the runtime modules
startModules(registry, modules);
SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
IntentAttachPointTypeFactory intentAttachPointTypeFactory = new DefaultIntentAttachPointTypeFactory();
factories.addFactory(intentAttachPointTypeFactory);
ContributionFactory contributionFactory = factories.getFactory(ContributionFactory.class);
// Create a monitor
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
if (monitorFactory != null){
monitor = monitorFactory.createMonitor();
} else {
monitorFactory = new DefaultMonitorFactory();
monitor = monitorFactory.createMonitor();
utilities.addUtility(monitorFactory);
//logger.fine("No MonitorFactory is found on the classpath.");
}
// Create a contribution service
policyDefinitions = new ArrayList<SCADefinitions>();
policyDefinitionsResolver = new DefaultModelResolver();
contributionService = ReallySmallRuntimeBuilder.createContributionService(classLoader,
registry,
contributionFactory,
assemblyFactory,
policyFactory,
mapper,
policyDefinitions,
policyDefinitionsResolver,
monitor);
// Create the ScopeRegistry
scopeRegistry = ReallySmallRuntimeBuilder.createScopeRegistry(registry);
// Create a composite activator
compositeActivator = ReallySmallRuntimeBuilder.createCompositeActivator(registry,
assemblyFactory,
messageFactory,
scaBindingFactory,
mapper,
proxyFactory,
scopeRegistry,
workScheduler);
// Load the definitions.xml
loadSCADefinitions();
if (logger.isLoggable(Level.FINE)) {
long end = System.currentTimeMillis();
logger.fine("The tuscany runtime is started in " + (end - start) + " ms.");
}
}
public void stop() throws ActivationException {
long start = System.currentTimeMillis();
// Stop the runtime modules
stopModules(registry, modules);
// Stop and destroy the work manager
workScheduler.destroy();
// Cleanup
modules = null;
registry = null;
assemblyFactory = null;
contributionService = null;
compositeActivator = null;
workScheduler = null;
scopeRegistry = null;
if (logger.isLoggable(Level.FINE)) {
long end = System.currentTimeMillis();
logger.fine("The tuscany runtime is stopped in " + (end - start) + " ms.");
}
}
public void buildComposite(Composite composite) throws CompositeBuilderException {
//Get factory extension point
FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
IntentAttachPointTypeFactory intentAttachPointTypeFactory = factories.getFactory(IntentAttachPointTypeFactory.class);
EndpointFactory endpointFactory = factories.getFactory(EndpointFactory.class);
UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
DocumentBuilderFactory documentBuilderFactory = factories.getFactory(DocumentBuilderFactory.class);
TransformerFactory transformerFactory = factories.getFactory(TransformerFactory.class);
//Create a composite builder
SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl();
for ( SCADefinitions definition : ((List<SCADefinitions>)policyDefinitions) ) {
SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions);
}
compositeBuilder = ReallySmallRuntimeBuilder.createCompositeBuilder(monitor,
assemblyFactory,
scaBindingFactory,
endpointFactory,
intentAttachPointTypeFactory,
documentBuilderFactory,
transformerFactory,
mapper,
aggregatedDefinitions);
compositeBuilder.build(composite);
}
public ContributionService getContributionService() {
return contributionService;
}
public CompositeActivator getCompositeActivator() {
return compositeActivator;
}
public CompositeBuilder getCompositeBuilder() {
return compositeBuilder;
}
public AssemblyFactory getAssemblyFactory() {
return assemblyFactory;
}
private void loadSCADefinitions() throws ActivationException {
try {
URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
URLArtifactProcessor<SCADefinitions> definitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
SCADefinitionsProviderExtensionPoint scaDefnProviders = registry.getExtensionPoint(SCADefinitionsProviderExtensionPoint.class);
SCADefinitions systemSCADefinitions = new SCADefinitionsImpl();
SCADefinitions aSCADefn = null;
for ( SCADefinitionsProvider aProvider : scaDefnProviders.getSCADefinitionsProviders() ) {
aSCADefn = aProvider.getSCADefinition();
SCADefinitionsUtil.aggregateSCADefinitions(aSCADefn, systemSCADefinitions);
}
policyDefinitions.add(systemSCADefinitions);
//we cannot expect that providers will add the intents and policysets into the resolver
//so we do this here explicitly
for ( Intent intent : systemSCADefinitions.getPolicyIntents() ) {
policyDefinitionsResolver.addModel(intent);
}
for ( PolicySet policySet : systemSCADefinitions.getPolicySets() ) {
policyDefinitionsResolver.addModel(policySet);
}
for ( IntentAttachPointType attachPoinType : systemSCADefinitions.getBindingTypes() ) {
policyDefinitionsResolver.addModel(attachPoinType);
}
for ( IntentAttachPointType attachPoinType : systemSCADefinitions.getImplementationTypes() ) {
policyDefinitionsResolver.addModel(attachPoinType);
}
//now that all system sca definitions have been read, lets resolve them right away
definitionsProcessor.resolve(systemSCADefinitions,
policyDefinitionsResolver);
} catch ( Exception e ) {
throw new ActivationException(e);
}
}
@SuppressWarnings("unchecked")
private List<ModuleActivator> loadModules(ExtensionPointRegistry registry) throws ActivationException {
// Load and instantiate the modules found on the classpath (or any registered ClassLoaders)
modules = new ArrayList<ModuleActivator>();
try {
Set<ServiceDeclaration> moduleActivators =
ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class.getName());
Set<String> moduleClasses = new HashSet<String>();
for (ServiceDeclaration moduleDeclarator : moduleActivators) {
if (moduleClasses.contains(moduleDeclarator.getClassName())) {
continue;
}
moduleClasses.add(moduleDeclarator.getClassName());
Class<?> moduleClass = moduleDeclarator.loadClass();
ModuleActivator module = (ModuleActivator)moduleClass.newInstance();
modules.add(module);
}
} catch (IOException e) {
throw new ActivationException(e);
} catch (ClassNotFoundException e) {
throw new ActivationException(e);
} catch (InstantiationException e) {
throw new ActivationException(e);
} catch (IllegalAccessException e) {
throw new ActivationException(e);
}
return modules;
}
private void startModules(ExtensionPointRegistry registry, List<ModuleActivator> modules)
throws ActivationException {
boolean debug = logger.isLoggable(Level.FINE);
// Start all the extension modules
for (ModuleActivator module : modules) {
long start = 0L;
if (debug) {
logger.fine(module.getClass().getName() + " is starting.");
start = System.currentTimeMillis();
}
try {
module.start(registry);
if (debug) {
long end = System.currentTimeMillis();
logger.fine(module.getClass().getName() + " is started in " + (end - start) + " ms.");
}
} catch (Throwable e) {
logger.log(Level.WARNING, "Exception starting module " + module.getClass().getName() + " :" + e.getMessage());
logger.log(Level.FINE, "Exception starting module " + module.getClass().getName(), e);
}
}
}
private void stopModules(final ExtensionPointRegistry registry, List<ModuleActivator> modules) {
boolean debug = logger.isLoggable(Level.FINE);
for (ModuleActivator module : modules) {
long start = 0L;
if (debug) {
logger.fine(module.getClass().getName() + " is stopping.");
start = System.currentTimeMillis();
}
module.stop(registry);
if (debug) {
long end = System.currentTimeMillis();
logger.fine(module.getClass().getName() + " is stopped in " + (end - start) + " ms.");
}
}
}
/**
* @return the proxyFactory
*/
public ProxyFactory getProxyFactory() {
return proxyFactory;
}
/**
* @return the registry
*/
public ExtensionPointRegistry getExtensionPointRegistry() {
return registry;
}
}

View file

@ -1,275 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.TransformerFactory;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.EndpointFactory;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
import org.apache.tuscany.sca.context.RequestContextFactory;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory;
import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
import org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint;
import org.apache.tuscany.sca.contribution.service.ContributionRepository;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener;
import org.apache.tuscany.sca.contribution.service.TypeDescriber;
import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl;
import org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl;
import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
import org.apache.tuscany.sca.core.conversation.ConversationManager;
import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.core.scope.CompositeScopeContainerFactory;
import org.apache.tuscany.sca.core.scope.ConversationalScopeContainerFactory;
import org.apache.tuscany.sca.core.scope.RequestScopeContainerFactory;
import org.apache.tuscany.sca.core.scope.ScopeContainerFactory;
import org.apache.tuscany.sca.core.scope.ScopeRegistry;
import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl;
import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory;
import org.apache.tuscany.sca.definitions.SCADefinitions;
import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.invocation.MessageFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
import org.apache.tuscany.sca.work.WorkScheduler;
/**
*
* @version $Rev$ $Date$
*/
public class ReallySmallRuntimeBuilder {
// private static final Logger logger = Logger.getLogger(ReallySmallRuntimeBuilder.class.getName());
public static CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
AssemblyFactory assemblyFactory,
MessageFactory messageFactory,
SCABindingFactory scaBindingFactory,
InterfaceContractMapper mapper,
ProxyFactory proxyFactory,
ScopeRegistry scopeRegistry,
WorkScheduler workScheduler) {
// Create a wire post processor extension point
RuntimeWireProcessorExtensionPoint wireProcessors =
registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
RuntimeWireProcessor wireProcessor = new ExtensibleWireProcessor(wireProcessors);
// Retrieve the processors extension point
StAXArtifactProcessorExtensionPoint processors =
registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
// Create a provider factory extension point
ProviderFactoryExtensionPoint providerFactories =
registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
// Create a endpoint resolver factory extension point
EndpointResolverFactoryExtensionPoint endpointResolverFactories =
registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class);
JavaInterfaceFactory javaInterfaceFactory =
registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class);
RequestContextFactory requestContextFactory =
registry.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class);
UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
ConversationManager conversationManager = utilities.getUtility(ConversationManager.class);
// Create the composite activator
CompositeActivator compositeActivator =
new CompositeActivatorImpl(assemblyFactory, messageFactory, javaInterfaceFactory, scaBindingFactory,
mapper, scopeRegistry, workScheduler, wireProcessor, requestContextFactory,
proxyFactory, providerFactories, endpointResolverFactories, processors, conversationManager);
return compositeActivator;
}
public static CompositeBuilder createCompositeBuilder(Monitor monitor,
AssemblyFactory assemblyFactory,
SCABindingFactory scaBindingFactory,
EndpointFactory endpointFactory,
IntentAttachPointTypeFactory intentAttachPointTypeFactory,
DocumentBuilderFactory documentBuilderFactory,
TransformerFactory transformerFactory,
InterfaceContractMapper interfaceContractMapper,
SCADefinitions policyDefinitions) {
return new CompositeBuilderImpl(assemblyFactory,
endpointFactory,
scaBindingFactory,
intentAttachPointTypeFactory,
documentBuilderFactory,
transformerFactory,
interfaceContractMapper,
policyDefinitions,
monitor);
}
/**
* Create the contribution service used by this domain.
*
* @throws ActivationException
*/
public static ContributionService createContributionService(ClassLoader classLoader,
ExtensionPointRegistry registry,
ContributionFactory contributionFactory,
AssemblyFactory assemblyFactory,
PolicyFactory policyFactory,
InterfaceContractMapper mapper,
List<SCADefinitions> policyDefinitions,
ModelResolver policyDefinitionResolver,
Monitor monitor)
throws ActivationException {
// Get the model factory extension point
FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
// Create a new XML input factory
// Allow privileged access to factory. Requires RuntimePermission in security policy file.
XMLInputFactory inputFactory = AccessController.doPrivileged(new PrivilegedAction<XMLInputFactory>() {
public XMLInputFactory run() {
return XMLInputFactory.newInstance();
}
});
modelFactories.addFactory(inputFactory);
// Create a validation XML schema extension point
ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
// Create a validating XML input factory
XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, monitor);
modelFactories.addFactory(validatingInputFactory);
// Create StAX artifact processor extension point
StAXArtifactProcessorExtensionPoint staxProcessors =
registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
// Create and register StAX processors for SCA assembly XML
// Allow privileged access to factory. Requires RuntimePermission in security policy file.
XMLOutputFactory outputFactory = AccessController.doPrivileged(new PrivilegedAction<XMLOutputFactory>() {
public XMLOutputFactory run() {
return XMLOutputFactory.newInstance();
}
});
ExtensibleStAXArtifactProcessor staxProcessor =
new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor);
// Create URL artifact processor extension point
URLArtifactProcessorExtensionPoint documentProcessors =
registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
// Create and register document processors for SCA assembly XML
documentProcessors.getProcessor(Composite.class);
DocumentBuilderFactory documentBuilderFactory = AccessController.doPrivileged(new PrivilegedAction<DocumentBuilderFactory>() {
public DocumentBuilderFactory run() {
return DocumentBuilderFactory.newInstance();
}
});
documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, documentBuilderFactory, policyDefinitions, monitor));
// Create Model Resolver extension point
ModelResolverExtensionPoint modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
// Create contribution package processor extension point
TypeDescriber describer = new PackageTypeDescriberImpl();
PackageProcessor packageProcessor =
new ExtensiblePackageProcessor(registry.getExtensionPoint(PackageProcessorExtensionPoint.class), describer, monitor);
// Create contribution listener
ExtensibleContributionListener contributionListener =
new ExtensibleContributionListener(registry.getExtensionPoint(ContributionListenerExtensionPoint.class));
// Create a contribution repository
ContributionRepository repository;
try {
repository = new ContributionRepositoryImpl("target", inputFactory, monitor);
} catch (IOException e) {
throw new ActivationException(e);
}
ExtensibleURLArtifactProcessor documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, monitor);
// Create the contribution service
ContributionService contributionService =
new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor,
contributionListener, policyDefinitionResolver, modelResolvers, modelFactories,
assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor);
return contributionService;
}
public static ScopeRegistry createScopeRegistry(ExtensionPointRegistry registry) {
ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
ScopeContainerFactory[] factories =
new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(),
new RequestScopeContainerFactory(),
new ConversationalScopeContainerFactory(null),
// new HttpSessionScopeContainer(monitor)
};
for (ScopeContainerFactory f : factories) {
scopeRegistry.register(f);
}
//FIXME Pass the scope container differently as it's not an extension point
registry.addExtensionPoint(scopeRegistry);
return scopeRegistry;
}
}

View file

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.management;
import java.util.EventListener;
/**
* Component Listener interface.
*
* @version $Rev$ $Date$
*/
public interface ComponentListener extends EventListener {
void componentStarted(String componentName);
void componentStopped(String componentName);
}

View file

@ -1,48 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.management;
import java.util.Set;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.core.assembly.ActivationException;
/**
* Component Manager interface.
*
* @version $Rev$ $Date$
*/
public interface ComponentManager {
Set<String> getComponentNames();
Component getComponent(String componentName);
boolean isComponentStarted(String componentName);
void startComponent(String componentName) throws ActivationException;
void stopComponent(String componentName) throws ActivationException;
void addComponentListener(ComponentListener listener);
void removeComponentListener(ComponentListener listener);
}

View file

@ -1,57 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
import org.osoa.sca.ServiceReference;
/**
* Test creation of an SCADomainBean and invocation of a service.
*
* @version $Rev$ $Date$
*/
public class SCADomainBeanTestCase extends TestCase {
private SCADomainBean domain;
@Override
protected void setUp() throws Exception {
domain = new SCADomainBean();
domain.setDeployableComposites("test.composite");
}
public void testInvoke() throws Exception {
ServiceReference<TestService> serviceReference = domain.getServiceReference(TestService.class, "TestServiceComponent");
assertNotNull(serviceReference);
TestService service = serviceReference.getService();
String result = service.ping("Bob");
assertEquals("Hello Bob", result);
}
@Override
protected void tearDown() throws Exception {
domain.close();
}
}

View file

@ -1,56 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
import org.osoa.sca.ServiceReference;
/**
* Test SCADomain.newInstance and invocation of a service.
*
* @version $Rev$ $Date$
*/
public class SCADomainTestCase extends TestCase {
private SCADomain domain;
@Override
protected void setUp() throws Exception {
domain = SCADomain.newInstance("test.composite");
}
public void testInvoke() throws Exception {
ServiceReference<TestService> serviceReference = domain.getServiceReference(TestService.class, "TestServiceComponent");
assertNotNull(serviceReference);
TestService service = serviceReference.getService();
String result = service.ping("Bob");
assertEquals("Hello Bob", result);
}
@Override
protected void tearDown() throws Exception {
domain.close();
}
}

View file

@ -1,63 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import junit.framework.TestCase;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
/**
* Test creation of DefaultSCADomain.
*
* @version $Rev$ $Date$
*/
public class DefaultSCADomainTestCase extends TestCase {
private DefaultSCADomain domain;
@Override
protected void setUp() throws Exception {
domain = new DefaultSCADomain(getClass().getClassLoader(), getClass().getClassLoader(),
"http://localhost", "./target/test-classes", "test.composite");
}
public void testStart() throws Exception {
TestService service = domain.getService(TestService.class, "TestServiceComponent");
assertNotNull(service);
}
public void testComponentManager() throws Exception {
ComponentManager componentManager = domain.getComponentManager();
assertEquals(1, componentManager.getComponentNames().size());
assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next());
assertNotNull(componentManager.getComponent("TestServiceComponent"));
assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
componentManager.stopComponent("TestServiceComponent");
assertFalse(componentManager.isComponentStarted("TestServiceComponent"));
}
@Override
protected void tearDown() throws Exception {
domain.close();
}
}

View file

@ -1,189 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.net.URL;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
/**
* Test creation of an EmbeddedSCADomain and invocation of a service.
*
* @version $Rev$ $Date$
*/
public class EmbeddedSCADomainTestCase extends TestCase {
private EmbeddedSCADomain domain;
@Override
protected void setUp() throws Exception {
// Create a test embedded SCA domain
domain = new EmbeddedSCADomain(getClass().getClassLoader(), "http://localhost");
}
public void testDomain() throws Exception {
// Start the domain
domain.start();
// Determine my class loader and my test SCA contribution location
ClassLoader myClassLoader = getClass().getClassLoader();
String url = myClassLoader.getResource("test.txt").toString();
url = url.substring(0, url.length()-8);
// Contribute the SCA contribution
TestModelResolver myResolver = new TestModelResolver(myClassLoader);
ContributionService contributionService = domain.getContributionService();
Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
assertNotNull(contribution);
// Decide which SCA composite I want to deploy
Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
// Add the deployable composite to the domain
domain.getDomainComposite().getIncludes().add(myComposite);
domain.buildComposite(myComposite);
// Start the composite
domain.getCompositeActivator().activate(myComposite);
domain.getCompositeActivator().start(myComposite);
// At this point the domain contains my contribution, my composite and
// it's started, my application code can start using it
// Get the TestServiceComponent service
TestService service = domain.getService(TestService.class, "TestServiceComponent");
// Invoke the service
String result = service.ping("Bob");
assertEquals("Hello Bob", result);
// Stop my composite
domain.getCompositeActivator().stop(myComposite);
domain.getCompositeActivator().deactivate(myComposite);
// Remove my composite
domain.getDomainComposite().getIncludes().remove(myComposite);
// Remove my contribution
contributionService.remove("http://test/contribution");
// Stop the domain
domain.stop();
}
public void testComponentManager() throws Exception {
// Start the domain
domain.start();
// Determine my class loader and my test SCA contribution location
ClassLoader myClassLoader = getClass().getClassLoader();
String url = myClassLoader.getResource("test.txt").toString();
url = url.substring(0, url.length()-8);
// Contribute the SCA contribution
TestModelResolver myResolver = new TestModelResolver(myClassLoader);
ContributionService contributionService = domain.getContributionService();
Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
assertNotNull(contribution);
// Decide which SCA composite I want to deploy
Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
// Add the deployable composite to the domain
domain.getDomainComposite().getIncludes().add(myComposite);
domain.buildComposite(myComposite);
// Start the composite
domain.getCompositeActivator().activate(myComposite);
domain.getCompositeActivator().start(myComposite);
// At this point the domain contains my contribution, my composite and
// it's started, my application code can start using it
ComponentManager componentManager = domain.getComponentManager();
assertEquals(1, componentManager.getComponentNames().size());
assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next());
Component component = componentManager.getComponent("TestServiceComponent");
assertNotNull(component);
assertEquals("TestServiceComponent", component.getName());
MyComponentListener cl = new MyComponentListener();
componentManager.addComponentListener(cl);
assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
assertFalse(cl.stopCalled);
componentManager.stopComponent("TestServiceComponent");
assertTrue(cl.stopCalled);
assertFalse(componentManager.isComponentStarted("TestServiceComponent"));
assertFalse(cl.startCalled);
componentManager.startComponent("TestServiceComponent");
assertTrue(cl.startCalled);
assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
// Stop my composite
domain.getCompositeActivator().stop(myComposite);
domain.getCompositeActivator().deactivate(myComposite);
// Remove my composite
domain.getDomainComposite().getIncludes().remove(myComposite);
// Remove my contribution
contributionService.remove("http://test/contribution");
// Stop the domain
domain.stop();
}
class MyComponentListener implements ComponentListener {
boolean startCalled;
boolean stopCalled;
public void componentStarted(String componentName) {
startCalled = true;
}
public void componentStopped(String componentName) {
stopCalled = true;
}
}
@Override
protected void tearDown() throws Exception {
domain.close();
}
}

View file

@ -1,104 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tuscany.sca.host.embedded.impl;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
/**
* A test model resolver, based on a map.
*
* @version $Rev$ $Date$
*/
public class TestModelResolver implements ModelResolver {
private static final long serialVersionUID = -7826976465762296634L;
private Map<Object, Object> map = new HashMap<Object, Object>();
private WeakReference<ClassLoader> classLoader;
private Map<QName, Composite> composites = new HashMap<QName, Composite>();
public TestModelResolver(ClassLoader classLoader) {
this.classLoader = new WeakReference<ClassLoader>(classLoader);
}
public <T> T resolveModel(Class<T> modelClass, T unresolved) {
Object resolved = map.get(unresolved);
if (resolved != null) {
// Return the resolved object
return modelClass.cast(resolved);
} else if (unresolved instanceof ClassReference) {
// Load a class on demand
ClassReference classReference = (ClassReference)unresolved;
Class<?> clazz;
try {
clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
} catch (ClassNotFoundException e) {
// Return the unresolved object
return unresolved;
}
// Store a new ClassReference wrapping the loaded class
resolved = new ClassReference(clazz);
map.put(resolved, resolved);
// Return the resolved ClassReference
return modelClass.cast(resolved);
} else {
// Return the unresolved object
return unresolved;
}
}
public void addModel(Object resolved) {
map.put(resolved, resolved);
if (resolved instanceof Composite) {
Composite composite = (Composite)resolved;
composites.put(composite.getName(), composite);
}
}
public Object removeModel(Object resolved) {
if (resolved instanceof Composite) {
Composite composite = (Composite)resolved;
composites.remove(composite.getName());
}
return map.remove(resolved);
}
public Composite getComposite(QName qname) {
return composites.get(qname);
}
}

Some files were not shown because too many files have changed in this diff Show more