You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pubscribe-dev@ws.apache.org by sc...@apache.org on 2005/05/25 17:56:37 UTC
svn commit: r178462 - in /incubator/hermes/trunk/src:
java/org/apache/ws/notification/topics/expression/impl/
test/org/apache/ws/notification/base/
test/org/apache/ws/notification/base/impl/
test/org/apache/ws/notification/base/v2004_06/
test/org/apache/ws/notification/base/v2004_06/porttype/
test/org/apache/ws/notification/base/v2004_06/porttype/impl/
Author: scamp
Date: Wed May 25 08:56:36 2005
New Revision: 178462
URL: http://svn.apache.org/viewcvs?rev=178462&view=rev
Log: (empty)
Added:
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitExampleHome.java
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResource.java
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResourceContext.java
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/impl/
incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/impl/NotificationProducerPortTypeImplTest.java
Modified:
incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/expression/impl/TopicExpressionEngineImpl.java
Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/expression/impl/TopicExpressionEngineImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/expression/impl/TopicExpressionEngineImpl.java?rev=178462&r1=178461&r2=178462&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/expression/impl/TopicExpressionEngineImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/expression/impl/TopicExpressionEngineImpl.java Wed May 25 08:56:36 2005
@@ -101,6 +101,8 @@
catch ( NamingException ne )
{
LOG.warn( "topicEngineInitError: " + ne );
+ registerEvaluator( new SimpleTopicExpressionEvaluator() );
+ registerEvaluator( new ConcreteTopicExpressionEvaluator() );
registerEvaluator( new FullTopicExpressionEvaluator() );
}
finally
Added: incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitExampleHome.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitExampleHome.java?rev=178462&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitExampleHome.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitExampleHome.java Wed May 25 08:56:36 2005
@@ -0,0 +1,90 @@
+package org.apache.ws.notification.base.impl;
+
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.ResourceContext;
+import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.ResourceException;
+import org.apache.ws.resource.ResourceUnknownException;
+import org.apache.ws.resource.ResourceKey;
+import org.apache.ws.resource.impl.AbstractResourceHome;
+import org.apache.ws.resource.impl.SimpleTypeResourceKey;
+import org.apache.ws.notification.base.WsnNamespaceVersionHolder;
+import org.apache.ws.notification.base.impl.UnitResource;
+import org.apache.ws.notification.base.v2004_06.impl.WsnNamespaceVersionHolderImpl;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author Sal Campana
+ */
+public class UnitExampleHome extends AbstractResourceHome
+{
+ public static final String SERVICE_NAME = "UnitHome";
+ public static final String TARGET_NAMESPACE = "http://unittest";
+ public static final QName SERVICE_QNAME = new QName(TARGET_NAMESPACE, SERVICE_NAME);
+ public static final String TARGET_NSPREFIX = "unit";
+ public static final QName PORT_TYPE = new QName(TARGET_NAMESPACE, "UnitTestExamples");
+ public static final String SERVICE_PORT_NAME = SERVICE_NAME;
+ public static final QName RESOURCE_KEY_NAME = new QName(TARGET_NAMESPACE, "ResourceIdentifier", TARGET_NSPREFIX);
+ private Resource m_resource;
+ public static final ResourceKey RESOURCE_KEY = new SimpleTypeResourceKey(RESOURCE_KEY_NAME, "unit_key");
+ public WsnNamespaceVersionHolder m_namespaceSet = new WsnNamespaceVersionHolderImpl();
+
+ public UnitExampleHome()
+ {
+ setResourceKeyName( SimpleTypeResourceKey.class.getName() );
+ setResourceClassName( UnitResource.class.getName() );
+ try
+ {
+ init();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public QName getServiceName()
+ {
+ return SERVICE_QNAME;
+ }
+
+ public QName getPortType()
+ {
+ return PORT_TYPE;
+ }
+
+ public String getServicePortName()
+ {
+ return SERVICE_PORT_NAME;
+ }
+
+ public QName getResourceKeyNameQName()
+ {
+ return RESOURCE_KEY_NAME;
+ }
+
+ public Resource getInstance(ResourceContext resourceContext) throws ResourceException, ResourceContextException, ResourceUnknownException
+ {
+ if(m_resource == null)
+ {
+ try
+ {
+ UnitResource myresource = new UnitResource(); //this will create the resource IF it is has default constructor
+ myresource.setID("123");
+ m_resource = myresource;
+ myresource.init();
+ //the next line will create an EPR
+ EndpointReference epr = getEndpointReference(resourceContext.getBaseURL() + "/" + getServiceName().getLocalPart(), RESOURCE_KEY, m_namespaceSet.getAddressingNamespace());
+ myresource.setEndpointReference(epr); //make sure to set the EPR on your new instance
+ add(RESOURCE_KEY, myresource);
+ }
+ catch (Exception e)
+ {
+ throw new ResourceException(e);
+ }
+ }
+ return m_resource;
+ }
+}
Added: incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResource.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResource.java?rev=178462&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResource.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResource.java Wed May 25 08:56:36 2005
@@ -0,0 +1,96 @@
+package org.apache.ws.notification.base.impl;
+
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.notification.base.NotificationProducerResource;
+import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
+import org.apache.ws.resource.PropertiesResource;
+import org.apache.ws.resource.lifetime.ResourceTerminationListener;
+import org.apache.ws.resource.properties.ResourcePropertySet;
+import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationProducerRPDocument;
+
+/**
+ * @author Sal Campana
+ */
+public class UnitResource implements PropertiesResource, NotificationProducerResource
+{
+ ResourcePropertySet m_resourcePropertySet;
+ private EndpointReference m_epr;
+ private Object m_id;
+ public static final String TOPIC_NAME = "test";
+ org.apache.ws.notification.topics.TopicSpaceSet m_topicSpaceSet = new org.apache.ws.notification.topics.impl.TopicSpaceSetImpl(true);
+
+ public UnitResource()
+ {
+
+ }
+
+ public ResourcePropertySet getResourcePropertySet()
+ {
+ return m_resourcePropertySet;
+ }
+
+ public void setResourcePropertySet(ResourcePropertySet resourcePropertySet)
+ {
+ m_resourcePropertySet = resourcePropertySet;
+ }
+
+ public void setID(Object o)
+ {
+ m_id = o;
+ }
+
+ public Object getID()
+ {
+ return m_id;
+ }
+
+ public void destroy()
+ {
+
+ }
+
+ public void init()
+ {
+ NotificationProducerRPDocument notificationProducerRPDocument = NotificationProducerRPDocument.Factory.newInstance();
+ NotificationProducerRPDocument.NotificationProducerRP notificationProducerRP = notificationProducerRPDocument.addNewNotificationProducerRP();
+ m_resourcePropertySet = new XmlBeansResourcePropertySet(notificationProducerRPDocument);
+
+ TopicSpaceImpl topicSpace = new TopicSpaceImpl(UnitExampleHome.TARGET_NAMESPACE);
+
+
+ try
+ {
+ topicSpace.addTopic(TOPIC_NAME);
+ getTopicSpaceSet().addTopicSpace(topicSpace);
+ org.apache.ws.notification.topics.util.TopicUtils.addResourcePropertyValueChangeTopics(getResourcePropertySet(), getTopicSpaceSet());
+ }
+ catch (Exception e)
+ {
+ throw new javax.xml.rpc.JAXRPCException("Unable to init the ResourceProperty Changed topics. Cause: " + e.getLocalizedMessage(), e);
+ }
+
+ org.apache.ws.notification.topics.util.TopicUtils.initNotificationProducerProperties(getTopicSpaceSet(), getResourcePropertySet());
+ }
+
+ public void addTerminationListener(ResourceTerminationListener resourceTerminationListener)
+ {
+
+ }
+
+ public EndpointReference getEndpointReference()
+ {
+ return m_epr;
+ }
+
+ public void setEndpointReference(EndpointReference epr)
+ {
+ m_epr = epr;
+ }
+
+ public org.apache.ws.notification.topics.TopicSpaceSet getTopicSpaceSet()
+ {
+ return m_topicSpaceSet;
+ }
+
+}
Added: incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResourceContext.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResourceContext.java?rev=178462&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResourceContext.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/base/impl/UnitResourceContext.java Wed May 25 08:56:36 2005
@@ -0,0 +1,164 @@
+package org.apache.ws.notification.base.impl;
+
+import org.apache.ws.resource.ResourceContext;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.ResourceException;
+import org.apache.ws.resource.ResourceHome;
+import org.apache.ws.resource.ResourceKey;
+import org.apache.ws.resource.InvalidResourceKeyException;
+import org.apache.ws.resource.impl.SimpleTypeResourceKey;
+import org.apache.ws.resource.faults.ResourceKeyHeaderNotFoundFaultException;
+import org.apache.ws.util.NameUtils;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import java.util.Iterator;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+
+/**
+ * @author Sal Campana
+ */
+public class UnitResourceContext extends ResourceContext
+{
+ ResourceHome m_home = new UnitExampleHome();
+ private Resource m_resource = null;
+ private SimpleTypeResourceKey m_key = null;
+ public static final String ID_KEY = "1212";
+ private String m_serviceName = UnitExampleHome.SERVICE_NAME;
+ private static final String TARGET_NSURI = UnitExampleHome.TARGET_NAMESPACE;
+ public static final String TARGET_NSPREFIX = UnitExampleHome.TARGET_NSPREFIX;
+
+
+ public synchronized ResourceHome getResourceHome() throws ResourceContextException
+ {
+ return m_home;
+ }
+
+ public ResourceKey getResourceKey( QName keyName, Class keyClass ) throws ResourceContextException, ResourceKeyHeaderNotFoundFaultException
+ {
+ return m_key;
+ }
+
+ public SOAPHeaderElement getResourceKeyHeader() throws ResourceContextException
+ {
+ return (SOAPHeaderElement) m_key.toSOAPElement();
+ }
+
+ public SOAPHeaderElement getResourceKeyHeader( QName keyName ) throws ResourceContextException
+ {
+ return (SOAPHeaderElement) m_key.toSOAPElement();
+ }
+
+ public SOAPMessage getSOAPMessage()
+ {
+ try
+ {
+ return MessageFactory.newInstance().createMessage();
+ }
+ catch ( SOAPException e )
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public ResourceKey getResourceKey() throws ResourceContextException
+ {
+ if ( m_key == null )
+ {
+ try
+ {
+ MessageFactory messageFactory = MessageFactory.newInstance();
+ SOAPMessage message = messageFactory.createMessage();
+ SOAPHeader soapHeader = message.getSOAPHeader();
+ SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement( NameUtils.toName( new QName( TARGET_NSURI, "ResourceIdentifier", TARGET_NSPREFIX ) ) );
+ soapHeaderElement.addTextNode( ID_KEY );
+ m_key = new SimpleTypeResourceKey( soapHeaderElement );
+ }
+ catch ( SOAPException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( InvalidResourceKeyException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ return m_key;
+ }
+
+ public String getServiceName()
+ {
+ return m_serviceName;
+ }
+
+ public URL getServiceURL()
+ {
+ try
+ {
+ return new URL( "http://localhost:8080/hermes/" + m_serviceName );
+ }
+ catch ( MalformedURLException murle )
+ {
+ murle.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the base URL from which service urls are based.
+ *
+ * @return The String representation of the base url
+ */
+ public String getBaseURL()
+ {
+ return null;
+ }
+
+ public boolean containsProperty( String name )
+ {
+ return false;
+ }
+
+ public void removeProperty( String name )
+ {
+
+ }
+
+ /**
+ * Returns the value of the WS-Addressing Action header
+ *
+ * @return WS-Addressing Action Header value
+ */
+ public String getAddressingAction()
+ {
+ return null;
+ }
+
+ public void setProperty( String name, Object value )
+ {
+
+ }
+
+ public Object getProperty( String name )
+ {
+ return null;
+ }
+
+ public Iterator getPropertyNames()
+ {
+ return null;
+ }
+
+ public Resource getResource() throws ResourceContextException, ResourceException
+ {
+ return m_resource;
+ }
+}
Added: incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/impl/NotificationProducerPortTypeImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/impl/NotificationProducerPortTypeImplTest.java?rev=178462&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/impl/NotificationProducerPortTypeImplTest.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/base/v2004_06/porttype/impl/NotificationProducerPortTypeImplTest.java Wed May 25 08:56:36 2005
@@ -0,0 +1,151 @@
+package org.apache.ws.notification.base.v2004_06.porttype.impl;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.notification.base.impl.UnitExampleHome;
+import org.apache.ws.notification.base.impl.UnitResource;
+import org.apache.ws.notification.base.impl.UnitResourceContext;
+import org.apache.ws.notification.base.v2004_06.BaseNotificationConstants;
+import org.apache.ws.notification.base.v2004_06.porttype.NotificationProducerPortType;
+import org.apache.ws.notification.topics.v2004_06.TopicsConstants;
+import org.apache.ws.resource.PropertiesResource;
+import org.apache.ws.resource.ResourceContext;
+import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.ResourceException;
+import org.apache.ws.resource.properties.ResourceProperty;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.ws.util.test.PortListen;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeResponseDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionDialectsDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+import org.xmlsoap.schemas.soap.envelope.Body;
+import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
+
+import javax.xml.namespace.QName;
+import java.util.Calendar;
+
+/**
+ * NotificationProducerPortTypeImpl Tester.
+ *
+ * @author Sal Campana
+ */
+public class NotificationProducerPortTypeImplTest extends TestCase
+{
+ ResourceContext m_resourceContext;
+ private NotificationProducerPortTypeImpl m_portTypeImpl;
+ protected static final int NOTIF_LISTENER_TIMEOUT = 20000;
+ protected static final int NOTIF_LISTENER_PORT = 9101;
+ private String m_consumerURL = "http://localhost:" + Integer.toString(NOTIF_LISTENER_PORT);
+ private QName m_topic = new QName(UnitExampleHome.TARGET_NAMESPACE, UnitResource.TOPIC_NAME, UnitExampleHome.TARGET_NSPREFIX);
+
+ public NotificationProducerPortTypeImplTest(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ m_resourceContext = new UnitResourceContext();
+ m_portTypeImpl = new NotificationProducerPortTypeImpl(m_resourceContext);
+
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testSubscribeWrapped() throws Exception
+ {
+ /* subscribe(true);
+ PortListen listener = new PortListen(NOTIF_LISTENER_PORT, NOTIF_LISTENER_TIMEOUT);
+ triggerChangeEvent();
+ assertIncomingMessage(listener, true);*/
+ }
+
+ public void testSubscribeUnwrapped() throws Exception
+ {
+ /*subscribe(false);
+ PortListen listener = new PortListen(NOTIF_LISTENER_PORT, NOTIF_LISTENER_TIMEOUT);
+ triggerChangeEvent();
+ assertIncomingMessage(listener, false);*/
+ }
+
+ private void triggerChangeEvent() throws ResourceContextException, ResourceException
+ {
+ PropertiesResource resource = (PropertiesResource) m_resourceContext.getResourceHome().find(UnitExampleHome.RESOURCE_KEY);
+ ResourceProperty resourceProperty = resource.getResourcePropertySet().get(NotificationProducerPortType.PROP_QNAME_TOPIC_EXPRESSION_DIALECTS);
+ TopicExpressionDialectsDocument topicExpressionDialectsDocument = TopicExpressionDialectsDocument.Factory.newInstance();
+ topicExpressionDialectsDocument.setTopicExpressionDialects("foo-dialect");
+ resourceProperty.add(topicExpressionDialectsDocument);
+ }
+
+ private void assertIncomingMessage(PortListen listener, boolean isWrapped) throws XmlException
+ {
+ String incomingMsg = listener.waitForIncomingMessage();
+ assertTrue(incomingMsg, incomingMsg.indexOf("ERROR") == -1);
+
+ //get envelope
+ XmlObject xmlObject = XmlObject.Factory.parse(incomingMsg);
+ assertTrue("The returned message was not a SOAP Envelope.", xmlObject instanceof EnvelopeDocument);
+ EnvelopeDocument envelope = (EnvelopeDocument) xmlObject;
+ Body body = envelope.getEnvelope().getBody();
+
+ XmlObject event = null;
+ if (isWrapped) //wrapped
+ {
+ //get notify
+ XmlObject bodyElems[] = XmlBeanUtils.getChildElements(body,
+ new QName(BaseNotificationConstants.NSURI_WSNT_SCHEMA, "Notify"));
+ assertEquals("The SOAP Body does not contain exactly one wsnt:Notify element.", 1, bodyElems.length);
+ XmlObject notifyDoc = bodyElems[0];
+ assertTrue("The SOAP Body does not contain a wrapped notification with a Notify element.",
+ notifyDoc instanceof NotifyDocument.Notify);
+ }
+ else //unwrapped
+ { //todo see what this should be
+ XmlObject bodyElems[] = XmlBeanUtils.getChildElements(body,
+ new QName(BaseNotificationConstants.NSURI_WSNT_SCHEMA, "Notify"));
+ }
+ }
+
+ private XmlBeansEndpointReference subscribe(boolean isWrapped)
+ {
+ SubscribeDocument requestDoc = SubscribeDocument.Factory.newInstance();
+ SubscribeDocument.Subscribe subscribe = requestDoc.addNewSubscribe();
+ subscribe.setUseNotify(true);
+ Calendar instance = Calendar.getInstance();
+ instance.setTimeInMillis(instance.getTimeInMillis() + 20000);
+ subscribe.setInitialTerminationTime(instance);
+ org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType consumerRef = subscribe.addNewConsumerReference();
+ org.xmlsoap.schemas.ws.x2003.x03.addressing.AttributedURI address = consumerRef.addNewAddress();
+ address.setStringValue(m_consumerURL);
+ TopicExpressionType topicExpr = subscribe.addNewTopicExpression();
+ topicExpr.setDialect(TopicsConstants.TOPIC_EXPR_DIALECT_SIMPLE);
+ XmlBeanUtils.setValueAsQName(topicExpr, m_topic);
+ XmlObject response = m_portTypeImpl.subscribe(requestDoc);
+ assertTrue(response instanceof SubscribeResponseDocument.SubscribeResponse);
+ SubscribeResponseDocument.SubscribeResponse subscribeResponse = (SubscribeResponseDocument.SubscribeResponse) response;
+ XmlBeansEndpointReference xmlBeansEndpointReference = new XmlBeansEndpointReference(subscribeResponse.getSubscriptionReference());
+ return xmlBeansEndpointReference;
+ }
+
+ public void testGetCurrentMessage() throws Exception
+ {
+ //TODO: Test goes here...
+ }
+
+
+ public static Test suite()
+ {
+ return new TestSuite(NotificationProducerPortTypeImplTest.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: hermes-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: hermes-dev-help@ws.apache.org