diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-13 20:02:36 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-13 20:02:36 +0000 |
commit | 4ed0ed906e82c9484b384419fa4ef4c980768731 (patch) | |
tree | e0250b6d10349e29522a2b1667d2e1db4d9dab84 /branches/sca-java-1.x/vtest/java-api/apis/componentcontext | |
parent | ba73f8abcef884936f965c3085b80485bf2b5e1a (diff) |
Creating Java SCA 1.x branch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@713805 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/vtest/java-api/apis/componentcontext')
12 files changed, 775 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/pom.xml b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/pom.xml new file mode 100644 index 0000000000..9af4b21f8a --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/pom.xml @@ -0,0 +1,45 @@ +<?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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>java-api-apis</artifactId> + <version>1.4-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>vtest-java-api-apis-componentcontext</artifactId> + <name>Apache Tuscany SCA Java APIs and Annotations Verification Tests - APIs - ComponentContext</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + </dependencies> +</project> diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java new file mode 100644 index 0000000000..b2c8c07866 --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/AComponent.java @@ -0,0 +1,42 @@ +/* + * 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 A. + */ +public interface AComponent { + + 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(); + + public String testServiceLookup(); + public String getRequestContextContent(); + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BComponent.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BComponent.java new file mode 100644 index 0000000000..7e425c740f --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BComponent.java @@ -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 B. + */ +public interface BComponent { + + String getName(); + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.java new file mode 100644 index 0000000000..eff7cc5a88 --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/BService.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 org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext; + +import org.osoa.sca.annotations.Remotable; + +/** + * Simple Service B. + */ +@Remotable +public interface BService { + + String getBName(); + + String getSelfReferenceWithServiceName(); + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java new file mode 100644 index 0000000000..d0da012f6f --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/CService.java @@ -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(); + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/DComponent.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/DComponent.java new file mode 100644 index 0000000000..a221ba11fc --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/DComponent.java @@ -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; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface DComponent { + + public String getName(); + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java new file mode 100644 index 0000000000..606443a480 --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AComponentImpl.java @@ -0,0 +1,124 @@ +/* + * 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.impl; + +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.AComponent; +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.BService; +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.DComponent; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(AComponent.class) +@Scope("COMPOSITE") +@EagerInit +public class AComponentImpl implements AComponent { + + public static String rcContent = null; + + protected ComponentContext componentContext; + + @Reference + protected BService bReference; + + @Reference + protected DComponent dReference; + + @Property(name="aProperty", required=true) + protected String aProperty; + + public String getName() { + return "ComponentA"; + } + + @Context + public void setComponentContext(ComponentContext context) { + this.componentContext = context; + } + + @Init + public void init() { + RequestContext rc = componentContext.getRequestContext(); + if (rc != null) { + rcContent = "NotNull"; + } else { + rcContent = "Null"; + } + } + + public String getContextURI() { + return componentContext.getURI(); + } + + public String getServiceBName() { + return componentContext.getService(BService.class, "bReference").getBName(); + } + + public String getServiceReferenceBName() { + 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(""); + } + + public String testServiceLookup() { + return componentContext.getService(DComponent.class, "dReference").getName(); + } + + public String getRequestContextContent() { + return rcContent; + } + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AUnannotatedComponentImpl.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AUnannotatedComponentImpl.java new file mode 100644 index 0000000000..34a71e1318 --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/AUnannotatedComponentImpl.java @@ -0,0 +1,121 @@ +/* + * 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.impl; + +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.AComponent; +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.BService; +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.DComponent; +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(AComponent.class) +@Scope("COMPOSITE") +@EagerInit +public class AUnannotatedComponentImpl implements AComponent { + + public static String rcContent = null; + + protected ComponentContext componentContext; + + protected BService bReference; + + protected DComponent dReference; + + protected String aProperty; + + public String getName() { + return "ComponentA"; + } + + @Context + public void setComponentContext(ComponentContext context) { + this.componentContext = context; + } + + @Init + public void init() { + RequestContext rc = componentContext.getRequestContext(); + if (rc != null) { + rcContent = "NotNull"; + } else { + rcContent = "Null"; + } + } + + public String getContextURI() { + return componentContext.getURI(); + } + + public String getServiceBName() { + return componentContext.getService(BService.class, "bReference").getBName(); + } + + public String getServiceReferenceBName() { + 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(""); + } + + public String testServiceLookup() { + return componentContext.getService(DComponent.class, "dReference").getName(); + } + + public String getRequestContextContent() { + return rcContent; + } + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java new file mode 100644 index 0000000000..71d2eade2b --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/BComponentImpl.java @@ -0,0 +1,52 @@ +/* + * 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.impl; + +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(interfaces={BService.class, CService.class}) +public class BComponentImpl implements BService, CService { + + 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(); + } + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/DComponentImpl.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/DComponentImpl.java new file mode 100644 index 0000000000..4b2c8c183b --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/impl/DComponentImpl.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 org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl; + +import org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.DComponent; +import org.osoa.sca.annotations.Service; + +@Service(DComponent.class) +public class DComponentImpl implements DComponent { + + public String getName() { + return "ComponentD"; + } + +} diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite new file mode 100644 index 0000000000..19f110d5dc --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/main/resources/ab.composite @@ -0,0 +1,47 @@ +<?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://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/BService"/> + <reference name="dReference" target="DComponent"/> + <property name="aProperty" type="xsd:string">PropertyA</property> + </component> + + <component name="AUnannotatedComponent"> + <implementation.java class="org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl.AUnannotatedComponentImpl"/> + <reference name="bReference" target="BComponent/BService"/> + <reference name="dReference" target="DComponent"/> + <property name="aProperty" type="xsd:string">PropertyA</property> + </component> + + <component name="BComponent"> + <implementation.java class="org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl.BComponentImpl"/> + </component> + + <component name="DComponent"> + <implementation.java class="org.apache.tuscany.sca.vtest.javaapi.apis.componentcontext.impl.DComponentImpl"/> + </component> + +</composite> diff --git a/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java new file mode 100644 index 0000000000..3f4150c64f --- /dev/null +++ b/branches/sca-java-1.x/vtest/java-api/apis/componentcontext/src/test/java/org/apache/tuscany/sca/vtest/javaapi/apis/componentcontext/ComponentContextTestCase.java @@ -0,0 +1,191 @@ +/* + * 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; + +import org.apache.tuscany.sca.vtest.utilities.ServiceFinder; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * This test class tests the ComponentContext interface described in 1.7.1 of + * the SCA Java Annotations & APIs Specification 1.0. Relevant sections of 1.4 + * will also be covered here. + */ +public class ComponentContextTestCase { + + protected static String compositeName = "ab.composite"; + protected static AComponent a; + protected static AComponent aUnannotated; + protected static BService b; + + @BeforeClass + public static void init() throws Exception { + try { + System.out.println("Setting up"); + ServiceFinder.init(compositeName); + a = ServiceFinder.getService(AComponent.class, "AComponent"); + aUnannotated = ServiceFinder.getService(AComponent.class, "AUnannotatedComponent"); + b = ServiceFinder.getService(BService.class, "BComponent/BService"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + System.out.println("Cleaning up"); + ServiceFinder.cleanup(); + } + + /** + * Lines 776 <br> + * getURI() - Returns the absolute URI of the component within the SCA + * domain. + * + * @throws Exception + */ + @Test + public void testGetURI() throws Exception { + Assert.assertEquals("AComponent", a.getContextURI()); + Assert.assertEquals("AUnannotatedComponent", aUnannotated.getContextURI()); + } + + /** + * Lines 778 <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(), "ServiceB"); + } + + /** + * Lines 780 <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(), "ServiceB"); + } + + /** + * Lines 783 <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"); + } + + /** + * Lines 785 <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()); + } + + /** + * Lines 788 <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()); + } + + /** + * Lines 793 <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()); + Assert.assertEquals("NotNull", a.getRequestContextContent()); + } + + /** + * Lines 790,794 <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"; + } catch (ServiceRuntimeException sre) { + if (sre.getCause() instanceof IllegalArgumentException) { + check = "IllegalCast"; + } + } + Assert.assertEquals("IllegalCast", check); + } + + /** + * Lines 342-344 <br> + * When a component implementation needs access to a service where the + * reference to the service is not known at compile time, the reference can + * be located using the component?s ComponentContext. + * + * @throws Exception + */ + @Test + @Ignore("TUSCANY-2609") + public void testServiceLookup() throws Exception { + Assert.assertEquals("ComponentD", a.testServiceLookup()); + } + +} |