org.apache.qpid.proton.amqp.messaging.AmqpValue Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.messaging.AmqpValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertStreamMessageToAmqpMessageWithAmqpValueBodyNoPropertySet() throws Exception {
   ServerJMSStreamMessage outbound = createStreamMessage();
   outbound.writeBoolean(false);
   outbound.writeString("test");
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof AmqpValue);

   AmqpValue list = (AmqpValue) amqp.getBody();

   @SuppressWarnings("unchecked")
   List<Object> amqpList = (List<Object>) list.getValue();

   assertEquals(2, amqpList.size());
}
 
Example #2
Source File: ProtonRequestClientTest.java    From enmasse with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequest() throws Exception {
    try (ProtonRequestClient client = new ProtonRequestClient(Vertx.vertx(), "test-client")) {
        CompletableFuture<Void> future = new CompletableFuture<>();
        client.connect("127.0.0.1", 12347, future);
        future.get(10, TimeUnit.SECONDS);
        Message request = Message.Factory.create();
        request.setAddress("health-check");
        request.setBody(new AmqpValue("[{\"name\":\"myqueue\",\"store_and_forward\":true,\"multicast\":false}]"));
        request.setSubject("health-check");
        Message response = client.request(request, 10, TimeUnit.SECONDS);
        assertTrue((Boolean) ((AmqpValue) response.getBody()).getValue());

        future = new CompletableFuture<>();
        client.connect("127.0.0.1", 12347, future);
        future.get(10, TimeUnit.SECONDS);
    }
}
 
Example #3
Source File: Artemis.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Set<String> getConnectorNames() throws TimeoutException {
    log.info("Retrieving conector names for broker {}", syncRequestClient.getRemoteContainer());
    Message response = doOperation("broker", "getConnectorServices");

    Set<String> connectors = new LinkedHashSet<>();
    JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
    for (int i = 0; i < payload.size(); i++) {
        JsonArray inner = payload.getJsonArray(i);
        for (int j = 0; j < inner.size(); j++) {
            String connector = inner.getString(j);
            if (!connector.equals("amqp-connector")) {
                connectors.add(connector);
            }
        }
    }
    return connectors;
}
 
Example #4
Source File: BlockingClientTest.java    From enmasse with Apache License 2.0 6 votes vote down vote up
@Test
public void testReceive() throws Exception {
    try (BlockingClient client = new BlockingClient("127.0.0.1", actualPort)) {
        Message m = Message.Factory.create();
        m.setAddress("testreceive");
        m.setBody(new AmqpValue("hello there"));
        outbox.put(m);

        List<Message> messages = client.recv("testsend", 1, 1, TimeUnit.MINUTES);
        assertThat(messages.size(), is(1));

        Message received = messages.get(0);
        assertNotNull(received);
        assertThat(received.getMessageId(), is(m.getMessageId()));
        assertThat(((AmqpValue) received.getBody()).getValue(), is("hello there"));
    }
}
 
Example #5
Source File: Artemis.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Set<String> getQueueNames() throws TimeoutException {
    log.info("Retrieving queue names for broker {}", syncRequestClient.getRemoteContainer());
    Message response = doOperation("broker", "getQueueNames");

    Set<String> queues = new LinkedHashSet<>();
    JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
    for (int i = 0; i < payload.size(); i++) {
        JsonArray inner = payload.getJsonArray(i);
        for (int j = 0; j < inner.size(); j++) {
            String queueName = inner.getString(j);
            if (!queueName.equals(syncRequestClient.getReplyTo())) {
                queues.add(queueName);
            }
        }
    }
    return queues;
}
 
Example #6
Source File: Artemis.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public Set<String> getAddressNames() throws TimeoutException {
    log.info("Retrieving address names for broker {}", syncRequestClient.getRemoteContainer());
    Message response = doOperation("broker", "getAddressNames");

    Set<String> addressNames = new LinkedHashSet<>();
    JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
    for (int i = 0; i < payload.size(); i++) {
        JsonArray inner = payload.getJsonArray(i);
        for (int j = 0; j < inner.size(); j++) {
            String addressName = inner.getString(j);
            if (!addressName.equals(syncRequestClient.getReplyTo())) {
                addressNames.add(addressName);
            }
        }
    }
    return addressNames;
}
 
