use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.
the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationFails.
public void testPublishContentHeaderWhenMessageAuthorizationFails() throws Exception {
final String impostorId = "impostor";
doThrow(new AccessControlException("fail")).when(_amqConnection).checkAuthorizedMessagePrincipal(eq(impostorId));
when(_virtualHost.getDefaultDestination()).thenReturn(mock(MessageDestination.class));
when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {
@Override
public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
return messageHandle;
}
});
int channelId = 1;
AMQChannel channel = new AMQChannel(_amqConnection, channelId, _virtualHost.getMessageStore());
BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
properties.setUserId(impostorId);
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, AMQShortString.EMPTY_STRING, false, false);
channel.receiveMessageHeader(properties, 0);
verify(_amqConnection).sendConnectionClose(eq(ErrorCodes.ACCESS_REFUSED), anyString(), eq(channelId));
verifyZeroInteractions(_messageDestination);
}
use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.
the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationSucceeds.
public void testPublishContentHeaderWhenMessageAuthorizationSucceeds() throws Exception {
when(_virtualHost.getDefaultDestination()).thenReturn(_messageDestination);
when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {
@Override
public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
return messageHandle;
}
});
final ArgumentCaptor<ServerMessage> messageCaptor = ArgumentCaptor.forClass(ServerMessage.class);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
ServerMessage message = messageCaptor.getValue();
return new RoutingResult(message);
}
}).when(_messageDestination).route(messageCaptor.capture(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
properties.setUserId(_amqConnection.getAuthorizedPrincipal().getName());
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, ROUTING_KEY, false, false);
channel.receiveMessageHeader(properties, 0);
verify(_messageDestination).route((ServerMessage) any(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
}
use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.
the class MessageMetaDataFactoryTest method createTestMessageMetaData.
private MessageMetaData createTestMessageMetaData() {
final MessagePublishInfo publishBody = new MessagePublishInfo(_exchange, false, false, _routingKey);
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
props.setContentType(CONTENT_TYPE);
final ContentHeaderBody contentHeaderBody = new ContentHeaderBody(props);
return new MessageMetaData(publishBody, contentHeaderBody, _arrivalTime);
}
use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.
the class PropertyConverter_v0_8_to_InternalTest method testContentEncodingConversion.
public void testContentEncodingConversion() {
String contentEncoding = "my-test-encoding";
BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setEncoding(contentEncoding);
final AMQMessage originalMessage = createTestMessage(header);
InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("Unexpected content encoding", contentEncoding, convertedMessage.getMessageHeader().getEncoding());
}
use of org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties in project qpid-broker-j by apache.
the class PropertyConverter_v0_8_to_InternalTest method testHeadersConversion.
public void testHeadersConversion() {
Map<String, Object> properties = new HashMap<>();
properties.put("testProperty1", "testProperty1Value");
properties.put("intProperty", 1);
BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setHeaders(FieldTable.convertToFieldTable(properties));
final AMQMessage originalMessage = createTestMessage(header);
final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
final Map<String, Object> headers = convertedMessage.getMessageHeader().getHeaderMap();
assertEquals("Unexpected headers", properties, new HashMap<>(headers));
}
Aggregations