cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1179981 [7/7] - in /cxf/trunk/services: ./ wsn/ wsn/src/ wsn/src/main/ wsn/src/main/java/ wsn/src/main/java/org/ wsn/src/main/java/org/apache/ wsn/src/main/java/org/apache/cxf/ wsn/src/main/java/org/apache/cxf/wsn/ wsn/src/main/java/org/ap...
Date Fri, 07 Oct 2011 09:41:14 GMT
Added: cxf/trunk/services/wsn/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java?rev=1179981&view=auto
==============================================================================
--- cxf/trunk/services/wsn/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java (added)
+++ cxf/trunk/services/wsn/src/test/java/org/apache/cxf/wsn/WsnBrokerTest.java Fri Oct  7
09:41:10 2011
@@ -0,0 +1,224 @@
+/*
+ * 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.wsn;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.cxf.wsn.client.Consumer;
+import org.apache.cxf.wsn.client.CreatePullPoint;
+import org.apache.cxf.wsn.client.NotificationBroker;
+import org.apache.cxf.wsn.client.Publisher;
+import org.apache.cxf.wsn.client.PullPoint;
+import org.apache.cxf.wsn.client.Registration;
+import org.apache.cxf.wsn.client.Subscription;
+import org.apache.cxf.wsn.jaxws.JaxwsCreatePullPoint;
+import org.apache.cxf.wsn.jaxws.JaxwsNotificationBroker;
+import org.apache.cxf.wsn.util.WSNHelper;
+import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
+import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
+
+public abstract class WsnBrokerTest extends TestCase {
+
+    private ActiveMQConnectionFactory activemq;
+    private JaxwsNotificationBroker notificationBrokerServer;
+    private JaxwsCreatePullPoint createPullPointServer;
+    private NotificationBroker notificationBroker;
+    private CreatePullPoint createPullPoint;
+
+    private int port1;
+    private int port2;
+
+    @Override
+    public void setUp() throws Exception {
+
+        port1 = getFreePort();
+        port2 = getFreePort();
+
+        System.setProperty("java.util.logging.config.file", getClass().getClassLoader().getResource("logging.properties").getPath());
+        java.util.logging.LogManager.getLogManager().readConfiguration();
+
+        activemq = new ActiveMQConnectionFactory("vm:(broker:(tcp://localhost:6000)?persistent=false)");
+
+        notificationBrokerServer = new JaxwsNotificationBroker("WSNotificationBroker", activemq);
+        notificationBrokerServer.setAddress("http://0.0.0.0:" + port1 + "/wsn/NotificationBroker");
+        notificationBrokerServer.init();
+
+        createPullPointServer = new JaxwsCreatePullPoint("CreatePullPoint", activemq);
+        createPullPointServer.setAddress("http://0.0.0.0:" + port1 + "/wsn/CreatePullPoint");
+        createPullPointServer.init();
+
+        notificationBroker = new NotificationBroker("http://0.0.0.0:" + port1 + "/wsn/NotificationBroker");
+        createPullPoint = new CreatePullPoint("http://0.0.0.0:" + port1 + "/wsn/CreatePullPoint");
+    }
+
+    private int getFreePort() throws IOException {
+        ServerSocket socket = new ServerSocket(0);
+        int port = socket.getLocalPort();
+        socket.close();
+        return port;
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        notificationBrokerServer.destroy();
+        createPullPointServer.destroy();
+    }
+
+    public void testBroker() throws Exception {
+        TestConsumer callback = new TestConsumer();
+        Consumer consumer = new Consumer(callback, "http://0.0.0.0:" + port2 + "/test/consumer");
+
+        Subscription subscription = notificationBroker.subscribe(consumer, "myTopic");
+
+        synchronized (callback.notifications) {
+            notificationBroker.notify("myTopic", new JAXBElement(new QName("urn:test:org",
"foo"), String.class, "bar"));
+            callback.notifications.wait(1000000);
+        }
+        assertEquals(1, callback.notifications.size());
+        NotificationMessageHolderType message = callback.notifications.get(0);
+        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()), WSNHelper.getWSAAddress(message.getSubscriptionReference()));
+
+        subscription.unsubscribe();
+        consumer.stop();
+    }
+
+    public void testPullPoint() throws Exception {
+        PullPoint pullPoint = createPullPoint.create();
+        Subscription subscription = notificationBroker.subscribe(pullPoint, "myTopic");
+        notificationBroker.notify("myTopic", new JAXBElement(new QName("urn:test:org", "foo"),
String.class, "bar"));
+
+        boolean received = false;
+        for (int i = 0; i < 50; i++) {
+            List<NotificationMessageHolderType> messages = pullPoint.getMessages(10);
+            if (!messages.isEmpty()) {
+                received = true;
+                 break;
+            }
+            Thread.sleep(100);
+        }
+        assertTrue(received);
+
+        subscription.unsubscribe();
+        pullPoint.destroy();
+    }
+
+    public void testPublisher() throws Exception {
+        TestConsumer consumerCallback = new TestConsumer();
+        Consumer consumer = new Consumer(consumerCallback, "http://0.0.0.0:" + port2 + "/test/consumer");
+
+        Subscription subscription = notificationBroker.subscribe(consumer, "myTopic");
+
+        PublisherCallback publisherCallback = new PublisherCallback();
+        Publisher publisher = new Publisher(publisherCallback, "http://0.0.0.0:" + port2
+ "/test/publisher");
+        Registration registration = notificationBroker.registerPublisher(publisher, "myTopic");
+
+        synchronized (consumerCallback.notifications) {
+            notificationBroker.notify(publisher, "myTopic", new JAXBElement(new QName("urn:test:org",
"foo"), String.class, "bar"));
+            consumerCallback.notifications.wait(1000000);
+        }
+        assertEquals(1, consumerCallback.notifications.size());
+        NotificationMessageHolderType message = consumerCallback.notifications.get(0);
+        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()), WSNHelper.getWSAAddress(message.getSubscriptionReference()));
+        assertEquals(WSNHelper.getWSAAddress(publisher.getEpr()), WSNHelper.getWSAAddress(message.getProducerReference()));
+
+        subscription.unsubscribe();
+        registration.destroy();
+        publisher.stop();
+        consumer.stop();
+    }
+
+    public void testPublisherOnDemand() throws Exception {
+        TestConsumer consumerCallback = new TestConsumer();
+        Consumer consumer = new Consumer(consumerCallback, "http://0.0.0.0:" + port2 + "/test/consumer");
+
+        PublisherCallback publisherCallback = new PublisherCallback();
+        Publisher publisher = new Publisher(publisherCallback, "http://0.0.0.0:" + port2
+ "/test/publisher");
+        Registration registration = notificationBroker.registerPublisher(publisher, Arrays.asList("myTopic1",
"myTopic2"), true);
+
+        Subscription subscription = notificationBroker.subscribe(consumer, "myTopic1");
+        assertTrue(publisherCallback.subscribed.await(5, TimeUnit.SECONDS));
+
+        synchronized (consumerCallback.notifications) {
+            notificationBroker.notify(publisher, "myTopic1", new JAXBElement(new QName("urn:test:org",
"foo"), String.class, "bar"));
+            consumerCallback.notifications.wait(1000000);
+        }
+
+        subscription.unsubscribe();
+
+        assertTrue(publisherCallback.unsubscribed.await(5, TimeUnit.SECONDS));
+
+        registration.destroy();
+        publisher.stop();
+        consumer.stop();
+    }
+
+    public static class TestConsumer implements Consumer.Callback {
+
+        public final List<NotificationMessageHolderType> notifications = new ArrayList<NotificationMessageHolderType>();
+
+        public void notify(NotificationMessageHolderType message) {
+            synchronized (notifications) {
+                notifications.add(message);
+                notifications.notify();
+            }
+        }
+    }
+
+    public static class PublisherCallback implements Publisher.Callback {
+        public final CountDownLatch subscribed = new CountDownLatch(1);
+        public final CountDownLatch unsubscribed = new CountDownLatch(1);
+
+        public void subscribe(TopicExpressionType topic) {
+            subscribed.countDown();
+        }
+
+        public void unsubscribe(TopicExpressionType topic) {
+            unsubscribed.countDown();
+        }
+    }
+
+    protected static class FakeClassLoader extends URLClassLoader {
+        private final String provider;
+        public FakeClassLoader(String provider) {
+            super(new URL[0], FakeClassLoader.class.getClassLoader());
+            this.provider = provider;
+        }
+        @Override
+        public InputStream getResourceAsStream(String name) {
+            if ("META-INF/services/javax.xml.ws.spi.Provider".equals(name)) {
+                return provider != null ? new ByteArrayInputStream(provider.getBytes()) :
null;
+            } else {
+                return super.getResourceAsStream(name);
+            }
+        }
+    }
+
+}

Added: cxf/trunk/services/wsn/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/src/test/resources/log4j.properties?rev=1179981&view=auto
==============================================================================
--- cxf/trunk/services/wsn/src/test/resources/log4j.properties (added)
+++ cxf/trunk/services/wsn/src/test/resources/log4j.properties Fri Oct  7 09:41:10 2011
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+#
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, stdout
+
+log4j.logger.org.springframework=INFO
+log4j.logger.org.apache.activemq=INFO
+log4j.logger.org.apache.activemq.spring=WARN
+log4j.logger.org.apache.activemq.store.journal=INFO
+log4j.logger.org.activeio.journal=INFO
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/servicemix-test.log
+log4j.appender.out.append=true

Added: cxf/trunk/services/wsn/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/src/test/resources/logging.properties?rev=1179981&view=auto
==============================================================================
--- cxf/trunk/services/wsn/src/test/resources/logging.properties (added)
+++ cxf/trunk/services/wsn/src/test/resources/logging.properties Fri Oct  7 09:41:10 2011
@@ -0,0 +1,19 @@
+# Specify the handlers to create in the root logger
+# (all loggers are children of the root logger)
+# The following creates two handlers
+handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
+
+# Set the default logging level for the root logger
+.level = ALL
+
+# Set the default logging level for new ConsoleHandler instances
+java.util.logging.ConsoleHandler.level = INFO
+
+# Set the default logging level for new FileHandler instances
+java.util.logging.FileHandler.level = ALL
+
+# Set the default formatter for new ConsoleHandler instances
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+# Set the default logging level for the logger named com.mycompany
+com.sun.xml.level = ALL



Mime
View raw message