當前位置: 首頁>>代碼示例>>Java>>正文


Java NamingManager.setInitialContextFactoryBuilder方法代碼示例

本文整理匯總了Java中javax.naming.spi.NamingManager.setInitialContextFactoryBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Java NamingManager.setInitialContextFactoryBuilder方法的具體用法?Java NamingManager.setInitialContextFactoryBuilder怎麽用?Java NamingManager.setInitialContextFactoryBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.spi.NamingManager的用法示例。


在下文中一共展示了NamingManager.setInitialContextFactoryBuilder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {

    // container.enableInterfaceMocking(true);
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder());
    }
    InitialContext initialContext = new InitialContext();
    Properties properties = new Properties();
    properties.put("mail.smtp.from", "[email protected]");
    mailMock = Session.getInstance(properties);
    initialContext.bind("java:openejb/Resource/" + DEFAULT_MAIL_RESOURCE, mailMock);
    configurationService = mock(APPConfigurationServiceBean.class);
    commService = spy(new APPCommunicationServiceBean());
    commService.configService = configurationService;
    doNothing().when(commService).transportMail(
            Matchers.any(MimeMessage.class));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:APPCommunicationServiceBeanTest.java

示例2: activate

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Register the context builder by registering it with the JNDI NamingManager.
 * Note that once this has been done, {@code new InitialContext()} will always
 * return a context from this factory. Use the {@code emptyActivatedContextBuilder()}
 * static method to get an empty context (for example, in test methods).
 * @throws IllegalStateException if there's already a naming context builder
 * registered with the JNDI NamingManager
 */
public void activate() throws IllegalStateException, NamingException {
	logger.info("Activating simple JNDI environment");
	synchronized (initializationLock) {
		if (!initialized) {
			if (NamingManager.hasInitialContextFactoryBuilder()) {
				throw new IllegalStateException(
						"Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " +
						"Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " +
						"with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.");
			}
			NamingManager.setInitialContextFactoryBuilder(this);
			initialized = true;
		}
	}
	activated = this;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:SimpleNamingContextBuilder.java

示例3: activate

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Register the context builder by registering it with the JNDI NamingManager.
 * Note that once this has been done, {@code new InitialContext()} will always
 * return a context from this factory. Use the {@code emptyActivatedContextBuilder()}
 * static method to get an empty context (for example, in test methods).
 * @throws IllegalStateException if there's already a naming context builder
 * registered with the JNDI NamingManager
 */
public void activate() throws IllegalStateException, NamingException {
  logger.info("Activating simple JNDI environment");
  synchronized (initializationLock) {
    if (!initialized) {
      if (NamingManager.hasInitialContextFactoryBuilder()) {
        throw new IllegalStateException(
            "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " +
                "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " +
                "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.");
      }
      NamingManager.setInitialContextFactoryBuilder(this);
      initialized = true;
    }
  }
  activated = this;
}
 
開發者ID:tzolov,項目名稱:springboot-gemfire-jpa-atomikos,代碼行數:25,代碼來源:SimpleNamingContextBuilder.java

示例4: setup

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {

    // container.enableInterfaceMocking(true);
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder());
    }
    InitialContext initialContext = new InitialContext();
    Properties properties = new Properties();
    properties.put("mail.from", "[email protected]");
    mailMock = Session.getInstance(properties);
    initialContext.bind("mail/BSSMail", mailMock);
    configurationService = mock(APPConfigurationServiceBean.class);
    commService = spy(new APPCommunicationServiceBean());
    commService.configService = configurationService;
    doNothing().when(commService).transportMail(
            Matchers.any(MimeMessage.class));
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:20,代碼來源:APPCommunicationServiceBeanTest.java

示例5: testHandleTimer_doHandleControllerProvisioning_bug11449

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Test
public void testHandleTimer_doHandleControllerProvisioning_bug11449()
        throws Exception {
    // given
    ServiceInstance instance = new ServiceInstance();
    instance.setInstanceId("123");
    instance.setSubscriptionId("subscriptionId");
    instance.setControllerId("ess.vmware");
    instance.setProvisioningStatus(ProvisioningStatus.WAITING_FOR_SYSTEM_CREATION);
    InstanceStatus status = new InstanceStatus();
    status.setIsReady(false);

    when(
            controller.getInstanceStatus(anyString(),
                    any(ProvisioningSettings.class))).thenReturn(status);
    doNothing().when(besDAOMock).notifyOnProvisioningStatusUpdate(
            any(ServiceInstance.class), anyListOf(LocalizedText.class));
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder());
    }
    InitialContext context = new InitialContext();
    context.bind(APPlatformController.JNDI_PREFIX + "ess.vmware",
            controller);

    // when
    timerService.doHandleControllerProvisioning(instance);

    // then
    verify(em, times(1)).refresh(any(ServiceInstance.class));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:32,代碼來源:APPTimerServiceBeanTest.java

