diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-08 12:00:38 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-08 12:00:38 +0000 |
commit | fa12862cdde921c4893204a0dc28cf7d80e2cebf (patch) | |
tree | 5310fd403d54e2d277047e8980838c674dc05a9c /sca-java-2.x | |
parent | df6bd28390b0cd99119934763a4a664b6aa5347d (diff) |
Switch binder interface over to throwing exceptions rather than returning booleans. Allows the full details of a missmatch to be retrieved in the runtime case as well as the build time case. Update the matching test case to take advantage of the extra information.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@920287 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
4 files changed, 27 insertions, 22 deletions
diff --git a/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java b/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java index d4ae722318..beadbec397 100644 --- a/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java +++ b/sca-java-2.x/trunk/itest/policy/matching/src/test/java/org/apache/tuscany/sca/policy/matching/MatchingTestCase.java @@ -20,6 +20,8 @@ package org.apache.tuscany.sca.policy.matching; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.Node; @@ -56,8 +58,9 @@ public class MatchingTestCase { HelloWorld helloWorld = node.getService(HelloWorld.class, "HelloWorldClientMutuallyExclusiveIntents"); try { helloWorld.getGreetings("petra"); + fail("Exception expected"); } catch (Exception ex) { - assertEquals("Unable to bind", ex.getMessage().substring(0, 14)); + assertTrue(ex.getMessage().indexOf("No match because the following intents are mutually exclusive {http://tuscany.apache.org/xmlns/sca/1.1}testIntent3 {http://tuscany.apache.org/xmlns/sca/1.1}testIntent1") > -1); } } @@ -72,8 +75,9 @@ public class MatchingTestCase { HelloWorld helloWorld = node.getService(HelloWorld.class, "HelloUnresolvedIntentsOnReference"); try { helloWorld.getGreetings("petra"); + fail("Exception expected"); } catch (Exception ex) { - assertEquals("Unable to bind", ex.getMessage().substring(0, 14)); + assertTrue(ex.getMessage().indexOf("No match because there are unresolved intents [{http://tuscany.apache.org/xmlns/sca/1.1}testIntent2]") > -1); } } @@ -90,9 +94,10 @@ public class MatchingTestCase { public void testSomePoliciesOnOneSideButNoneOnTheOther() throws Exception { try { HelloWorld helloWorld = node.getService(HelloWorld.class, "HelloWorldClientSomePoliciesOnOneSideButNoneOnTheOther"); - assertEquals("Hello petra", helloWorld.getGreetings("petra")); + helloWorld.getGreetings("petra"); + fail("Exception expected"); } catch (Exception ex) { - assertEquals("Unable to bind", ex.getMessage().substring(0, 14)); + assertTrue(ex.getMessage().indexOf("No match because there are policy sets at the endpoint but not at the endpoint reference") > -1); } } @@ -106,9 +111,10 @@ public class MatchingTestCase { public void testDifferentPolicyLanguage() throws Exception { try { HelloWorld helloWorld = node.getService(HelloWorld.class, "HelloWorldClientDifferentPolicyLanguage"); - assertEquals("Hello petra", helloWorld.getGreetings("petra")); + helloWorld.getGreetings("petra"); + fail("Exception expected"); } catch (Exception ex) { - assertEquals("Unable to bind", ex.getMessage().substring(0, 14)); + assertTrue(ex.getMessage().indexOf("No match because the policy sets on either side have policies in differnt languages {http://schemas.xmlsoap.org/ws/2004/09/policy}ExactlyOne and {http://tuscany.apache.org/xmlns/sca/1.1}jdkLogger") > -1); } } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java index 676a4fd489..b2ce3f5b7b 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReferenceBinder.java @@ -32,7 +32,7 @@ public interface EndpointReferenceBinder { * @param endpointReference * @return */ - boolean bindBuildTime(EndpointRegistry endpointRegistry, EndpointReference endpointReference); + void bindBuildTime(EndpointRegistry endpointRegistry, EndpointReference endpointReference); /** @@ -40,7 +40,7 @@ public interface EndpointReferenceBinder { * @param endpointReference * @return */ - boolean bindRunTime(EndpointRegistry endpointRegistry, EndpointReference endpointReference); + void bindRunTime(EndpointRegistry endpointRegistry, EndpointReference endpointReference); /** * diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java index 2e68602713..9ef0d8e728 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java @@ -302,10 +302,7 @@ public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implemen private void resolveEndpointReference() { resolve(); - boolean ok = eprBinder.bindRunTime(endpointRegistry, this); - if (!ok) { - throw new ServiceRuntimeException("Unable to bind " + this); - } + eprBinder.bindRunTime(endpointRegistry, this); // start the binding provider final ReferenceBindingProvider bindingProvider = getBindingProvider(); diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java index fe313e6472..e72a9f2e35 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/impl/EndpointReferenceBinderImpl.java @@ -49,6 +49,7 @@ import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.Qualifier; import org.apache.tuscany.sca.runtime.EndpointReferenceBinder; import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.oasisopen.sca.ServiceRuntimeException; /** * A builder that takes endpoint references and resolves them. It either finds local @@ -92,9 +93,9 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { * @param endpointRegistry * @param endpointReference */ - public boolean bindBuildTime(EndpointRegistry endpointRegistry, + public void bindBuildTime(EndpointRegistry endpointRegistry, EndpointReference endpointReference) { - return bind(endpointRegistry, endpointReference, false); + bind(endpointRegistry, endpointReference, false); } /** @@ -104,9 +105,9 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { * @param endpointRegistry * @param endpointReference */ - public boolean bindRunTime(EndpointRegistry endpointRegistry, + public void bindRunTime(EndpointRegistry endpointRegistry, EndpointReference endpointReference) { - return bind(endpointRegistry, endpointReference, true); + bind(endpointRegistry, endpointReference, true); } /** @@ -116,7 +117,7 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { * @param endpointReference * @param runtime set true if called from the runtime */ - public boolean bind(EndpointRegistry endpointRegistry, + public void bind(EndpointRegistry endpointRegistry, EndpointReference endpointReference, boolean runtime){ @@ -183,7 +184,8 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { "endpoint-validation-messages", "NoComponentReferenceTarget", endpointReference.getReference().getName()); - return false; + throw new ServiceRuntimeException("Unable to bind " + + monitor.getLastProblem().toString()); } } @@ -242,7 +244,8 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { "endpoint-validation-messages", "NoEndpointsFound", endpointReference.toString()); - return false; + throw new ServiceRuntimeException("Unable to bind " + + monitor.getLastProblem().toString()); } } @@ -277,10 +280,9 @@ public class EndpointReferenceBinderImpl implements EndpointReferenceBinder { endpointReference.toString()); } - return false; + throw new ServiceRuntimeException("Unable to bind " + + monitor.getLastProblem().toString()); } - - return true; } /** |