Search in sources :

Example 21 with NameClassPair

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

the class JndiTest method assertNameClassPair.

private void assertNameClassPair(NamingEnumeration<NameClassPair> namingEnumeration) {
    assertNotNull("namingEnumeration", namingEnumeration);
    Map<String, String> map = new HashMap<String, String>();
    while (namingEnumeration.hasMoreElements()) {
        NameClassPair pair = namingEnumeration.nextElement();
        map.put(pair.getName(), pair.getClassName());
    }
    assertTrue("OrangeRemote", map.containsKey("OrangeRemote"));
    assertTrue("AppleRemote", map.containsKey("AppleRemote"));
    assertTrue("PeachRemote", map.containsKey("PeachRemote"));
    assertTrue("PearRemote", map.containsKey("PearRemote"));
    assertTrue("PlumRemote", map.containsKey("PlumRemote"));
}
Also used : HashMap(java.util.HashMap) NameClassPair(javax.naming.NameClassPair)

Example 22 with NameClassPair

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

the class IvmContextTest method testListContextListsAllFederatedContextBindings.

public void testListContextListsAllFederatedContextBindings() throws SystemException, NamingException {
    // mimic logic from EnterpriseBeanBuilder.build, create compJndiContext and bind in it module, app, global
    Context compContext = new IvmContext();
    compContext.bind("java:comp/env/dummy", "dummy");
    Context moduleContext = new IvmContext();
    moduleContext.bind("module/env/test", String.class);
    moduleContext.bind("module/env/sub/test2", String.class);
    Context originalModuleSubContext = (IvmContext) moduleContext.lookup("module");
    compContext.bind("module", originalModuleSubContext);
    Context referencedModuleEnvSubContext = (IvmContext) compContext.lookup("module/env");
    NamingEnumeration<NameClassPair> referencedEnvLookupResult = referencedModuleEnvSubContext.list("");
    boolean testFound = false;
    boolean subFound = false;
    while (referencedEnvLookupResult.hasMore()) {
        String currentName = referencedEnvLookupResult.next().getName();
        if ("test".equals(currentName)) {
            testFound = true;
        } else if ("sub".equals(currentName)) {
            subFound = true;
        } else {
            fail();
        }
    }
    assertTrue(testFound);
    assertTrue(subFound);
}
Also used : Context(javax.naming.Context) NameClassPair(javax.naming.NameClassPair)

Example 23 with NameClassPair

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

the class NameClassPairEnumeration method writeExternal.

@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    // write out the version of the serialized data for future use
    out.writeByte(1);
    out.writeInt(list.size());
    for (final NameClassPair pair : list) {
        out.writeObject(pair.getName());
        out.writeObject(pair.getClassName());
    }
}
Also used : NameClassPair(javax.naming.NameClassPair)

Example 24 with NameClassPair

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

the class BlueprintURLContextTest method testList.

/**
 * Validate that list() function works for BlueprintURLContext.
 * This returns an enumeration of component id -> component class name pairs
 */
@Test
public void testList() throws Exception {
    InitialContext ctx = new InitialContext();
    NamingEnumeration<NameClassPair> compList = ctx.list("blueprint:comp");
    Set<String> expectedCompIds = new BlueprintContainerStub().getComponentIds();
    while (compList.hasMore()) {
        NameClassPair ncp = compList.next();
        String compId = ncp.getName();
        String compClass = ncp.getClassName();
        if (compId.equals("comp1")) {
            assertEquals("comp1 class wrong in list", SimpleComponent.class.getName(), compClass);
        } else if (compId.equals("comp2")) {
            assertEquals("comp2 class wrong in list", AnotherComponent.class.getName(), compClass);
        }
        expectedCompIds.remove(compId);
    }
    assertEquals("Not all expected components were found", expectedCompIds.size(), 0);
}
Also used : NameClassPair(javax.naming.NameClassPair) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 25 with NameClassPair

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

the class ServiceRegistryContextTest method listRepositoryContents.

/**
 * This test checks that we can list the contents of the repository using the
 * list method
 *
 * @throws NamingException
 */
public void listRepositoryContents() throws NamingException {
    InitialContext ctx = new InitialContext();
    NamingEnumeration<NameClassPair> serviceList = ctx.list("osgi:service/java.lang.Runnable/(rubbish=smelly)");
    checkThreadRetrievedViaListMethod(serviceList);
    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
    // Now add a second service
    registerService(new Thread());
    serviceList = ctx.list("osgi:service/java.lang.Runnable/(rubbish=smelly)");
    checkThreadRetrievedViaListMethod(serviceList);
    checkThreadRetrievedViaListMethod(serviceList);
    assertFalse("The repository contained more objects than we expected", serviceList.hasMoreElements());
}
Also used : NameClassPair(javax.naming.NameClassPair) InitialContext(javax.naming.InitialContext)

Aggregations

NameClassPair (javax.naming.NameClassPair)59 NamingException (javax.naming.NamingException)27 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 Resource (org.apache.naming.resources.Resource)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Vector (java.util.Vector)4 CompositeName (javax.naming.CompositeName)4 File (java.io.File)3