Example #7
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeliveryCountSetFromMessageWithNonDefaultValue() throws Exception {
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setDeliveryCount(2);
    message.setBody(new AmqpValue("test"));

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass());
    assertTrue(jmsMessage.getJMSRedelivered());

    assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, jmsMessage.getFacade().getClass());
    AmqpJmsTextMessageFacade facade = (AmqpJmsTextMessageFacade) jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals(2, facade.getRedeliveryCount());
    assertEquals(2, facade.getAmqpHeader().getDeliveryCount());
    assertEquals(UnsignedInteger.valueOf(2), facade.getHeader().getDeliveryCount());
}
 
Example #8
Source File: AmqpJmsMapMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that for a message received with an AmqpValue containing a Map with a Binary entry
 * value, we are able to read it back as a byte[].
 *
 * @throws Exception if an error occurs while running the test.
 */
@Test
public void testReceivedMapWithBinaryEntryReturnsByteArray() throws Exception {
    String myKey1 = "key1";
    String bytesSource = "myBytesAmqpValue";

    Map<String, Object> origMap = new HashMap<String, Object>();
    byte[] bytes = bytesSource.getBytes();
    origMap.put(myKey1, new Binary(bytes));

    Message message = Message.Factory.create();
    message.setBody(new AmqpValue(origMap));

    AmqpJmsMapMessageFacade amqpMapMessageFacade = createReceivedMapMessageFacade(createMockAmqpConsumer(), message);

    // retrieve the bytes using getBytes, check they match expectation
    Object objectValue = amqpMapMessageFacade.get(myKey1);
    assertTrue(byte[].class.equals(objectValue.getClass()));
    byte[] bytesValue = (byte[]) objectValue;
    assertTrue(Arrays.equals(bytes, bytesValue));
}
 
Example #9
Source File: PubSubBroker.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public synchronized List<String> recvMessages(String address, int numMessages) {
    Queue<Message> queue = queues.get(address);
    if (queue == null) {
        return null;
    }
    List<String> messages = new ArrayList<>();
    while (numMessages > 0) {
        Message message = queue.poll();
        if (message == null) {
            throw new RuntimeException("No more messages, " + numMessages + " remains");
        }
        messages.add((String)((AmqpValue)message.getBody()).getValue());
        numMessages--;
    }
    return messages;
}
 
Example #10
Source File: AMQPPersisterTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private MessageImpl createProtonMessage(String address, byte[] content) {
   MessageImpl message = (MessageImpl) Proton.message();

   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 9));

   Properties properties = new Properties();
   properties.setCreationTime(new Date(System.currentTimeMillis()));
   properties.setTo(address);
   properties.setMessageId(UUID.randomUUID());

   MessageAnnotations annotations = new MessageAnnotations(new LinkedHashMap<>());
   ApplicationProperties applicationProperties = new ApplicationProperties(new LinkedHashMap<>());

   AmqpValue body = new AmqpValue(Arrays.copyOf(content, content.length));

   message.setHeader(header);
   message.setMessageAnnotations(annotations);
   message.setProperties(properties);
   message.setApplicationProperties(applicationProperties);
   message.setBody(body);

   return message;
}
 
Example #11
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertMapMessageToAmqpMessageWithByteArrayValueInBody() throws Exception {
   final byte[] byteArray = new byte[]{1, 2, 3, 4, 5};

   ServerJMSMapMessage outbound = createMapMessage();
   outbound.setBytes("bytes", byteArray);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof AmqpValue);
   assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Map);

   @SuppressWarnings("unchecked")
   Map<Object, Object> amqpMap = (Map<Object, Object>) ((AmqpValue) amqp.getBody()).getValue();

   assertEquals(1, amqpMap.size());
   Binary readByteArray = (Binary) amqpMap.get("bytes");
   assertNotNull(readByteArray);
}
 
