From 6aeeff9e3b0b2a75f808d4937fd63312a632ba65 Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 14 Jun 2011 09:48:46 +0000 Subject: TUSCANY-3873 - start of a test case to check out policy matching and to look at where an how policy interceptors are added along the reference, service and binding chains git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1135444 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/helloworld/HelloWorld.java | 29 +++++++ .../src/main/java/helloworld/HelloWorldClient.java | 35 ++++++++ .../main/java/helloworld/HelloWorldService.java | 45 ++++++++++ .../src/main/java/testpolicy/TestPolicy.java | 63 ++++++++++++++ .../main/java/testpolicy/TestPolicyBuilder.java | 84 ++++++++++++++++++ .../java/testpolicy/TestPolicyInterceptor.java | 95 +++++++++++++++++++++ .../main/java/testpolicy/TestPolicyProcessor.java | 99 ++++++++++++++++++++++ .../java/testpolicy/TestPolicyProviderFactory.java | 68 +++++++++++++++ .../TestPolicyProviderImplementation.java | 48 +++++++++++ .../testpolicy/TestPolicyProviderReference.java | 45 ++++++++++ .../java/testpolicy/TestPolicyProviderService.java | 44 ++++++++++ .../main/resources/META-INF/sca-contribution.xml | 23 +++++ ...ache.tuscany.sca.assembly.builder.PolicyBuilder | 17 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 20 +++++ ....apache.tuscany.sca.definitions.xml.Definitions | 17 ++++ ...ache.tuscany.sca.provider.PolicyProviderFactory | 20 +++++ .../src/main/resources/definitions.xml | 43 ++++++++++ .../src/main/resources/helloworld.composite | 40 +++++++++ .../src/main/resources/helloworld.wsdl | 90 ++++++++++++++++++++ .../test/java/interceptors/HelloworldTestCase.java | 51 +++++++++++ 20 files changed, 976 insertions(+) create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicy.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyBuilder.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyInterceptor.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProcessor.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderFactory.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderImplementation.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderReference.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderService.java create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/definitions.xml create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.composite create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.wsdl create mode 100644 sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java (limited to 'sca-java-2.x/trunk/testing/itest/policy/interceptors/src') diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.java new file mode 100644 index 0000000000..295d8fee53 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorld.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 helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HelloWorld { + + String getGreetings(String s); + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..c51dc66caf --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldClient.java @@ -0,0 +1,35 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Reference; + +public class HelloWorldClient implements HelloWorld { + + @Reference + public HelloWorld helloWorldWS; + + public String getGreetings(String s) { + String response = helloWorldWS.getGreetings(s); + System.out.println("At client: " + response); + return response; + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..c72d41c851 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/helloworld/HelloWorldService.java @@ -0,0 +1,45 @@ +/* + * 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 helloworld; + +import javax.security.auth.Subject; + +import org.oasisopen.sca.RequestContext; +import org.oasisopen.sca.annotation.Context; + +public class HelloWorldService implements HelloWorld { + + @Context + protected RequestContext requestContext; + + public String getGreetings(String name) { + Subject subject = requestContext.getSecuritySubject(); + String response = "Hello " + name + " "; + + if (subject == null){ + response += "null subject"; + } else { + response += subject.getPrincipals().iterator().next().getName(); + } + + System.out.println("At service: " + response); + return response; + } +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicy.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicy.java new file mode 100644 index 0000000000..651208fa76 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicy.java @@ -0,0 +1,63 @@ +/* + * 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 testpolicy; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev: 824551 $ $Date: 2009-10-13 01:21:22 +0100 (Tue, 13 Oct 2009) $ + */ +public class TestPolicy { + static final String SCA11_NS = Base.SCA11_NS; + static final String SCA11_TUSCANY_NS = Base.SCA11_TUSCANY_NS; + static final QName TEST_POLICY_QNAME = new QName(SCA11_TUSCANY_NS, "testPolicy"); + + private String testString; + + public String getTestString() { + return testString; + } + + public void setTestString(String testString) { + this.testString = testString; + } + + public QName getSchemaName() { + return TEST_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public String toString() { + return "TestPolicy [testString=" + + testString + + "]"; + } +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyBuilder.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyBuilder.java new file mode 100644 index 0000000000..a7cceec4de --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyBuilder.java @@ -0,0 +1,84 @@ +/* + * 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 testpolicy; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * + */ +public class TestPolicyBuilder implements PolicyBuilder { + + public boolean build(Endpoint endpoint, BuilderContext context) { + List polices = getPolicies(endpoint); + System.out.println(endpoint + ": " + polices); + return true; + } + + public boolean build(EndpointReference endpointReference, BuilderContext context) { + List polices = getPolicies(endpointReference); + System.out.println(endpointReference + ": " + polices); + return true; + } + + public boolean build(Component component, Implementation implementation, BuilderContext context) { + List polices = getPolicies(implementation); + System.out.println(implementation + ": " + polices); + return true; + } + + public QName getPolicyType() { + return TestPolicy.TEST_POLICY_QNAME; + } + + public List getSupportedBindings() { + return null; + } + + private List getPolicies(PolicySubject subject) { + List polices = new ArrayList(); + for (PolicySet ps : subject.getPolicySets()) { + for (PolicyExpression exp : ps.getPolicies()) { + if (getPolicyType().equals(exp.getName())) { + polices.add((TestPolicy)exp.getPolicy()); + } + } + } + return polices; + } + + public boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context) { + return true; + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyInterceptor.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyInterceptor.java new file mode 100644 index 0000000000..be0c0a9eb6 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyInterceptor.java @@ -0,0 +1,95 @@ +/* + * 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 testpolicy; + +import java.util.List; +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicySubject; + + +public class TestPolicyInterceptor implements PhasedInterceptor { + public static final String loggingPolicy = "JDKLoggingPolicy"; + public static final QName policySetQName = new QName(TestPolicy.SCA11_TUSCANY_NS, loggingPolicy); + private Logger logger = null; + + private Invoker next; + private Operation operation; + private List policies; + private PolicySubject subject; + private String context; + private String phase; + + public TestPolicyInterceptor(PolicySubject subject, + String context, + Operation operation, + List policies, + String phase) { + super(); + this.operation = operation; + this.policies = policies; + this.subject = subject; + this.phase = phase; + this.context = getContext(); + } + + private String getContext() { + if (subject instanceof Endpoint) { + Endpoint endpoint = (Endpoint)subject; + return endpoint.getURI(); + } else if (subject instanceof EndpointReference) { + EndpointReference endpointReference = (EndpointReference)subject; + return endpointReference.getURI(); + } else if (subject instanceof Component) { + Component component = (Component)subject; + return component.getURI(); + } + return null; + } + + public Message invoke(Message msg) { + System.out.println("In interceptor"); + return msg; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public String getPhase() { + return phase; + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProcessor.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProcessor.java new file mode 100644 index 0000000000..0916534248 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProcessor.java @@ -0,0 +1,99 @@ +/* + * 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 testpolicy; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.logging.Level; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev: 883438 $ $Date: 2009-11-23 18:07:34 +0000 (Mon, 23 Nov 2009) $ + */ +public class TestPolicyProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return TestPolicy.TEST_POLICY_QNAME; + } + + public TestPolicyProcessor(FactoryExtensionPoint modelFactories) { + } + + + public TestPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + TestPolicy policy = new TestPolicy(); + int event = reader.getEventType(); + QName name = null; + + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals("testString") ) { + String testString = reader.getAttributeValue(null, "testString"); + policy.setTestString(testString); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( TestPolicy.TEST_POLICY_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(TestPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { + // TODO + } + + public Class getModelType() { + return TestPolicy.class; + } + + public void resolve(TestPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderFactory.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderFactory.java new file mode 100644 index 0000000000..75cb298f2d --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderFactory.java @@ -0,0 +1,68 @@ +/* + * 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 testpolicy; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev: 792622 $ $Date: 2009-07-09 19:14:18 +0100 (Thu, 09 Jul 2009) $ + */ +public class TestPolicyProviderFactory implements PolicyProviderFactory { + private ExtensionPointRegistry registry; + + public TestPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return new TestPolicyProviderImplementation(component); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new TestPolicyProviderReference(endpointReference); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new TestPolicyProviderService(endpoint); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + return TestPolicy.class; + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderImplementation.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderImplementation.java new file mode 100644 index 0000000000..90cf5e6523 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderImplementation.java @@ -0,0 +1,48 @@ +/* + * 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 testpolicy; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev: 792641 $ $Date: 2009-07-09 20:13:08 +0100 (Thu, 09 Jul 2009) $ + */ +public class TestPolicyProviderImplementation extends BasePolicyProvider { + + public TestPolicyProviderImplementation(RuntimeComponent component) { + super(TestPolicy.class, component); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public PhasedInterceptor createInterceptor(Operation operation) { + List policies = findPolicies(); + return policies.isEmpty() ? null : new TestPolicyInterceptor(subject, getContext(), operation, + policies, Phase.IMPLEMENTATION_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderReference.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderReference.java new file mode 100644 index 0000000000..eb546c0057 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderReference.java @@ -0,0 +1,45 @@ +/* + * 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 testpolicy; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev: 792641 $ $Date: 2009-07-09 20:13:08 +0100 (Thu, 09 Jul 2009) $ + */ +public class TestPolicyProviderReference extends BasePolicyProvider { + + public TestPolicyProviderReference(EndpointReference endpointReference) { + super(TestPolicy.class, endpointReference); + } + + public PhasedInterceptor createInterceptor(Operation operation) { + List policies = findPolicies(); + return policies.isEmpty() ? null : new TestPolicyInterceptor(subject, getContext(), operation, + policies, Phase.REFERENCE_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderService.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderService.java new file mode 100644 index 0000000000..adb5664a24 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/java/testpolicy/TestPolicyProviderService.java @@ -0,0 +1,44 @@ +/* + * 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 testpolicy; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +/** + * @version $Rev: 792641 $ $Date: 2009-07-09 20:13:08 +0100 (Thu, 09 Jul 2009) $ + */ +public class TestPolicyProviderService extends BasePolicyProvider { + + public TestPolicyProviderService(Endpoint endpoint) { + super(TestPolicy.class, endpoint); + } + + public PhasedInterceptor createInterceptor(Operation operation) { + List policies = findPolicies(); + return policies.isEmpty() ? null : new TestPolicyInterceptor(subject, getContext(), operation, policies, Phase.SERVICE_POLICY); + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/sca-contribution.xml b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..350ad6be96 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder new file mode 100644 index 0000000000..0177494120 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.PolicyBuilder @@ -0,0 +1,17 @@ +# 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. +testpolicy.TestPolicyBuilder;qname=http://tuscany.apache.org/xmlns/sca/1.1#testPolicy diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..32608ac7ce --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# 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. + +# Implementation class for the artifact processor extension +testpolicy.TestPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#testPolicy,model=testpolicy.TestPolicy + diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions new file mode 100644 index 0000000000..f362b64a1f --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions @@ -0,0 +1,17 @@ +# 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. +definitions.xml diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..08ff6bc2c9 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -0,0 +1,20 @@ +# 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. + +# Implementation class for the policy extension +testpolicy.TestPolicyProviderFactory;model=testpolicy.TestPolicy + diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/definitions.xml b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/definitions.xml new file mode 100644 index 0000000000..3f7e24e075 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/definitions.xml @@ -0,0 +1,43 @@ + + + + + + a test intent + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.composite b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.composite new file mode 100644 index 0000000000..fa3d9ee701 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.wsdl b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.wsdl new file mode 100644 index 0000000000..15b89dbcea --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/main/resources/helloworld.wsdl @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java new file mode 100644 index 0000000000..c2b2e7efba --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/policy/interceptors/src/test/java/interceptors/HelloworldTestCase.java @@ -0,0 +1,51 @@ +/* + * 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 interceptors; + +import junit.framework.TestCase; + +import helloworld.HelloWorld; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.Ignore; + +public class HelloworldTestCase extends TestCase { + + private Node node; + private HelloWorld helloWorld; + + @Override + protected void setUp() throws Exception { + node = NodeFactory.newInstance().createNode("helloworld.composite", new Contribution("test", "target/classes")); + node.start(); + helloWorld = node.getService(HelloWorld.class, "HelloWorldClient/HelloWorld"); + } + + public void testCalculator() throws Exception { + assertEquals("Hello fred myname", helloWorld.getGreetings("fred")); + } + + @Override + protected void tearDown() throws Exception { + node.stop(); + } + +} -- cgit v1.2.3