use of org.apache.qpid.disttest.client.property.ListPropertyValue in project qpid-broker-j by apache.
the class JsonHandlerTest method testGeneratorDesrialization.
@Test
public void testGeneratorDesrialization() throws Exception {
String json = "{'_messageProperties': {'test': 1, 'generator': {'@def': 'list', '_cyclic': false, '_items': ['first', " + "{'@def': 'range', '_upper':10, '_type':'int'}]}}}";
final TestCommand unmarshalledCommand = _jsonHandler.unmarshall(json, TestCommand.class);
Map<String, PropertyValue> properties = unmarshalledCommand.getMessageProperties();
assertNotNull("Properties should not be null", properties);
assertFalse("Properties should not be empty", properties.isEmpty());
assertEquals("Unexpected properties size", (long) 2, (long) properties.size());
PropertyValue testProperty = properties.get("test");
assertNotNull("Unexpected property test", testProperty);
final boolean condition1 = testProperty.getValue() instanceof Number;
assertTrue("Unexpected property test", condition1);
assertEquals("Unexpected property value", (long) 1, (long) ((Number) testProperty.getValue()).intValue());
Object generatorObject = properties.get("generator");
final boolean condition = generatorObject instanceof ListPropertyValue;
assertTrue("Unexpected generator object : " + generatorObject, condition);
PropertyValue generator = (PropertyValue) generatorObject;
assertEquals("Unexpected generator value", "first", generator.getValue());
for (int i = 0; i < 10; i++) {
assertEquals("Unexpected generator value", Integer.valueOf(i), generator.getValue());
}
String newJson = _jsonHandler.marshall(unmarshalledCommand);
final TestCommand newUnmarshalledCommand = _jsonHandler.unmarshall(newJson, TestCommand.class);
assertEquals("Unmarshalled command should be equal to the original object", unmarshalledCommand, newUnmarshalledCommand);
}
use of org.apache.qpid.disttest.client.property.ListPropertyValue in project qpid-broker-j by apache.
the class MessageProviderTest method testNextMessageWithProperties.
@Test
public void testNextMessageWithProperties() throws Exception {
Map<String, PropertyValue> properties = new HashMap<String, PropertyValue>();
properties.put("test1", new SimplePropertyValue("testValue1"));
properties.put("test2", new SimplePropertyValue(Integer.valueOf(1)));
properties.put("priority", new SimplePropertyValue(Integer.valueOf(2)));
List<PropertyValue> listItems = new ArrayList<PropertyValue>();
listItems.add(new SimplePropertyValue(Double.valueOf(2.0)));
ListPropertyValue list = new ListPropertyValue();
list.setItems(listItems);
properties.put("test3", list);
MessageProvider messageProvider = new MessageProvider(properties);
CreateProducerCommand command = new CreateProducerCommand();
command.setMessageSize(100);
Message message = messageProvider.nextMessage(_session, command);
assertNotNull("Mesage should be returned", message);
verify(_message, atLeastOnce()).setText(isA(String.class));
verify(_message, atLeastOnce()).setJMSPriority(2);
verify(_message, atLeastOnce()).setStringProperty("test1", "testValue1");
verify(_message, atLeastOnce()).setIntProperty("test2", 1);
verify(_message, atLeastOnce()).setDoubleProperty("test3", 2.0);
}
Aggregations