use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParser.
@Test
public void testLdifParser() throws LdapLdifException, LdapInvalidAttributeValueException, IOException {
String ldif = "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n" + "envVars:";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
assertNotNull(entry);
Attribute attr = entry.get("cn");
assertTrue(attr.contains("app1"));
attr = entry.get("objectclass");
assertTrue(attr.contains("top"));
assertTrue(attr.contains("apApplication"));
attr = entry.get("displayname");
assertTrue(attr.contains("app1"));
attr = entry.get("dependencies");
assertEquals("", attr.get().getValue());
attr = entry.get("envvars");
assertEquals("", attr.get().getValue());
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifEmpty.
@Test
public void testLdifEmpty() throws LdapLdifException, IOException {
String ldif = "";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
assertEquals(0, entry.size());
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifAttributesReaderDirServer.
@Test
public void testLdifAttributesReaderDirServer() throws NamingException, Exception {
String ldif = "# -------------------------------------------------------------------\n" + "#\n" + "# Licensed to the Apache Software Foundation (ASF) under one\n" + "# or more contributor license agreements. See the NOTICE file\n" + "# distributed with this work for additional information\n" + "# regarding copyright ownership. The ASF licenses this file\n" + "# to you under the Apache License, Version 2.0 (the\n" + "# \"License\"); you may not use this file except in compliance\n" + "# with the License. You may obtain a copy of the License at\n" + "# \n" + "# http://www.apache.org/licenses/LICENSE-2.0\n" + "# \n" + "# Unless required by applicable law or agreed to in writing,\n" + "# software distributed under the License is distributed on an\n" + "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" + "# KIND, either express or implied. See the License for the\n" + "# specific language governing permissions and limitations\n" + "# under the License. \n" + "# \n" + "#\n" + "# EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" + "#\n" + "# http://www.rfc-editor.org/rfc/rfc2606.txt\n" + "#\n" + "# -------------------------------------------------------------------\n" + "\n" + "objectclass: top\n" + "objectclass: organizationalunit\n" + "ou: Users";
LdifAttributesReader reader = new LdifAttributesReader();
Attributes attributes = reader.parseAttributes(ldif);
javax.naming.directory.Attribute attr = attributes.get("objectclass");
assertTrue(attr.contains("top"));
assertTrue(attr.contains("organizationalunit"));
attr = attributes.get("ou");
assertTrue(attr.contains("Users"));
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParserRFC2849Sample3VariousSpacing.
@Test
public void testLdifParserRFC2849Sample3VariousSpacing() throws LdapLdifException, Exception {
String ldif = "objectclass:top\n" + "objectclass: person \n" + "objectclass:organizationalPerson\n" + "cn:Gern Jensen\n" + "cn:Gern O Jensen\n" + "sn:Jensen\n" + "uid:gernj\n" + "telephonenumber:+1 408 555 1212 \n" + "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu ";
LdifAttributesReader reader = new LdifAttributesReader();
Attributes attributes = reader.parseAttributes(ldif);
javax.naming.directory.Attribute attr = attributes.get("objectclass");
assertTrue(attr.contains("top"));
assertTrue(attr.contains("person"));
assertTrue(attr.contains("organizationalPerson"));
attr = attributes.get("cn");
assertTrue(attr.contains("Gern Jensen"));
assertTrue(attr.contains("Gern O Jensen"));
attr = attributes.get("sn");
assertTrue(attr.contains("Jensen"));
attr = attributes.get("uid");
assertTrue(attr.contains("gernj"));
attr = attributes.get("telephonenumber");
assertTrue(attr.contains("+1 408 555 1212"));
attr = attributes.get("description");
assertTrue(attr.contains("What a careful reader you are! This value is base-64-encoded because it has a control character in it (a CR).\r By the way, you should really get out more.".getBytes(StandardCharsets.UTF_8)));
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifVersionStart.
@Test
public void testLdifVersionStart() throws LdapLdifException, IOException {
String ldif = "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n" + "envVars:";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
assertEquals(1, reader.getVersion());
assertNotNull(entry);
Attribute attr = entry.get("displayname");
assertTrue(attr.contains("app1"));
reader.close();
}
Aggregations