Search in sources :

Example 1 with BasicProperties

use of de.gessnerfl.rabbitmq.queue.management.model.BasicProperties in project rabbitmq-queue-management by gessnerfl.

the class MessageMapperTest method shouldMapAmqpBasicProperties.

@Test
public void shouldMapAmqpBasicProperties() {
    String contentType = "contentType";
    String contentEncoding = "contentEncoding";
    String headerKey = "headerKey";
    String headerValue = "headerValue";
    Map<String, Object> headers = new HashMap<>();
    headers.put(headerKey, headerValue);
    Integer deliveryMode = 12;
    Integer priority = 13;
    String correlationId = "correlationId";
    String replyTo = "replyTo";
    String expiration = "expiration";
    String messageId = "messageId";
    Date timestamp = new Date();
    String type = "type";
    String userId = "userId";
    String appId = "appId";
    String clusterId = "clusterId";
    AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
    when(basicProperties.getContentType()).thenReturn(contentType);
    when(basicProperties.getContentEncoding()).thenReturn(contentEncoding);
    when(basicProperties.getHeaders()).thenReturn(headers);
    when(basicProperties.getDeliveryMode()).thenReturn(deliveryMode);
    when(basicProperties.getPriority()).thenReturn(priority);
    when(basicProperties.getCorrelationId()).thenReturn(correlationId);
    when(basicProperties.getReplyTo()).thenReturn(replyTo);
    when(basicProperties.getExpiration()).thenReturn(expiration);
    when(basicProperties.getMessageId()).thenReturn(messageId);
    when(basicProperties.getTimestamp()).thenReturn(timestamp);
    when(basicProperties.getType()).thenReturn(type);
    when(basicProperties.getUserId()).thenReturn(userId);
    when(basicProperties.getAppId()).thenReturn(appId);
    when(basicProperties.getClusterId()).thenReturn(clusterId);
    Envelope envelope = mock(Envelope.class);
    GetResponse getResponse = mockResponse(envelope, basicProperties);
    Message result = sut.map(getResponse);
    BasicProperties basicPropertiesOfResult = result.getProperties();
    assertNotNull(basicPropertiesOfResult);
    assertEquals(contentType, basicPropertiesOfResult.getContentType());
    assertEquals(contentEncoding, basicPropertiesOfResult.getContentEncoding());
    assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
    assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
    assertEquals(headerValue, basicPropertiesOfResult.getHeaders().get(headerKey));
    assertEquals(deliveryMode, basicPropertiesOfResult.getDeliveryMode());
    assertEquals(priority, basicPropertiesOfResult.getPriority());
    assertEquals(correlationId, basicPropertiesOfResult.getCorrelationId());
    assertEquals(replyTo, basicPropertiesOfResult.getReplyTo());
    assertEquals(expiration, basicPropertiesOfResult.getExpiration());
    assertEquals(messageId, basicPropertiesOfResult.getMessageId());
    assertEquals(timestamp, basicPropertiesOfResult.getTimestamp());
    assertEquals(type, basicPropertiesOfResult.getType());
    assertEquals(userId, basicPropertiesOfResult.getUserId());
    assertEquals(appId, basicPropertiesOfResult.getAppId());
    assertEquals(clusterId, basicPropertiesOfResult.getClusterId());
}
Also used : Message(de.gessnerfl.rabbitmq.queue.management.model.Message) AMQP(com.rabbitmq.client.AMQP) BasicProperties(de.gessnerfl.rabbitmq.queue.management.model.BasicProperties) LongString(com.rabbitmq.client.LongString) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 2 with BasicProperties

use of de.gessnerfl.rabbitmq.queue.management.model.BasicProperties in project rabbitmq-queue-management by gessnerfl.

the class MessageMapperTest method shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeadersDeepInMap.

@Test
public void shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeadersDeepInMap() {
    String headerKey = "headerKey";
    String subHeaderKey = "subHeaderKey";
    String subHeaderValue = "subHeaderValue";
    LongString longStringValue = mock(LongString.class);
    when(longStringValue.toString()).thenReturn(subHeaderValue);
    Map<String, Object> subHeaders = new HashMap<>();
    subHeaders.put(subHeaderKey, longStringValue);
    Map<String, Object> headers = new HashMap<>();
    headers.put(headerKey, subHeaders);
    AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
    when(basicProperties.getHeaders()).thenReturn(headers);
    Envelope envelope = mock(Envelope.class);
    GetResponse getResponse = mockResponse(envelope, basicProperties);
    Message result = sut.map(getResponse);
    BasicProperties basicPropertiesOfResult = result.getProperties();
    assertNotNull(basicPropertiesOfResult);
    assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
    assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
    assertThat(basicPropertiesOfResult.getHeaders().get(headerKey), Matchers.instanceOf(Map.class));
    assertThat(((Map<String, Object>) basicPropertiesOfResult.getHeaders().get(headerKey)).keySet(), Matchers.hasSize(1));
    assertThat(((Map<String, Object>) basicPropertiesOfResult.getHeaders().get(headerKey)), Matchers.hasKey(subHeaderKey));
    assertEquals(subHeaderValue, ((Map) basicPropertiesOfResult.getHeaders().get(headerKey)).get(subHeaderKey));
}
Also used : Message(de.gessnerfl.rabbitmq.queue.management.model.Message) AMQP(com.rabbitmq.client.AMQP) BasicProperties(de.gessnerfl.rabbitmq.queue.management.model.BasicProperties) LongString(com.rabbitmq.client.LongString) LongString(com.rabbitmq.client.LongString) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 3 with BasicProperties

