Search in sources :

Example 1 with Attribute

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

the class OpenDJController method assertNoAttribute.

public static void assertNoAttribute(Entry response, String name) {
    List<Attribute> attrs = response.getAttribute(name.toLowerCase());
    if (attrs == null || attrs.size() == 0) {
        return;
    }
    assertEquals("Too many \"attributes\" for " + name + ": ", 1, attrs.size());
    Attribute attribute = response.getAttribute(name.toLowerCase()).get(0);
    if (attribute.size() == 0) {
        return;
    }
    if (attribute.isEmpty()) {
        return;
    }
    AssertJUnit.fail("Attribute " + name + " exists while not expecting it: " + attribute);
}
Also used : Attribute(org.opends.server.types.Attribute)

Example 2 with Attribute

use of org.opends.server.types.Attribute 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 3 with Attribute

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

the class OpenDJController method getAttributeValue.

public static String getAttributeValue(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);
    return getAttributeValue(attribute);
}
Also used : Attribute(org.opends.server.types.Attribute)

Example 4 with Attribute

use of org.opends.server.types.Attribute in project OpenAM by OpenRock.

the class EmbeddedSearchResultIterator method convertLDAPAttributeSetToMap.

static Map<String, Set<String>> convertLDAPAttributeSetToMap(List<Attribute> attributes) {
    Map<String, Set<String>> answer = null;
    if (CollectionUtils.isNotEmpty(attributes)) {
        for (Attribute attr : attributes) {
            if (attr != null) {
                Set<String> strValues = new HashSet<>();
                for (ByteString anAttr : attr) {
                    strValues.add(anAttr.toString());
                }
                if (answer == null) {
                    answer = new CaseInsensitiveHashMap<>(10);
                }
                answer.put(attr.getName(), strValues);
            }
        }
    }
    return (answer);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Attribute(org.opends.server.types.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) HashSet(java.util.HashSet)

Example 5 with Attribute

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

the class TestQuartzTaskManagerContract method assertAttribute.

protected void assertAttribute(SearchResultEntry response, String name, String value) {
    AssertJUnit.assertNotNull(response.getAttribute(name.toLowerCase()));
    AssertJUnit.assertEquals(1, response.getAttribute(name.toLowerCase()).size());
    Attribute attribute = response.getAttribute(name.toLowerCase()).get(0);
    AssertJUnit.assertEquals(value, attribute.iterator().next().getValue().toString());
}
Also used : Attribute(org.opends.server.types.Attribute)

Aggregations

Attribute (org.opends.server.types.Attribute)8 AttributeValue (org.opends.server.types.AttributeValue)3 ByteString (org.opends.server.types.ByteString)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ByteString (org.forgerock.opendj.ldap.ByteString)1