You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by an...@apache.org on 2007/02/21 13:02:08 UTC
svn commit: r509980 [2/3] - in /incubator/cxf/trunk:
api/src/main/java/org/apache/cxf/ws/policy/
api/src/main/java/org/apache/cxf/ws/policy/builder/
api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/
api/src/main/java/org/apache/cxf/ws/policy/bui...
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,100 @@
+/**
+ * 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.cxf.ws.policy.attachment.external;
+
+import java.util.Collection;
+
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.neethi.Policy;
+
+/**
+ *
+ */
+public class PolicyAttachment {
+
+ private Collection<DomainExpression> domainExpressions;
+ private Policy policy;
+
+ public Collection<DomainExpression> getDomainExpressions() {
+ return domainExpressions;
+ }
+
+ public void setDomainExpressions(Collection<DomainExpression> des) {
+ domainExpressions = des;
+ }
+
+ public Policy getPolicy() {
+ return policy;
+ }
+
+ public void setPolicy(Policy p) {
+ policy = p;
+ }
+
+ public boolean appliesTo(ServiceInfo si) {
+ for (DomainExpression de : domainExpressions) {
+ if (de.appliesTo(si)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean appliesTo(EndpointInfo ei) {
+ for (DomainExpression de : domainExpressions) {
+ if (de.appliesTo(ei)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean appliesTo(BindingOperationInfo boi) {
+ for (DomainExpression de : domainExpressions) {
+ if (de.appliesTo(boi)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean appliesTo(BindingMessageInfo bmi) {
+ for (DomainExpression de : domainExpressions) {
+ if (de.appliesTo(bmi)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean appliesTo(BindingFaultInfo bfi) {
+ for (DomainExpression de : domainExpressions) {
+ if (de.appliesTo(bfi)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachment.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Wsdl11XPointerDomainExpression.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Wsdl11XPointerDomainExpression.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Wsdl11XPointerDomainExpression.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Wsdl11XPointerDomainExpression.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,189 @@
+/**
+ * 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.cxf.ws.policy.attachment.external;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.XPathUtils;
+import org.apache.cxf.resource.ExtendedURIResolver;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.ws.policy.PolicyException;
+
+/**
+ *
+ */
+public class Wsdl11XPointerDomainExpression implements DomainExpression {
+
+ private static final String NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
+ private static final String SERVICE_ELEM_NAME = "service";
+ private static final String PORT_ELEM_NAME = "port";
+ private static final String PORTTYPE_ELEM_NAME = "portType";
+ private static final String BINDING_ELEM_NAME = "binding";
+ private static final String OPERATION_ELEM_NAME = "operation";
+ private static final String NAME_ATTR_NAME = "name";
+
+
+ private String baseURI;
+ private NodeList nodes;
+
+ Wsdl11XPointerDomainExpression(String u) {
+ baseURI = u;
+ }
+
+ public boolean appliesTo(BindingFaultInfo bfi) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean appliesTo(BindingMessageInfo bmi) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean appliesTo(BindingOperationInfo boi) {
+ if (baseURI.equals(boi.getBinding().getDescription().getBaseURI())) {
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+ if (Node.ELEMENT_NODE != n.getNodeType()) {
+ continue;
+ }
+ Element e = (Element)n;
+ if (matchesBindingOperation(e, boi)) {
+ Element p = (Element)e.getParentNode();
+ return matchesBinding(p, boi.getBinding());
+ } else if (matchesOperation(e, boi.getOperationInfo())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ public boolean appliesTo(EndpointInfo ei) {
+ if (baseURI.equals(ei.getDescription().getBaseURI())) {
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+ if (Node.ELEMENT_NODE != n.getNodeType()) {
+ continue;
+ }
+ Element e = (Element)n;
+ if (matchesPort(e, ei)) {
+ Element p = (Element)e.getParentNode();
+ return matchesService(p, ei.getService());
+ } else if (matchesPortType(e, ei.getInterface())) {
+ return true;
+ } else if (matchesBinding(e, ei.getBinding())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ public boolean appliesTo(ServiceInfo si) {
+ if (baseURI.equals(si.getDescription().getBaseURI())) {
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+ if (Node.ELEMENT_NODE != n.getNodeType()) {
+ continue;
+ }
+ Element e = (Element)n;
+ if (matchesService(e, si)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+
+ void evaluate(String uri) {
+ int pos = uri.indexOf('#');
+
+ String documentURI = uri.substring(0, pos);
+ String path = uri.substring(pos + 1);
+
+ InputSource is = new ExtendedURIResolver().resolve(documentURI, baseURI);
+ if (null == is) {
+ System.out.println("Failed to resolve: " + documentURI + " w.r.t baseURI: " + baseURI);
+ return;
+ }
+ Document doc = null;
+ try {
+ doc = DOMUtils.readXml(is.getByteStream());
+ } catch (Exception ex) {
+ throw new PolicyException(ex);
+ }
+
+ XPathUtils xu = new XPathUtils();
+ nodes = (NodeList)xu.getValue(path, doc, XPathConstants.NODESET);
+ }
+
+ boolean matchesService(Element e, ServiceInfo si) {
+ return NAMESPACE.equals(e.getNamespaceURI()) && SERVICE_ELEM_NAME.equals(e.getLocalName())
+ && si.getName().getLocalPart().equals(e.getAttribute(NAME_ATTR_NAME));
+ }
+
+ boolean matchesPortType(Element e, InterfaceInfo ii) {
+ return NAMESPACE.equals(e.getNamespaceURI()) && PORTTYPE_ELEM_NAME.equals(e.getLocalName())
+ && ii.getName().getLocalPart().equals(e.getAttribute(NAME_ATTR_NAME));
+ }
+
+ boolean matchesPort(Element e, EndpointInfo ei) {
+ return NAMESPACE.equals(e.getNamespaceURI()) && PORT_ELEM_NAME.equals(e.getLocalName())
+ && ei.getName().getLocalPart().equals(e.getAttribute(NAME_ATTR_NAME));
+ }
+
+ boolean matchesBinding(Element e, BindingInfo ei) {
+ return NAMESPACE.equals(e.getNamespaceURI()) && BINDING_ELEM_NAME.equals(e.getLocalName())
+ && ei.getName().getLocalPart().equals(e.getAttribute(NAME_ATTR_NAME));
+ }
+
+ boolean matchesBindingOperation(Element e, BindingOperationInfo boi) {
+ return NAMESPACE.equals(e.getNamespaceURI()) && OPERATION_ELEM_NAME.equals(e.getLocalName())
+ && boi.getName().getLocalPart().equals(e.getAttribute(NAME_ATTR_NAME));
+ }
+
+ boolean matchesOperation(Element e, OperationInfo boi) {
+ return NAMESPACE.equals(e.getNamespaceURI()) && OPERATION_ELEM_NAME.equals(e.getLocalName())
+ && boi.getName().getLocalPart().equals(e.getAttribute(NAME_ATTR_NAME));
+ }
+
+
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Wsdl11XPointerDomainExpression.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/Wsdl11XPointerDomainExpression.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalDocumentReferenceResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalDocumentReferenceResolver.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalDocumentReferenceResolver.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalDocumentReferenceResolver.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,57 @@
+/**
+ * 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.cxf.ws.policy.attachment.reference;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.neethi.Policy;
+
+/**
+ *
+ */
+public class LocalDocumentReferenceResolver implements ReferenceResolver {
+
+ private Document document;
+ private PolicyBuilder builder;
+
+ public LocalDocumentReferenceResolver(Document di, PolicyBuilder b) {
+ document = di;
+ builder = b;
+ }
+
+ public Policy resolveReference(String uri) {
+ NodeList nl = document.getElementsByTagNameNS(PolicyConstants.getNamespace(),
+ PolicyConstants.getPolicyElemName());
+
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element e = (Element)nl.item(i);
+ if (uri.equals(e.getAttributeNS(PolicyConstants.getWSUNamespace(),
+ PolicyConstants.getIdAttrName()))) {
+ return builder.getPolicy(e);
+ }
+ }
+ return null;
+ }
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalDocumentReferenceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalDocumentReferenceResolver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalServiceModelReferenceResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalServiceModelReferenceResolver.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalServiceModelReferenceResolver.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalServiceModelReferenceResolver.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,58 @@
+/**
+ * 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.cxf.ws.policy.attachment.reference;
+
+import java.util.List;
+
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+
+import org.apache.cxf.service.model.DescriptionInfo;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.neethi.Policy;
+
+/**
+ *
+ */
+public class LocalServiceModelReferenceResolver implements ReferenceResolver {
+
+ private DescriptionInfo descriptionInfo;
+ private PolicyBuilder builder;
+
+ public LocalServiceModelReferenceResolver(DescriptionInfo d, PolicyBuilder b) {
+ descriptionInfo = d;
+ builder = b;
+ }
+
+ public Policy resolveReference(String uri) {
+ List<UnknownExtensibilityElement> extensions =
+ descriptionInfo.getExtensors(UnknownExtensibilityElement.class);
+ for (UnknownExtensibilityElement e : extensions) {
+ if (PolicyConstants.getNamespace().equals(e.getElementType().getNamespaceURI())
+ && PolicyConstants.getPolicyElemName().equals(e.getElementType().getLocalPart())
+ && uri.equals(e.getElement().getAttributeNS(PolicyConstants.getWSUNamespace(),
+ PolicyConstants.getIdAttrName()))) {
+ return builder.getPolicy(e.getElement());
+ }
+ }
+ return null;
+ }
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalServiceModelReferenceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/LocalServiceModelReferenceResolver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolver.java (from r509965, incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/references/ReferenceResolver.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolver.java?view=diff&rev=509980&p1=incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/references/ReferenceResolver.java&r1=509965&p2=incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolver.java&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/references/ReferenceResolver.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolver.java Wed Feb 21 04:02:05 2007
@@ -17,11 +17,15 @@
* under the License.
*/
-package org.apache.cxf.ws.policy.attachment.references;
+package org.apache.cxf.ws.policy.attachment.reference;
+
+import org.apache.neethi.Policy;
/**
*
*/
-public class ReferenceResolver {
-
+public interface ReferenceResolver {
+
+ Policy resolveReference(String uri);
+
}
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/RemoteReferenceResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/RemoteReferenceResolver.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/RemoteReferenceResolver.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/RemoteReferenceResolver.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,76 @@
+/**
+ * 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.cxf.ws.policy.attachment.reference;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.resource.ExtendedURIResolver;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.cxf.ws.policy.PolicyException;
+import org.apache.neethi.Policy;
+
+/**
+ *
+ */
+public class RemoteReferenceResolver implements ReferenceResolver {
+
+ private String baseURI;
+ private PolicyBuilder builder;
+
+ public RemoteReferenceResolver(String uri, PolicyBuilder b) {
+ baseURI = uri;
+ builder = b;
+ }
+
+ public Policy resolveReference(String uri) {
+ int pos = uri.indexOf('#');
+ String documentURI = uri.substring(0, pos);
+
+ InputSource is = new ExtendedURIResolver().resolve(documentURI, baseURI);
+ if (null == is) {
+ return null;
+ }
+ Document doc = null;
+ try {
+ doc = DOMUtils.readXml(is.getByteStream());
+ } catch (Exception ex) {
+ throw new PolicyException(ex);
+ }
+
+ NodeList nl = doc.getElementsByTagNameNS(PolicyConstants.getNamespace(),
+ PolicyConstants.getPolicyElemName());
+ String id = uri.substring(pos + 1);
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element elem = (Element)nl.item(i);
+ if (id.equals(elem.getAttributeNS(PolicyConstants.getWSUNamespace(),
+ PolicyConstants.getIdAttrName()))) {
+ return builder.getPolicy(elem);
+ }
+ }
+
+ return null;
+ }
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/RemoteReferenceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/reference/RemoteReferenceResolver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java Wed Feb 21 04:02:05 2007
@@ -20,18 +20,14 @@
package org.apache.cxf.ws.policy.attachment.wsdl11;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
import javax.wsdl.Definition;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.UnknownExtensibilityElement;
import javax.xml.namespace.QName;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.Bus;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.service.model.AbstractDescriptionElement;
import org.apache.cxf.service.model.BindingFaultInfo;
@@ -43,36 +39,31 @@
import org.apache.cxf.service.model.FaultInfo;
import org.apache.cxf.service.model.MessageInfo;
import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.ws.policy.PolicyBuilder;
import org.apache.cxf.ws.policy.PolicyConstants;
-import org.apache.cxf.ws.policy.PolicyException;
import org.apache.cxf.ws.policy.PolicyProvider;
+import org.apache.cxf.ws.policy.attachment.AbstractPolicyProvider;
+import org.apache.cxf.ws.policy.attachment.reference.LocalServiceModelReferenceResolver;
+import org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver;
import org.apache.cxf.wsdl11.WSDLServiceBuilder;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyReference;
-import org.apache.neethi.PolicyRegistry;
/**
* PolicyAttachmentManager provides methods to retrieve element policies and
* calculate effective policies based on the policy subject's scope.
*
*/
-public class Wsdl11AttachmentPolicyProvider implements PolicyProvider {
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(Wsdl11AttachmentPolicyProvider.class);
-
- private PolicyBuilder builder;
- private PolicyRegistry registry;
- private Map<DescriptionInfo, Map<String, Policy>> resolved =
- new HashMap<DescriptionInfo, Map<String, Policy>>();
-
+public class Wsdl11AttachmentPolicyProvider extends AbstractPolicyProvider
+ implements PolicyProvider {
+
- public void setBuilder(PolicyBuilder b) {
- builder = b;
+ public Wsdl11AttachmentPolicyProvider() {
+ this(null);
}
- public void setRegistry(PolicyRegistry r) {
- registry = r;
- }
+ public Wsdl11AttachmentPolicyProvider(Bus bus) {
+ super(bus);
+ }
public Policy getEffectivePolicy(ServiceInfo si) {
return getElementPolicy(si);
@@ -172,17 +163,13 @@
for (UnknownExtensibilityElement e : extensions) {
Policy p = null;
- if (PolicyConstants.POLICY_ELEM_QNAME.equals(e.getElementType())) {
+ if (PolicyConstants.getPolicyElemQName().equals(e.getElementType())) {
p = builder.getPolicy(e.getElement());
- } else if (PolicyConstants.POLICYREF_ELEM_QNAME.equals(e.getElementType())) {
+ } else if (PolicyConstants.getPolicyReferenceElemQName().equals(e.getElementType())) {
PolicyReference ref = builder.getPolicyReference(e.getElement());
if (null != ref) {
p = resolveReference(ref, di);
- if (null == p) {
- throw new PolicyException(new Message("UNRESOLVED_POLICY_REEFERENCE_EXC",
- BUNDLE, ref.getURI()));
- }
}
}
if (null != p) {
@@ -193,63 +180,34 @@
return elementPolicy;
}
-
Policy resolveReference(PolicyReference ref, DescriptionInfo di) {
- String uri = ref.getURI();
+ Policy p = null;
if (isExternal(ref)) {
- return resolveExternal(ref);
- }
-
- // Resolve the reference now that we have access to the wsdl and
- // store the referenced policy in the registry using a *qualified* key
- // so that later on the policy reference can be normalised with the help
- // of the registry.
-
- Policy p = resolveLocal(uri.substring(1), di);
- if (null != p) {
- ref.setURI(di.getBaseURI() + uri);
- registry.register(ref.getURI(), p);
- }
-
- return p;
- }
-
- Policy resolveLocal(String uri, DescriptionInfo description) {
- Policy resolvedPolicy = null;
- Map<String, Policy> policyMap = resolved.get(description);
- if (null == policyMap) {
- policyMap = new HashMap<String, Policy>();
- resolved.put(description, policyMap);
+ p = resolveExternal(ref, di.getBaseURI());
} else {
- resolvedPolicy = policyMap.get(uri);
- if (null != resolvedPolicy) {
- return resolvedPolicy;
- }
+ p = resolveLocal(ref, di);
}
-
- List<UnknownExtensibilityElement> extensions =
- description.getExtensors(UnknownExtensibilityElement.class);
- for (UnknownExtensibilityElement e : extensions) {
- if (PolicyConstants.POLICY_ELEM_QNAME.equals(e.getElementType())) {
- Policy p = builder.getPolicy(e.getElement());
- policyMap.put(p.getId(), p);
- if (uri.equals(p.getId())) {
- resolvedPolicy = p;
- break;
- }
- }
- }
- return resolvedPolicy;
- }
-
- Policy resolveExternal(PolicyReference ref) {
- throw new PolicyException(new Message("REMOTE_POLICY_RESOLUTION_NOT_SUPPORTED_EXC", BUNDLE));
+ checkResolved(ref, p);
+ return p;
}
- private boolean isExternal(PolicyReference ref) {
- return !ref.getURI().startsWith("#");
+ Policy resolveLocal(PolicyReference ref, DescriptionInfo di) {
+ String uri = ref.getURI().substring(1);
+ String absoluteURI = di.getBaseURI() + uri;
+ Policy resolved = registry.lookup(absoluteURI);
+ if (null != resolved) {
+ return resolved;
+ }
+ ReferenceResolver resolver = new LocalServiceModelReferenceResolver(di, builder);
+ resolved = resolver.resolveReference(uri);
+ if (null != resolved) {
+ ref.setURI(absoluteURI);
+ registry.register(absoluteURI, resolved);
+ }
+ return resolved;
}
+
private Extensible getMessageTypeInfo(QName name, DescriptionInfo di) {
Definition def = (Definition)di.getProperty(WSDLServiceBuilder.WSDL_DEFINITION);
if (null == def) {
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/spring/InitializingPolicyEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/spring/InitializingPolicyEngine.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/spring/InitializingPolicyEngine.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/spring/InitializingPolicyEngine.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,49 @@
+/**
+ * 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.cxf.ws.policy.spring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.cxf.ws.policy.PolicyProvider;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+public class InitializingPolicyEngine extends PolicyEngine implements InitializingBean,
+ ApplicationContextAware {
+
+ private ApplicationContext context;
+
+ public void setApplicationContext(ApplicationContext c) throws BeansException {
+ context = c;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ String[] beanNames = context.getBeanNamesForType(PolicyProvider.class);
+ List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+ for (String bn : beanNames) {
+ providers.add((PolicyProvider)context.getBean(bn));
+ }
+ super.setPolicyProviders(providers);
+ }
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/spring/InitializingPolicyEngine.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/spring/InitializingPolicyEngine.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml Wed Feb 21 04:02:05 2007
@@ -44,8 +44,12 @@
<property name="assertionBuilderRegistry" ref="org.apache.cxf.ws.policy.AssertionBuilderRegistry"/>
</bean>
- <bean class="org.apache.cxf.ws.policy.PolicyEngine">
+ <bean class="org.apache.cxf.ws.policy.spring.InitializingPolicyEngine">
<property name="bus" ref="cxf"/>
+ </bean>
+
+ <bean class="org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider">
+ <constructor-arg ref="cxf"/>
</bean>
</beans>
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java Wed Feb 21 04:02:05 2007
@@ -25,11 +25,22 @@
import junit.framework.TestCase;
-import org.apache.cxf.ws.policy.builders.xml.XMLPrimitiveAssertionBuilder;
+import org.apache.cxf.ws.policy.builder.xml.XMLPrimitiveAssertionBuilder;
import org.apache.neethi.Policy;
import org.apache.neethi.util.PolicyComparator;
public class NormalizeTest extends TestCase {
+
+ private String originalNamespace;
+
+ public void setUp() {
+ originalNamespace = PolicyConstants.getNamespace();
+ PolicyConstants.setNamespace("http://schemas.xmlsoap.org/ws/2004/09/policy");
+ }
+
+ public void tearDown() {
+ PolicyConstants.setNamespace(originalNamespace);
+ }
public void testNormalise() throws Exception {
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyBuilderTest.java?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyBuilderTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyBuilderTest.java Wed Feb 21 04:02:05 2007
@@ -27,7 +27,7 @@
import junit.framework.TestCase;
import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.ws.policy.builders.xml.XMLPrimitiveAssertionBuilder;
+import org.apache.cxf.ws.policy.builder.xml.XMLPrimitiveAssertionBuilder;
import org.apache.neethi.Constants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyComponent;
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java Wed Feb 21 04:02:05 2007
@@ -58,9 +58,9 @@
public void testAccessors() {
engine = new PolicyEngine();
+ assertNotNull(engine.getRegistry());
assertNull(engine.getBus());
- assertNull(engine.getPolicyProviders());
- assertNull(engine.getRegistry());
+ assertNull(engine.getPolicyProviders());
assertTrue(!engine.getRegisterInterceptors());
Bus bus = control.createMock(Bus.class);
engine.setBus(bus);
@@ -73,19 +73,6 @@
assertSame(providers, engine.getPolicyProviders());
assertSame(reg, engine.getRegistry());
assertTrue(engine.getRegisterInterceptors());
- }
-
- public void testInit() {
- engine = new PolicyEngine();
- Bus bus = control.createMock(Bus.class);
- engine.setBus(bus);
- PolicyBuilder pb = control.createMock(PolicyBuilder.class);
- EasyMock.expect(bus.getExtension(PolicyBuilder.class)).andReturn(pb);
- control.replay();
- engine.init();
- assertEquals(1, engine.getPolicyProviders().size());
- assertNotNull(engine.getRegistry());
- control.verify();
}
public void testDontAddBusInterceptors() {
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyExtensionsTest.java Wed Feb 21 04:02:05 2007
@@ -32,6 +32,7 @@
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.interceptor.AbstractAttributedInterceptorProvider;
+import org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider;
import org.apache.neethi.Assertion;
/**
@@ -66,7 +67,13 @@
assertNotNull(engine);
assertNotNull(engine.getPolicyProviders());
assertNotNull(engine.getRegistry());
-
+
+ Collection<PolicyProvider> pps = engine.getPolicyProviders();
+ assertEquals(1, pps.size());
+ for (PolicyProvider pp : pps) {
+ assertTrue(pp instanceof Wsdl11AttachmentPolicyProvider);
+ }
+
PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
assertNotNull(builder);
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyTest.java?view=diff&rev=509980&r1=509979&r2=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyTest.java Wed Feb 21 04:02:05 2007
@@ -23,7 +23,7 @@
import junit.framework.TestCase;
-import org.apache.cxf.ws.policy.builders.primitive.PrimitiveAssertion;
+import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
import org.apache.neethi.All;
import org.apache.neethi.Assertion;
import org.apache.neethi.ExactlyOne;
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,82 @@
+/**
+ * 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.cxf.ws.policy.attachment.external;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.ws.policy.PolicyException;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ *
+ */
+public class DomainExpressionBuilderRegistryTest extends TestCase {
+
+ private IMocksControl control;
+
+ public void setUp() {
+ control = EasyMock.createNiceControl();
+ }
+
+ public void testNoBuilder() {
+ DomainExpressionBuilderRegistry reg = new DomainExpressionBuilderRegistry();
+ assertEquals(DomainExpressionBuilderRegistry.class, reg.getRegistrationType());
+
+ Element e = control.createMock(Element.class);
+ EasyMock.expect(e.getNamespaceURI()).andReturn("http://a.b.c");
+ EasyMock.expect(e.getLocalName()).andReturn("x");
+
+ control.replay();
+ try {
+ reg.build(e);
+ fail("Expected PolicyException not thrown.");
+ } catch (PolicyException ex) {
+ // expected
+ }
+ control.verify();
+
+ }
+
+ public void testBuild() {
+ DomainExpressionBuilder builder = control.createMock(DomainExpressionBuilder.class);
+ Map<QName, DomainExpressionBuilder> builders = new HashMap<QName, DomainExpressionBuilder>();
+ QName qn = new QName("http://a.b.c", "x");
+ builders.put(qn, builder);
+ DomainExpressionBuilderRegistry reg = new DomainExpressionBuilderRegistry(builders);
+
+ Element e = control.createMock(Element.class);
+ EasyMock.expect(e.getNamespaceURI()).andReturn("http://a.b.c");
+ EasyMock.expect(e.getLocalName()).andReturn("x");
+ DomainExpression de = control.createMock(DomainExpression.class);
+ EasyMock.expect(builder.build(e)).andReturn(de);
+
+ control.replay();
+ assertSame(de, reg.build(e));
+ control.verify();
+ }
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,81 @@
+/**
+ * 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.cxf.ws.policy.attachment.external;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ *
+ */
+public class EndpointReferenceDomainExpressionTest extends TestCase {
+
+ private IMocksControl control;
+
+ public void setUp() {
+ control = EasyMock.createNiceControl();
+ }
+
+ public void testEndpointReferenceDomainExpression() {
+ EndpointReferenceType epr = control.createMock(EndpointReferenceType.class);
+
+ EndpointReferenceDomainExpression eprde = new EndpointReferenceDomainExpression();
+ assertNull(eprde.getEndpointReference());
+ eprde.setEndpointReference(epr);
+ assertSame(epr, eprde.getEndpointReference());
+
+ ServiceInfo si = control.createMock(ServiceInfo.class);
+ BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+ BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+ BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+
+ assertTrue(!eprde.appliesTo(si));
+ assertTrue(!eprde.appliesTo(boi));
+ assertTrue(!eprde.appliesTo(bmi));
+ assertTrue(!eprde.appliesTo(bfi));
+
+ EndpointInfo ei = control.createMock(EndpointInfo.class);
+ EasyMock.expect(ei.getAddress()).andReturn("http://localhost:8080/GreeterPort");
+ AttributedURIType auri = control.createMock(AttributedURIType.class);
+ EasyMock.expect(epr.getAddress()).andReturn(auri);
+ EasyMock.expect(auri.getValue()).andReturn("http://localhost:8080/Greeter");
+ control.replay();
+ assertTrue(!eprde.appliesTo(ei));
+ control.verify();
+
+ control.reset();
+ EasyMock.expect(ei.getAddress()).andReturn("http://localhost:8080/GreeterPort");
+ EasyMock.expect(epr.getAddress()).andReturn(auri);
+ EasyMock.expect(auri.getValue()).andReturn("http://localhost:8080/GreeterPort");
+ control.replay();
+ assertTrue(eprde.appliesTo(ei));
+ control.verify();
+ }
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,249 @@
+/**
+ * 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.cxf.ws.policy.attachment.external;
+
+import java.io.FileNotFoundException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.policy.PolicyException;
+import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ *
+ */
+public class ExternalAttachmentProviderTest extends TestCase {
+
+ private static final QName TEST_ASSERTION_TYPE = new QName("http://a.b.c", "x");
+
+ private ExternalAttachmentProvider eap;
+
+ private IMocksControl control;
+ private Policy policy;
+ private Assertion assertion;
+ private PolicyAttachment attachment;
+ private Collection<PolicyAttachment> attachments = new ArrayList<PolicyAttachment>();
+
+
+ public void setUp() {
+ eap = new ExternalAttachmentProvider();
+ control = EasyMock.createNiceControl();
+ }
+
+ public void testBasic() {
+ assertNull(eap.getURI());
+ eap.setURI("abc.xml");
+ assertEquals("abc.xml", eap.getURI());
+
+ }
+
+ public void testGetEffectiveFaultPolicy() {
+ BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+ setUpAttachment(bfi, false);
+ control.replay();
+ assertTrue(eap.getEffectivePolicy(bfi).isEmpty());
+ control.verify();
+
+ control.reset();
+ setUpAttachment(bfi, true);
+ control.replay();
+ assertSame(assertion, eap.getEffectivePolicy(bfi).getAssertions().get(0));
+ control.verify();
+ }
+
+ public void testGetEffectiveMessagePolicy() {
+ BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+ setUpAttachment(bmi, false);
+ control.replay();
+ assertTrue(eap.getEffectivePolicy(bmi).isEmpty());
+ control.verify();
+
+ control.reset();
+ setUpAttachment(bmi, true);
+ control.replay();
+ assertSame(assertion, eap.getEffectivePolicy(bmi).getAssertions().get(0));
+ control.verify();
+ }
+
+ public void testGetEffectiveOperationPolicy() {
+ BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+ setUpAttachment(boi, false);
+ control.replay();
+ assertTrue(eap.getEffectivePolicy(boi).isEmpty());
+ control.verify();
+
+ control.reset();
+ setUpAttachment(boi, true);
+ control.replay();
+ assertSame(assertion, eap.getEffectivePolicy(boi).getAssertions().get(0));
+ control.verify();
+ }
+
+ public void testGetEffectiveEndpointPolicy() {
+ EndpointInfo ei = control.createMock(EndpointInfo.class);
+ setUpAttachment(ei, false);
+ control.replay();
+ assertTrue(eap.getEffectivePolicy(ei).isEmpty());
+ control.verify();
+
+ control.reset();
+ setUpAttachment(ei, true);
+ control.replay();
+ assertSame(assertion, eap.getEffectivePolicy(ei).getAssertions().get(0));
+ control.verify();
+ }
+
+ public void testGetEffectiveServicePolicy() {
+ ServiceInfo si = control.createMock(ServiceInfo.class);
+ setUpAttachment(si, false);
+ control.replay();
+ assertTrue(eap.getEffectivePolicy(si).isEmpty());
+ control.verify();
+
+ control.reset();
+ setUpAttachment(si, true);
+ control.replay();
+ assertSame(assertion, eap.getEffectivePolicy(si).getAssertions().get(0));
+ control.verify();
+ }
+
+ public void testReadDocumentNotExisting() {
+ URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments1.xml");
+ String uri = url.toExternalForm();
+ uri = uri.replaceAll("attachments1.xml", "attachments0.xml");
+ eap.setURI(uri);
+ try {
+ eap.readDocument();
+ fail("Expected PolicyException not thrown.");
+ } catch (PolicyException ex) {
+ assertTrue(ex.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testReadDocumentWithoutAttachmentElements() {
+ URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments1.xml");
+ String uri = url.toExternalForm();
+ eap.setURI(uri);
+ eap.readDocument();
+ assertTrue(eap.getAttachments().isEmpty());
+ }
+
+ public void testReadDocumentAttachmentElementWithoutAppliesTo() {
+ URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments2.xml");
+ String uri = url.toExternalForm();
+ eap.setURI(uri);
+ eap.readDocument();
+ assertTrue(eap.getAttachments().isEmpty());
+ }
+
+ public void testReadDocumentUnknownDomainExpression() {
+ Bus bus = control.createMock(Bus.class);
+ eap = new ExternalAttachmentProvider(bus);
+ DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class);
+ EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr);
+ EasyMock.expect(debr.build(EasyMock.isA(Element.class)))
+ .andThrow(new PolicyException(new Exception()));
+ URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments3.xml");
+ String uri = url.toExternalForm();
+ eap.setURI(uri);
+
+ control.replay();
+ try {
+ eap.readDocument();
+ fail("Expected PolicyException not thrown.");
+ } catch (PolicyException ex) {
+ // expected
+ }
+ control.verify();
+ }
+
+ public void testReadDocumentEPRDomainExpression() {
+ Bus bus = control.createMock(Bus.class);
+ eap = new ExternalAttachmentProvider(bus);
+ DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class);
+ EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr);
+ DomainExpression de = control.createMock(DomainExpression.class);
+ EasyMock.expect(debr.build(EasyMock.isA(Element.class))).andReturn(de);
+ PolicyBuilder pb = control.createMock(PolicyBuilder.class);
+ eap.setBuilder(pb);
+ Policy p = control.createMock(Policy.class);
+ EasyMock.expect(pb.getPolicy(EasyMock.isA(Element.class))).andReturn(p);
+
+ URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments4.xml");
+ String uri = url.toExternalForm();
+ eap.setURI(uri);
+
+ control.replay();
+ eap.readDocument();
+ assertEquals(1, eap.getAttachments().size());
+ PolicyAttachment pa = eap.getAttachments().iterator().next();
+ assertSame(p, pa.getPolicy());
+ assertEquals(1, pa.getDomainExpressions().size());
+ assertSame(de, pa.getDomainExpressions().iterator().next());
+ control.verify();
+ }
+
+ void setUpAttachment(Object subject, boolean applies) {
+ attachments.clear();
+ attachment = control.createMock(PolicyAttachment.class);
+ attachments.add(attachment);
+ policy = new Policy();
+ assertion = new PrimitiveAssertion(TEST_ASSERTION_TYPE);
+ policy.addAssertion(assertion);
+ eap.setAttachments(attachments);
+ if (subject instanceof ServiceInfo) {
+ EasyMock.expect(attachment.appliesTo((ServiceInfo)subject)).andReturn(applies);
+ } else if (subject instanceof EndpointInfo) {
+ EasyMock.expect(attachment.appliesTo((EndpointInfo)subject)).andReturn(applies);
+ } else if (subject instanceof BindingOperationInfo) {
+ EasyMock.expect(attachment.appliesTo((BindingOperationInfo)subject)).andReturn(applies);
+ } else if (subject instanceof BindingMessageInfo) {
+ EasyMock.expect(attachment.appliesTo((BindingMessageInfo)subject)).andReturn(applies);
+ } else if (subject instanceof BindingFaultInfo) {
+ EasyMock.expect(attachment.appliesTo((BindingFaultInfo)subject)).andReturn(applies);
+ } else {
+ System.out.println("subject class: " + subject.getClass());
+ }
+ if (applies) {
+ EasyMock.expect(attachment.getPolicy()).andReturn(policy);
+ }
+ }
+
+
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,143 @@
+/**
+ * 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.cxf.ws.policy.attachment.external;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.neethi.Policy;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ *
+ */
+public class PolicyAttachmentTest extends TestCase {
+
+ private IMocksControl control;
+
+ public void setUp() {
+ control = EasyMock.createNiceControl();
+ }
+
+ public void testBasic() {
+ PolicyAttachment pa = new PolicyAttachment();
+ assertNull(pa.getDomainExpressions());
+ assertNull(pa.getPolicy());
+
+ Policy p = control.createMock(Policy.class);
+ Collection<DomainExpression> des = CastUtils.cast(Collections.emptyList(), DomainExpression.class);
+
+ pa.setPolicy(p);
+ pa.setDomainExpressions(des);
+ assertSame(p, pa.getPolicy());
+ assertSame(des, pa.getDomainExpressions());
+ }
+
+ public void testAppliesToService() {
+ ServiceInfo si1 = control.createMock(ServiceInfo.class);
+ ServiceInfo si2 = control.createMock(ServiceInfo.class);
+ DomainExpression de = control.createMock(DomainExpression.class);
+ Collection<DomainExpression> des = Collections.singletonList(de);
+ PolicyAttachment pa = new PolicyAttachment();
+ pa.setDomainExpressions(des);
+
+ EasyMock.expect(de.appliesTo(si1)).andReturn(false);
+ EasyMock.expect(de.appliesTo(si2)).andReturn(true);
+ control.replay();
+ assertTrue(!pa.appliesTo(si1));
+ assertTrue(pa.appliesTo(si2));
+ control.verify();
+ }
+
+ public void testAppliesToEndpoint() {
+ EndpointInfo ei1 = control.createMock(EndpointInfo.class);
+ EndpointInfo ei2 = control.createMock(EndpointInfo.class);
+ DomainExpression de = control.createMock(DomainExpression.class);
+ Collection<DomainExpression> des = Collections.singletonList(de);
+ PolicyAttachment pa = new PolicyAttachment();
+ pa.setDomainExpressions(des);
+
+ EasyMock.expect(de.appliesTo(ei1)).andReturn(false);
+ EasyMock.expect(de.appliesTo(ei2)).andReturn(true);
+ control.replay();
+ assertTrue(!pa.appliesTo(ei1));
+ assertTrue(pa.appliesTo(ei2));
+ control.verify();
+ }
+
+ public void testAppliesToOperation() {
+ BindingOperationInfo boi1 = control.createMock(BindingOperationInfo.class);
+ BindingOperationInfo boi2 = control.createMock(BindingOperationInfo.class);
+ DomainExpression de = control.createMock(DomainExpression.class);
+ Collection<DomainExpression> des = Collections.singletonList(de);
+ PolicyAttachment pa = new PolicyAttachment();
+ pa.setDomainExpressions(des);
+
+ EasyMock.expect(de.appliesTo(boi1)).andReturn(false);
+ EasyMock.expect(de.appliesTo(boi2)).andReturn(true);
+ control.replay();
+ assertTrue(!pa.appliesTo(boi1));
+ assertTrue(pa.appliesTo(boi2));
+ control.verify();
+ }
+
+ public void testAppliesToMessage() {
+ BindingMessageInfo bmi1 = control.createMock(BindingMessageInfo.class);
+ BindingMessageInfo bmi2 = control.createMock(BindingMessageInfo.class);
+ DomainExpression de = control.createMock(DomainExpression.class);
+ Collection<DomainExpression> des = Collections.singletonList(de);
+ PolicyAttachment pa = new PolicyAttachment();
+ pa.setDomainExpressions(des);
+
+ EasyMock.expect(de.appliesTo(bmi1)).andReturn(false);
+ EasyMock.expect(de.appliesTo(bmi2)).andReturn(true);
+ control.replay();
+ assertTrue(!pa.appliesTo(bmi1));
+ assertTrue(pa.appliesTo(bmi2));
+ control.verify();
+ }
+
+ public void testAppliesToFault() {
+ BindingFaultInfo bfi1 = control.createMock(BindingFaultInfo.class);
+ BindingFaultInfo bfi2 = control.createMock(BindingFaultInfo.class);
+ DomainExpression de = control.createMock(DomainExpression.class);
+ Collection<DomainExpression> des = Collections.singletonList(de);
+ PolicyAttachment pa = new PolicyAttachment();
+ pa.setDomainExpressions(des);
+
+ EasyMock.expect(de.appliesTo(bfi1)).andReturn(false);
+ EasyMock.expect(de.appliesTo(bfi2)).andReturn(true);
+ control.replay();
+ assertTrue(!pa.appliesTo(bfi1));
+ assertTrue(pa.appliesTo(bfi2));
+ control.verify();
+ }
+
+
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml Wed Feb 21 04:02:05 2007
@@ -0,0 +1,20 @@
+<?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.
+-->
+<attachments/>
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments1.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml Wed Feb 21 04:02:05 2007
@@ -0,0 +1,30 @@
+<?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.
+-->
+<attachments xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:test="http://x.y.z/Assertions">
+ <wsp:PolicyAttachment>
+ <wsp:AppliesTo>
+ </wsp:AppliesTo>
+ <!--
+ <wsp:Policy>
+ <test:A>A</test:A>
+ </wsp:Policy>
+ -->
+ </wsp:PolicyAttachment>
+</attachments>
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments2.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml Wed Feb 21 04:02:05 2007
@@ -0,0 +1,31 @@
+<?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.
+-->
+<attachments xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:test="http://x.y.z/Assertions">
+ <wsp:PolicyAttachment>
+ <wsp:AppliesTo>
+ <test:T>Target</test:T>
+ </wsp:AppliesTo>
+ <!--
+ <wsp:Policy>
+ <test:A>A</test:A>
+ </wsp:Policy>
+ -->
+ </wsp:PolicyAttachment>
+</attachments>
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments3.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml Wed Feb 21 04:02:05 2007
@@ -0,0 +1,31 @@
+<?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.
+-->
+<attachments xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:test="http://x.y.z/Assertions">
+ <wsp:PolicyAttachment>
+ <wsp:AppliesTo>
+ <wsa:EndpointReferenceType xmlns:wsa="http://www.w3.org/2005/08/addressing">
+ <wsa:Address>http://x.y.z/GreeterPort</wsa:Address>
+ </wsa:EndpointReferenceType>
+ </wsp:AppliesTo>
+ <wsp:Policy>
+ <test:A>A</test:A>
+ </wsp:Policy>
+ </wsp:PolicyAttachment>
+</attachments>
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/resources/attachments4.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java Wed Feb 21 04:02:05 2007
@@ -0,0 +1,130 @@
+/**
+ * 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.cxf.ws.policy.attachment.reference;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.service.model.DescriptionInfo;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.neethi.Policy;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ *
+ */
+public class ReferenceResolverTest extends TestCase {
+
+ private IMocksControl control;
+
+ public void setUp() {
+ control = EasyMock.createNiceControl();
+ }
+
+ public void testLocalServiceModelReferenceResolver() {
+ DescriptionInfo di = control.createMock(DescriptionInfo.class);
+ PolicyBuilder builder = control.createMock(PolicyBuilder.class);
+ LocalServiceModelReferenceResolver resolver = new LocalServiceModelReferenceResolver(di, builder);
+
+ List<UnknownExtensibilityElement> extensions = new ArrayList<UnknownExtensibilityElement>();
+ EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions);
+
+ control.replay();
+ assertNull(resolver.resolveReference("A"));
+ control.verify();
+
+ control.reset();
+ UnknownExtensibilityElement extension = control.createMock(UnknownExtensibilityElement.class);
+ extensions.add(extension);
+ EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions);
+ Element e = control.createMock(Element.class);
+ EasyMock.expect(extension.getElement()).andReturn(e).times(2);
+ QName qn = new QName(PolicyConstants.getNamespace(), PolicyConstants.getPolicyElemName());
+ EasyMock.expect(extension.getElementType()).andReturn(qn).times(2);
+ EasyMock.expect(e.getAttributeNS(PolicyConstants.getWSUNamespace(), PolicyConstants.getIdAttrName()))
+ .andReturn("A");
+ Policy p = control.createMock(Policy.class);
+ EasyMock.expect(builder.getPolicy(e)).andReturn(p);
+
+ control.replay();
+ assertSame(p, resolver.resolveReference("A"));
+ control.verify();
+
+ }
+
+ public void testLocalDocumentReferenceResolver() {
+ Document doc = control.createMock(Document.class);
+ PolicyBuilder builder = control.createMock(PolicyBuilder.class);
+ LocalDocumentReferenceResolver resolver = new LocalDocumentReferenceResolver(doc, builder);
+
+ NodeList nl = control.createMock(NodeList.class);
+ EasyMock.expect(doc.getElementsByTagNameNS(PolicyConstants.getNamespace(),
+ PolicyConstants.getPolicyElemName())).andReturn(nl);
+ EasyMock.expect(nl.getLength()).andReturn(0);
+
+ control.replay();
+ assertNull(resolver.resolveReference("A"));
+ control.verify();
+
+ control.reset();
+ EasyMock.expect(doc.getElementsByTagNameNS(PolicyConstants.getNamespace(),
+ PolicyConstants.getPolicyElemName())).andReturn(nl);
+ EasyMock.expect(nl.getLength()).andReturn(1);
+ Element e = control.createMock(Element.class);
+ EasyMock.expect(nl.item(0)).andReturn(e);
+ EasyMock.expect(e.getAttributeNS(PolicyConstants.getWSUNamespace(), PolicyConstants.getIdAttrName()))
+ .andReturn("A");
+ Policy p = control.createMock(Policy.class);
+ EasyMock.expect(builder.getPolicy(e)).andReturn(p);
+
+ control.replay();
+ assertSame(p, resolver.resolveReference("A"));
+ control.verify();
+ }
+
+ public void testRemoteReferenceResolver() {
+
+ URL url = ReferenceResolverTest.class.getResource("referring.wsdl");
+ String baseURI = url.toString();
+ PolicyBuilder builder = control.createMock(PolicyBuilder.class);
+ RemoteReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder);
+
+ assertNull(resolver.resolveReference("referred.wsdl#PolicyB"));
+
+ Policy p = control.createMock(Policy.class);
+ EasyMock.expect(builder.getPolicy(EasyMock.isA(Element.class))).andReturn(p);
+
+ control.replay();
+ assertSame(p, resolver.resolveReference("referred.wsdl#PolicyA"));
+ control.verify();
+ }
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl?view=auto&rev=509980
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl Wed Feb 21 04:02:05 2007
@@ -0,0 +1,41 @@
+<?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.
+-->
+
+<definitions name="Calculator"
+ targetNamespace="http://apache.org/cxf/calculator"
+ xmlns:tns="http://apache.org/cxf/calculator"
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:x1="http://apache.org/cxf/calculator/types"
+ xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
+ xmlns:ta="http://cxf.apache.org/test/assertions"
+ xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
+ xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" >
+
+ <wsp:Policy wsu:Id="PolicyA">
+ <ta:A>A</ta:A>
+ <ta:B>B></ta:B>
+ </wsp:Policy>
+
+ <wsp:Policy wsu:Id="PolicyC">
+ <ta:C>C</ta:C>
+ </wsp:Policy>
+
+</definitions>
\ No newline at end of file
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referred.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referring.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referring.wsdl?view=auto&rev=509980
==============================================================================
(empty)
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referring.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referring.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/referring.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml