activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1366571 [2/2] - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/store/ apollo-network/src/main/scala/org/apache/activemq/apollo/broker/network/web/ apollo-stomp/src/test/scala/org/apache/a...
Date Sat, 28 Jul 2012 00:25:44 GMT
Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslSecurityTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslSecurityTest.scala?rev=1366571&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslSecurityTest.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslSecurityTest.scala
Sat Jul 28 00:25:43 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.stomp.test
+
+import java.lang.String
+import org.apache.activemq.apollo.util._
+import FileSupport._
+import org.apache.activemq.apollo.broker._
+import org.apache.activemq.apollo.dto.KeyStorageDTO
+
+class StompSslSecurityTest extends StompTestSupport {
+
+  override def broker_config_uri: String = "xml:classpath:apollo-stomp-ssl-secure.xml"
+
+  override def is_parallel_test_class: Boolean = false
+
+  override 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)
+    } catch {
+      case x: Throwable => x.printStackTrace
+    }
+    super.beforeAll
+  }
+
+  def use_client_cert = {
+    val config = new KeyStorageDTO
+    config.file = basedir / "src" / "test" / "resources" / "client.ks"
+    config.password = "password"
+    config.key_password = "password"
+    client.key_storeage = new KeyStorage(config)
+  }
+
+  test("Connect with cert and no id password") {
+    use_client_cert
+    connect("1.1", client)
+  }
+
+}

Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslTest.scala?rev=1366571&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslTest.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompSslTest.scala
Sat Jul 28 00:25:43 2012
@@ -0,0 +1,39 @@
+/**
+ * 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.stomp.test
+
+import java.lang.String
+import org.apache.activemq.apollo.util._
+import FileSupport._
+import org.apache.activemq.apollo.broker._
+import org.apache.activemq.apollo.dto.KeyStorageDTO
+
+class StompSslTest extends StompTestSupport with BrokerParallelTestExecution {
+
+  override def broker_config_uri: String = "xml:classpath:apollo-stomp-ssl.xml"
+
+  val config = new KeyStorageDTO
+  config.file = basedir / "src" / "test" / "resources" / "client.ks"
+  config.password = "password"
+  config.key_password = "password"
+
+  client.key_storeage = new KeyStorage(config)
+
+  test("Connect over SSL") {
+    connect("1.1")
+  }
+}

Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompTestSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompTestSupport.scala?rev=1366571&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompTestSupport.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompTestSupport.scala
Sat Jul 28 00:25:43 2012
@@ -0,0 +1,171 @@
+/**
+ * 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.stomp.test
+
+import org.scalatest.matchers.ShouldMatchers
+import org.scalatest._
+import java.lang.String
+import java.util.concurrent.atomic.AtomicLong
+import org.apache.activemq.apollo.broker._
+
+class StompTestSupport extends BrokerFunSuiteSupport with ShouldMatchers with BeforeAndAfterEach
{
+
+  override def broker_config_uri = "xml:classpath:apollo-stomp.xml"
+
+  var client = new StompClient
+  var clients = List[StompClient]()
+
+  override protected def afterEach() = {
+    super.afterEach
+    clients.foreach(_.close)
+    clients = Nil
+  }
+
+  def connect_request(version: String, c: StompClient, headers: String = "", connector: String
= null) = {
+    val p = connector_port(connector).getOrElse(port)
+    c.open("localhost", p)
+    version match {
+      case "1.0" =>
+        c.write(
+          "CONNECT\n" +
+                  headers +
+                  "\n")
+      case "1.1" =>
+        c.write(
+          "CONNECT\n" +
+                  "accept-version:1.1\n" +
+                  "host:localhost\n" +
+                  headers +
+                  "\n")
+      case x => throw new RuntimeException("invalid version: %f".format(x))
+    }
+    clients ::= c
+    c.receive()
+  }
+
+  def connect(version: String, c: StompClient = client, headers: String = "", connector:
String = null) = {
+    val frame = connect_request(version, c, headers, connector)
+    frame should startWith("CONNECTED\n")
+    frame should include regex ("""session:.+?\n""")
+    frame should include("version:" + version + "\n")
+    c
+  }
+
+  def disconnect(c: StompClient = client) = {
+    val rid = receipt_counter.incrementAndGet()
+    client.write(
+      "DISCONNECT\n" +
+              "receipt:" + rid + "\n" +
+              "\n")
+    wait_for_receipt("" + rid, c)
+    close(c)
+  }
+
+  def close(c: StompClient = client) = c.close()
+
+  val receipt_counter = new AtomicLong()
+
+  def sync_send(dest: String, body: Any, headers: String = "", c: StompClient = client) =
{
+    val rid = receipt_counter.incrementAndGet()
+    c.write(
+      "SEND\n" +
+              "destination:" + dest + "\n" +
+              "receipt:" + rid + "\n" +
+              headers +
+              "\n" +
+              body)
+    wait_for_receipt("" + rid, c)
+  }
+
+  def async_send(dest: String, body: Any, headers: String = "", c: StompClient = client)
= {
+    c.write(
+      "SEND\n" +
+              "destination:" + dest + "\n" +
+              headers +
+              "\n" +
+              body)
+  }
+
+  def subscribe(id: String, dest: String, mode: String = "auto", persistent: Boolean = false,
headers: String = "", sync: Boolean = true, c: StompClient = client) = {
+    val rid = receipt_counter.incrementAndGet()
+    c.write(
+      "SUBSCRIBE\n" +
+              "destination:" + dest + "\n" +
+              "id:" + id + "\n" +
+              (if (persistent) "persistent:true\n" else "") +
+              "ack:" + mode + "\n" +
+              (if (sync) "receipt:" + rid + "\n" else "") +
+              headers +
+              "\n")
+    if (sync) {
+      wait_for_receipt("" + rid, c)
+    }
+  }
+
+  def unsubscribe(id: String, headers: String = "", c: StompClient = client) = {
+    val rid = receipt_counter.incrementAndGet()
+    c.write(
+      "UNSUBSCRIBE\n" +
+              "id:" + id + "\n" +
+              "receipt:" + rid + "\n" +
+              headers +
+              "\n")
+    wait_for_receipt("" + rid, c)
+  }
+
+  def assert_received(body: Any, sub: String = null, c: StompClient = client, txid: String
= null): (Boolean) => Unit = {
+    val frame = c.receive()
+    frame should startWith("MESSAGE\n")
+    if (sub != null) {
+      frame should include("subscription:" + sub + "\n")
+    }
+    body match {
+      case null =>
+      case body: scala.util.matching.Regex => frame should endWith regex (body)
+      case body => frame should endWith("\n\n" + body)
+    }
+    // return a func that can ack the message.
+    (ack: Boolean) => {
+      val sub_regex = """(?s).*\nsubscription:([^\n]+)\n.*""".r
+      val msgid_regex = """(?s).*\nmessage-id:([^\n]+)\n.*""".r
+      val sub_regex(sub) = frame
+      val msgid_regex(msgid) = frame
+      c.write(
+        (if (ack) "ACK\n" else "NACK\n") +
+                "subscription:" + sub + "\n" +
+                "message-id:" + msgid + "\n" +
+                (if (txid != null) "transaction:" + txid + "\n" else "") +
+
+                "\n")
+    }
+  }
+
+  def wait_for_receipt(id: String, c: StompClient = client, discard_others: Boolean = false):
Unit = {
+    if (!discard_others) {
+      val frame = c.receive()
+      frame should startWith("RECEIPT\n")
+      frame should include("receipt-id:" + id + "\n")
+    } else {
+      while (true) {
+        val frame = c.receive()
+        if (frame.startsWith("RECEIPT\n") && frame.indexOf("receipt-id:" + id + "\n")
>= 0) {
+          return
+        }
+      }
+    }
+  }
+}

Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardCustomParallelTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardCustomParallelTest.scala?rev=1366571&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardCustomParallelTest.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardCustomParallelTest.scala
Sat Jul 28 00:25:43 2012
@@ -0,0 +1,25 @@
+/**
+ * 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.stomp.test
+
+import java.lang.String
+
+class StompWildcardCustomParallelTest extends StompWildcardParallelTest {
+  override def broker_config_uri: String = "xml:classpath:apollo-stomp-custom-dest-delimiters.xml"
+
+  override def path_separator = "/"
+}

Added: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardParallelTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardParallelTest.scala?rev=1366571&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardParallelTest.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/test/StompWildcardParallelTest.scala
Sat Jul 28 00:25:43 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.stomp.test
+
+import java.lang.String
+import org.apache.activemq.apollo.broker._
+
+class StompWildcardParallelTest extends StompTestSupport with BrokerParallelTestExecution
{
+
+  def path_separator = "."
+
+  test("Wildcard subscription") {
+    connect("1.1")
+
+    client.write(
+      "SUBSCRIBE\n" +
+              "destination:/queue/foo" + path_separator + "*\n" +
+              "id:1\n" +
+              "receipt:0\n" +
+              "\n")
+
+    wait_for_receipt("0")
+
+    def put(dest: String) = {
+      client.write(
+        "SEND\n" +
+                "destination:/queue/" + dest + "\n" +
+                "\n" +
+                "message:" + dest + "\n")
+    }
+
+    def get(dest: String) = {
+      val frame = client.receive()
+      frame should startWith("MESSAGE\n")
+      frame should endWith("\n\nmessage:%s\n".format(dest))
+    }
+
+    // We should not get this one..
+    put("bar" + path_separator + "a")
+
+    put("foo" + path_separator + "a")
+    get("foo" + path_separator + "a")
+
+    put("foo" + path_separator + "b")
+    get("foo" + path_separator + "b")
+  }
+}



Mime
View raw message