use of de.gessnerfl.rabbitmq.queue.management.model.BasicProperties in project rabbitmq-queue-management by gessnerfl.

the class MessageMapperTest method shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeaders.

@Test
public void shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeaders() {
    String headerKey = "headerKey";
    String headerValue = "headerValue";
    LongString longStringValue = mock(LongString.class);
    when(longStringValue.toString()).thenReturn(headerValue);
    Map<String, Object> headers = new HashMap<>();
    headers.put(headerKey, longStringValue);
    AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
    when(basicProperties.getHeaders()).thenReturn(headers);
    Envelope envelope = mock(Envelope.class);
    GetResponse getResponse = mockResponse(envelope, basicProperties);
    Message result = sut.map(getResponse);
    BasicProperties basicPropertiesOfResult = result.getProperties();
    assertNotNull(basicPropertiesOfResult);
    assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
    assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
    assertEquals(headerValue, basicPropertiesOfResult.getHeaders().get(headerKey));
}
Also used : Message(de.gessnerfl.rabbitmq.queue.management.model.Message) AMQP(com.rabbitmq.client.AMQP) BasicProperties(de.gessnerfl.rabbitmq.queue.management.model.BasicProperties) LongString(com.rabbitmq.client.LongString) LongString(com.rabbitmq.client.LongString) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 4 with BasicProperties

use of de.gessnerfl.rabbitmq.queue.management.model.BasicProperties in project rabbitmq-queue-management by gessnerfl.

the class MessageMapperTest method shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeadersDeepInLists.

@Test
public void shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeadersDeepInLists() {
    String headerKey = "headerKey";
    String listValue = "listValue";
    List<String> list = Arrays.asList(listValue);
    Map<String, Object> headers = new HashMap<>();
    headers.put(headerKey, list);
    AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
    when(basicProperties.getHeaders()).thenReturn(headers);
    Envelope envelope = mock(Envelope.class);
    GetResponse getResponse = mockResponse(envelope, basicProperties);
    Message result = sut.map(getResponse);
    BasicProperties basicPropertiesOfResult = result.getProperties();
    assertNotNull(basicPropertiesOfResult);
    assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
    assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
    assertThat(basicPropertiesOfResult.getHeaders().get(headerKey), Matchers.instanceOf(List.class));
    assertThat(((List<String>) basicPropertiesOfResult.getHeaders().get(headerKey)), Matchers.hasSize(1));
    assertThat(((List<String>) basicPropertiesOfResult.getHeaders().get(headerKey)), Matchers.contains(listValue));
}
Also used : Message(de.gessnerfl.rabbitmq.queue.management.model.Message) AMQP(com.rabbitmq.client.AMQP) BasicProperties(de.gessnerfl.rabbitmq.queue.management.model.BasicProperties) LongString(com.rabbitmq.client.LongString) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 5 with BasicProperties

use of de.gessnerfl.rabbitmq.queue.management.model.BasicProperties in project rabbitmq-queue-management by gessnerfl.

the class MessageMapper method mapProperties.

private BasicProperties mapProperties(AMQP.BasicProperties input) {
    BasicProperties result = new BasicProperties();
    result.setContentType(input.getContentType());
    result.setContentEncoding(input.getContentEncoding());
    mapHeaders(input, result);
    result.setDeliveryMode(input.getDeliveryMode());
    result.setPriority(input.getPriority());
    result.setCorrelationId(input.getCorrelationId());
    result.setReplyTo(input.getReplyTo());
    result.setExpiration(input.getExpiration());
    result.setMessageId(input.getMessageId());
    result.setTimestamp(input.getTimestamp());
    result.setType(input.getType());
    result.setUserId(input.getUserId());
    result.setAppId(input.getAppId());
    result.setClusterId(input.getClusterId());
    return result;
}
Also used : BasicProperties(de.gessnerfl.rabbitmq.queue.management.model.BasicProperties)

Aggregations

BasicProperties (de.gessnerfl.rabbitmq.queue.management.model.BasicProperties)5 AMQP (com.rabbitmq.client.AMQP)4 Envelope (com.rabbitmq.client.Envelope)4 GetResponse (com.rabbitmq.client.GetResponse)4 LongString (com.rabbitmq.client.LongString)4 Message (de.gessnerfl.rabbitmq.queue.management.model.Message)4 Test (org.junit.Test)4