Search in sources :

Example 56 with NameClassPair

use of javax.naming.NameClassPair in project wildfly by wildfly.

the class ServiceBasedNamingStoreTestCase method testList.

@Test
public void testList() throws Exception {
    final Object value = new Object();
    bindObject(ServiceName.JBOSS.append("TestBean"), value);
    bindObject(ServiceName.JBOSS.append("foo", "TestBean"), value);
    bindObject(ServiceName.JBOSS.append("foo", "bar", "TestBean"), value);
    bindObject(ServiceName.JBOSS.append("foo", "bar", "baz", "TestBean"), value);
    store.add(ServiceName.JBOSS.append("foos", "bar"));
    store.add(ServiceName.JBOSS.append("fo", "bar"));
    store.add(ServiceName.JBOSS.append("foo", "ba", "baz"));
    store.add(ServiceName.JBOSS.append("foo", "bart", "baz"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "ba"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "bazt"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "art"));
    store.add(ServiceName.JBOSS.append("other", "one"));
    List<NameClassPair> list = store.list(new CompositeName(""));
    assertEquals(5, list.size());
    assertContains(list, "TestBean", Object.class);
    assertContains(list, "foo", Context.class);
    assertContains(list, "fo", Context.class);
    assertContains(list, "foos", Context.class);
    assertContains(list, "other", Context.class);
    list = store.list(new CompositeName("foo"));
    assertEquals(4, list.size());
    assertContains(list, "TestBean", Object.class);
    assertContains(list, "ba", Context.class);
    assertContains(list, "bart", Context.class);
    assertContains(list, "bar", Context.class);
}
Also used : NameClassPair(javax.naming.NameClassPair) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 57 with NameClassPair

use of javax.naming.NameClassPair in project wildfly by wildfly.

the class NamingContextTestCase method testList.

@Test
@SuppressWarnings("unchecked")
public void testList() throws Exception {
    bindList();
    NamingEnumeration<NameClassPair> results = namingContext.list(new CompositeName());
    checkListResults(results);
    // the same with security permissions
    results = (NamingEnumeration<NameClassPair>) testActionPermission(JndiPermission.ACTION_LIST, namingContext, null);
    checkListResults(results);
}
Also used : NameClassPair(javax.naming.NameClassPair) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 58 with NameClassPair

use of javax.naming.NameClassPair in project wildfly by wildfly.

the class InMemoryNamingStoreTestCase method testList.

@Test
public void testList() throws Exception {
    final Name name = new CompositeName("test");
    final Object object = new Object();
    nameStore.bind(name, object, Object.class);
    final Name nameTwo = new CompositeName("testTwo");
    final Object objectTwo = new Object();
    nameStore.bind(nameTwo, objectTwo, Object.class);
    final Name nameThree = new CompositeName("testThree");
    final Object objectThree = new Object();
    nameStore.bind(nameThree, objectThree, Object.class);
    nameStore.bind(new CompositeName("testContext/test"), "test");
    final List<NameClassPair> results = nameStore.list(new CompositeName());
    assertEquals(4, results.size());
    final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
    for (NameClassPair result : results) {
        final String resultName = result.getName();
        if ("test".equals(resultName) || "testTwo".equals(resultName) || "testThree".equals(resultName)) {
            assertEquals(Object.class.getName(), result.getClassName());
        } else if ("testContext".equals(resultName)) {
            assertEquals(Context.class.getName(), result.getClassName());
        } else {
            fail("Unknown result name: " + resultName);
        }
        expected.remove(resultName);
    }
    assertTrue("Not all expected results were returned", expected.isEmpty());
}
Also used : NameClassPair(javax.naming.NameClassPair) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with NameClassPair

use of javax.naming.NameClassPair in project aries by apache.

the class ServiceRegistryContextTest method checkServiceListList.

@Test
public void checkServiceListList() throws NamingException {
    BundleMock mock = new BundleMock("scooby.doo", new Properties());
    Thread.currentThread().setContextClassLoader(mock.getClassLoader());
    InitialContext ctx = new InitialContext();
    String className = Runnable.class.getName();
    Runnable t = Skeleton.newMock(Runnable.class);
    // we don't want the default service
    reg.unregister();
    ServiceRegistration reg = bc.registerService(className, t, null);
    ServiceRegistration reg2 = bc.registerService(className, new Thread(), null);
    NamingEnumeration<NameClassPair> ne = ctx.list("osgi:servicelist/" + className);
    assertTrue(ne.hasMoreElements());
    NameClassPair ncp = ne.nextElement();
    assertEquals(String.valueOf(reg.getReference().getProperty(Constants.SERVICE_ID)), ncp.getName());
    assertTrue("Class name not correct. Was: " + ncp.getClassName(), ncp.getClassName().contains("Proxy"));
    assertTrue(ne.hasMoreElements());
    ncp = ne.nextElement();
    assertEquals(String.valueOf(reg2.getReference().getProperty(Constants.SERVICE_ID)), ncp.getName());
    assertEquals("Class name not correct.", Thread.class.getName(), ncp.getClassName());
    assertFalse(ne.hasMoreElements());
}
Also used : NameClassPair(javax.naming.NameClassPair) BundleMock(org.apache.aries.mocks.BundleMock) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 60 with NameClassPair

use of javax.naming.NameClassPair in project pentaho-kettle by pentaho.

the class LDAPConnection method getPaths.

@SuppressWarnings("rawtypes")
private void getPaths(String rootName, Map<String, Attributes> childs, List<String> paths) throws Exception {
    NamingEnumeration ne = getInitialContext().list(rootName);
    while (ne.hasMore()) {
        NameClassPair nameCP = (NameClassPair) ne.next();
        childs.put(nameCP.getName() + "," + rootName, getInitialContext().getAttributes(nameCP.getName() + "," + rootName));
        getPaths(nameCP.getName() + "," + rootName, childs, paths);
        paths.add(nameCP.getName() + "," + rootName);
    }
}
Also used : NameClassPair(javax.naming.NameClassPair) NamingEnumeration(javax.naming.NamingEnumeration)

Aggregations

NameClassPair (javax.naming.NameClassPair)60 NamingException (javax.naming.NamingException)28 DirContext (javax.naming.directory.DirContext)19 Test (org.junit.Test)17 HashSet (java.util.HashSet)13 Context (javax.naming.Context)11 InitialContext (javax.naming.InitialContext)10 Hashtable (java.util.Hashtable)9 NamingEnumeration (javax.naming.NamingEnumeration)8 InitialDirContext (javax.naming.directory.InitialDirContext)8 IOException (java.io.IOException)7 FileNotFoundException (java.io.FileNotFoundException)5 HashMap (java.util.HashMap)5 Vector (java.util.Vector)5 Resource (org.apache.naming.resources.Resource)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 CompositeName (javax.naming.CompositeName)4 File (java.io.File)3