diff options
author | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-30 12:09:15 +0000 |
---|---|---|
committer | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-30 12:09:15 +0000 |
commit | dce7df4ffe8b3fd8687a3f467f43ce27cc4b021a (patch) | |
tree | 567b107fb15dc5fc8d52fc80805b4d5ccb89199b /sca-java-2.x/contrib/modules/binding-comet-runtime | |
parent | 76af457fb057473b1af2a4b5c78f6444e9a953cc (diff) |
Added unit test.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980746 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/contrib/modules/binding-comet-runtime')
5 files changed, 149 insertions, 0 deletions
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 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://samples" + name="Stock"> + + <component name="StockApp"> + <implementation.java class="org.apache.tuscany.sca.test.StockApp"/> + <service name="service"> + <interface.java interface="org.apache.tuscany.sca.test.StockService"/> + <tuscany:binding.comet/> + </service> + </component> + +</composite>
\ No newline at end of file |