| Commit in servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification on MAIN | |||
| impl/ActiveMQNotificationBrokerTest.java | +140 | added 1.1 | |
| /ActiveSOAPNotificationBrokerTest.java | +59 | added 1.1 | |
| /StubNotificationConsumer.java | +66 | added 1.1 | |
| /TestSupport.java | +102 | added 1.1 | |
| /TopicExpressionConverterTest.java | +22 | added 1.1 | |
| SubscribeParseTest.java | +87 | added 1.1 | |
| +476 | |||
migrated the XMLBeans code into a sub module
servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification/impl
ActiveMQNotificationBrokerTest.java added at 1.1
diff -N ActiveMQNotificationBrokerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ActiveMQNotificationBrokerTest.java 23 Aug 2005 09:04:32 -0000 1.1 @@ -0,0 +1,140 @@
+/**
+ *
+ * Copyright 2004 Protique Ltd
+ *
+ * Licensed 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.servicemix.ws.notification.impl;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.xml.namespace.QName;
+
+import org.activemq.ActiveMQConnection;
+import org.activemq.message.ActiveMQTopic;
+import org.servicemix.ws.xmlbeans.addressing.v2003_03.EndpointReferenceType;
+import org.servicemix.ws.xmlbeans.notification.base.NotificationMessageHolderType;
+import org.servicemix.ws.xmlbeans.notification.base.NotifyDocument;
+import org.servicemix.ws.xmlbeans.notification.base.PauseSubscriptionDocument;
+import org.servicemix.ws.xmlbeans.notification.base.ResumeSubscriptionDocument;
+import org.servicemix.ws.xmlbeans.notification.base.NotifyDocument.Notify;
+import org.servicemix.ws.xmlbeans.resource.properties.GetResourcePropertyDocument;
+import org.servicemix.ws.xmlbeans.resource.properties.GetResourcePropertyResponseDocument;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.servicemix.ws.notification.impl.ActiveMQNotificationBroker;
+import org.servicemix.ws.notification.impl.TopicExpressionConverter;
+
+import EDU.oswego.cs.dl.util.concurrent.Slot;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ActiveMQNotificationBrokerTest extends TestSupport {
+
+ public void testGetRequiresRegistrationProperty() throws Exception {
+ ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker();
+
+ GetResourcePropertyDocument request = GetResourcePropertyDocument.Factory.newInstance();
+ QName property = new QName("http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BrokeredNotification-1.2-draft-01.xsd", "RequiresRegistration");
+ request.setGetResourceProperty( property );
+ System.out.println(request);
+ GetResourcePropertyResponseDocument response = broker.getResourceProperty(null, request);
+ System.out.println(response);
+ assertNotNull(response);
+ XmlCursor cursor = response.newCursor();
+ cursor.toChild(property);
+ cursor.toFirstContentToken();
+ assertEquals("false", cursor.getTextValue());
+ }
+
+ public void XtestSendNotify() throws Exception {
+
+ ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker();
+ ActiveMQConnection connection = broker.getConnection();
+ Session session = connection.createSession(false, 0);
+ ActiveMQTopic topic = new ActiveMQTopic("Test");
+ MessageConsumer consumer = session.createConsumer(topic);
+
+ NotifyDocument request = NotifyDocument.Factory.newInstance();
+ Notify notify = request.addNewNotify();
+ NotificationMessageHolderType messageHolder = notify.addNewNotificationMessage();
+ messageHolder.setTopic( TopicExpressionConverter.toTopicExpression(topic) );
+ XmlObject o = createMessage();
+ messageHolder.setMessage(o);
+
+ System.out.println(request);
+ broker.notify(request);
+
+ Message message = consumer.receive(3000);
+ assertNotNull(message);
+ }
+
+ public void testSubscribe() throws JMSException, InterruptedException {
+
+ final Slot result = new Slot();
+ ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker() {
+ protected org.servicemix.ws.notification.NotificationConsumer createNotificationConsumer(EndpointReferenceType consumerReference) {
+ return new StubNotificationConsumer(result);
+ }
+ };
+
+ addSubscription(broker);
+ sendNotification(broker);
+
+ NotifyDocument subNotifyDoc = (NotifyDocument) result.poll(2000);
+ System.out.println("Got Notify: "+subNotifyDoc);
+
+ assertValidMessage(subNotifyDoc);
+ }
+
+
+ public void testSubscriptionPauseResume() throws JMSException, InterruptedException {
+
+ final Slot result = new Slot();
+ ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker() {
+ protected org.servicemix.ws.notification.NotificationConsumer createNotificationConsumer(EndpointReferenceType consumerReference) {
+ return new StubNotificationConsumer(result);
+ }
+ };
+
+ EndpointReferenceType subRef = addSubscription(broker);
+
+ // The sub should be running and we should be getting notifed now.
+ sendNotification(broker);
+ NotifyDocument subNotifyDoc = (NotifyDocument) result.poll(2000);
+ assertNotNull(subNotifyDoc);
+
+ // Pause the subscription.
+ PauseSubscriptionDocument pauseRequest = PauseSubscriptionDocument.Factory.newInstance();
+ pauseRequest.addNewPauseSubscription();
+ broker.getSubscriptionManager().pauseSubcription(pauseRequest, subRef);
+
+ // The sub should be stopped and we should not be getting notifed now.
+ sendNotification(broker);
+ subNotifyDoc = (NotifyDocument) result.poll(2000);
+ assertNull(subNotifyDoc);
+
+ // Resume the subscription.
+ ResumeSubscriptionDocument resumeRequest = ResumeSubscriptionDocument.Factory.newInstance();
+ resumeRequest.addNewResumeSubscription();
+ broker.getSubscriptionManager().resumeSubscription(resumeRequest, subRef);
+
+ // We should now get the message that was previously sent since the sub is now running.
+ subNotifyDoc = (NotifyDocument) result.poll(2000);
+ assertNotNull(subNotifyDoc);
+ }
+}
servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification/impl
ActiveSOAPNotificationBrokerTest.java added at 1.1
diff -N ActiveSOAPNotificationBrokerTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ActiveSOAPNotificationBrokerTest.java 23 Aug 2005 09:04:32 -0000 1.1 @@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2004 Protique Ltd
+ *
+ * Licensed 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.servicemix.ws.notification.impl;
+
+import org.servicemix.ws.xmlbeans.addressing.v2003_03.EndpointReferenceType;
+import org.servicemix.ws.xmlbeans.notification.base.NotifyDocument;
+import org.codehaus.activesoap.SoapService;
+import org.codehaus.activesoap.handler.xmlbeans.XMLBeansRegistry;
+import org.codehaus.activesoap.transport.LocalTransportClient;
+import org.servicemix.ws.notification.impl.ActiveMQNotificationBroker;
+import org.servicemix.ws.notification.impl.invoke.ActiveSOAPNotificationConsumer;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ActiveSOAPNotificationBrokerTest extends TestSupport {
+
+ public void testSubscribeWithSOAPEndpoint() throws Exception {
+ StubNotificationConsumer service = new StubNotificationConsumer();
+
+ XMLBeansRegistry registry = new XMLBeansRegistry();
+ registry.registerService(service);
+
+ final SoapService serverSide = new SoapService(registry);
+ serverSide.setRepairingNamespace(true);
+
+ ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker() {
+ protected org.servicemix.ws.notification.NotificationConsumer createNotificationConsumer(EndpointReferenceType consumerReference) {
+ return ActiveSOAPNotificationConsumer.newSoapInstance(new LocalTransportClient(serverSide));
+ }
+ };
+
+ addSubscription(broker);
+ sendNotification(broker);
+
+ NotifyDocument subNotifyDoc = (NotifyDocument) service.getResult().poll(2000);
+ System.out.println("Got Notify: "+subNotifyDoc);
+
+ assertValidMessage(subNotifyDoc);
+ }
+
+
+
+}
servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification/impl
StubNotificationConsumer.java added at 1.1
diff -N StubNotificationConsumer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ StubNotificationConsumer.java 23 Aug 2005 09:04:32 -0000 1.1 @@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2004 Protique Ltd
+ *
+ * Licensed 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.servicemix.ws.notification.impl;
+
+import EDU.oswego.cs.dl.util.concurrent.Slot;
+import org.servicemix.ws.xmlbeans.notification.base.NotifyDocument;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.servicemix.ws.notification.NotificationConsumer;
+
+/**
+ * A simple NotificationConsumer used for unit testing.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class StubNotificationConsumer implements NotificationConsumer {
+ private static final transient Log log = LogFactory.getLog(StubNotificationConsumer.class);
+
+ private Slot result;
+ private int timeout;
+
+ public StubNotificationConsumer() {
+ this(new Slot());
+ }
+
+ public StubNotificationConsumer(Slot result) {
+ this.result = result;
+ }
+
+ public void notify(NotifyDocument notify) {
+ try {
+ timeout = 1000;
+ result.offer(notify, timeout);
+ }
+ catch (InterruptedException e) {
+ log.warn("Could not offer notification: " + e, e);
+ }
+ }
+
+ public Slot getResult() {
+ return result;
+ }
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout) {
+ this.timeout = timeout;
+ }
+}
servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification/impl
TestSupport.java added at 1.1
diff -N TestSupport.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ TestSupport.java 23 Aug 2005 09:04:32 -0000 1.1 @@ -0,0 +1,102 @@
+/**
+ *
+ * Copyright 2004 Protique Ltd
+ *
+ * Licensed 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.servicemix.ws.notification.impl;
+
+import junit.framework.TestCase;
+import org.apache.xmlbeans.XmlObject;
+import org.servicemix.ws.xmlbeans.resource.properties.GetResourcePropertyDocument;
+import org.servicemix.ws.xmlbeans.addressing.v2003_03.EndpointReferenceType;
+import org.servicemix.ws.xmlbeans.notification.base.SubscribeDocument;
+import org.servicemix.ws.xmlbeans.notification.base.SubscribeResponseDocument;
+import org.servicemix.ws.xmlbeans.notification.base.NotifyDocument;
+import org.servicemix.ws.xmlbeans.notification.base.NotificationMessageHolderType;
+import org.activemq.message.ActiveMQTopic;
+import org.servicemix.ws.notification.impl.ActiveMQNotificationBroker;
+import org.servicemix.ws.notification.impl.TopicExpressionConverter;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public abstract class TestSupport extends TestCase {
+ protected ActiveMQTopic topic = new ActiveMQTopic("Test");
+
+ protected XmlObject createMessage() {
+ GetResourcePropertyDocument xml = GetResourcePropertyDocument.Factory.newInstance();
+ QName property = new QName("test", "test");
+ xml.setGetResourceProperty( property );
+ return xml;
+ }
+
+ protected EndpointReferenceType addSubscription(ActiveMQNotificationBroker broker) {
+ // Create a subscription
+
+ // START SNIPPET: subscribe
+ SubscribeDocument subrequest = SubscribeDocument.Factory.newInstance();
+ SubscribeDocument.Subscribe subscribe = subrequest.addNewSubscribe();
+ subscribe.setTopicExpression( TopicExpressionConverter.toTopicExpression(topic) );
+ subscribe.setUseNotify(true);
+ SubscribeResponseDocument subresponse = broker.Subscribe(subrequest);
+ // END SNIPPET: subscribe
+
+
+ System.out.println("Sub request: "+subrequest);
+ System.out.println("Sub response: "+subresponse);
+ assertNotNull(subresponse);
+
+ return subresponse.getSubscribeResponse().getSubscriptionReference();
+ }
+
+ protected void sendNotification(ActiveMQNotificationBroker broker) {
+ // START SNIPPET: notify
+ NotifyDocument request = NotifyDocument.Factory.newInstance();
+ NotifyDocument.Notify notify = request.addNewNotify();
+ NotificationMessageHolderType messageHolder = notify.addNewNotificationMessage();
+ messageHolder.setTopic( TopicExpressionConverter.toTopicExpression(topic) );
+
+ // create some XMLBean for the payload
+ XmlObject o = createMessage();
+ messageHolder.setMessage(o);
+ broker.notify(request);
+ // END SNIPPET: notify
+
+ assertValidMessage(request);
+
+ System.out.println("Sending Notify: "+request);
+ }
+
+ protected void assertValidMessage(NotifyDocument document) {
+ assertNotNull("null: document", document);
+
+ NotifyDocument.Notify notify = document.getNotify();
+ assertNotNull("null: notify", notify);
+
+ NotificationMessageHolderType[] messageArray = notify.getNotificationMessageArray();
+ assertNotNull("null: messageArray", messageArray);
+ assertTrue("Must have at least one message entry", messageArray.length > 0);
+
+ for (int i = 0; i < messageArray.length; i++) {
+ NotificationMessageHolderType messageHolder = messageArray[i];
+ assertNotNull("null: messageHolder[" + i + "]", messageHolder);
+
+ XmlObject message = messageHolder.getMessage();
+ assertNotNull("null: message[" + i + "]", message);
+ }
+ }
+}
servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification/impl
TopicExpressionConverterTest.java added at 1.1
diff -N TopicExpressionConverterTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ TopicExpressionConverterTest.java 23 Aug 2005 09:04:32 -0000 1.1 @@ -0,0 +1,22 @@
+package org.servicemix.ws.notification.impl;
+
+import org.activemq.message.ActiveMQTopic;
+import org.servicemix.ws.xmlbeans.notification.base.TopicExpressionType;
+import org.servicemix.ws.notification.impl.TopicExpressionConverter;
+
+import junit.framework.TestCase;
+
+public class TopicExpressionConverterTest extends TestCase {
+
+ public void testConvert() {
+ ActiveMQTopic topic1 = new ActiveMQTopic("Hello");
+ TopicExpressionType type = TopicExpressionConverter.toTopicExpression(topic1);
+ ActiveMQTopic topic2 = TopicExpressionConverter.toActiveMQTopic(type);
+ assertEquals(topic1, topic2);
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(TopicExpressionConverterTest.class);
+ }
+
+}
servicemix/ws/xmlbeans/src/test/java/org/servicemix/ws/notification
SubscribeParseTest.java added at 1.1
diff -N SubscribeParseTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ SubscribeParseTest.java 23 Aug 2005 09:04:32 -0000 1.1 @@ -0,0 +1,87 @@
+/**
+ *
+ * Copyright 2004 Protique Ltd
+ *
+ * Licensed 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.servicemix.ws.notification;
+
+import junit.framework.TestCase;
+import org.servicemix.ws.xmlbeans.addressing.v2003_03.AttributedURI;
+import org.servicemix.ws.xmlbeans.addressing.v2003_03.EndpointReferenceType;
+import org.servicemix.ws.xmlbeans.addressing.v2003_03.ReferencePropertiesType;
+import org.servicemix.ws.xmlbeans.notification.base.SubscribeDocument;
+import org.servicemix.ws.xmlbeans.resource.properties.QueryExpressionType;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlAnyURI;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Calendar;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class SubscribeParseTest extends TestCase {
+ public void testParseXmlBeansUsingURL() throws Exception {
+ SubscribeDocument doc = SubscribeDocument.Factory.parse(getClass().getResource("wsn-subscribe.xml"));
+ //System.out.println("Parsed: " + doc);
+ }
+
+ public void testParseXmlBeansUsingStAX() throws Exception {
+ XMLStreamReader in = createXMLStreamReader(getClass().getResource("wsn-subscribe.xml"));
+
+ XmlObject xmlObject = XmlObject.Factory.parse(in);
+ assertTrue("should be a SubscribeDocument: " + xmlObject.getClass(), xmlObject instanceof SubscribeDocument);
+
+ SubscribeDocument doc = (SubscribeDocument) xmlObject;
+ SubscribeDocument.Subscribe subscribe = doc.getSubscribe();
+
+
+ // lets get the endpoint reference
+ EndpointReferenceType endpointReference = subscribe.getConsumerReference();
+ AttributedURI address = endpointReference.getAddress();
+ System.out.println("EndpointReference address is: " + address.getStringValue());
+
+ ReferencePropertiesType referenceProperties = endpointReference.getReferenceProperties();
+ System.out.println("Reference properties: " + referenceProperties);
+
+
+ // lets get the selector
+ QueryExpressionType selector = subscribe.getSelector();
+ String dialect = selector.getDialect();
+ XmlAnyURI dialectURI = selector.xgetDialect();
+ String text = selector.xmlText();
+ System.out.println("Selector dialect: " + dialect + " of uri: " + dialectURI + " with value: " + text);
+
+
+ // termination time
+ Calendar initialTerminationTime = subscribe.getInitialTerminationTime();
+ System.out.println("initialTerminationTime: " + initialTerminationTime);
+
+
+ //System.out.println("Parsed: " + doc);
+ }
+
+ protected XMLStreamReader createXMLStreamReader(URL resource) throws XMLStreamException, IOException {
+ assertTrue("Found resource", resource != null);
+
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLStreamReader in = inputFactory.createXMLStreamReader(resource.openStream());
+ return in;
+ }
+}
