Search in sources :

Example 1 with ConfiguredObjectAttribute

use of org.apache.qpid.server.model.ConfiguredObjectAttribute 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"));
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry) Model(org.apache.qpid.server.model.Model) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ConfiguredObjectAttribute

use of org.apache.qpid.server.model.ConfiguredObjectAttribute 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;
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) Model(org.apache.qpid.server.model.Model) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectMethodAttribute(org.apache.qpid.server.model.ConfiguredObjectMethodAttribute) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry)

Example 3 with ConfiguredObjectAttribute

use of org.apache.qpid.server.model.ConfiguredObjectAttribute in project qpid-broker-j by apache.

the class ApiDocsServlet method writeAttributesTable.

private void writeAttributesTable(final PrintWriter writer, final Collection<ConfiguredObjectAttribute<?, ?>> attributeTypes) {
    writer.println("<table class=\"attributes\">");
    writer.println("<thead>");
    writer.println("<tr><th class=\"name\">Attribute Name</th><th class=\"type\">Type</th><th class=\"properties\">Properties</th><th class=\"description\">Description</th></tr>");
    writer.println("</thead>");
    writer.println("<tbody>");
    for (ConfiguredObjectAttribute attribute : attributeTypes) {
        String properties;
        if (attribute instanceof ConfiguredSettableAttribute) {
            ConfiguredSettableAttribute settableAttribute = (ConfiguredSettableAttribute) attribute;
            if (settableAttribute.isImmutable()) {
                properties = "read/settable on create only";
            } else {
                properties = "read/write";
            }
        } else {
            properties = "read only";
        }
        writer.println("<tr><td class=\"name\">" + attribute.getName() + "</td><td class=\"type\">" + renderType(attribute) + "</td><td class=\"properties\">" + properties + "</td><td class=\"description\">" + attribute.getDescription() + "</td></tr>");
    }
    writer.println("</tbody>");
    writer.println("</table>");
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) ConfiguredSettableAttribute(org.apache.qpid.server.model.ConfiguredSettableAttribute)

Example 4 with ConfiguredObjectAttribute

use of org.apache.qpid.server.model.ConfiguredObjectAttribute in project qpid-broker-j by apache.

the class MetaDataServlet method processAttributes.

private Map<String, Map> processAttributes(final Class<? extends ConfiguredObject> type, final Model model) {
    Collection<ConfiguredObjectAttribute<?, ?>> attributes = model.getTypeRegistry().getAttributeTypes(type).values();
    Map<String, Map> attributeDetails = new LinkedHashMap<>();
    for (ConfiguredObjectAttribute<?, ?> attribute : attributes) {
        Map<String, Object> attrDetails = new LinkedHashMap<>();
        attrDetails.put("type", attribute.getType().getSimpleName());
        if (!"".equals(attribute.getDescription())) {
            attrDetails.put("description", attribute.getDescription());
        }
        if (attribute.isDerived()) {
            attrDetails.put("derived", attribute.isDerived());
        }
        if (!attribute.isDerived()) {
            ConfiguredSettableAttribute automatedAttribute = (ConfiguredSettableAttribute) attribute;
            if (!"".equals(automatedAttribute.defaultValue())) {
                attrDetails.put("defaultValue", automatedAttribute.defaultValue());
            }
            if (automatedAttribute.isMandatory()) {
                attrDetails.put("mandatory", automatedAttribute.isMandatory());
            }
            if (automatedAttribute.isImmutable()) {
                attrDetails.put("immutable", automatedAttribute.isImmutable());
            }
            if (!(automatedAttribute.validValues()).isEmpty()) {
                Collection<String> validValues = ((ConfiguredSettableAttribute<?, ?>) attribute).validValues();
                Collection<Object> convertedValues = new ArrayList<>(validValues.size());
                for (String value : validValues) {
                    convertedValues.add(((ConfiguredSettableAttribute<?, ?>) attribute).convert(value, null));
                }
                attrDetails.put("validValues", convertedValues);
            } else if (!"".equals(automatedAttribute.validValuePattern())) {
                attrDetails.put("validValuesPattern", automatedAttribute.validValuePattern());
            }
        }
        if (attribute.isSecure()) {
            attrDetails.put("secure", attribute.isSecure());
        }
        if (attribute.isOversized()) {
            attrDetails.put("oversize", attribute.isOversized());
        }
        attributeDetails.put(attribute.getName(), attrDetails);
    }
    return attributeDetails;
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ConfiguredSettableAttribute(org.apache.qpid.server.model.ConfiguredSettableAttribute) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ManagedObject(org.apache.qpid.server.model.ManagedObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 5 with ConfiguredObjectAttribute

use of org.apache.qpid.server.model.ConfiguredObjectAttribute 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"));
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry) Model(org.apache.qpid.server.model.Model) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConfiguredObjectAttribute (org.apache.qpid.server.model.ConfiguredObjectAttribute)7 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 ConfiguredObjectTypeRegistry (org.apache.qpid.server.model.ConfiguredObjectTypeRegistry)5 Model (org.apache.qpid.server.model.Model)5 ConfiguredSettableAttribute (org.apache.qpid.server.model.ConfiguredSettableAttribute)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Set (java.util.Set)2 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 ConfiguredObjectMethodAttribute (org.apache.qpid.server.model.ConfiguredObjectMethodAttribute)1 ManagedObject (org.apache.qpid.server.model.ManagedObject)1 Protocol (org.apache.qpid.server.model.Protocol)1 ProtocolType (org.apache.qpid.server.model.Protocol.ProtocolType)1