示例6: start

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Override
public void start(BundleContext bundleContext) throws Exception {

    try {
        NamingManager.setInitialContextFactoryBuilder(new DefaultContextFactoryBuilder());
        NamingManager.setObjectFactoryBuilder(new DefaultObjectFactoryBuilder());

        Dictionary<String, String> propertyMap = new Hashtable<>();
        propertyMap.put(JNDIConstants.JNDI_URLSCHEME, "java");
        bundleContext.registerService(ObjectFactory.class, new JavaURLContextFactory(), propertyMap);

        //register osgi url scheme
        Dictionary<String, String> osgiPropertyMap = new Hashtable<>();
        osgiPropertyMap.put(JNDIConstants.JNDI_URLSCHEME, "osgi");
        bundleContext.registerService(ObjectFactory.class.getName(),
                new OSGiURLContextServiceFactory(), osgiPropertyMap);

        // InitialContextFactory Provider should be registered with its implementation class as well as the
        // InitialContextFactory class.
        bundleContext.registerService(InitialContextFactory.class, new InMemoryInitialContextFactory(), null);

        logger.debug("Registering JNDIContextManager OSGi service.");
        bundleContext.registerService(JNDIContextManager.class, new JNDIContextManagerServiceFactory(), null);
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
    }
}
 
開發者ID:wso2,項目名稱:carbon-jndi,代碼行數:28,代碼來源:JNDIActivator.java

示例7: beforeClass

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
    URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties");
    configuration = new PropertiesConfiguration(sqlProperties);
    if (!configuration.containsKey("jdbc.url")) {
        throw new IllegalArgumentException(String.format("SqlGraph configuration requires that the %s be set", "jdbc.url"));
    }

    String url = configuration.getString("jdbc.url");
    //obtain the connection that we will later supply from JNDI
    SqlgPlugin p = findSqlgPlugin(url);
    Assert.assertNotNull(p);
    ds = new C3p0DataSourceFactory().setup(p.getDriverFor(url), configuration).getDatasource();
    //change the connection url to be a JNDI one
    configuration.setProperty("jdbc.url", "jndi:testConnection");

    //set up the initial context
    NamingManager.setInitialContextFactoryBuilder(environment -> {
        InitialContextFactory mockFactory = mock(InitialContextFactory.class);
        Context mockContext = mock(Context.class);
        when(mockFactory.getInitialContext(any())).thenReturn(mockContext);

        when(mockContext.lookup("testConnection")).thenReturn(ds);

        return mockFactory;
    });
}
 
開發者ID:pietermartin,項目名稱:sqlg,代碼行數:28,代碼來源:TestJNDIInitialization.java

示例8: myTestSetInitialContextFactoryBuilder_SetNull

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Set the initial context factory builder to null.
 * 
 */
