Search in sources :

Example 46 with ConfiguredObject

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());
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 47 with ConfiguredObject

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));
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 48 with ConfiguredObject

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);
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Test(org.junit.Test)

Example 49 with ConfiguredObject

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);
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Test(org.junit.Test)

Example 50 with ConfiguredObject

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);
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)117 ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)35 Test (org.junit.Test)33 Map (java.util.Map)29 List (java.util.List)27 LinkedHashMap (java.util.LinkedHashMap)25 UUID (java.util.UUID)21 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)21 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)15 Collection (java.util.Collection)12 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)12 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 State (org.apache.qpid.server.model.State)10 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 GenericLegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6