diff options
Diffstat (limited to '')
24 files changed, 1451 insertions, 0 deletions
diff --git a/tags/java/sca/1.5/itest/references-collection/pom.xml b/tags/java/sca/1.5/itest/references-collection/pom.xml new file mode 100644 index 0000000000..8c9a9bdacc --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/pom.xml @@ -0,0 +1,53 @@ +<?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-itest</artifactId> + <version>1.5</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>itest-references-collection</artifactId> + <name>Apache Tuscany SCA iTest References Collection</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.5</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.5</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-axis2</artifactId> + <version>1.5</version> + <scope>runtime</scope> + </dependency> + + </dependencies> +</project> diff --git a/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/Crawler.java b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/Crawler.java new file mode 100644 index 0000000000..2607e9aabc --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/Crawler.java @@ -0,0 +1,46 @@ +/* + * 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 crawler; + +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; +import org.osoa.sca.annotations.Remotable; + +@Remotable +@Conversational +public interface Crawler +{ + /** + * Returns the crawler Id. + * @return a String containing the CrawlerId + */ + String getCrawlerId(); + + /** + * Starts a crawl process. + * @return a message that the crawl was started + */ + String crawl(); + + /** + * Closes the conversation. + */ + @EndsConversation + String close(); +} diff --git a/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/CrawlerController.java b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/CrawlerController.java new file mode 100644 index 0000000000..11b1b6b580 --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/CrawlerController.java @@ -0,0 +1,41 @@ +/* + * 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 crawler; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface CrawlerController +{ + /** + * Tries to return a Crawler with the given Id in the list of crawlers. + * It uses the getServiceReference() method which should throw an exception because of multiplicity 0..n + * @param crawlerId the id of the Crawler + * @return the Crawler + */ + Crawler getCrawler(String crawlerId); + + /** + * Tries to return a Crawler with the given Id in the list of crawlers. + * It uses the getServiceReferences() method which shoulkd work properly with multiplicity 0..n + * @param crawlerId the id of the Crawler + * @return the Crawler + */ + Crawler findCrawler(String crawlerId); +} diff --git a/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/CrawlerControllerImpl.java b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/CrawlerControllerImpl.java new file mode 100644 index 0000000000..1ca2a3797a --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/CrawlerControllerImpl.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 crawler.impl; + +import crawler.Crawler; +import crawler.CrawlerController; + +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sca.api.ComponentContextExtension; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(CrawlerController.class) +@Scope("COMPOSITE") +@AllowsPassByReference +public class CrawlerControllerImpl implements CrawlerController +{ + @Context + protected ComponentContext componentContext; + + @Reference + public List<Crawler> crawlers; + + /** + * @see CrawlerController#getCrawler(String) + */ + public Crawler getCrawler(String crawlerId) + { + for (int i = 0; i < crawlers.size(); i++) + { + Crawler crawler = crawlers.get(i); + String id = crawler.getCrawlerId(); + if (crawlerId.equals(id)) + { + Crawler newCrawler = componentContext.getService(Crawler.class, "crawlers"); + return newCrawler; + } + } + throw new RuntimeException("No crawler with id " + crawlerId + " found"); + } + + /** + * @see CrawlerController#findCrawler(String) + */ + public Crawler findCrawler(String crawlerId) + { + Collection<Crawler> crawlers = ((ComponentContextExtension)componentContext).getServices(Crawler.class, "crawlers"); + for (Crawler crawler : crawlers) + { + String id = crawler.getCrawlerId(); + if (crawlerId.equals(id)) + { + return crawler; + } + } + throw new RuntimeException("No crawler with id " + crawlerId + " found"); + } +} diff --git a/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/CrawlerImpl.java b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/CrawlerImpl.java new file mode 100644 index 0000000000..0224d7750e --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/CrawlerImpl.java @@ -0,0 +1,69 @@ +/* + * 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 crawler.impl; + +import crawler.Crawler; + +import org.osoa.sca.ComponentContext; +import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.ConversationID; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(Crawler.class) +@AllowsPassByReference +@Scope("CONVERSATION") +public class CrawlerImpl implements Crawler +{ + @ConversationID + protected String conversationId; + + @Property + protected String crawlerId; + + @Context + protected ComponentContext componentContext; + + /** + * @see Crawler#getCrawlerId() + */ + public String getCrawlerId() + { + return crawlerId; + } + + /** + * @see Crawler#crawl() + */ + public String crawl() + { + System.out.println("started crawl with conversation " + conversationId); + return "started crawl with id " + getCrawlerId(); + } + + /** + * @see Crawler#close() + */ + public String close() + { + return "ended conversation with id " + getCrawlerId(); + } +}
\ No newline at end of file diff --git a/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/SpecialCrawlerImpl.java b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/SpecialCrawlerImpl.java new file mode 100644 index 0000000000..e486a23e23 --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/main/java/crawler/impl/SpecialCrawlerImpl.java @@ -0,0 +1,69 @@ +/* + * 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 crawler.impl; + +import crawler.Crawler; + +import org.osoa.sca.ComponentContext; +import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.ConversationID; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(Crawler.class) +@AllowsPassByReference +@Scope("CONVERSATION") +public class SpecialCrawlerImpl implements Crawler +{ + @ConversationID + protected String conversationId; + + @Property + protected String crawlerId; + + @Context + protected ComponentContext componentContext; + + /** + * @see Crawler#getCrawlerId() + */ + public String getCrawlerId() + { + return crawlerId; + } + + /** + * @see Crawler#crawl() + */ + public String crawl() + { + System.out.println("started crawl with conversation " + conversationId); + return "started crawl with id " + getCrawlerId(); + } + + /** + * @see Crawler#close() + */ + public String close() + { + return "ended conversation with id " + getCrawlerId(); + } +}
\ No newline at end of file diff --git a/tags/java/sca/1.5/itest/references-collection/src/main/resources/test.composite b/tags/java/sca/1.5/itest/references-collection/src/main/resources/test.composite new file mode 100644 index 0000000000..ed3adfc7ae --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/main/resources/test.composite @@ -0,0 +1,51 @@ +<?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. +--> + +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace="http://crawler" + xmlns:crawler="http://crawler" + name="crawler"> + + <component name="CrawlerControllerComponent"> + <implementation.java class="crawler.impl.CrawlerControllerImpl"/> + <service name="CrawlerController"> + <interface.java interface="crawler.CrawlerController" /> + </service> + <reference name="crawlers" multiplicity="1..n" target="CrawlerComponent SpecialCrawlerComponent" /> + </component> + + <component name="CrawlerComponent"> + <implementation.java class="crawler.impl.CrawlerImpl"/> + <property name="crawlerId">normalcrawler</property> + <service name="Crawler"> + <interface.java interface="crawler.Crawler" /> + </service> + </component> + + <component name="SpecialCrawlerComponent"> + <implementation.java class="crawler.impl.SpecialCrawlerImpl"/> + <property name="crawlerId">specialcrawler</property> + <service name="Crawler"> + <interface.java interface="crawler.Crawler" /> + </service> + </component> + +</composite>
\ No newline at end of file diff --git a/tags/java/sca/1.5/itest/references-collection/src/test/java/crawler/ReferenceMultiplicityTestCase.java b/tags/java/sca/1.5/itest/references-collection/src/test/java/crawler/ReferenceMultiplicityTestCase.java new file mode 100644 index 0000000000..1fc0e758c4 --- /dev/null +++ b/tags/java/sca/1.5/itest/references-collection/src/test/java/crawler/ReferenceMultiplicityTestCase.java @@ -0,0 +1,134 @@ +/* + * 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 crawler; + +import crawler.Crawler; +import crawler.CrawlerController; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +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.osoa.sca.ServiceRuntimeException; + +import junit.framework.TestCase; + +public class ReferenceMultiplicityTestCase extends TestCase +{ + private final String CRAWLER_ID = "normalcrawler"; + private final String SPECIAL_CRAWLER_ID = "specialcrawler"; + + private static SCANode _scaDomain; + private CrawlerController _controller; + + /** + * {@inheritDoc} + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception + { + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); + _scaDomain = nodeFactory.createSCANode("test.composite", + new SCAContribution("crawler", "./target/classes")); + assertNotNull(_scaDomain); + _scaDomain.start(); + _controller = ((SCAClient)_scaDomain).getService(CrawlerController.class, "CrawlerControllerComponent"); + assertNotNull(_controller); + } + + /** + * {@inheritDoc} + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + _controller = null; + if (_scaDomain != null) + { + _scaDomain.stop(); + _scaDomain = null; + } + } + + public void testGetCrawler() throws Exception + { + try + { + _controller.getCrawler(CRAWLER_ID); + fail("Expected exception"); + } + catch (ServiceRuntimeException e) + { + assertEquals("Unexpected error message", "Reference crawlers has multiplicity ONE_N", e.getMessage()); + } + catch (Exception e) + { + fail("Expected ServiceRuntimeException, not a " + e.getClass()); + } + + try + { + _controller.getCrawler(SPECIAL_CRAWLER_ID); + fail("Expected exception"); + } + catch (ServiceRuntimeException e) + { + assertEquals("Unexpected error message", "Reference crawlers has multiplicity ONE_N", e.getMessage()); + } + catch (Exception e) + { + fail("Expected ServiceRuntimeException, not a " + e.getClass()); + } + } +/* + public void testFindCrawler() throws Exception + { + try + { + Crawler crawler = _controller.findCrawler(CRAWLER_ID); + assertNotNull(crawler); + String msg = crawler.crawl(); + assertEquals("Received unexpected msg", "started crawl with id " + CRAWLER_ID, msg); + msg = crawler.close(); + assertEquals("Received unexpected msg", "ended conversation with id " + CRAWLER_ID, msg); + } + catch (Exception e) + { + fail("Unexpected Exception " + e.getClass()); + } + + try + { + Crawler crawler = _controller.findCrawler(SPECIAL_CRAWLER_ID); + assertNotNull(crawler); + String msg = crawler.crawl(); + assertEquals("Received unexpected msg", "started crawl with id " + SPECIAL_CRAWLER_ID, msg); + msg = crawler.close(); + assertEquals("Received unexpected msg", "ended conversation with id " + SPECIAL_CRAWLER_ID, msg); + } + catch (Exception e) + { + fail("Unexpected Exception " + e.getClass()); + } + } +*/ +} diff --git a/tags/java/sca/1.5/itest/references/pom.xml b/tags/java/sca/1.5/itest/references/pom.xml new file mode 100644 index 0000000000..043bcb0df8 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/pom.xml @@ -0,0 +1,53 @@ +<?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-itest</artifactId> + <version>1.5</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>itest-references</artifactId> + <name>Apache Tuscany SCA iTest References</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.5</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.5</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-axis2</artifactId> + <version>1.5</version> + <scope>runtime</scope> + </dependency> + + </dependencies> +</project> diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponent.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponent.java new file mode 100644 index 0000000000..f8c0850118 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponent.java @@ -0,0 +1,40 @@ +/* + * 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.itest.references; + +public interface AComponent { + + String fooB(); + + String fooC(); + + String fooBC(); + + String fooD1(); + + String fooD2(); + + String fooMultipleD(); + + String fooMultipleDArray(); + + String fooMultipleDServiceRef(); + + DComponent getDReference(); +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java new file mode 100644 index 0000000000..647fff0159 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/AComponentImpl.java @@ -0,0 +1,126 @@ +/* + * 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.itest.references; + +import java.util.Collection; +import java.util.List; + +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Reference; + +public class AComponentImpl implements AComponent { + + @Reference(name = "bReference") + protected BComponent b; + + @Reference + protected CComponent cReference; + + @Reference(required = false) + protected DComponent dReference; + + @Reference(name = "dReferences") + public Collection<DComponent> dReferences; + + @Reference(name = "dReferenceArray") + public DComponent[] dReferenceArray; + + + @Reference(name = "dServiceReferences") + public List<ServiceReference<DComponent>> dServiceReferences; + + private DComponent dReference1; + + private DComponent dReference2; + + @Reference(name = "dReference1") + public void setDReference(DComponent dReference) { + this.dReference1 = dReference; + } + + @Reference + public void setDReference2(DComponent dReference2) { + this.dReference2 = dReference2; + } + + public String fooB() { + return b.bFoo(); + } + + public String fooC() { + return cReference.cFoo(); + } + + public String fooBC() { + return b.fooC(); + } + + public String fooD() { + return dReference1.dFoo(); + } + + public String fooD1() { + return dReference1.dFoo(); + } + + public String fooD2() { + return dReference2.dFoo(); + } + + public String fooMultipleDArray() { + StringBuffer str = new StringBuffer(); + for (DComponent d : dReferenceArray) { + str.append(d.getComponentName()); + str.append(','); + } + if (str.length() > 0) { + str.deleteCharAt(str.length() - 1); + } + return str.toString(); + } + + public String fooMultipleD() { + StringBuffer str = new StringBuffer(); + for (DComponent d : dReferences) { + str.append(d.getComponentName()); + str.append(','); + } + if (str.length() > 0) { + str.deleteCharAt(str.length() - 1); + } + return str.toString(); + } + + public String fooMultipleDServiceRef() { + StringBuffer str = new StringBuffer(); + for (ServiceReference<DComponent> d : dServiceReferences) { + str.append(d.getService().getComponentName()); + str.append(','); + } + if (str.length() > 0) { + str.deleteCharAt(str.length() - 1); + } + return str.toString(); + } + + public DComponent getDReference() { + return dReference; + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponent.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponent.java new file mode 100644 index 0000000000..785920bb2d --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponent.java @@ -0,0 +1,26 @@ +/* + * 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.itest.references; + +public interface BComponent { + + String bFoo(); + + String fooC(); +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentImpl.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentImpl.java new file mode 100644 index 0000000000..6b1065ab0d --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentImpl.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 org.apache.tuscany.sca.itest.references; + +import org.osoa.sca.annotations.Reference; + +public class BComponentImpl implements BComponent { + + protected CComponent cReference; + + public BComponentImpl(@Reference(name = "cReference") CComponent cReference) { + this.cReference = cReference; + } + + public String bFoo() { + return "BComponent"; + } + + public String fooC() { + return "B" + cReference.cFoo(); + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentWrongTargetImpl.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentWrongTargetImpl.java new file mode 100644 index 0000000000..1cd7cb7fe5 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/BComponentWrongTargetImpl.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 org.apache.tuscany.sca.itest.references; + +import org.osoa.sca.annotations.Reference; + +public class BComponentWrongTargetImpl implements BComponent { + + protected CComponent cReference; + + public BComponentWrongTargetImpl(@Reference(name = "cReference") CComponent cReference) { + this.cReference = cReference; + } + + public String bFoo() { + return "BComponentWrongTarget"; + } + + public String fooC() { + return "B" + cReference.cFoo(); + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/CComponent.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/CComponent.java new file mode 100644 index 0000000000..d436c28adc --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/CComponent.java @@ -0,0 +1,24 @@ +/* + * 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.itest.references; + +public interface CComponent { + + String cFoo(); +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/CComponentImpl.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/CComponentImpl.java new file mode 100644 index 0000000000..a1823e1cdc --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/CComponentImpl.java @@ -0,0 +1,27 @@ +/* + * 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.itest.references; + +public class CComponentImpl implements CComponent { + + public String cFoo() { + return "CComponent"; + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/DComponent.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/DComponent.java new file mode 100644 index 0000000000..2618ec7095 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/DComponent.java @@ -0,0 +1,27 @@ +/* + * 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.itest.references; + +import org.osoa.sca.annotations.Remotable; + +public interface DComponent { + + String dFoo(); + String getComponentName(); +} diff --git a/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/DComponentImpl.java b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/DComponentImpl.java new file mode 100644 index 0000000000..79c802bc97 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/java/org/apache/tuscany/sca/itest/references/DComponentImpl.java @@ -0,0 +1,35 @@ +/* + * 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.itest.references; + +import org.osoa.sca.annotations.ComponentName; + +public class DComponentImpl implements DComponent { + @ComponentName + public String name; + + public String dFoo() { + return "DComponent"; + } + + public String getComponentName() { + return name; + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/main/resources/AutoWiredReferencesTest.composite b/tags/java/sca/1.5/itest/references/src/main/resources/AutoWiredReferencesTest.composite new file mode 100644 index 0000000000..894f6681c2 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/resources/AutoWiredReferencesTest.composite @@ -0,0 +1,65 @@ +<?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
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:foo="http://foo" targetNamespace="http://foo"
+ name="AutowireReferencesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autowire="true">
+
+ <service name="AComponent" promote="AComponent">
+ <interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" />
+ </service>
+
+ <component name="AComponent" autowire="false">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" />
+ <reference name="bReference" target="BComponent" />
+ <reference name="cReference" autowire="true" />
+ <reference name="dReference1" />
+ <!--
+ <reference name="dReference1" target="DComponent" />
+ -->
+ <reference name="DReference2" target="DComponent" />
+ <reference name="dReferences" autowire="true" />
+ <reference name="dReferenceArray" autowire="true" />
+ <reference name="dServiceReferences" target="DComponent DComponent1" />
+
+ </component>
+
+ <component name="AComponentAutowire" autowire="true">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" />
+ <reference name="bReference" target="BComponent" />
+ </component>
+
+ <component name="BComponentWrongTarget">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentWrongTargetImpl" />
+ </component>
+
+ <component name="BComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" />
+ </component>
+
+ <component name="CComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.CComponentImpl" />
+ </component>
+
+ <component name="DComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" />
+ </component>
+
+ <component name="DComponent1">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" />
+ </component>
+</composite>
\ No newline at end of file diff --git a/tags/java/sca/1.5/itest/references/src/main/resources/InnerReferencesTest.composite b/tags/java/sca/1.5/itest/references/src/main/resources/InnerReferencesTest.composite new file mode 100644 index 0000000000..6cadc52c13 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/resources/InnerReferencesTest.composite @@ -0,0 +1,54 @@ +<?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
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:foo="http://foo" targetNamespace="http://foo"
+ name="InnerReferencesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <service name="AComponent" promote="AComponent">
+ <interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" />
+ </service>
+
+ <component name="AComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" />
+ <reference name="bReference" target="BComponent" />
+ <reference name="cReference" target="CComponent" />
+ <reference name="dReference1" target="DComponent" />
+ <reference name="DReference2" target="DComponent" />
+ <reference name="dReferences" target="DComponent DComponent1" />
+ <reference name="dReferenceArray" target="DComponent1" />
+ <reference name="dServiceReferences" target="DComponent DComponent1" />
+ </component>
+
+ <component name="BComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" />
+ <reference name="cReference" target="CComponent" />
+ </component>
+
+ <component name="CComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.CComponentImpl" />
+ </component>
+
+ <component name="DComponent">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" />
+ </component>
+
+ <component name="DComponent1">
+ <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/tags/java/sca/1.5/itest/references/src/main/resources/ManualWiredReferencesTest.composite b/tags/java/sca/1.5/itest/references/src/main/resources/ManualWiredReferencesTest.composite new file mode 100644 index 0000000000..708960974b --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/main/resources/ManualWiredReferencesTest.composite @@ -0,0 +1,64 @@ +<?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 + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:foo="http://foo" targetNamespace="http://foo" + name="ManualWiredReferencesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autowire="true"> + + <service name="AComponent" promote="AComponent"> + <interface.java interface="org.apache.tuscany.sca.itest.references.AComponent" /> + </service> + + <component name="AComponent" > + <implementation.java class="org.apache.tuscany.sca.itest.references.AComponentImpl" /> + <reference name="bReference" target="BComponent" /> + <reference name="cReference" target="CComponent/CComponentImpl"> + <!-- reference name="cReference" target="CComponent"--> + <binding.sca uri="DComponent"/> + </reference> + <reference name="dReference1" > + <binding.sca uri="DComponent"/> + </reference> + <reference name="DReference2" target="DComponent" > + <!-- binding.ws uri="DComponent"/--> + </reference> + <reference name="dReferences" target="DComponent DComponent1" /> + <reference name="dReferenceArray" target="DComponent DComponent1" /> + <reference name="dServiceReferences" target="DComponent DComponent1" /> + + </component> + + <component name="BComponent"> + <implementation.java class="org.apache.tuscany.sca.itest.references.BComponentImpl" /> + </component> + + <component name="CComponent"> + <implementation.java class="org.apache.tuscany.sca.itest.references.CComponentImpl" /> + </component> + + <component name="DComponent"> + <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> + <service name="DComponentImpl"> + <binding.sca/> + <!-- binding.ws/--> + </service> + </component> + + <component name="DComponent1"> + <implementation.java class="org.apache.tuscany.sca.itest.references.DComponentImpl" /> + </component> +</composite>
\ No newline at end of file diff --git a/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java b/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java new file mode 100644 index 0000000000..bfd542e2f2 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/AutoWiredReferenceTestCase.java @@ -0,0 +1,102 @@ +/* + * 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.itest.references; + +import static junit.framework.Assert.assertEquals; +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AutoWiredReferenceTestCase { + private static SCADomain domain; + private static AComponent acomponent; + private static AComponent acomponentAutowire; + + @BeforeClass + public static void init() throws Exception { + domain = SCADomain.newInstance("AutoWiredReferencesTest.composite"); + acomponent = domain.getService(AComponent.class, "AComponent"); + acomponentAutowire = domain.getService(AComponent.class, "AComponentAutowire"); + } + + @AfterClass + public static void destroy() throws Exception { + domain.close(); + } + + @Test + public void testBReference() { + assertEquals("BComponent", acomponent.fooB()); + } + + @Test + public void testCReference() { + assertEquals("CComponent", acomponent.fooC()); + } + + @Test + public void testBCReference() { + assertEquals("BCComponent", acomponent.fooBC()); + } + + @Test(expected = NullPointerException.class) + public void testD1Reference() { + acomponent.fooD1(); + } + + @Test + public void testD2Reference() { + assertEquals("DComponent", acomponent.fooD2()); + } + + @Test + public void testMultiDReferenceArray() { + String components = acomponent.fooMultipleDArray(); + Assert.assertTrue(components.contains("DComponent1")); + } + + @Test + public void testMultiDServiceReference() { + String components = acomponent.fooMultipleDServiceRef(); + Assert.assertTrue(components.contains("DComponent")); + Assert.assertTrue(components.contains("DComponent1")); + } + + @Test + public void testRequiredFalseReference() { + try { + acomponent.getDReference().dFoo(); + } catch (Exception e) { + Assert.assertTrue(true); + } + } + + @Test + public void testTargetPrecendence() { + try { + assertEquals("BComponent", acomponentAutowire.fooB()); + } catch (Exception e) { + Assert.assertTrue(true); + } + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/InnerReferenceTestCase.java b/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/InnerReferenceTestCase.java new file mode 100644 index 0000000000..1d8284f0fd --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/InnerReferenceTestCase.java @@ -0,0 +1,94 @@ +/* + * 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.itest.references; + +import static junit.framework.Assert.assertEquals; +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class InnerReferenceTestCase { + private static SCADomain domain; + private static AComponent acomponent; + + @BeforeClass + public static void init() throws Exception { + domain = SCADomain.newInstance("InnerReferencesTest.composite"); + acomponent = domain.getService(AComponent.class, "AComponent"); + } + + @AfterClass + public static void destroy() throws Exception { + domain.close(); + } + + @Test + public void testBReference() { + assertEquals("BComponent", acomponent.fooB()); + } + + @Test + public void testCReference() { + assertEquals("CComponent", acomponent.fooC()); + } + + @Test + public void testBCReference() { + assertEquals("BCComponent", acomponent.fooBC()); + } + + @Test + public void testD1Reference() { + assertEquals("DComponent", acomponent.fooD1()); + } + + @Test + public void testD2Reference() { + assertEquals("DComponent", acomponent.fooD2()); + } + + @Test + public void testMultiDReference() { + String components = acomponent.fooMultipleD(); + Assert.assertTrue(components.contains("DComponent")); + Assert.assertTrue(components.contains("DComponent1")); + } + + @Test + public void testMultiDReferenceArray() { + String components = acomponent.fooMultipleDArray(); + Assert.assertTrue(components.equals("DComponent1")); + } + + @Test + public void testMultiDServiceReference() { + String components = acomponent.fooMultipleDServiceRef(); + Assert.assertTrue(components.contains("DComponent")); + Assert.assertTrue(components.contains("DComponent1")); + } + + @Test(expected = NullPointerException.class) + public void testRequiredFalseReference() { + acomponent.getDReference().dFoo(); + } + +} diff --git a/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/ManualWiredReferenceTestCase.java b/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/ManualWiredReferenceTestCase.java new file mode 100644 index 0000000000..4b3a745a19 --- /dev/null +++ b/tags/java/sca/1.5/itest/references/src/test/java/org/apache/tuscany/sca/itest/references/ManualWiredReferenceTestCase.java @@ -0,0 +1,93 @@ +/* + * 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.itest.references; + +import static junit.framework.Assert.assertEquals; +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +public class ManualWiredReferenceTestCase { + private static SCADomain domain; + private static AComponent acomponent; + + @BeforeClass + public static void init() throws Exception { + domain = SCADomain.newInstance("ManualWiredReferencesTest.composite"); + acomponent = domain.getService(AComponent.class, "AComponent"); + } + + @AfterClass + public static void destroy() throws Exception { + domain.close(); + } + + @Test + public void testBReference() { + assertEquals("BComponent", acomponent.fooB()); + } + + @Test + public void testCReference() { + assertEquals("CComponent", acomponent.fooC()); + } + + @Test + public void testBCReference() { + assertEquals("BCComponent", acomponent.fooBC()); + } + + @Test + public void testD1Reference() { + acomponent.fooD1(); + } + + @Ignore + @Test + public void testD2Reference() { + assertEquals("DComponent", acomponent.fooD2()); + } + + @Test + public void testMultiDReferenceArray() { + String components = acomponent.fooMultipleDArray(); + Assert.assertTrue(components.contains("DComponent1")); + } + + @Test + public void testMultiDServiceReference() { + String components = acomponent.fooMultipleDServiceRef(); + Assert.assertTrue(components.contains("DComponent")); + Assert.assertTrue(components.contains("DComponent1")); + } + + @Test + public void testRequiredFalseReference() { + try { + acomponent.getDReference().dFoo(); + } catch (Exception e) { + Assert.assertTrue(true); + } + } + +} |