Example #12
Source File: MessagingEndpointTest.java    From enmasse with Apache License 2.0 6 votes vote down vote up
void doTestSendReceiveOutsideCluster(String host, int port, String address, boolean tls, boolean verifyHost, String caCert) throws Exception {
    ProtonClientOptions protonClientOptions = new ProtonClientOptions();
    if (tls) {
        protonClientOptions.setSsl(true);
        if (!verifyHost) {
            protonClientOptions.setHostnameVerificationAlgorithm("");
        }
        if (caCert != null) {
            protonClientOptions.setTrustOptions(new PemTrustOptions()
                    .addCertValue(Buffer.buffer(caCert)));
        }
    }
    AmqpClient client = resourceManager.getAmqpClientFactory().createClient(new AmqpConnectOptions()
            .setSaslMechanism("ANONYMOUS")
            .setQos(ProtonQoS.AT_LEAST_ONCE)
            .setEndpoint(new Endpoint(host, port))
            .setProtonClientOptions(protonClientOptions)
            .setTerminusFactory(new QueueTerminusFactory()));

    assertEquals(1, client.sendMessages(address, Collections.singletonList("hello")).get(1, TimeUnit.MINUTES));
    var result = client.recvMessages(address, 1).get();
    assertEquals(1, result.size());
    assertEquals("hello", ((AmqpValue) result.get(0).getBody()).getValue());
}
 
Example #13
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testPersistentSetFromMessageWithNonDefaultValue() throws Exception {
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setDurable(true);
    message.setBody(new AmqpValue("test"));

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass());
    assertEquals(DeliveryMode.PERSISTENT, jmsMessage.getJMSDeliveryMode());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass());
    assertTrue(facade.isPersistent());
}
 
Example #14
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleConversionText() throws Exception {
   Map<String, Object> mapprop = createPropertiesMap();
   ApplicationProperties properties = new ApplicationProperties(mapprop);
   MessageImpl message = (MessageImpl) Message.Factory.create();
   message.setApplicationProperties(properties);

   String text = "someText";
   message.setBody(new AmqpValue(text));

   AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message);

   ICoreMessage serverMessage = encodedMessage.toCore();

   ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
   textMessage.decode();

   verifyProperties(textMessage);

   assertEquals(text, textMessage.getText());
}
 
Example #15
Source File: DeferredSettlementTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private Delivery sendMessageToClient(String deliveryTag, int messageBody)
{
    byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);

    Message m = Proton.message();
    m.setBody(new AmqpValue(messageBody));

    byte[] encoded = new byte[BUFFER_SIZE];
    int len = m.encode(encoded, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Sender serverSender = getServer().getSender();
    Delivery serverDelivery = serverSender.delivery(tag);
    int sent = serverSender.send(encoded, 0, len);

    assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);

    boolean senderAdvanced = serverSender.advance();
    assertTrue("sender has not advanced", senderAdvanced);

    return serverDelivery;
}
 
Example #16
Source File: ProtonClientTest.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testNonAnonymousSenderDoesNotEnforceMessageHasAddress(TestContext context) {
  Async async = context.async();
  connect(context, connection -> {
    connection.open();
    ProtonSender sender = connection.createSender(MockServer.Addresses.drop.toString());
    sender.open();

    Message messageWithNoAddress = Proton.message();
    messageWithNoAddress.setBody(new AmqpValue("bodyString"));

    sender.send(messageWithNoAddress);
    connection.disconnect();
    async.complete();
  });
}
 
Example #17
Source File: AmqpTypedObjectDelegate.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
public void setObject(Serializable value) throws IOException {
    if (value == null) {
        parent.setBody(NULL_OBJECT_BODY);
        encodedBody = null;
    } else if (isSupportedAmqpValueObjectType(value)) {
        // Exchange the incoming body value for one that is created from encoding
        // and decoding the value. Save the bytes for subsequent getObject and
        // copyInto calls to use.
        encodedBody = AmqpCodec.encode(new AmqpValue(value));
        Section decodedBody = AmqpCodec.decode(encodedBody);

        // This step requires a heavy-weight operation of both encoding and decoding the
        // incoming body value in order to create a copy such that changes to the original
        // do not affect the stored value, and also verifies we can actually encode it at all
        // now instead of later during send. In the future it makes sense to try to enhance
        // proton such that we can encode the body and use those bytes directly on the
        // message as it is being sent.

        parent.setBody(decodedBody);
    } else {
        // TODO: Data and AmqpSequence?
        throw new IllegalArgumentException("Encoding this object type with the AMQP type system is not supported: " + value.getClass().getName());
    }
}
 