public void myTestSetInitialContextFactoryBuilder_SetNull()
		throws NamingException {
	log.setMethod("myTestSetInitialContextFactoryBuilder_SetNull");
	NamingManager.setInitialContextFactoryBuilder(null);
	assertFalse(NamingManager.hasInitialContextFactoryBuilder());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:11,代碼來源:NamingManagerBuilderTest.java

示例9: myTestSetInitialContextFactoryBuilder_SetNormal

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Set the initial context factory builder to a mock instance.
 * 
 */
public void myTestSetInitialContextFactoryBuilder_SetNormal()
		throws NamingException {
	log.setMethod("myTestSetInitialContextFactoryBuilder_SetNormal");
	InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
			.getInstance();
	NamingManager.setInitialContextFactoryBuilder(contextFactoryBuilder);
	assertTrue(NamingManager.hasInitialContextFactoryBuilder());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:13,代碼來源:NamingManagerBuilderTest.java

示例10: myTestSetInitialContextFactoryBuilder_ResetNormal

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Reset the initial context factory builder to another mock instance.
 * 
 */
public void myTestSetInitialContextFactoryBuilder_ResetNormal()
		throws NamingException {
	log.setMethod("myTestSetInitialContextFactoryBuilder_ResetNormal");
	try {
		NamingManager
				.setInitialContextFactoryBuilder(new MockInitialContextFactoryBuilder());
		fail("Reset initialContextFactoryBuilder is forbidden!");
	} catch (IllegalStateException e) {
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:15,代碼來源:NamingManagerBuilderTest.java

示例11: myTestSetInitialContextFactoryBuilder_ResetSame

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Reset the initial context factory builder to the same mock instance.
 * 
 */
public void myTestSetInitialContextFactoryBuilder_ResetSame()
		throws NamingException {
	log.setMethod("myTestSetInitialContextFactoryBuilder_ResetSame");
	try {
		NamingManager
				.setInitialContextFactoryBuilder(MockInitialContextFactoryBuilder
						.getInstance());
		fail("Reset initialContextFactoryBuilder is forbidden!");
	} catch (IllegalStateException e) {
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:16,代碼來源:NamingManagerBuilderTest.java

示例12: myTestSetInitialContextFactoryBuilder_ResetNull

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Reset the initial context factory builder to null.
 * 
 */
public void myTestSetInitialContextFactoryBuilder_ResetNull()
		throws NamingException {
	log.setMethod("myTestSetInitialContextFactoryBuilder_ResetNull");
	try {
		NamingManager.setInitialContextFactoryBuilder(null);
		fail("Reset initialContextFactoryBuilder to null is forbidden!");
	} catch (IllegalStateException e) {
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:14,代碼來源:NamingManagerBuilderTest.java

示例13: testFactoryBuilder

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testFactoryBuilder() throws IllegalStateException,
		SecurityException, NamingException {
	// log.setMethod("testFactoryBuilder");

	if (!NamingManager.hasInitialContextFactoryBuilder()) {
		InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
				.getInstance();
		NamingManager
				.setInitialContextFactoryBuilder(contextFactoryBuilder);
	}

	Hashtable<Object, Object> env = new Hashtable<Object, Object>();
	env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");

	MyInitialContext context = new MyInitialContext(env);
	// log.log(context.getEnvironment().toString());
	// log.log("DefaultContext:" +
	// context.getDefaultContext().getClass().getName());
	//
	Context urlContext = NamingManager.getURLContext("http", env);
	assertEquals("http", urlContext.getEnvironment().get("url.schema"));

	String name = "http://www.apache.org";
	String obj = "String object";
	context.bind(name, obj);

	assertNull(InvokeRecord.getLatestUrlSchema());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:29,代碼來源:NamingManagerExploreTest.java

示例14: testFactoryBuilder_name

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testFactoryBuilder_name() throws IllegalStateException,
		SecurityException, NamingException {
	// log.setMethod("testFactoryBuilder_name");

	if (!NamingManager.hasInitialContextFactoryBuilder()) {
		InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
				.getInstance();
		NamingManager
				.setInitialContextFactoryBuilder(contextFactoryBuilder);
	}

	Hashtable<Object, Object> env = new Hashtable<Object, Object>();
	env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");

	MyInitialContext context = new MyInitialContext(env);
	// log.log(context.getEnvironment().toString());
	// log.log("DefaultContext:" +
	// context.getDefaultContext().getClass().getName());
	//
	Context urlContext = NamingManager.getURLContext("http", env);
	assertEquals("http", urlContext.getEnvironment().get("url.schema"));

	Name name = new CompositeName("http://www.apache.org");
	String obj = "Name object";
	context.bind(name, obj);

	assertNull(InvokeRecord.getLatestUrlSchema());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:29,代碼來源:NamingManagerExploreTest.java

示例15: enableJndiMock

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Tries to register a mocked <code>NamingContextFactoryBuilder</code> to
 * enable basic JNDI functionality in the test code.
 * 
 * @throws NamingException
 * @see {@link TestNamingContext}
 */
protected static void enableJndiMock() throws NamingException {
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder(PERSISTENCE));
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:14,代碼來源:BaseAdmUmTest.java


注:本文中的javax.naming.spi.NamingManager.setInitialContextFactoryBuilder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。