use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testLimitWithoutOffset.
@Test
public void testLimitWithoutOffset() {
int numberOfTestObjects = 3;
for (int i = 0; i < numberOfTestObjects; i++) {
final String name = "test-" + i;
ConfiguredObject object = createCO(new HashMap<String, Object>() {
{
put("name", name);
}
});
_objects.add(object);
}
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "1", "0");
assertQueryResults(new Object[][] { { "test-0" } }, _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "1", "1");
assertQueryResults(new Object[][] { { "test-1" } }, _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "1", "3");
assertQueryResults(new Object[0][1], _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "-1", "1");
assertQueryResults(new Object[][] { { "test-1" }, { "test-2" } }, _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "-1", "-4");
assertQueryResults(new Object[][] { { "test-0" }, { "test-1" }, { "test-2" } }, _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "-1", "-2");
assertQueryResults(new Object[][] { { "test-1" }, { "test-2" } }, _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", "invalidLimit", "invalidOffset");
assertQueryResults(new Object[][] { { "test-0" }, { "test-1" }, { "test-2" } }, _query.getResults());
_query = new ConfiguredObjectQuery(_objects, "name", null, "name", null, null);
assertQueryResults(new Object[][] { { "test-0" }, { "test-1" }, { "test-2" } }, _query.getResults());
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testSelectClause_NonExistingColumn.
@Test
public void testSelectClause_NonExistingColumn() {
ConfiguredObject obj = createCO(new HashMap<String, Object>() {
{
put(ConfiguredObject.ID, UUID.randomUUID());
}
});
_objects.add(obj);
_query = new ConfiguredObjectQuery(_objects, "foo", null);
List<List<Object>> results = _query.getResults();
assertEquals("Unexpected number of results", (long) 1, (long) results.size());
assertEquals("Unexpected headers", Collections.singletonList("foo"), _query.getHeaders());
assertEquals("Unexpected row", Collections.singletonList(null), results.get(0));
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testSelectClause.
@Test
public void testSelectClause() {
final UUID objectUuid = UUID.randomUUID();
ConfiguredObject obj = createCO(new HashMap<String, Object>() {
{
put(ConfiguredObject.ID, objectUuid);
put(NUMBER_ATTR, 1234);
}
});
_objects.add(obj);
_query = new ConfiguredObjectQuery(_objects, String.format("%s,%s", ConfiguredObject.ID, NUMBER_ATTR), null);
List<List<Object>> results = _query.getResults();
assertEquals("Unexpected number of results", (long) 1, (long) results.size());
final List<String> headers = _query.getHeaders();
assertEquals("Unexpected headers", Lists.newArrayList(ConfiguredObject.ID, NUMBER_ATTR), headers);
final Iterator<List<Object>> iterator = results.iterator();
List<Object> row = iterator.next();
assertEquals("Unexpected row", Lists.newArrayList(objectUuid, 1234), row);
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testNoClauses_SingleResult.
@Test
public void testNoClauses_SingleResult() {
final UUID objectUuid = UUID.randomUUID();
final String objectName = "obj1";
ConfiguredObject obj1 = createCO(new HashMap<String, Object>() {
{
put(ConfiguredObject.ID, objectUuid);
put(ConfiguredObject.NAME, objectName);
}
});
_objects.add(obj1);
_query = new ConfiguredObjectQuery(_objects, null, null);
final List<String> headers = _query.getHeaders();
assertEquals("Unexpected headers", Lists.newArrayList(ConfiguredObject.ID, ConfiguredObject.NAME), headers);
List<List<Object>> results = _query.getResults();
assertEquals("Unexpected number of results", (long) 1, (long) results.size());
List<Object> row = results.iterator().next();
assertEquals("Unexpected row", Lists.newArrayList(objectUuid, objectName), row);
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testSingleOrderByClause.
@Test
public void testSingleOrderByClause() {
final int NUMBER_OF_OBJECTS = 3;
for (int i = 0; i < NUMBER_OF_OBJECTS; ++i) {
final int foo = (i + 1) % NUMBER_OF_OBJECTS;
ConfiguredObject object = createCO(new HashMap<String, Object>() {
{
put("foo", foo);
}
});
_objects.add(object);
}
ConfiguredObject object = createCO(new HashMap<String, Object>() {
{
put("foo", null);
}
});
_objects.add(object);
List<List<Object>> results;
_query = new ConfiguredObjectQuery(_objects, "foo", null, "foo ASC");
results = _query.getResults();
assertQueryResults(new Object[][] { { null }, { 0 }, { 1 }, { 2 } }, results);
_query = new ConfiguredObjectQuery(_objects, "foo", null, "foo DESC");
results = _query.getResults();
assertQueryResults(new Object[][] { { 2 }, { 1 }, { 0 }, { null } }, results);
// if not specified order should be ASC
_query = new ConfiguredObjectQuery(_objects, "foo", null, "foo");
results = _query.getResults();
assertQueryResults(new Object[][] { { null }, { 0 }, { 1 }, { 2 } }, results);
}
Aggregations