Example #18
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertMapMessageToAmqpMessage() throws Exception {
   ServerJMSMapMessage outbound = createMapMessage();
   outbound.setString("property-1", "string");
   outbound.setInt("property-2", 1);
   outbound.setBoolean("property-3", true);
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof AmqpValue);
   assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Map);

   @SuppressWarnings("unchecked")
   Map<Object, Object> amqpMap = (Map<Object, Object>) ((AmqpValue) amqp.getBody()).getValue();

   assertEquals(3, amqpMap.size());
   assertTrue("string".equals(amqpMap.get("property-1")));
}
 
Example #19
Source File: MessageTransformationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testHeaderButNoPropertiesEncodeDecode() throws Exception {
   MessageImpl incomingMessage = (MessageImpl) Proton.message();

   incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
   incomingMessage.setDurable(true);

   ICoreMessage core = encodeAndCreateAMQPMessage(incomingMessage).toCore();
   AMQPMessage outboudMessage = AMQPConverter.getInstance().fromCore(core, null);

   assertNotNull(outboudMessage.getHeader());

   Section body = outboudMessage.getBody();
   assertNotNull(body);
   assertTrue(body instanceof AmqpValue);
   assertTrue(((AmqpValue) body).getValue() instanceof String);
}
 
Example #20
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class<? extends Destination> expectedClass)
   throws Exception {

   String toAddress = "toAddress";
   MessageImpl message = (MessageImpl) Message.Factory.create();
   message.setBody(new AmqpValue("myTextMessageContent"));
   message.setAddress(toAddress);
   if (toTypeAnnotationValue != null) {
      Map<Symbol, Object> map = new HashMap<>();
      map.put(Symbol.valueOf("x-opt-to-type"), toTypeAnnotationValue);
      MessageAnnotations ma = new MessageAnnotations(map);
      message.setMessageAnnotations(ma);
   }

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());
   assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage);
}
 
Example #21
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertStreamMessageToAmqpMessageWithAmqpValueBody() throws Exception {
   ServerJMSStreamMessage outbound = createStreamMessage();
   outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_VALUE_LIST);
   outbound.writeBoolean(false);
   outbound.writeString("test");
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof AmqpValue);

   AmqpValue list = (AmqpValue) amqp.getBody();

   @SuppressWarnings("unchecked")
   List<Object> amqpList = (List<Object>) list.getValue();

   assertEquals(2, amqpList.size());
}
 
Example #22
Source File: CredentialsMessageFilterTest.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Verifies that a message that does not contain a message-id nor correlation-id
 * does not pass the filter.
 */
@Test
public void testVerifyFailsForMissingCorrelationId() {

    // GIVEN a message with an unsupported subject
    final Message msg = ProtonHelper.message();
    msg.setReplyTo("reply");
    msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD));
    msg.setContentType("application/json");

    // WHEN receiving the message via a link with any tenant
    final boolean filterResult = CredentialsMessageFilter.verify(target, msg);

    // THEN message validation fails
    assertFalse(filterResult);
}
 
Example #23
Source File: ProtonClientTest.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testAnonymousSenderEnforcesMessageHasAddress(TestContext context) {
  Async async = context.async();
  connect(context, connection -> {
    connection.open();
    ProtonSender sender = connection.createSender(null);
    sender.open();

    Message messageWithNoAddress = Proton.message();
    messageWithNoAddress.setBody(new AmqpValue("bodyString"));
    try {
      sender.send(messageWithNoAddress);
      context.fail("Send should have thrown IAE due to lack of message address");
    } catch (IllegalArgumentException iae) {
      // Expected
      connection.disconnect();
      async.complete();
    }
  });
}
 
Example #24
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertMapMessageToAmqpMessageWithNoBody() throws Exception {
   ServerJMSMapMessage outbound = createMapMessage();
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof AmqpValue);
   assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Map);
}
 
Example #25
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleConversionMap() throws Exception {
   Map<String, Object> mapprop = createPropertiesMap();
   ApplicationProperties properties = new ApplicationProperties(mapprop);
   MessageImpl message = (MessageImpl) Message.Factory.create();
   message.setApplicationProperties(properties);

   Map<String, Object> mapValues = new HashMap<>();
   mapValues.put("somestr", "value");
   mapValues.put("someint", Integer.valueOf(1));

   message.setBody(new AmqpValue(mapValues));

   AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message);

   ICoreMessage serverMessage = encodedMessage.toCore();
   serverMessage.getReadOnlyBodyBuffer();

   ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
   mapMessage.decode();

   verifyProperties(mapMessage);

   assertEquals(1, mapMessage.getInt("someint"));
   assertEquals("value", mapMessage.getString("somestr"));

   AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage(), null);
   assertNotNull(newAMQP.getBody());
}
 
