You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2008/04/15 17:05:05 UTC
svn commit: r648273 - in
/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src:
main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/
main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/
main/resourc...
Author: antelder
Date: Tue Apr 15 08:05:02 2008
New Revision: 648273
URL: http://svn.apache.org/viewvc?rev=648273&view=rev
Log:
TUSCANY-2195: Apply patch from Yee-Kang Chang for Test cases for ComponentContext API
Added:
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java (with props)
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java (with props)
Modified:
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite
incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java
Modified: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java?rev=648273&r1=648272&r2=648273&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java Tue Apr 15 08:05:02 2008
@@ -27,8 +27,13 @@
public String getName();
public String getContextURI();
-
public String getServiceBName();
public String getServiceReferenceBName();
+ public String getSelfReferenceName();
+ public String getProperty();
+ public String getRequestContextServiceName();
+ public String getCastCallableReferenceServiceName();
+ public String getCastServiceReferenceServiceName();
+ public void illegalCast();
}
Added: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java?rev=648273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java Tue Apr 15 08:05:02 2008
@@ -0,0 +1,31 @@
+/*
+ * 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.vtest.javaapi.apis.componentcontext;
+
+/**
+ * Simple Service B.
+ */
+public interface BService {
+
+ String getBName();
+
+ String getSelfReferenceWithServiceName();
+
+}
Propchange: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java?rev=648273&view=auto
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java (added)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java Tue Apr 15 08:05:02 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.vtest.javaapi.apis.componentcontext;
+
+/**
+ * Simple Service C.
+ */
+public interface CService {
+
+ String getCName();
+
+}
Propchange: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java?rev=648273&r1=648272&r2=648273&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java Tue Apr 15 08:05:02 2008
@@ -20,10 +20,12 @@
package org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl;
import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.AComponent;
-import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.BComponent;
+import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.BService;
+import org.osoa.sca.CallableReference;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Service;
@@ -33,7 +35,10 @@
protected ComponentContext componentContext;
@Reference
- protected BComponent bReference;
+ protected BService bReference;
+
+ @Property(name="aProperty", required=true)
+ protected String aProperty;
public String getName() {
return "ComponentA";
@@ -49,12 +54,41 @@
}
public String getServiceBName() {
- return componentContext.getService(BComponent.class, "bReference").getName();
+ return componentContext.getService(BService.class, "bReference").getBName();
}
public String getServiceReferenceBName() {
- ServiceReference<BComponent> bSR = componentContext.getServiceReference(BComponent.class, "bReference");
- return bSR.getService().getName();
+ ServiceReference<BService> bSR = componentContext.getServiceReference(BService.class, "bReference");
+ return bSR.getService().getBName();
+ }
+
+ public String getSelfReferenceName() {
+ ServiceReference<AComponent> aSR = componentContext.createSelfReference(AComponent.class);
+ return aSR.getService().getName();
+ }
+
+ public String getProperty() {
+ return componentContext.getProperty(String.class, "aProperty");
+ }
+
+ public String getRequestContextServiceName() {
+ return componentContext.getRequestContext().getServiceName();
+ }
+
+ public String getCastCallableReferenceServiceName() {
+ BService b = componentContext.getService(BService.class, "bReference");
+ CallableReference<BService> bCR = componentContext.cast(b);
+ return bCR.getService().getBName();
+ }
+
+ public String getCastServiceReferenceServiceName() {
+ BService b = componentContext.getService(BService.class, "bReference");
+ ServiceReference<BService> bSR = componentContext.cast(b);
+ return bSR.getService().getBName();
+ }
+
+ public void illegalCast() {
+ componentContext.cast("");
}
}
Modified: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java?rev=648273&r1=648272&r2=648273&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java Tue Apr 15 08:05:02 2008
@@ -19,14 +19,34 @@
package org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl;
-import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.BComponent;
+import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.BService;
+import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.CService;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.Context;
import org.osoa.sca.annotations.Service;
-@Service(BComponent.class)
-public class BComponentImpl implements BComponent {
+@Service(interfaces={BService.class, CService.class})
+public class BComponentImpl implements BService, CService {
- public String getName() {
- return "ComponentB";
+ protected ComponentContext componentContext;
+
+ @Context
+ public void setComponentContext(ComponentContext context) {
+ this.componentContext = context;
+ }
+
+ public String getBName() {
+ return "ServiceB";
+ }
+
+ public String getCName() {
+ return "ServiceC";
+ }
+
+ public String getSelfReferenceWithServiceName() {
+ ServiceReference<CService> cSR = componentContext.createSelfReference(CService.class, "CService");
+ return cSR.getService().getCName();
}
}
Modified: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite?rev=648273&r1=648272&r2=648273&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite (original)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite Tue Apr 15 08:05:02 2008
@@ -18,12 +18,14 @@
* under the License.
-->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://java-api-tests"
name="AB-Composite">
<component name="AComponent">
<implementation.java class="org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl.AComponentImpl"/>
- <reference name="bReference" target="BComponent"/>
+ <reference name="bReference" target="BComponent/BService"/>
+ <property name="aProperty" type="xsd:string">PropertyA</property>
</component>
<component name="BComponent">
Modified: incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java?rev=648273&r1=648272&r2=648273&view=diff
==============================================================================
--- incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java (original)
+++ incubator/tuscany/java/sca/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java Tue Apr 15 08:05:02 2008
@@ -33,6 +33,7 @@
protected static SCADomain domain;
protected static String compositeName = "ab.composite";
protected static AComponent a;
+ protected static BService b;
@BeforeClass
public static void init() throws Exception {
@@ -40,6 +41,7 @@
System.out.println("Setting up");
domain = SCADomain.newInstance(compositeName);
a = domain.getService(AComponent.class, "AComponent");
+ b = domain.getService(BService.class, "BComponent/BService");
} catch (Exception e) {
e.printStackTrace();
}
@@ -54,30 +56,104 @@
}
/**
- * L776: Tests getURI() of the ComponentContext interface.
+ * L776 <br>
+ * getURI() - Returns the absolute URI of the component within the SCA domain.
+ *
* @throws Exception
*/
@Test
public void testGetURI() throws Exception {
- Assert.assertEquals(a.getContextURI(), "AComponent");
+ Assert.assertEquals("AComponent", a.getContextURI());
}
/**
- * L778: Tests getService() of the ComponentContext interface.
+ * L778 <br>
+ * getService(Class<B> businessInterface, String referenceName) ? Returns a proxy for the reference defined by the current component.
+ *
* @throws Exception
*/
@Test
public void testGetService() throws Exception {
- Assert.assertEquals(a.getServiceBName(), "ComponentB");
+ Assert.assertEquals(a.getServiceBName(), "ServiceB");
}
/**
- * L780: Tests getServiceReference() of the ComponentContext interface.
+ * L780 <br>
+ * getServiceReference(Class<B> businessInterface, String referenceName) ? Returns a ServiceReference defined by the current component.
+ *
* @throws Exception
*/
@Test
public void testGetServiceReference() throws Exception {
- Assert.assertEquals(a.getServiceReferenceBName(), "ComponentB");
+ Assert.assertEquals(a.getServiceReferenceBName(), "ServiceB");
+ }
+
+ /**
+ * L783 <br>
+ * createSelfReference(Class<B> businessInterface) ?
+ * Returns a ServiceReference that can be used to invoke this component over the designated service.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCreateSelfReference() throws Exception {
+ Assert.assertEquals(a.getSelfReferenceName(), "ComponentA");
+ }
+
+ /**
+ * L785 <br>
+ * getSelfReference(Class<B> businessInterface, String serviceName) -
+ * Returns a ServiceReference that can be used to invoke this component over the designated service.
+ * Service name explicitly declares the service name to invoke.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCreateSelfReferenceWithServiceName() throws Exception {
+ Assert.assertEquals("ServiceC", b.getSelfReferenceWithServiceName());
+ }
+
+ /**
+ * L788 <br>
+ * getProperty (Class<B> type, String propertyName) - Returns the value of an SCA property defined by this component.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testGetProperty() throws Exception {
+ Assert.assertEquals("PropertyA", a.getProperty());
+ }
+
+ /**
+ * L793 <br>
+ * getRequestContext() -
+ * Returns the context for the current SCA service request, or null if there is no current request or if the context is unavailable.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testGetRequestContext() throws Exception {
+ Assert.assertEquals("AComponent", a.getRequestContextServiceName());
+ }
+
+ /**
+ * L790, L794 <br>
+ * cast(B target) - Casts a type-safe reference to a CallableReference.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCast() throws Exception {
+ Assert.assertEquals("ServiceB", a.getCastCallableReferenceServiceName());
+ Assert.assertEquals("ServiceB", a.getCastServiceReferenceServiceName());
+
+ String check = "";
+ try {
+ a.illegalCast();
+ } catch (IllegalArgumentException iae) {
+ check = "IllegalCast";
+ }
+ Assert.assertEquals("IllegalCast", check);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org