use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.
the class MessageOperationExecutorTest method mockDefaultGetResponse.
private GetResponse mockDefaultGetResponse() {
GetResponse response = mock(GetResponse.class);
when(response.getEnvelope()).thenReturn(DEFAULT_ENVELOPE);
when(response.getProps()).thenReturn(DEFAULT_BASIC_PROPERTIES);
when(response.getBody()).thenReturn(DEFAULT_PAYLOAD);
return response;
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.
the class MessageOperationExecutorTest method shouldRetrieveMessageFromQueueAndNackWithRequeuWhenChecksumDoesNotMatch.
@Test
public void shouldRetrieveMessageFromQueueAndNackWithRequeuWhenChecksumDoesNotMatch() throws Exception {
GetResponse response = mockDefaultGetResponse();
when(channel.basicGet(DEFAULT_QUEUE_NAME, false)).thenReturn(response);
try {
sut.consumeMessageApplyFunctionAndAckknowlegeOnSuccess(DEFAULT_BROKER_NAME, DEFAULT_QUEUE_NAME, "invalidChecksum", function);
fail();
} catch (MessageOperationFailedException e) {
}
verify(channel).basicNack(DEFAULT_DELIVERY_TAG, false, true);
verify(function, never()).apply(any(Channel.class), any(GetResponse.class));
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.
the class MessageOperationExecutorTest method shouldThrowExceptionWhenNackCannotBeSentAfterChecksumMatchFailed.
@Test
public void shouldThrowExceptionWhenNackCannotBeSentAfterChecksumMatchFailed() throws Exception {
GetResponse getResponse = mockDefaultGetResponse();
when(channel.basicGet(DEFAULT_QUEUE_NAME, false)).thenReturn(getResponse);
when(messageChecksum.createFor(DEFAULT_BASIC_PROPERTIES, DEFAULT_PAYLOAD)).thenReturn(DEFAULT_CHECKSUM);
IOException expectedException = new IOException();
doThrow(expectedException).when(channel).basicNack(DEFAULT_DELIVERY_TAG, false, true);
try {
sut.consumeMessageApplyFunctionAndAckknowlegeOnSuccess(DEFAULT_BROKER_NAME, DEFAULT_QUEUE_NAME, "invalidMessage", function);
} catch (MessageOperationFailedException e) {
assertSame(expectedException, e.getCause());
}
verify(messageChecksum).createFor(DEFAULT_BASIC_PROPERTIES, DEFAULT_PAYLOAD);
verify(channel).basicGet(DEFAULT_QUEUE_NAME, false);
verify(channel).basicNack(DEFAULT_DELIVERY_TAG, false, true);
verifyNoMoreInteractions(channel);
verify(function, never()).apply(any(Channel.class), any(GetResponse.class));
}
use of com.rabbitmq.client.GetResponse 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));
}
use of com.rabbitmq.client.GetResponse 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));
}
Aggregations