You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/06/20 23:46:58 UTC

svn commit: r1137797 - in /activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire: DestinationWildcardTest.scala OpenwireTestSupport.scala QueueTest.scala SslSecurityTest.scala

Author: tabish
Date: Mon Jun 20 21:46:58 2011
New Revision: 1137797

URL: http://svn.apache.org/viewvc?rev=1137797&view=rev
Log:
https://issues.apache.org/jira/browse/APLO-30

Tweak the test support class some and add a couple more test cases.

Added:
    activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/DestinationWildcardTest.scala
    activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/SslSecurityTest.scala
Modified:
    activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala
    activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/QueueTest.scala

Added: activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/DestinationWildcardTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/DestinationWildcardTest.scala?rev=1137797&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/DestinationWildcardTest.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/DestinationWildcardTest.scala Mon Jun 20 21:46:58 2011
@@ -0,0 +1,103 @@
+/**
+ * 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.activemq.apollo.openwire
+
+import javax.jms.{MessageConsumer, MessageProducer, TextMessage, Session}
+
+class DestinationWildcardTest extends OpenwireTestSupport {
+
+  def path_separator = "."
+
+  test("Wildcard subscription") {
+    connect()
+
+    val prefix = "foo" + path_separator
+
+    val session = default_connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
+    val producer1 = session.createProducer(queue(prefix + "A"))
+    val producer2 = session.createProducer(queue(prefix + "B"))
+    val producer3 = session.createProducer(queue("bar.A"))
+    def put(producer:MessageProducer, id:Int) {
+      producer.send(session.createTextMessage("message:"+id))
+    }
+
+    List(1,2,3).foreach(put(producer1, _))
+    producer3.send(session.createTextMessage("This one shouldn't get consumed."))
+    List(1,2,3).foreach(put(producer2, _))
+
+    val consumer = session.createConsumer(queue(prefix + "*"))
+
+    def get(id:Int) {
+      val m = consumer.receive().asInstanceOf[TextMessage]
+      m.getText should equal ("message:"+id)
+    }
+
+    List(1,2,3).foreach(get _)
+    List(1,2,3).foreach(get _)
+
+    consumer.receive(1000) should be(null)
+  }
+
+  test("Wildcard subscription with multiple path sections") {
+    connect()
+
+    val prefix1 = "foo" + path_separator + "bar" + path_separator
+    val prefix2 = "foo" + path_separator + "bar" + path_separator + "cheeze" + path_separator
+    val prefix3 = "foo" + path_separator + "bar" + path_separator + "cracker" + path_separator
+
+    val session = default_connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
+    val producer1 = session.createProducer(topic(prefix1 + "A"))
+    val producer2 = session.createProducer(topic(prefix2 + "B"))
+    val producer3 = session.createProducer(topic(prefix3 + "C"))
+
+    def put(producer:MessageProducer, id:Int) {
+      producer.send(session.createTextMessage("message:"+id))
+    }
+
+    val consumer1 = session.createConsumer(topic(prefix1 + "*"))
+    val consumer2 = session.createConsumer(topic(prefix2 + "*"))
+    val consumer3 = session.createConsumer(topic(prefix3 + "*"))
+
+    def get(consumer:MessageConsumer, id:Int) {
+      val m = consumer.receive(2000).asInstanceOf[TextMessage]
+      m should not be(null)
+      m.getText should equal ("message:"+id)
+    }
+
+    // They only consumer one should see these.
+    List(1,2,3).foreach(put(producer1, _))
+
+    List(1,2,3).foreach(get(consumer1, _))
+    consumer2.receive(2000) should be(null)
+    consumer3.receive(2000) should be(null)
+
+    // They only consumer two should see these.
+    List(1,2,3).foreach(put(producer2, _))
+
+    List(1,2,3).foreach(get(consumer2, _))
+    consumer1.receive(2000) should be(null)
+    consumer3.receive(2000) should be(null)
+
+    // They only consumer two should see these.
+    List(1,2,3).foreach(put(producer3, _))
+
+    List(1,2,3).foreach(get(consumer3, _))
+    consumer1.receive(2000) should be(null)
+    consumer2.receive(2000) should be(null)
+  }
+
+}
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala?rev=1137797&r1=1137796&r2=1137797&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala Mon Jun 20 21:46:58 2011
@@ -33,6 +33,9 @@ class OpenwireTestSupport extends FunSui
   var port = 0
 
   val broker_config_uri = "xml:classpath:apollo-openwire.xml"
+  val transport_scheme = "tcp"
+  val transport_host = "localhost"
+  val uri_options = "?wireFormat.maxInactivityDuration=1000000&wireFormat.maxInactivityDurationInitalDelay=1000000"
 
   override protected def beforeAll() {
     info("Loading broker configuration from the classpath with URI: " + broker_config_uri)
@@ -55,7 +58,8 @@ class OpenwireTestSupport extends FunSui
     default_connection = null
   }
 
-  def connection_uri = "tcp://localhost:%d?wireFormat.maxInactivityDuration=1000000&wireFormat.maxInactivityDurationInitalDelay=1000000".format(port)
+//  def connection_uri = transportScheme + "://localhost:%d?wireFormat.maxInactivityDuration=1000000&wireFormat.maxInactivityDurationInitalDelay=1000000".format(port)
+  def connection_uri = (transport_scheme + "://" + transport_host + ":%d" + uri_options).format(port)
   def create_connection_factory = new ActiveMQConnectionFactory(connection_uri)
   def create_connection: Connection = create_connection_factory.createConnection
   def queue(value:String) = new ActiveMQQueue(value);

Modified: activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/QueueTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/QueueTest.scala?rev=1137797&r1=1137796&r2=1137797&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/QueueTest.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/QueueTest.scala Mon Jun 20 21:46:58 2011
@@ -55,7 +55,7 @@ class QueueTest extends OpenwireTestSupp
     // Consume the message...
     var consumer = session.createConsumer(queue)
     var msg = consumer.receive(1000)
-    assert(msg != null)
+    msg should not be(null)
 
     Thread.sleep(1000)
 
@@ -63,7 +63,7 @@ class QueueTest extends OpenwireTestSupp
     // Attempt to Consume the message...check if message was acknowledge
     consumer = session.createConsumer(queue)
     msg = consumer.receive(1000)
-    assert(msg == null)
+    msg should be(null)
 
     session.close()
   }

Added: activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/SslSecurityTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/SslSecurityTest.scala?rev=1137797&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/SslSecurityTest.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/SslSecurityTest.scala Mon Jun 20 21:46:58 2011
@@ -0,0 +1,71 @@
+/**
+ * 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.activemq.apollo.openwire
+
+import javax.jms.{TextMessage, Session}
+
+class SslSecurityTest extends OpenwireTestSupport {
+
+  override val broker_config_uri: String = "xml:classpath:apollo-openwire-ssl-secure.xml"
+  override val transport_scheme = "ssl"
+
+  override protected def beforeAll = {
+    // System.setProperty("javax.net.debug", "all")
+    try {
+      val login_file = new java.io.File(getClass.getClassLoader.getResource("login.config").getFile())
+      System.setProperty("java.security.auth.login.config", login_file.getCanonicalPath)
+      System.setProperty("javax.net.ssl.trustStore", basedir + "/src/test/resources/apollo.ks");
+      System.setProperty("javax.net.ssl.trustStorePassword", "password");
+      System.setProperty("javax.net.ssl.trustStoreType", "jks");
+      System.setProperty("javax.net.ssl.keyStore", basedir + "/src/test/resources/client.ks");
+      System.setProperty("javax.net.ssl.keyStorePassword", "password");
+      System.setProperty("javax.net.ssl.keyStoreType", "jks");
+    } catch {
+      case x:Throwable => x.printStackTrace
+    }
+    super.beforeAll
+  }
+
+  ignore("Connect with cert and no id password") {
+
+    connect()
+
+    val session = default_connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
+    val producer = session.createProducer(topic("example"))
+    def put(id:Int) {
+      producer.send(session.createTextMessage("message:"+id))
+    }
+
+    put(1)
+
+    val consumer = session.createConsumer(topic("example"))
+
+    put(2)
+    put(3)
+
+    def get(id:Int) {
+      val m = consumer.receive().asInstanceOf[TextMessage]
+      m.getJMSDestination should equal(topic("example"))
+      m.getText should equal ("message:"+id)
+    }
+
+    List(2,3).foreach(get _)
+
+  }
+
+}
\ No newline at end of file