use of org.apache.qpid.server.model.ConfiguredObjectTypeRegistry in project qpid-broker-j by apache.
the class ConfiguredObjectToMapConverterTest method testOversizedAttributes.
public void testOversizedAttributes() {
Model model = createTestModel();
ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
final Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = typeRegistry.getAttributeTypes(TestChild.class);
final ConfiguredObjectAttribute longAttr = mock(ConfiguredObjectMethodAttribute.class);
when(longAttr.isOversized()).thenReturn(true);
when(longAttr.getOversizedAltText()).thenReturn("");
when(attributeTypes.get(eq("longAttr"))).thenReturn(longAttr);
TestChild mockChild = mock(TestChild.class);
when(mockChild.getModel()).thenReturn(model);
when(_configuredObject.getModel()).thenReturn(model);
configureMockToReturnOneAttribute(mockChild, "longAttr", "this is not long");
when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, new ConfiguredObjectToMapConverter.ConverterOptions(1, false, 20, false, false));
Object children = resultMap.get("testchilds");
assertNotNull(children);
assertTrue(children instanceof Collection);
assertTrue(((Collection) children).size() == 1);
Object attrs = ((Collection) children).iterator().next();
assertTrue(attrs instanceof Map);
assertEquals("this is not long", ((Map) attrs).get("longAttr"));
resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, new ConfiguredObjectToMapConverter.ConverterOptions(1, false, 8, false, false));
children = resultMap.get("testchilds");
assertNotNull(children);
assertTrue(children instanceof Collection);
assertTrue(((Collection) children).size() == 1);
attrs = ((Collection) children).iterator().next();
assertTrue(attrs instanceof Map);
assertEquals("this...", ((Map) attrs).get("longAttr"));
when(longAttr.getOversizedAltText()).thenReturn("test alt text");
resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, new ConfiguredObjectToMapConverter.ConverterOptions(1, false, 8, false, false));
children = resultMap.get("testchilds");
assertNotNull(children);
assertTrue(children instanceof Collection);
assertTrue(((Collection) children).size() == 1);
attrs = ((Collection) children).iterator().next();
assertTrue(attrs instanceof Map);
assertEquals("test alt text", ((Map) attrs).get("longAttr"));
}
use of org.apache.qpid.server.model.ConfiguredObjectTypeRegistry 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.ConfiguredObjectTypeRegistry in project qpid-broker-j by apache.
the class MetaDataServlet method processCategory.
private Map<String, Map> processCategory(final Class<? extends ConfiguredObject> clazz, final Model model) {
Map<String, Map> typeToDataMap = new TreeMap<>();
ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
for (Class<? extends ConfiguredObject> type : typeRegistry.getTypeSpecialisations(clazz)) {
typeToDataMap.put(ConfiguredObjectTypeRegistry.getType(type), processType(type, model));
}
return typeToDataMap;
}
use of org.apache.qpid.server.model.ConfiguredObjectTypeRegistry in project qpid-broker-j by apache.
the class ManagementNode method generateAttributeNames.
private List<String> generateAttributeNames(String entityType) {
Set<String> attrNameSet = new HashSet<>();
List<String> attributeNames = new ArrayList<>();
for (String standardAttribute : Arrays.asList(IDENTITY_ATTRIBUTE, TYPE_ATTRIBUTE, QPID_TYPE, OBJECT_PATH)) {
attrNameSet.add(standardAttribute);
attributeNames.add(standardAttribute);
}
final ConfiguredObjectTypeRegistry typeRegistry = _model.getTypeRegistry();
List<Class<? extends ConfiguredObject>> classes = new ArrayList<>();
if (entityType != null && !entityType.trim().equals("")) {
Class<? extends ConfiguredObject> clazz = _managedTypes.get(entityType);
if (clazz != null) {
classes.add(clazz);
if (ConfiguredObjectTypeRegistry.getCategory(clazz) == clazz) {
classes.addAll(_model.getTypeRegistry().getTypeSpecialisations(clazz));
}
}
} else {
for (Class<? extends ConfiguredObject> clazz : _managedCategories) {
classes.add(clazz);
classes.addAll(_model.getTypeRegistry().getTypeSpecialisations(clazz));
}
}
for (Class<? extends ConfiguredObject> clazz : classes) {
for (String name : typeRegistry.getAttributeNames(clazz)) {
if (!ConfiguredObject.ID.equals(name) && attrNameSet.add(name)) {
attributeNames.add(name);
}
}
final Class<? extends ConfiguredObject> category = ConfiguredObjectTypeRegistry.getCategory(clazz);
if (category != _managedObject.getCategoryClass() && !isSyntheticChildClass(category)) {
Class<? extends ConfiguredObject> parentType = _model.getParentType(category);
if (parentType != _managedObject.getCategoryClass()) {
attributeNames.add(parentType.getSimpleName().toLowerCase());
}
}
}
return attributeNames;
}
use of org.apache.qpid.server.model.ConfiguredObjectTypeRegistry in project qpid-broker-j by apache.
the class ConfiguredObjectToMapConverterTest method testSecureAttributes.
public void testSecureAttributes() {
Model model = createTestModel();
ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = typeRegistry.getAttributeTypes(TestChild.class);
ConfiguredObjectAttribute secureAttribute = mock(ConfiguredObjectMethodAttribute.class);
when(secureAttribute.isSecure()).thenReturn(true);
when(secureAttribute.isSecureValue(any())).thenReturn(true);
when(attributeTypes.get(eq("secureAttribute"))).thenReturn(secureAttribute);
TestChild mockChild = mock(TestChild.class);
when(mockChild.getModel()).thenReturn(model);
when(_configuredObject.getModel()).thenReturn(model);
// set encoded value
configureMockToReturnOneAttribute(mockChild, "secureAttribute", "*****");
// set actual values
when(mockChild.getActualAttributes()).thenReturn(Collections.singletonMap("secureAttribute", "secret"));
when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
when(model.getParentType(TestChild.class)).thenReturn((Class) TestChild.class);
when(_configuredObject.getCategoryClass()).thenReturn(TestChild.class);
when(mockChild.isDurable()).thenReturn(true);
Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, new ConfiguredObjectToMapConverter.ConverterOptions(1, false, 20, false, false));
Object children = resultMap.get("testchilds");
assertNotNull(children);
assertTrue(children instanceof Collection);
assertTrue(((Collection) children).size() == 1);
Object attrs = ((Collection) children).iterator().next();
assertTrue(attrs instanceof Map);
assertEquals("*****", ((Map) attrs).get("secureAttribute"));
resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, new ConfiguredObjectToMapConverter.ConverterOptions(1, true, 20, true, false));
children = resultMap.get("testchilds");
assertNotNull(children);
assertTrue(children instanceof Collection);
assertTrue(((Collection) children).size() == 1);
attrs = ((Collection) children).iterator().next();
assertTrue(attrs instanceof Map);
assertEquals("*****", ((Map) attrs).get("secureAttribute"));
}
Aggregations