/**
  * ************************************************************************* Create the entry in
  * the ldap directory for the given string
  *
  * @param attributes add all the attributes and values from the attributes object
  * @param string The string (dn) value
  *     ************************************************************************
  */
 public static DirContext createTest(DirContext dirContext, Attributes attributes, String string)
     throws NamingException {
   if (dirContext == null) {
     throw new NamingException(CONTEXT_IS_NULL);
   }
   return dirContext.createSubcontext(string, attributes);
 }
 public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
   ResolveResult res = getRootURLContext(name, myEnv);
   DirContext ctx = (DirContext) res.getResolvedObj();
   try {
     return ctx.createSubcontext(res.getRemainingName(), attrs);
   } finally {
     ctx.close();
   }
 }
 public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
   if (name.size() == 1) {
     return createSubcontext(name.get(0), attrs);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       return ctx.createSubcontext(name.getSuffix(1), attrs);
     } finally {
       ctx.close();
     }
   }
 }
Esempio n. 4
0
 /**
  * Create the attribute in the ldap directory for the given string.
  *
  * @param basicattributes add all the entry in to the basicattribute
  * @param string the string (dn) value
  */
 public void createTest(BasicAttributes basicattributes, String string) throws NamingException {
   // DirContext dc = //TODO perhaps return this?
   dirContext.createSubcontext(string, basicattributes);
 }
Esempio n. 5
0
  /*
   * Test for String get(String)
   */
  public void testGetString() throws Exception {
    DirContext ctx = contextFactory.getDirContext("people");
    assertNotNull(ctx);
    Attributes attrs = new BasicAttributes(true);
    ctx.createSubcontext("bar", attrs);
    DirContext dctx = (DirContext) ctx.lookup("bar");
    assertNotNull(dctx);
    Parameters parameters = new DirectoryParameters(dctx);
    assertEquals(parameters.getParameterNames().length, 0);
    assertEquals(parameters.get("foo", "foo"), "foo");
    try {
      parameters.get("foo");
      fail("should throw the exception");
    } catch (UndefinedParameterException e) {
      // ok!
    }
    parameters.add("foo", "bar");
    assertEquals(parameters.get("foo", "foo"), "bar");
    parameters.add("foo", "bar2");
    try {
      parameters.get("foo");
      fail("should throw the exception");
    } catch (AmbiguousParameterException e) {
      // ok!
    }
    assertEquals(parameters.getStrings("foo").length, 2);
    assertEquals(parameters.getStrings("bar").length, 0);
    assertEquals(parameters.getParameterNames().length, 1);
    assertEquals(parameters.isDefined("foo"), true);
    assertEquals(parameters.isDefined("bar"), false);
    parameters.add("bar", "foo");
    assertEquals(parameters.get("bar", "bar"), "foo");
    parameters.remove("bar");
    assertEquals(parameters.get("bar", "bar"), "bar");
    parameters.add("bar", "foo");
    assertEquals(parameters.get("bar", "bar"), "foo");
    parameters.remove("bar", "foo");
    assertEquals(parameters.get("bar", "bar"), "bar");
    parameters.remove();
    assertEquals(parameters.getParameterNames().length, 0);
    parameters.add("bar", "foo");
    parameters.add("foo", "bar");
    assertEquals(parameters.getParameterNames().length, 2);
    HashSet<String> set = new HashSet<String>();
    set.add("foo");
    parameters.remove(set);
    assertEquals(parameters.get("bar", "bar"), "foo");
    assertEquals(parameters.get("foo", "foo"), "foo");
    parameters.add("bar", "foo2");
    parameters.add("foo", "bar");
    parameters.removeExcept(set);
    assertEquals(parameters.get("bar", "bar"), "bar");
    assertEquals(parameters.get("foo", "foo"), "bar");
    parameters.remove();
    parameters.add("foo", new String[] {"bar"});
    parameters.add("foo", new String[] {"foo", "buz"});
    parameters.add("bar", new String[] {"foo"});
    assertEquals(parameters.getParameterNames().length, 2);
    assertEquals(parameters.getStrings("foo").length, 3);

    parameters.remove();
    Parameters temp = new DefaultParameters();
    temp.add("foo", 2);
    temp.add("bar", 2);
    parameters.add("foo", 1);
    parameters.add("bar", 1);
    parameters.add(temp, false);
    assertEquals(parameters.getInts("foo").length, 2);
    assertEquals(parameters.getInts("bar").length, 2);
    parameters.remove();
    parameters.add("foo", 1);
    parameters.add("bar", 1);
    parameters.add(temp, true);
    assertEquals(parameters.getInts("foo").length, 1);
    assertEquals(parameters.getInts("bar").length, 1);
    assertEquals(parameters.getInt("foo"), 2);
    assertEquals(parameters.getInt("bar"), 2);

    parameters.remove();
    parameters.add("foo", "bar");
    parameters.set("foo", "foo");
    assertEquals(parameters.get("foo", "bar"), "foo");
    parameters.set("foo", new String[] {"foo", "buz"});
    assertEquals(parameters.getStrings("foo").length, 2);
    parameters.set("foo", new boolean[] {true});
    assertEquals(parameters.getBoolean("foo"), true);
    parameters.set("foo", new float[] {1.0F, 2.0F});
    assertEquals(parameters.getStrings("foo").length, 2);
    parameters.set("foo", new int[] {1, 2});
    assertEquals(parameters.getStrings("foo").length, 2);
    parameters.set("foo", new long[] {1, 2});
    assertEquals(parameters.getStrings("foo").length, 2);
    parameters.toString();
    Parameters params = parameters.getChild("bar");
    assertEquals(params.getParameterNames().length, 0);
  }