use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testQuery_EnumEquality.
public void testQuery_EnumEquality() {
final UUID objectUuid = UUID.randomUUID();
ConfiguredObject obj = createCO(new HashMap<String, Object>() {
{
put(ConfiguredObject.ID, objectUuid);
put(ENUM_ATTR, Snakes.PYTHON);
put(ENUM2_ATTR, Snakes.PYTHON);
}
});
_objects.add(obj);
_query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("%s = '%s'", ENUM_ATTR, Snakes.PYTHON));
List<List<Object>> results = _query.getResults();
assertEquals("Unexpected number of results - enumAttr equality with enum constant", 1, results.size());
List<Object> row = _query.getResults().iterator().next();
assertEquals("Unexpected row", objectUuid, row.get(0));
_query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("'%s' = %s", Snakes.PYTHON, ENUM_ATTR));
results = _query.getResults();
assertEquals("Unexpected number of results - enum constant equality with enumAttr", 1, results.size());
row = _query.getResults().iterator().next();
assertEquals("Unexpected row", objectUuid, row.get(0));
_query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("%s <> '%s'", ENUM_ATTR, "toad"));
results = _query.getResults();
assertEquals("Unexpected number of results - enumAttr not equal enum constant", 1, results.size());
_query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("%s = %s", ENUM_ATTR, ENUM2_ATTR));
results = _query.getResults();
assertEquals("Unexpected number of results - two attributes of type enum", 1, results.size());
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQueryTest method testSelectClause.
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", 1, 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 ConfiguredObjectToMapConverterTest method createTestModel.
private Model createTestModel() {
Model model = mock(Model.class);
final List<Class<? extends ConfiguredObject>> list = new ArrayList<Class<? extends ConfiguredObject>>();
list.add(TestChild.class);
when(model.getChildTypes(ConfiguredObject.class)).thenReturn(list);
final ConfiguredObjectTypeRegistry typeRegistry = mock(ConfiguredObjectTypeRegistry.class);
final Map<String, ConfiguredObjectAttribute<?, ?>> attrTypes = mock(Map.class);
when(attrTypes.get(any(String.class))).thenReturn(mock(ConfiguredObjectMethodAttribute.class));
when(typeRegistry.getAttributeTypes(any(Class.class))).thenReturn(attrTypes);
when(model.getTypeRegistry()).thenReturn(typeRegistry);
return model;
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ConfiguredObjectQuery method filterObjects.
private List<ConfiguredObject<?>> filterObjects(final List<ConfiguredObject<?>> objects, final String whereClause) {
List<ConfiguredObject<?>> filteredObjects = new ArrayList<>();
ConfiguredObjectFilterParser parser = new ConfiguredObjectFilterParser();
parser.setConfiguredObjectExpressionFactory(_expressionFactory);
try {
final BooleanExpression<ConfiguredObject> expression = parser.parseWhere(whereClause);
for (ConfiguredObject<?> object : objects) {
try {
if (expression.matches(object)) {
filteredObjects.add(object);
}
} catch (RuntimeException e) {
throw new EvaluationException("Error while evaluating object against where clause", e);
}
}
} catch (ParseException | TokenMgrError e) {
throw new SelectorParsingException("Unable to parse where clause", e);
}
return filteredObjects;
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class AbstractServlet method getConfiguredObjectFinder.
protected final ConfiguredObjectFinder getConfiguredObjectFinder(final ConfiguredObject<?> root) {
ConfiguredObjectFinder finder = _configuredObjectFinders.get(root);
if (finder == null) {
finder = new ConfiguredObjectFinder(root);
final ConfiguredObjectFinder existingValue = _configuredObjectFinders.putIfAbsent(root, finder);
if (existingValue != null) {
finder = existingValue;
} else {
final AbstractConfigurationChangeListener deletionListener = new AbstractConfigurationChangeListener() {
@Override
public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
if (newState == State.DELETED) {
_configuredObjectFinders.remove(root);
}
}
};
root.addChangeListener(deletionListener);
if (root.getState() == State.DELETED) {
_configuredObjectFinders.remove(root);
root.removeChangeListener(deletionListener);
}
}
}
return finder;
}
Aggregations