Author: slaws
Date: Thu Mar 6 04:02:33 2008
New Revision: 634233
URL: http://svn.apache.org/viewvc?rev=634233&view=rev
Log:
Added function to calculate binding URIs specifically in accordance with
assembly spec.
Added:
incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java
(with props)
Modified:
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
Modified:
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java?rev=634233&r1=634232&r2=634233&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
Thu Mar 6 04:02:33 2008
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.assembly.builder.impl;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -41,6 +42,7 @@
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor;
import org.apache.tuscany.sca.assembly.builder.Problem.Severity;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
@@ -1085,6 +1087,295 @@
return scaBinding;
}
+
+ /**
+ * Fully resolve the binding URIs based on available information. This
includes information
+ * from the ".composite" files, from resources associated with the
binding, e.g. WSDL files,
+ * from any associated policies and from the default information for each
binding type.
+ *
+ * TODO: Share the URL calculation algorithm with the
configureComponents() method above
+ * although keeping the configureComponents() methods signature as
is because when
+ * a composite is actually build in a node the node default
information is currently
+ * available
+ *
+ * @param defaultBindings list of default bindings (from the node
configuration composite)
+ * @param composite the composite to be configured
+ * @param uri the path to the composite provided through any nested
composite component implementations
+ */
+ public void calculateBindingURIs(List<Binding> defaultBindings, Composite
composite, String uri) throws CompositeBuilderException {
+
+ String parentComponentURI = uri;
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+
+ // Initialize component URI
+ String componentURI;
+ if (parentComponentURI == null) {
+ componentURI = component.getName();
+ } else {
+ componentURI = URI.create(parentComponentURI +
'/').resolve(component.getName()).toString();
+ }
+ component.setURI(componentURI);
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // Process nested composite
+ calculateBindingURIs(defaultBindings,
(Composite)implementation, componentURI);
+ }
+ }
+
+ // Initialize composite service binding URIs
+ List<Service> compositeServices = composite.getServices();
+ for (Service service : compositeServices) {
+ // Set default binding names
+
+ // Create default SCA binding
+ if (service.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ service.getBindings().add(scaBinding);
+ }
+
+ // Initialize binding names and URIs
+ for (Binding binding : service.getBindings()) {
+ constructBindingName(service, binding);
+ constructBindingURI(parentComponentURI, composite, service,
binding, defaultBindings);
+ }
+ }
+
+ // Initialize component service binding URIs
+ for (Component component : composite.getComponents()) {
+ for (ComponentService service : component.getServices()) {
+ // Create default SCA binding
+ if (service.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ service.getBindings().add(scaBinding);
+ }
+
+ // Initialize binding names and URIs
+ for (Binding binding : service.getBindings()) {
+
+ constructBindingName(service, binding);
+ constructBindingURI(component, service, binding,
defaultBindings);
+ }
+ }
+ }
+ }
+
+ /**
+ * If a binding name is not provided by the user construct it based on the
service name
+ *
+ * @param service
+ * @param binding
+ */
+ private void constructBindingName(Service service, Binding binding) throws
CompositeBuilderException{
+
+ // set the default binding name if one is required
+ // if there is no name on the binding then set it to the service name
+ if (binding.getName() == null){
+ binding.setName(service.getName());
+ }
+
+ // Check that multiple bindings do not have the same name
+ // TODO: this test needs to be refined to take into account the
+ // scheme that the binding is using.
+ for (Binding serviceBinding : service.getBindings()){
+ if ((!binding.equals(serviceBinding)) &&
+ (binding.getName().equals(serviceBinding.getName()))){
+
+ throw new CompositeBuilderException("Multiple bindings for
service " +
+ service.getName() +
+ " have the same binding
name " +
+ binding.getName() +
+ ". This means Tuscany SCA
can't create unique URIs to differenetiate these bindings ");
+ }
+ }
+ }
+
+ /**
+ * URI construction for composite bindings based on Assembly spec section
1.7.2, This method
+ * assumes that the component URI part of the binding URI is formed from
the part to the
+ * composite in question and just calls the generic constructBindingURI
method with this
+ * information
+ *
+ * @param parentComponentURI
+ * @param composite
+ * @param service
+ * @param binding
+ * @param defaultBindings
+ */
+ private void constructBindingURI(String parentComponentURI, Composite
composite, Service service, Binding binding, List<Binding> defaultBindings)
+ throws CompositeBuilderException{
+ // This is a composite service so there is no component to provide a
component URI
+ // The path to this composite (through nested composites) is used.
+ constructBindingURI(parentComponentURI, service, binding,
composite.getServices().size() > 1, defaultBindings);
+ }
+ /**
+ * URI construction for component bindings based on Assembly spec section
1.7.2. This method
+ * calculates the component URI part based on component information
before calling the generic
+ * constructBindingURI method
+ *
+ * @param component the component that holds the service
+ * @param service the service that holds the binding
+ * @param binding the binding for which the URI is being constructed
+ * @param defaultBindings the list of default binding configurations
+ */
+ private void constructBindingURI(Component component, Service service,
Binding binding, List<Binding> defaultBindings)
+ throws CompositeBuilderException{
+ constructBindingURI(component.getURI(), service, binding,
component.getServices().size() > 1, defaultBindings);
+ }
+
+ /**
+ * Generic URI construction for bindings based on Assembly spec section
1.7.2
+ *
+ * @param componentURIString the string version of the URI part that comes
from the component name
+ * @param service the service in question
+ * @param binding the binding for which the URI is being constructed
+ * @param includeServiceBindingURI when set true the serviceBindingURI
part should be used
+ * @param defaultBindings the list of default binding configurations
+ * @throws CompositeBuilderException
+ */
+ private void constructBindingURI(String componentURIString, Service
service, Binding binding, boolean includeServiceBindingURI, List<Binding>
defaultBindings)
+ throws CompositeBuilderException{
+
+ try {
+ URI baseURI = null;
+ URI componentURI = null;
+ URI serviceBindingURI = null;
+
+ // calculate the service binding URI
+ if (binding.getURI() == null){
+ serviceBindingURI = new URI(binding.getName());
+ } else {
+ serviceBindingURI = new URI(binding.getURI());
+ }
+
+ // if the user has provided an absolute binding URI then use it
+ if (serviceBindingURI != null && serviceBindingURI.isAbsolute()){
+ binding.setURI(serviceBindingURI.toString());
+ return;
+ }
+
+ // calculate the component URI
+ if (componentURIString != null) {
+ componentURI = new URI(addSlashToPath(componentURIString));
+ } else {
+ componentURI = null;
+ }
+
+ // if the user has provided an absolute component URI then use it
+ if (componentURI != null && componentURI.isAbsolute()){
+ binding.setURI(concatenateModelURI(null, componentURI,
serviceBindingURI, includeServiceBindingURI));
+ return;
+ }
+
+ // calculate the base URI
+
+ // get the protocol for this binding/URI
+/* some code that allows binding specific code to run. Being discussed on ML
+ BindingURICalculator uriCalculator =
bindingURICalcualtorExtensionPoint.getBindingURICalculator(binding);
+
+ if (uriCalculator != null){
+ String protocol = uriCalculator.getProtocol(binding);
+
+ // find the default binding with the right protocol
+ Binding defaultBinding = nodeInfo.getBindingDefault(binding,
protocol);
+
+ if (defaultBinding != null){
+ baseURI = new URI(defaultBinding.getURI());
+ } else {
+ baseURI = null;
+ }
+
+ } else {
+ baseURI = null;
+ }
+*/
+ // as a simpler alternative to the above commented out code.
+ baseURI = null;
+ if (defaultBindings != null) {
+ for (Binding defaultBinding : defaultBindings){
+ if (binding.getClass() == defaultBinding.getClass()){
+ baseURI = new
URI(addSlashToPath(defaultBinding.getURI()));
+ }
+ }
+ }
+
+ binding.setURI(concatenateModelURI(baseURI, componentURI,
serviceBindingURI,includeServiceBindingURI));
+ } catch (URISyntaxException ex){
+ throw new CompositeBuilderException("URLSyntaxException when
creating binding URI at component " +
+ componentURIString +
+ " service " +
+ service.getName() +
+ " binding " +
+ binding.getName(),
+ ex);
+ }
+ }
+
+ /**
+ * Use to ensure that URI paths end in "/" as here we want to maintain the
+ * last path element of an base URI when other URI are resolved against
it. This is
+ * not the default behaviour of URI resolution as defined in RFC 2369
+ *
+ * @param path the path string to which the "/" is to be added
+ * @return the resulting path with a "/" added if it not already there
+ */
+ private String addSlashToPath(String path){
+ if (path.endsWith("/")){
+ return path;
+ } else {
+ return path + "/";
+ }
+ }
+
+ /**
+ * Concatenate binding URI parts together based on Assembly spec section
1.7.2
+ *
+ * @param baseURI the base of the binding URI
+ * @param componentURI the middle part of the binding uri derived from the
component name
+ * @param serviceBindingURI the end part of the binding uri derived from
the service name
+ * @param includeServiceBindingURI when set true the serviceBindingURI
part should be used
+ * @return the resulting URI as a string
+ */
+ private String concatenateModelURI(URI baseURI, URI componentURI, URI
serviceBindingURI, boolean includeServiceBindingURI){
+
+ String uriString;
+
+ if (baseURI == null){
+ if (componentURI == null){
+ uriString = serviceBindingURI.toString();
+ } else {
+ if (includeServiceBindingURI){
+ uriString =
componentURI.resolve(serviceBindingURI).toString();
+ } else {
+ uriString = componentURI.toString();
+ }
+ }
+ } else {
+ if (componentURI == null){
+ if (includeServiceBindingURI){
+ uriString = baseURI.resolve(serviceBindingURI).toString();
+ } else {
+ uriString = baseURI.toString();
+ }
+ } else {
+ if (includeServiceBindingURI){
+ uriString =
baseURI.resolve(componentURI).resolve(serviceBindingURI).toString();
+ } else {
+ uriString = baseURI.resolve(componentURI).toString();
+ }
+ }
+ }
+
+ // tidy up by removing any trailing "/"
+ if (uriString.endsWith("/")){
+ uriString = uriString.substring(0, uriString.length()-1);
+ }
+
+ return uriString;
+ }
}
Added:
incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java?rev=634233&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java
(added)
+++
incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java
Thu Mar 6 04:02:33 2008
@@ -0,0 +1,551 @@
+/*
+ * 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.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor;
+import org.apache.tuscany.sca.assembly.builder.Problem;
+import org.apache.tuscany.sca.assembly.builder.Problem.Severity;
+
+public class CalculateBindingURITestCase extends TestCase {
+ private final static Logger logger =
Logger.getLogger(CalculateBindingURITestCase.class.getName());
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory = null;
+ private CompositeBuilderMonitor monitor = null;
+ private CompositeConfigurationBuilderImpl configurationBuilder = null;
+ private List<Binding> defaultBindings = new ArrayList<Binding>();
+
+ @Override
+ protected void setUp() throws Exception {
+ assemblyFactory = new DefaultAssemblyFactory();
+ scaBindingFactory = new TestBindingFactory();
+ monitor = new CompositeBuilderMonitor() {
+ public void problem(Problem problem) {
+ if (problem.getSeverity() == Severity.INFO) {
+ logger.info(problem.toString());
+ } else if (problem.getSeverity() == Severity.WARNING) {
+ logger.warning(problem.toString());
+ } else if (problem.getSeverity() == Severity.ERROR) {
+ if (problem.getCause() != null) {
+ logger.log(Level.SEVERE, problem.toString(),
problem.getCause());
+ } else {
+ logger.severe(problem.toString());
+ }
+ }
+ }
+ };
+ configurationBuilder = new
CompositeConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, null,
null, monitor);
+ Binding defaultBinding = new TestBindingImpl();
+ defaultBinding.setURI("http://myhost:8080/root");
+ defaultBindings.add(defaultBinding);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ assemblyFactory = null;
+ }
+
+ /**
+ * Test that URI are generated in accordance with the assembly spec
section 1.7.2.1 as
+ * follows. For the 3 parts that make up the URI;
+ *
+ * BaseURI / Component URI / Service Binding URI
+ *
+ * Test the following combinations for:
+ *
+ * NB. The short hand here, e.g. <service name="s1"> <binding.sca>
<service name="s2"> means
+ * two services appear where the first has the sca binding specified.
+ *
+ * component service bindings
+ *
+ * http://myhost:8080/root / <component name="c1"> / <service
name="s1"> <binding.sca>
+ * --> http://myhost:8080/root/c1
+ * http://myhost:8080/root / <component name="c1"> / <service
name="s1"> <binding.sca> <service name="s2">
+ * --> http://myhost:8080/root/c1/s1
+ * http://myhost:8080/root / <component name="c1"> / <service
name="s1"> <binding.sca name="n"> <service name="s2">
+ * --> http://myhost:8080/root/c1/n
+ * http://myhost:8080/root / <component name="c1"> / <service
name="s1"> <binding.sca uri="b"> <service name="s2">
+ * --> http://myhost:8080/root/c1/b
+ * http://myhost:8080/root / <component name="c1"> / <service
name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
+ * --> http://myhost:8080/b
+ * http://myhost:8080/root / <component name="c1"> / <service
name="s1"> <binding.sca uri="../../b"> <service name="s2">
+ * --> http://myhost:8080/b
+ *
+ * top level composite service bindings
+ *
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca>
<service name="s2">
+ * --> http://myhost:8080/root
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca>
<service name="s2">
+ * --> http://myhost:8080/root/s1
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca
name="n"> <service name="s2">
+ * --> http://myhost:8080/root/n
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca
uri="b"> <service name="s2">
+ * --> http://myhost:8080/root/b
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca
uri="http://myhost:8080/b"> <service name="s2">
+ * --> http://myhost:8080/b
+ *
+ * nested composite service bindings
+ *
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca>
+ * --> http://myhost:8080/root/c1/c2
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca>
<service name="s2">
+ * --> http://myhost:8080/root/c1/c2/s1
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca
name="n"> <service name="s2">
+ * --> http://myhost:8080/root/c1/c2/n
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca
uri="b"> <service name="s2">
+ * --> http://myhost:8080/root/c1/c2/b
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca
uri="http://myhost:8080/b"> <service name="s2">
+ * --> http://myhost:8080/b
+ *
+ * binding name duplication errors
+ *
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca>
<binding.xyz>
+ * --> Error
+ * http://myhost:8080/root / <component name="c1"> implemented by
composite with <component name="c2"> / <service name="s1"> <binding.sca
name="b1"> <binding.xyz name="b1">
+ * --> Error
+ */
+
+ private Composite createComponentServiceBinding() {
+ Composite composite1 = assemblyFactory.createComposite();
+ composite1.setName(new QName("http://foo", "C1"));
+
+ Component c1 = assemblyFactory.createComponent();
+ c1.setName("c1");
+ composite1.getComponents().add(c1);
+
+ ComponentService s1 = assemblyFactory.createComponentService();
+ c1.getServices().add(s1);
+ s1.setName("s1");
+
+ ComponentService s2 = assemblyFactory.createComponentService();
+ c1.getServices().add(s2);
+ s2.setName("s2");
+
+ Binding b1 = new TestBindingImpl();
+ s1.getBindings().add(b1);
+
+ Binding b2 = new TestBindingImpl();
+ s2.getBindings().add(b2);
+
+ return composite1;
+ }
+
+ private Composite createTopLevelCompositeServiceBinding(){
+ Composite composite1 = assemblyFactory.createComposite();
+ composite1.setName(new QName("http://foo", "C1"));
+
+ CompositeService s1 = assemblyFactory.createCompositeService();
+ s1.setName("s1");
+ composite1.getServices().add(s1);
+
+ Binding b1 = new TestBindingImpl();
+ s1.getBindings().add(b1);
+
+ CompositeService s2 = assemblyFactory.createCompositeService();
+ s2.setName("s2");
+ composite1.getServices().add(s2);
+
+ Binding b2 = new TestBindingImpl();
+ s2.getBindings().add(b2);
+
+ return composite1;
+ }
+
+ private Composite createNestCompositeServiceBinding(){
+ Composite composite1 = assemblyFactory.createComposite();
+ composite1.setName(new QName("http://foo", "C1"));
+
+ Component c1 = assemblyFactory.createComponent();
+ c1.setName("c1");
+ composite1.getComponents().add(c1);
+
+ Composite composite2 = assemblyFactory.createComposite();
+ c1.setImplementation(composite2);
+ composite2.setName(new QName("http://foo", "C2"));
+
+ Component c2 = assemblyFactory.createComponent();
+ composite2.getComponents().add(c2);
+ c2.setName("c2");
+
+ ComponentService s1 = assemblyFactory.createComponentService();
+ c2.getServices().add(s1);
+ s1.setName("s1");
+
+ ComponentService s2 = assemblyFactory.createComponentService();
+ c2.getServices().add(s2);
+ s2.setName("s2");
+
+ Binding b1 = new TestBindingImpl();
+ s1.getBindings().add(b1);
+
+ Binding b2 = new TestBindingImpl();
+ s2.getBindings().add(b2);
+
+ return composite1;
+ }
+
+ // component service binding tests
+
+ public void testComponentServiceSingleService() {
+ Composite composite = createComponentServiceBinding();
+ composite.getComponents().get(0).getServices().remove(1);
+ Binding b =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingDefault() {
+ Composite composite = createComponentServiceBinding();
+ Binding b =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/s1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingName() {
+ Composite composite = createComponentServiceBinding();
+ Binding b =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/n", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingURIRelative() {
+ Composite composite = createComponentServiceBinding();
+ Binding b =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingURIAbsolute() {
+ Composite composite = createComponentServiceBinding();
+ Binding b =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("http://myhost:8080/b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingURIRelative2() {
+ Composite composite = createComponentServiceBinding();
+ Binding b =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("../../b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ // top level composite service binding tests
+
+ public void testCompositeServiceSingleService() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ composite.getServices().remove(1);
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingDefault() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/s1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingName() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+ b.setName("n");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/n", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingURIRelative() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingURIAbsolute() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("http://myhost:8080/b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ // nested composite service binding tests
+
+ public void testNestedCompositeServiceSingleService() {
+ Composite composite = createNestCompositeServiceBinding();
+
((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().remove(1);
+ Binding b =
((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/c2", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingDefault() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b =
((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/c2/s1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingName() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b =
((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/c2/n", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingURIRelative() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b =
((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/root/c1/c2/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingURIAbsolute() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b =
((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("http://myhost:8080/b");
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ // component service binding name error tests
+
+ public void testComponentServiceBindingNameError1() {
+ Composite composite = createComponentServiceBinding();
+ Binding b1 =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ Binding b2 = new TestBindingImpl();
+
composite.getComponents().get(0).getServices().get(0).getBindings().add(b2);
+
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+ fail();
+ } catch(Exception ex){
+ //System.out.println(ex.toString());
+ }
+ }
+
+ public void testComponentServiceBindingNameError2() {
+ Composite composite = createComponentServiceBinding();
+ Binding b1 =
composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ Binding b2 = new TestBindingImpl();
+
composite.getComponents().get(0).getServices().get(0).getBindings().add(b2);
+
+ b1.setName("b");
+ b2.setName("b");
+
+
+ try {
+ configurationBuilder.calculateBindingURIs(defaultBindings,
composite, null);
+ fail();
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ }
+ }
+
+
+ public class TestBindingFactory implements SCABindingFactory {
+ public SCABinding createSCABinding() {
+ return new TestBindingImpl();
+ }
+ }
+
+ public class TestBindingImpl implements SCABinding {
+ private String name;
+ private String uri;
+ private boolean unresolved;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CalculateBindingURITestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]