<commit_before>/*
 * Copyright 2011-2019 GatlingCorp (https://gatling.io)
 *
 * 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 io.gatling.jms.compile

import javax.jms._

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.jms.Predef._
import io.gatling.jms.protocol.JmsMessageMatcher

object headerMatcher extends JmsMessageMatcher {
  override def prepareRequest(msg: Message): Unit = {}
  override def responseMatchId(msg: Message): String = requestMatchId(msg)
  override def requestMatchId(msg: Message): String = msg.getStringProperty("header")
}

class JmsCompileTest extends Simulation {

  // create JmsProtocol from standard ConnectionFactory
  val jmsProtocolWithNativeConnectionFactory = jms
    .connectionFactory(new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616"))

  // create JmsProtocol from JNDI based ConnectionFactory
  val jmsProtocolWithJndiConnectionFactory = jms
    .connectionFactory(
      jmsJndiConnectionFactory
        .connectionFactoryName("ConnectionFactory")
        .url("tcp://localhost:10002")
        .credentials("user", "secret")
        .property("FOO", "BAR")
        .contextFactory("org.apache.activemq.jndi.ActiveMQInitialContextFactory")
    )
    .usePersistentDeliveryMode
    .replyTimeout(1000)
    .messageMatcher(headerMatcher)
    .matchByCorrelationId
    .matchByMessageId

  val scn = scenario("scn")
    // requestReply
    // textMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .replyQueue("responseQueue")
      .textMessage("hello"))
    // bytesMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .bytesMessage(new Array[Byte](1)))
    // mapMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .mapMessage(Map("foo" -> "bar")))
    // objectMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .objectMessage("hello"))
    // destination
    .exec(jms("req").requestReply
      .destination(topic("topic"))
      .noJmsReplyTo
      .replyDestination(queue("queue"))
      .trackerQueue("queue")
      .trackerDestination(topic("topic"))
      .selector("selector")
      .textMessage("hello"))
    // check
    .exec(jms("req").requestReply
      .queue("queue")
      .textMessage("hello")
      .check(checkBodyTextCorrect)
      .check(xpath("//TEST").saveAs("name")))
    // extra
    .exec(jms("req").requestReply
      .queue("queue")
      .textMessage("hello")
      .property("header", "value")
      .property("header", "${value}")
      .property("header", _ => "value")
      .jmsType("foo"))

    // send
    // textMessage
    .exec(jms("req").send
      .queue("queue")
      .textMessage("hello"))
    // bytesMessage
    .exec(jms("req").send
      .queue("queue")
      .bytesMessage(new Array[Byte](1)))
    // objectMessage
    .exec(jms("req").send
      .queue("queue")
      .objectMessage("hello"))
    // destination: topic
    .exec(jms("req").send
      .destination(topic("topic"))
      .textMessage("hello"))
    // destination: queue
    .exec(jms("req").send
      .destination(queue("queue"))
      .textMessage("hello"))
    // extra
    .exec(jms("req").send
      .queue("queue")
      .textMessage("hello")
      .property("header", "value")
      .property("header", "${value}")
      .property("header", _ => "value")
      .jmsType("foo"))

  setUp(scn.inject(rampUsersPerSec(10) to 1000 during (2 minutes)))
    .protocols(jmsProtocolWithNativeConnectionFactory)

  def checkBodyTextCorrect = simpleCheck {
    case tm: TextMessage => tm.getText == "hello"
    case _               => false
  }
}
<commit_msg>Prove JMS messages work with proper bodies<commit_after>/*
 * Copyright 2011-2019 GatlingCorp (https://gatling.io)
 *
 * 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 io.gatling.jms.compile

import javax.jms._

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.jms.Predef._
import io.gatling.jms.protocol.JmsMessageMatcher

object headerMatcher extends JmsMessageMatcher {
  override def prepareRequest(msg: Message): Unit = {}
  override def responseMatchId(msg: Message): String = requestMatchId(msg)
  override def requestMatchId(msg: Message): String = msg.getStringProperty("header")
}

class JmsCompileTest extends Simulation {

  // create JmsProtocol from standard ConnectionFactory
  val jmsProtocolWithNativeConnectionFactory = jms
    .connectionFactory(new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616"))

  // create JmsProtocol from JNDI based ConnectionFactory
  val jmsProtocolWithJndiConnectionFactory = jms
    .connectionFactory(
      jmsJndiConnectionFactory
        .connectionFactoryName("ConnectionFactory")
        .url("tcp://localhost:10002")
        .credentials("user", "secret")
        .property("FOO", "BAR")
        .contextFactory("org.apache.activemq.jndi.ActiveMQInitialContextFactory")
    )
    .usePersistentDeliveryMode
    .replyTimeout(1000)
    .messageMatcher(headerMatcher)
    .matchByCorrelationId
    .matchByMessageId

  val scn = scenario("scn")
    // requestReply
    // textMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .replyQueue("responseQueue")
      .textMessage("hello"))
    // textMessage with ElFileBody
    .exec(jms("req").requestReply
      .queue("queue")
      .textMessage(ElFileBody("file")))
    // bytesMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .bytesMessage(new Array[Byte](1)))
    // bytesMessage with RawFileBody
    .exec(jms("req").requestReply
      .queue("queue")
      .bytesMessage(RawFileBody("file")))
    // mapMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .mapMessage(Map("foo" -> "bar")))
    // objectMessage
    .exec(jms("req").requestReply
      .queue("queue")
      .objectMessage("hello"))
    // destination
    .exec(jms("req").requestReply
      .destination(topic("topic"))
      .noJmsReplyTo
      .replyDestination(queue("queue"))
      .trackerQueue("queue")
      .trackerDestination(topic("topic"))
      .selector("selector")
      .textMessage("hello"))
    // check
    .exec(jms("req").requestReply
      .queue("queue")
      .textMessage("hello")
      .check(checkBodyTextCorrect)
      .check(xpath("//TEST").saveAs("name")))
    // extra
    .exec(jms("req").requestReply
      .queue("queue")
      .textMessage("hello")
      .property("header", "value")
      .property("header", "${value}")
      .property("header", _ => "value")
      .jmsType("foo"))

    // send
    // textMessage
    .exec(jms("req").send
      .queue("queue")
      .textMessage("hello"))
    // bytesMessage
    .exec(jms("req").send
      .queue("queue")
      .bytesMessage(new Array[Byte](1)))
    // objectMessage
    .exec(jms("req").send
      .queue("queue")
      .objectMessage("hello"))
    // destination: topic
    .exec(jms("req").send
      .destination(topic("topic"))
      .textMessage("hello"))
    // destination: queue
    .exec(jms("req").send
      .destination(queue("queue"))
      .textMessage("hello"))
    // extra
    .exec(jms("req").send
      .queue("queue")
      .textMessage("hello")
      .property("header", "value")
      .property("header", "${value}")
      .property("header", _ => "value")
      .jmsType("foo"))

  setUp(scn.inject(rampUsersPerSec(10) to 1000 during (2 minutes)))
    .protocols(jmsProtocolWithNativeConnectionFactory)

  def checkBodyTextCorrect = simpleCheck {
    case tm: TextMessage => tm.getText == "hello"
    case _               => false
  }
}

{'fraction_non_alphanumeric': 0.14366949054195197, 'fraction_numerical': 0.008123476848090982, 'mean_word_length': 3.1693275278180937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2371378', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2528, 'n_words': 526}