From dce7df4ffe8b3fd8687a3f467f43ce27cc4b021a Mon Sep 17 00:00:00 2001 From: fmoga Date: Fri, 30 Jul 2010 12:09:15 +0000 Subject: Added unit test. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980746 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/test/CometTest.java | 27 +++++++++++++ .../java/org/apache/tuscany/sca/test/StockApp.java | 15 ++++++++ .../org/apache/tuscany/sca/test/StockService.java | 30 +++++++++++++++ .../apache/tuscany/sca/test/StockServiceImpl.java | 44 ++++++++++++++++++++++ .../src/test/resources/test.composite | 33 ++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTest.java create mode 100644 sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockApp.java create mode 100644 sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockService.java create mode 100644 sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockServiceImpl.java create mode 100644 sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/resources/test.composite (limited to 'sca-java-2.x/contrib/modules/binding-comet-runtime') diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTest.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTest.java new file mode 100644 index 0000000000..e1fbfc7c79 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTest.java @@ -0,0 +1,27 @@ +package org.apache.tuscany.sca.test; + +import java.io.IOException; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import junit.framework.TestCase; + +public class CometTest extends TestCase { + + public void testComet() { + String location = ContributionLocationHelper.getContributionLocation("test.composite"); + Node node = NodeFactory.newInstance().createNode("test.composite", new Contribution("c1", location)); + node.start(); + try { + System.out.println("Press any key to stop the node."); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + node.stop(); + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockApp.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockApp.java new file mode 100644 index 0000000000..a7175e7de7 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockApp.java @@ -0,0 +1,15 @@ +package org.apache.tuscany.sca.test; + +public class StockApp { + + private StockService service = new StockServiceImpl(); + + public StockService getService() { + return service; + } + + public void setService(StockService service) { + this.service = service; + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockService.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockService.java new file mode 100644 index 0000000000..4bb364918a --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockService.java @@ -0,0 +1,30 @@ +/* + * 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.test; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface StockService { + + String getSymbol(); + + Double getValue(); + +} diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockServiceImpl.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockServiceImpl.java new file mode 100644 index 0000000000..46401748c8 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/StockServiceImpl.java @@ -0,0 +1,44 @@ +/* + * 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.test; + +import java.text.DecimalFormat; +import java.util.Date; +import java.util.Random; + +import org.oasisopen.sca.annotation.Service; + +@Service(StockService.class) +public class StockServiceImpl implements StockService { + + public static final int MAX_VALUE = 1000; + private Random random = new Random(new Date().getTime()); + + @Override + public String getSymbol() { + return "ASF"; + } + + @Override + public Double getValue() { + Double value = Math.abs(random.nextDouble() * random.nextInt(MAX_VALUE)); + return Double.valueOf(new DecimalFormat("#.##").format(value)); + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/resources/test.composite b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/resources/test.composite new file mode 100644 index 0000000000..1815393dfc --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/resources/test.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3