diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-13 20:02:36 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-13 20:02:36 +0000 |
commit | 4ed0ed906e82c9484b384419fa4ef4c980768731 (patch) | |
tree | e0250b6d10349e29522a2b1667d2e1db4d9dab84 /branches/sca-java-1.x/itest/recursive/src/test/java | |
parent | ba73f8abcef884936f965c3085b80485bf2b5e1a (diff) |
Creating Java SCA 1.x branch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@713805 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
18 files changed, 981 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java new file mode 100644 index 0000000000..1f7c35dd91 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/circular/include/CircularIncludeTestCase.java @@ -0,0 +1,39 @@ +/* + * 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 circular.include; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.Test; + +public class CircularIncludeTestCase { + + @Test + public void testCyclicInclude() { + SCADomain scaDomain = SCADomain.newInstance("Demo1Composite.composite"); + + DemoClass demoService = scaDomain.getService(DemoClass.class, "Demo1Component"); + String demo = demoService.demo(); + Assert.assertEquals("hello", demo); + scaDomain.close(); + } + +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/composite/CompositeTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/composite/CompositeTestCase.java new file mode 100644 index 0000000000..5482e47463 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/composite/CompositeTestCase.java @@ -0,0 +1,51 @@ +/* + * 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 composite; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class CompositeTestCase extends TestCase { + + private SCADomain domain; + private Source source; + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("OuterComposite.composite"); + source = domain.getService(Source.class, "SourceComponent"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + public void test() throws Exception { + try { + System.out.println("Main thread " + Thread.currentThread()); + source.clientMethod("Client.main"); + System.out.println("Sleeping ..."); + Thread.sleep(1000); + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java new file mode 100644 index 0000000000..f042113f7a --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java @@ -0,0 +1,113 @@ +/*
+ * 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 composite;
+
+import java.io.File;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+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.impl.EmbeddedSCADomain;
+
+public class LocateServiceEmbeddedSCADomainTestCase extends TestCase {
+ private ClassLoader cl;
+ private EmbeddedSCADomain domain;
+ private Contribution contribution;
+
+ @Override
+ protected void setUp() throws Exception {
+ // Create a test embedded SCA domain
+ cl = getClass().getClassLoader();
+ domain = new EmbeddedSCADomain(cl, "http://localhost");
+
+ // Start the domain
+ domain.start();
+
+ // Contribute the SCA contribution
+ ContributionService contributionService = domain.getContributionService();
+
+ File contribLocation = new File("./target/classes/");
+ URL contributionURL = contribLocation.toURL();
+ contribution = contributionService.contribute("http://contribution", contributionURL, false);
+ for (Composite deployable : contribution.getDeployables()) {
+ domain.getDomainComposite().getIncludes().add(deployable);
+ domain.buildComposite(deployable);
+ }
+
+ // Start Components from my composite
+ for (Composite deployable : contribution.getDeployables() ) {
+ domain.getCompositeActivator().activate(deployable);
+ domain.getCompositeActivator().start(deployable);
+ }
+ }
+
+ public void testValidLocateService() throws Exception {
+ Source source;
+ try {
+ source = domain.getService(Source.class, "SourceComponent");
+ assertNotNull(source);
+ } catch (Throwable t) {
+ fail("Could not locate service");
+ }
+ }
+
+ public void testInvalidLocateService() throws Exception {
+ Source source;
+ try {
+ source = domain.getService(Source.class, "SourceComponentXXX");
+ // The source proxy can be created for the remote target but it will throw exception when a method is invoked
+ source.clientMethod("ABC");
+ fail("Expected to generate org.osoa.sca.ServiceRuntimeException but did not when invoking service with async");
+ } catch (org.osoa.sca.ServiceRuntimeException e) {
+ // expected.
+ }
+ }
+
+ public void testValidRecursiveLocateService() throws Exception {
+ Source source;
+ try {
+ source = domain.getService(Source.class, "SourceComponent/InnerSourceService");
+ assertNotNull(source);
+ } catch (Throwable t) {
+ fail("Could not locate service");
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ ContributionService contributionService = domain.getContributionService();
+
+ // Remove the contribution from the in-memory repository
+ contributionService.remove("http://contribution");
+
+ // Stop Components from my composite
+ for (Composite deployable : contribution.getDeployables() ) {
+ domain.getCompositeActivator().stop(deployable);
+ domain.getCompositeActivator().deactivate(deployable);
+ }
+
+ domain.stop();
+ domain.close();
+ }
+
+}
diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java new file mode 100644 index 0000000000..87eb948452 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java @@ -0,0 +1,73 @@ +/*
+ * 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 composite;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+public class LocateServiceSCADomainTestCase extends TestCase {
+
+ private SCADomain domain;
+
+
+ @Override
+ protected void setUp() throws Exception {
+ domain = SCADomain.newInstance("OuterComposite.composite");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+ public void testValidLocateService() throws Exception {
+ Source source;
+ try {
+ source = domain.getService(Source.class, "SourceComponent");
+ assertNotNull(source);
+ } catch (Throwable t) {
+ fail("Could not locate service");
+ }
+ }
+
+ public void testInvalidLocateService() throws Exception {
+ Source source;
+ try {
+ source = domain.getService(Source.class, "SourceComponentXXX");
+ // The source proxy can be created for the remote target but it will throw exception when a method is invoked
+ source.clientMethod("ABC");
+ fail("Expected to generate org.osoa.sca.ServiceRuntimeException but did not when invoking service with async");
+ } catch (org.osoa.sca.ServiceRuntimeException e) {
+ // expected.
+ }
+ }
+
+ public void testValidRecursiveLocateService() throws Exception {
+ Source source;
+ try {
+ source = domain.getService(Source.class, "SourceComponent/InnerSourceService");
+ assertNotNull(source);
+ } catch (Throwable t) {
+ fail("Could not locate service");
+ }
+ }
+
+}
diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/foo/O2TestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/foo/O2TestCase.java new file mode 100644 index 0000000000..d617ec8592 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/foo/O2TestCase.java @@ -0,0 +1,32 @@ +/* + * 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 foo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class O2TestCase extends TestCase { + + public void testGet() throws Exception { + SCADomain sca = SCADomain.newInstance("foo/o2.composite"); + I i = sca.getService(I.class, "O1Component"); + assertEquals("foo.A", i.get(0)); + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/foo/O4TestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/foo/O4TestCase.java new file mode 100644 index 0000000000..15626c75ac --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/foo/O4TestCase.java @@ -0,0 +1,39 @@ +/* + * 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 foo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class O4TestCase extends TestCase { + + public void testO3Component() throws Exception { + SCADomain sca = SCADomain.newInstance("foo/o4.composite"); + I i = sca.getService(I.class, "O3Component"); + assertEquals("foo.A", i.get(0)); + } + + public void testO2Component() throws Exception { + SCADomain sca = SCADomain.newInstance("foo/o4.composite"); + I i = sca.getService(I.class, "O2Component"); + assertEquals("foo.A", i.get(0)); + } + +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/policy/PolicyTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/policy/PolicyTestCase.java new file mode 100644 index 0000000000..c9cc84f7d4 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/policy/PolicyTestCase.java @@ -0,0 +1,68 @@ +/* + * 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 policy; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.impl.CompositeImpl; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PolicyTestCase { + + private SCADomain domain; + private Target targetClient; + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance("policy/PolicyOuterComposite.composite"); + targetClient = domain.getService(Target.class, "TargetClientComponent"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + @Test + public void test() throws Exception { + try { + //Check that the implementation policy sets don't flow down to the components + //implementations that are themselves composites (implementation.composite) + Component outerComponent = ((DefaultSCADomain)domain).getComponent("OuterTargetServiceComponent"); + + Assert.assertEquals(0, outerComponent.getPolicySets().size()); + + for (Component component :((CompositeImpl)outerComponent.getImplementation()).getComponents()){ + Assert.assertEquals(0, component.getPolicySets().size()); + } + + // debugging + String result = targetClient.hello("Fred"); + + System.out.println(result); + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/C.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/C.java new file mode 100644 index 0000000000..bf8391348b --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/C.java @@ -0,0 +1,32 @@ +/* + * 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 sample; + +/** + * Simple Service + */ +public interface C { + + /** + * Sample operation + * + * @return A String + */ + String cOp(); +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/CImpl.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/CImpl.java new file mode 100644 index 0000000000..466284983e --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/CImpl.java @@ -0,0 +1,80 @@ +/* + * 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 sample; + +import junit.framework.Assert; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * Implementation of a simple service + */ +@Service(C.class) +public class CImpl implements C { + + /** + * Reference to X + */ + private X xRef; + + /** + * Reference to Y + */ + private Y yRef; + + /** + * Setter for refX + * + * @param x Reference to X + */ + @Reference(name="refX") + protected void setX(X x) + { + System.out.println("Setting X on CImpl to " + x); + xRef = x; + } + + /** + * Setter for refY + * + * @param y Reference to Y + */ + @Reference(name="refY") + protected void setY(Y y) + { + System.out.println("Setting Y on CImpl to " + y); + yRef = y; + } + + /** + * Simple operation that uses the injected references to X and Y + * + * @return "C:cOp() - xResult = " + xRef.xOP() + " yResult = " + yRef.yOp(); + */ + public String cOp() { + Assert.assertNotNull(xRef); + Assert.assertNotNull(yRef); + + String xResult = xRef.xOp(); + String yResult = yRef.yOp(); + + return "C:cOp() - xResult = " + xResult + " yResult = " + yResult; + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/NestedTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/NestedTestCase.java new file mode 100644 index 0000000000..fc5d251460 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/NestedTestCase.java @@ -0,0 +1,96 @@ +/* + * 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 sample; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + + +/** + * Test for implementation.composite using implementation.composite + */ +public class NestedTestCase extends TestCase { + + /** + * Reference to the domain + */ + private SCADomain domain; + + /** + * Tear down the domain + */ + @Override + protected void tearDown() throws Exception { + if (domain != null) { + domain.close(); + } + } + + /** + * This tests having: + * + * AComponent -> implementation.composite(BComposite) + * BComposite -> implementation.composite(CComposite) + * + * This test fails. + * + * @throws Exception Failed + */ + public void testAComponent() throws Exception { + domain = SCADomain.newInstance("AComposite.composite"); + + System.out.println("Deployed names = " + domain.getComponentManager().getComponentNames()); + + C c = domain.getService(C.class, "AComponent"); + + String result = c.cOp(); + System.out.println("Method call returned [" + result + "]"); + Assert.assertNotNull(result); + Assert.assertTrue(result.indexOf("C:cOp()") != -1); + Assert.assertTrue(result.indexOf("X:xOp()") != -1); + Assert.assertTrue(result.indexOf("Y:yOp()") != -1); + } + + + /** + * This tests having: + * + * BComposite -> implementation.composite(CComposite) + * + * This test works. + * + * @throws Exception Failed + */ + public void testBComponent() throws Exception { + domain = SCADomain.newInstance("BComposite.composite"); + + System.out.println("Deployed names = " + domain.getComponentManager().getComponentNames()); + + C c = domain.getService(C.class, "BComponent"); + + String result = c.cOp(); + System.out.println("Method call returned [" + result + "]"); + Assert.assertNotNull(result); + Assert.assertTrue(result.indexOf("C:cOp()") != -1); + Assert.assertTrue(result.indexOf("X:xOp()") != -1); + Assert.assertTrue(result.indexOf("Y:yOp()") != -1); + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/RecursiveCompositeTestCaseFIXME.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/RecursiveCompositeTestCaseFIXME.java new file mode 100644 index 0000000000..a543add69b --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/RecursiveCompositeTestCaseFIXME.java @@ -0,0 +1,53 @@ +/* + * 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 sample; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +//FIXME Fix this test case +public class RecursiveCompositeTestCaseFIXME extends TestCase { + + private SCADomain domain; + private Service1 tracker, tracker2; + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("http://localhost", "/", "Composite1.composite", "Composite2.composite"); + tracker = domain.getService(Service1.class, "ComponentC"); + tracker2 = domain.getService(Service1.class, "ComponentB"); + + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + public void test() throws Exception { + try { + System.out.println("Main thread " + Thread.currentThread()); + System.out.println(tracker.track("Client")); + System.out.println(tracker2.track("Client")); + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/X.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/X.java new file mode 100644 index 0000000000..e3a9335068 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/X.java @@ -0,0 +1,32 @@ +/* + * 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 sample; + +/** + * Simple Service + */ +public interface X { + + /** + * Simple Operation + * + * @return A String + */ + String xOp(); +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/XImpl.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/XImpl.java new file mode 100644 index 0000000000..e430807568 --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/XImpl.java @@ -0,0 +1,37 @@ +/* + * 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 sample; + +import org.osoa.sca.annotations.Service; + +/** + * Implementation of a simple service + */ +@Service(X.class) +public class XImpl implements X { + + /** + * Simple operation + * + * @return "X:xOp()" + */ + public String xOp() { + return "X:xOp()"; + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/Y.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/Y.java new file mode 100644 index 0000000000..c15a4f635a --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/Y.java @@ -0,0 +1,32 @@ +/* + * 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 sample; + +/** + * Simple Service + */ +public interface Y { + + /** + * Simple Operation + * + * @return A String + */ + String yOp(); +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/sample/YImpl.java b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/YImpl.java new file mode 100644 index 0000000000..994c9eb95f --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/sample/YImpl.java @@ -0,0 +1,38 @@ +/* + * 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 sample; + +import org.osoa.sca.annotations.Service; + +/** + * Implementation of a Simple Service + */ +@Service(Y.class) +public class YImpl implements Y { + + /** + * A simple operation + * + * @return "Y:yOp()" + */ + public String yOp() { + return "Y:yOp()"; + } + +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/test/InnerTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/test/InnerTestCase.java new file mode 100644 index 0000000000..ebb4bc7acb --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/test/InnerTestCase.java @@ -0,0 +1,51 @@ +/* + * 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 test; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class InnerTestCase extends TestCase { + + private SCADomain domain; + private Aggregator aggregator; + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("Inner.composite"); + aggregator = domain.getService(Aggregator.class, "Aggregator"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + public void test() throws Exception { + try { + String result = aggregator.getAggregatedData(); + assertTrue(result.contains("InnerSource")); + assertTrue(result.contains("InnerSource")); + System.out.println(result); + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/test/OuterTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/test/OuterTestCase.java new file mode 100644 index 0000000000..6e95f5808b --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/test/OuterTestCase.java @@ -0,0 +1,53 @@ +/* + * 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 test; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class OuterTestCase { + + private SCADomain domain; + private Aggregator aggregator; + + @Before + public void setUp() throws Exception { + domain = SCADomain.newInstance("Outer.composite"); + aggregator = domain.getService(Aggregator.class, "Inner"); + } + + @After + public void tearDown() throws Exception { + domain.close(); + } + + @Ignore("TUSCANY-2484") + @Test + public void test() throws Exception { + String result = aggregator.getAggregatedData(); + Assert.assertTrue(result.contains("InnerSource")); + Assert.assertTrue(result.contains("OuterSource")); + System.out.println(result); + } +} diff --git a/branches/sca-java-1.x/itest/recursive/src/test/java/test1/composite/CompositeClientTestCase.java b/branches/sca-java-1.x/itest/recursive/src/test/java/test1/composite/CompositeClientTestCase.java new file mode 100644 index 0000000000..b3abcac06e --- /dev/null +++ b/branches/sca-java-1.x/itest/recursive/src/test/java/test1/composite/CompositeClientTestCase.java @@ -0,0 +1,62 @@ +/* + * 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 test1.composite; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Simple client program that invokes the components that we wired together. + */ +public class CompositeClientTestCase extends TestCase { + + private SCADomain scaDomain; + private Target target; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("test1/OuterComposite.composite"); + target = scaDomain.getService(Target.class, "Test1TargetComponent/Service_Two"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testComposite() throws Exception { + String res = target.hello("Wang Feng"); + assertEquals("TargetTwo: Hello Wang Feng!", res); + } + + // Test for problem in TUSCANY-2010 + public void testURLs() throws Exception { + try { + System.out.println("Component URI: " + scaDomain.getComponentManager().getComponent("Test1TargetComponent").getURI()); + System.out.println(" Service Name: " + scaDomain.getComponentManager().getComponent("Test1TargetComponent").getServices().get(0).getName()); + System.out.println(" Binding Name: " + scaDomain.getComponentManager().getComponent("Test1TargetComponent").getServices().get(0).getBindings().get(0).getName()); + System.out.println(" Binding URI: " + scaDomain.getComponentManager().getComponent("Test1TargetComponent").getServices().get(0).getBindings().get(0).getURI()); + assertEquals("/Test1TargetComponent/Service_One", scaDomain.getComponentManager().getComponent("Test1TargetComponent").getServices().get(0).getBindings().get(0).getURI()); + } catch (Throwable t) { + t.printStackTrace(); + } + } +} |