Example #26
Source File: AMQPMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the AMQP Section that composes the body of this message by decoding a
 * fresh copy from the encoded message data.  Changes to the returned value are not
 * reflected in the value encoded in the original message.
 *
 * @return the Section that makes up the body of this message.
 */
public final Section getBody() {
   ensureScanning();

   // We only handle Sections of AmqpSequence, AmqpValue and Data types so we filter on those.
   // There could also be a Footer and no body so this will prevent a faulty return type in case
   // of no body or message type we don't handle.
   return scanForMessageSection(Math.max(0, remainingBodyPosition), AmqpSequence.class, AmqpValue.class, Data.class);
}
 
Example #27
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that an amqp-value body containing a null results in an TextMessage when not
 * otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateTextMessageFromAmqpValueWithNull() throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   message.setBody(new AmqpValue(null));

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());

   assertNotNull("Message should not be null", jmsMessage);
   assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass());
}
 
Example #28
Source File: AmqpJmsMapMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithEmptyMap() throws Exception {
    Message message = Message.Factory.create();
    message.setBody(new AmqpValue(new HashMap<String, Object>()));

    AmqpJmsMapMessageFacade amqpMapMessageFacade = createReceivedMapMessageFacade(createMockAmqpConsumer(), message);

    // Should be able to use the message, e.g clearing it and adding to it.
    amqpMapMessageFacade.clearBody();
    amqpMapMessageFacade.put("entry", "value");
}
 
Example #29
Source File: LinkTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private Delivery receiveMessageFromServer(String deliveryTag, String messageContent)
{
    Delivery delivery = getClient().connection.getWorkHead();

    assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag()));
    assertEquals("The received delivery should be on our receiver",
                        getClient().receiver, delivery.getLink());

    assertNull(delivery.getLocalState());
    assertNull(delivery.getRemoteState());

    assertFalse(delivery.isPartial());
    assertTrue(delivery.isReadable());

    byte[] received = new byte[BUFFER_SIZE];
    int len = getClient().receiver.recv(received, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Message m = Proton.message();
    m.decode(received, 0, len);

    Object messageBody = ((AmqpValue)m.getBody()).getValue();
    assertEquals("Unexpected message content", messageContent, messageBody);

    boolean receiverAdvanced = getClient().receiver.advance();
    assertTrue("receiver has not advanced", receiverAdvanced);

    return delivery;
}
 
Example #30
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpandNoReencode() throws Exception {

   Map<String, Object> mapprop = createPropertiesMap();
   ApplicationProperties properties = new ApplicationProperties(mapprop);
   properties.getValue().put("hello", "hello");
   MessageImpl message = (MessageImpl) Message.Factory.create();
   MessageAnnotations annotations = new MessageAnnotations(new HashMap<>());
   message.setMessageAnnotations(annotations);
   message.setApplicationProperties(properties);

   String text = "someText";
   message.setBody(new AmqpValue(text));

   AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message);
   TypedProperties extraProperties = new TypedProperties();
   encodedMessage.setAddress(SimpleString.toSimpleString("xxxx.v1.queue"));

   for (int i = 0; i < 100; i++) {
      encodedMessage.setMessageID(333L);
      if (i % 3 == 0) {
         encodedMessage.referenceOriginalMessage(encodedMessage, "SOME-OTHER-QUEUE-DOES-NOT-MATTER-WHAT");
      } else {
         encodedMessage.referenceOriginalMessage(encodedMessage, "XXX");
      }
      encodedMessage.putStringProperty("another " + i, "value " + i);
      encodedMessage.messageChanged();
      if (i % 2 == 0) {
         encodedMessage.setAddress("THIS-IS-A-BIG-THIS-IS-A-BIG-ADDRESS-THIS-IS-A-BIG-ADDRESS-RIGHT");
      } else {
         encodedMessage.setAddress("A"); // small address
      }
      encodedMessage.messageChanged();
      ICoreMessage coreMessage = encodedMessage.toCore();
   }
}