From 725006d4c47e63986ac042ade23a4d193298b1fe Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:08:29 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835131 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/crawler/Crawler.java | 46 +++++++ .../src/main/java/crawler/CrawlerController.java | 41 +++++++ .../java/crawler/impl/CrawlerControllerImpl.java | 80 ++++++++++++ .../src/main/java/crawler/impl/CrawlerImpl.java | 69 +++++++++++ .../main/java/crawler/impl/SpecialCrawlerImpl.java | 69 +++++++++++ .../src/main/resources/test.composite | 51 ++++++++ .../crawler/ReferenceMultiplicityTestCase.java | 134 +++++++++++++++++++++ 7 files changed, 490 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/Crawler.java create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/CrawlerController.java create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/CrawlerControllerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/CrawlerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/SpecialCrawlerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/resources/test.composite create mode 100644 sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/test/java/crawler/ReferenceMultiplicityTestCase.java (limited to 'sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src') diff --git a/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/Crawler.java b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/Crawler.java new file mode 100644 index 0000000000..2607e9aabc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/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/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/CrawlerController.java b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/CrawlerController.java new file mode 100644 index 0000000000..11b1b6b580 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/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/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/CrawlerControllerImpl.java b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/CrawlerControllerImpl.java new file mode 100644 index 0000000000..1ca2a3797a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/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 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 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/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/CrawlerImpl.java b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/CrawlerImpl.java new file mode 100644 index 0000000000..0224d7750e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/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/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/SpecialCrawlerImpl.java b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/java/crawler/impl/SpecialCrawlerImpl.java new file mode 100644 index 0000000000..e486a23e23 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/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/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/resources/test.composite b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/resources/test.composite new file mode 100644 index 0000000000..ed3adfc7ae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/main/resources/test.composite @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + normalcrawler + + + + + + + + specialcrawler + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/test/java/crawler/ReferenceMultiplicityTestCase.java b/sca-java-1.x/branches/sca-java-1.4/itest/references-collection/src/test/java/crawler/ReferenceMultiplicityTestCase.java new file mode 100644 index 0000000000..1fc0e758c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.4/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()); + } + } +*/ +} -- cgit v1.2.3