Search in sources :

Example 1 with AttributeValue

use of org.opends.server.types.AttributeValue in project midpoint by Evolveum.

the class OpenDJController method assertAttribute.

public static void assertAttribute(Entry response, String name, String... values) {
    List<Attribute> attrs = response.getAttribute(name.toLowerCase());
    if (attrs == null || attrs.size() == 0) {
        if (values.length == 0) {
            return;
        } else {
            AssertJUnit.fail("Attribute " + name + " does not have any value");
        }
    }
    assertEquals("Too many \"attributes\" for " + name + ": ", 1, attrs.size());
    Attribute attribute = response.getAttribute(name.toLowerCase()).get(0);
    if (values.length != attribute.size()) {
        AssertJUnit.fail("Wrong number of values for attribute " + name + ", expected " + values.length + " values but got " + attribute.size() + " values: " + attribute);
    }
    for (String value : values) {
        boolean found = false;
        Iterator<AttributeValue> iterator = attribute.iterator();
        List<String> attrVals = new ArrayList<String>();
        while (iterator.hasNext()) {
            AttributeValue attributeValue = iterator.next();
            String attrVal = attributeValue.toString();
            attrVals.add(attrVal);
            if (attrVal.equals(value)) {
                found = true;
            }
        }
        if (!found) {
            AssertJUnit.fail("Attribute " + name + " does not contain value " + value + ", it has values: " + attrVals);
        }
    }
}
Also used : AttributeValue(org.opends.server.types.AttributeValue) Attribute(org.opends.server.types.Attribute) ArrayList(java.util.ArrayList) ByteString(org.opends.server.types.ByteString)

Example 2 with AttributeValue

use of org.opends.server.types.AttributeValue in project midpoint by Evolveum.

the class OpenDJController method getAttributeValues.

public static Collection<String> getAttributeValues(Entry response, String name) {
    List<Attribute> attrs = response.getAttribute(name.toLowerCase());
    if (attrs == null || attrs.size() == 0) {
        return null;
    }
    assertEquals("Too many attributes for name " + name + ": ", 1, attrs.size());
    Attribute attribute = attrs.get(0);
    Collection<String> values = new ArrayList<String>(attribute.size());
    Iterator<AttributeValue> iterator = attribute.iterator();
    while (iterator.hasNext()) {
        AttributeValue attributeValue = iterator.next();
        values.add(attributeValue.getValue().toString());
    }
    return values;
}
Also used : AttributeValue(org.opends.server.types.AttributeValue) Attribute(org.opends.server.types.Attribute) ArrayList(java.util.ArrayList) ByteString(org.opends.server.types.ByteString)

Example 3 with AttributeValue

use of org.opends.server.types.AttributeValue in project midpoint by Evolveum.

the class OpenDJController method toHumanReadableLdifoid.

public String toHumanReadableLdifoid(Entry entry) {
    StringBuilder sb = new StringBuilder();
    sb.append("dn: ").append(entry.getDN()).append("\n");
    for (Attribute attribute : entry.getAttributes()) {
        for (AttributeValue val : attribute) {
            sb.append(attribute.getName());
            sb.append(": ");
            sb.append(val);
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : AttributeValue(org.opends.server.types.AttributeValue) Attribute(org.opends.server.types.Attribute)

Aggregations

Attribute (org.opends.server.types.Attribute)3 AttributeValue (org.opends.server.types.AttributeValue)3 ArrayList (java.util.ArrayList)2 ByteString (org.opends.server.types.ByteString)2