diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/node-manager/src/test')
4 files changed, 206 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResourceTestCase.java b/sca-java-2.x/trunk/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResourceTestCase.java new file mode 100644 index 0000000000..ded7a3a7f2 --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResourceTestCase.java @@ -0,0 +1,85 @@ +/* + * 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.node.manager; + +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 org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class DomainAssetManagerResourceTestCase { + private static String SERVICE_URL; + private static Node node; + + + @BeforeClass + public static void init() throws Exception { + try { + String contribution = ContributionLocationHelper.getContributionLocation(DomainCompositeResourceTestCase.class); + node = NodeFactory.newInstance().createNode("node-asset-manager-test.composite", new Contribution("node-manager", contribution)); + node.start(); + + SERVICE_URL = node.getEndpointAddress("NodeAssetManagerComponent"); + + System.out.println(">>" + SERVICE_URL); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + if (node != null) { + node.stop(); + } + } + + + @Test + public void testServiceManagement() throws Exception { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest(SERVICE_URL + "default/services/status"); + request.setHeaderField("Accept","application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + System.out.println(">>>" + response.getText()); + } + + @Test + public void testResourceManagement() throws Exception { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest(SERVICE_URL + "default/resources/status"); + request.setHeaderField("Accept","application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + System.out.println(">>>" + response.getText()); + } +} diff --git a/sca-java-2.x/trunk/modules/node-manager/src/test/java/services/MyResourceImpl.java b/sca-java-2.x/trunk/modules/node-manager/src/test/java/services/MyResourceImpl.java new file mode 100644 index 0000000000..ac8b84a19d --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-manager/src/test/java/services/MyResourceImpl.java @@ -0,0 +1,34 @@ +/* + * 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 services; + +import javax.ws.rs.core.Response; + +import org.apache.tuscany.sca.node.manager.ManageableResource; + +public class MyResourceImpl implements ManageableResource { + + @Override + public Response ping() { + System.out.println(">>> ping"); + return Response.ok("pong").build(); + } + +} diff --git a/sca-java-2.x/trunk/modules/node-manager/src/test/java/services/MyServiceImpl.java b/sca-java-2.x/trunk/modules/node-manager/src/test/java/services/MyServiceImpl.java new file mode 100644 index 0000000000..770be99bc3 --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-manager/src/test/java/services/MyServiceImpl.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 services; + +import org.apache.tuscany.sca.node.manager.ManageableService; + +public class MyServiceImpl implements ManageableService { + + + @Override + public void isAlive() { + System.out.println(">>> isAlive"); + } + +} diff --git a/sca-java-2.x/trunk/modules/node-manager/src/test/resources/node-asset-manager-test.composite b/sca-java-2.x/trunk/modules/node-manager/src/test/resources/node-asset-manager-test.composite new file mode 100644 index 0000000000..c3eeba8149 --- /dev/null +++ b/sca-java-2.x/trunk/modules/node-manager/src/test/resources/node-asset-manager-test.composite @@ -0,0 +1,55 @@ +<?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://node-manager" + name="NodeAssetManager"> + + <component name="NodeAssetManagerComponent"> + <implementation.java class="org.apache.tuscany.sca.node.manager.impl.DomainAssetManagerResourceImpl"/> + <service name="DomainAssetManagerResource"> + <tuscany:binding.rest uri="/services/manager" /> + </service> + </component> + + <component name="Resource"> + <implementation.java class="services.MyResourceImpl"/> + <service name="ManageableResource"> + <tuscany:binding.rest uri="/services/resource" /> + </service> + </component> + + <!-- --> + <component name="AnotherResource"> + <implementation.java class="services.MyResourceImpl"/> + <service name="ManageableResource"> + <tuscany:binding.rest uri="/services/another/resource" /> + </service> + </component> + <!-- --> + + + <component name="Service"> + <implementation.java class="services.MyServiceImpl"/> + <service name="ManageableService"> + <binding.sca /> + </service> + </component> +</composite> |