本文整理汇总了Java中javax.naming.InitialContext.bind方法的典型用法代码示例。如果您正苦于以下问题:Java InitialContext.bind方法的具体用法?Java InitialContext.bind怎么用?Java InitialContext.bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.InitialContext
的用法示例。
在下文中一共展示了InitialContext.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import javax.naming.InitialContext; //导入方法依赖的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));
}
示例2: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
public void setup(TestContainer container) throws Exception {
platformService = mock(APPlatformService.class);
enableJndiMock();
InitialContext context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
parameters = new HashMap<>();
configSettings = new HashMap<>();
settings = new ProvisioningSettings(parameters, configSettings, "en");
aws = Mockito.spy(new AWSController());
ec2mock = new EC2Mockup();
ec2 = ec2mock.getEC2();
EC2Communication.useMock(ec2);
PropertyHandler.useMock(null);
ec2mock.createDescribeImagesResult(IMAGE_ID);
ec2mock.createRunInstancesResult(INSTANCE_ID);
// new mock
ec2mock.createDescribeSubnetsResult(SUBNET);
ec2mock.createDescribeSecurityGroupResult(SUBNET, SECURITY_GROUP_NAMES);
ec2mock.createDescribeInstancesResult(INSTANCE_ID, "ok", "1.2.3.4");
}
示例3: getTestBean
import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
* Init and return testing bean
*/
private TemplateBean getTestBean() throws Exception {
InitialContext context = new InitialContext();
context.bind(APPTemplateService.JNDI_NAME, templateService);
templateService = new APPTemplateServiceMockup();
facesContext = Mockito.mock(FacesContext.class);
externalContext = Mockito.mock(ExternalContext.class);
httpSession = Mockito.mock(HttpSession.class);
application = Mockito.mock(Application.class);
controllerAccess = Mockito.mock(ControllerAccess.class);
viewRoot = Mockito.mock(UIViewRoot.class);
Mockito.when(facesContext.getExternalContext())
.thenReturn(externalContext);
Mockito.when(facesContext.getApplication()).thenReturn(application);
Mockito.when(externalContext.getSession(Matchers.anyBoolean()))
.thenReturn(httpSession);
Mockito.when(httpSession.getAttribute(Matchers.anyString()))
.thenReturn("aValue");
Mockito.when(facesContext.getViewRoot()).thenReturn(viewRoot);
Mockito.when(viewRoot.getLocale()).thenReturn(new Locale("en"));
Mockito.when(controllerAccess.getControllerId())
.thenReturn("ess.common");
// Init testing bean
TemplateBean bean = new TemplateBean() {
@Override
protected FacesContext getContext() {
return facesContext;
}
};
bean.setTemplateService(templateService);
bean.setControllerAccess(controllerAccess);
return bean;
}
示例4: testHandleTimer_doHandleControllerProvisioning_bug11449
import javax.naming.InitialContext; //导入方法依赖的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));
}
示例5: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected void setup(TestContainer container) throws Exception {
platformService = mock(APPlatformService.class);
enableJndiMock();
InitialContext context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
parameters = new HashMap<>();
configSettings = new HashMap<>();
settings = new ProvisioningSettings(parameters, configSettings,
Messages.DEFAULT_LOCALE);
container.addBean(new AWSController());
aws = container.get(APPlatformController.class);
ec2mock = new EC2Mockup();
ec2 = ec2mock.getEC2();
EC2Communication.useMock(ec2);
PropertyHandler ph = new PropertyHandler(settings) {
@Override
public <T> T getWebService(java.lang.Class<T> serviceClass)
throws Exception {
return mock(serviceClass);
};
};
PropertyHandler.useMock(ph);
}
示例6: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected void setup(TestContainer container) throws Exception {
platformService = mock(APPlatformService.class);
enableJndiMock();
context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
container.addBean(new OpenStackController());
controller = container.get(APPlatformController.class);
}
示例7: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected void setup(TestContainer container) throws Exception {
platformService = mock(APPlatformService.class);
enableJndiMock();
context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
container.addBean(new OpenStackInstanceAccess());
instanceAccess = container.get(OpenStackInstanceAccess.class);
OpenStackConnection.setURLStreamHandler(streamHandler);
paramHandler.setStackId("sID");
}
示例8: testConfiguredContext
import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
* Tests that the new mechanism for configuring a launcher from a
* servlet context works.
*
* @throws NamingException a problem with the test
*/
public void testConfiguredContext() throws NamingException
{
JdbcMigrationLauncherFactory launcherFactory = new JdbcMigrationLauncherFactory();
MockServletContext sc = new MockServletContext();
String dbType = "mysql";
String sysName = "testSystem";
sc.setInitParameter("migration.systemname", sysName);
sc.setInitParameter("migration.readonly", "true");
sc.setInitParameter("migration.databasetype", dbType);
sc.setInitParameter("migration.patchpath", "patches");
sc.setInitParameter("migration.datasource", "java:comp/env/jdbc/testsource");
MockDataSource ds = new MockDataSource();
InitialContext context = new InitialContext();
context.bind("java:comp/env/jdbc/testsource", ds);
ServletContextEvent sce = new ServletContextEvent(sc);
JdbcMigrationLauncher launcher = null;
try
{
launcher = launcherFactory.createMigrationLauncher(sce);
}
catch (MigrationException e)
{
e.printStackTrace();
fail("There should not have been an exception");
}
JdbcMigrationContext jdbcContext =
(JdbcMigrationContext) launcher.getContexts().keySet().iterator().next();
assertEquals(dbType, jdbcContext.getDatabaseType().getDatabaseType());
assertEquals(sysName, jdbcContext.getSystemName());
assertEquals(true, launcher.isReadOnly());
}
示例9: bind
import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
* Bind a stub to a registry.
* @param jndiUrl URL of the stub in the registry, extracted
* from the <code>JMXServiceURL</code>.
* @param attributes A Hashtable containing environment parameters,
* built from the Map specified at this object creation.
* @param rmiServer The object to bind in the registry
* @param rebind true if the object must be rebound.
**/
void bind(String jndiUrl, Hashtable<?, ?> attributes,
RMIServer rmiServer, boolean rebind)
throws NamingException, MalformedURLException {
// if jndiURL is not null, we nust bind the stub to a
// directory.
InitialContext ctx =
new InitialContext(attributes);
if (rebind)
ctx.rebind(jndiUrl, rmiServer);
else
ctx.bind(jndiUrl, rmiServer);
ctx.close();
}
示例10: setUp
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Hashtable table = new Hashtable();
table.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.geode.internal.jndi.InitialContextFactoryImpl");
initialContext = new InitialContext(table);
initialContext.bind("java:gf/env/datasource/oracle", "a");
gemfireContext = (Context) initialContext.lookup("java:gf");
envContext = (Context) gemfireContext.lookup("env");
dataSourceContext = (Context) envContext.lookup("datasource");
}
示例11: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected void setup(TestContainer container) throws Exception {
container.addBean(LoggerFactory.getLogger(APPTimerServiceBean.class));
container.addBean(instanceDAO = new ServiceInstanceDAO());
container.addBean(configService = Mockito
.mock(APPConfigurationServiceBean.class));
container.addBean(mock(APPConcurrencyServiceBean.class));
container.addBean(provFactoryBean = Mockito
.mock(ProductProvisioningServiceFactoryBean.class));
provService = mock(ProvisioningService.class);
doReturn(provService).when(provFactoryBean)
.getInstance(any(ServiceInstance.class));
container.addBean(
mailService = Mockito.mock(APPCommunicationServiceBean.class));
container.addBean(besDAOMock = mock(BesDAO.class));
doReturn(Arrays.asList(new VOUserDetails())).when(besDAOMock)
.getBESTechnologyManagers(any(ServiceInstance.class));
operationDAOMock = mock(OperationDAO.class);
container.addBean(operationDAOMock);
container.addBean(opBean = mock(OperationServiceBean.class));
container.addBean(mock(APPAuthenticationServiceBean.class));
container.addBean(new APPlatformServiceBean());
controller = mock(APPlatformController.class);
InitialContext context = new InitialContext();
context.bind("bss/app/controller/ess.vmware", controller);
container.addBean(controller);
timer = mock(Timer.class);
defaultUser = new VOUser();
defaultUser.setUserId("user");
em = instanceDAO.em;
container.addBean(timerService = spy(new APPTimerServiceBean()));
container.addBean(timerService1 = spy(new APPTimerServiceBean()));
timerService.em = em;
timerService1.em = em;
timerService.instanceDAO = instanceDAO;
timerService1.instanceDAO = instanceDAO;
timerService.configService = configService;
timerService1.configService = configService;
timerService.provServFact = provFactoryBean;
timerService1.provServFact = provFactoryBean;
timerService.besDAO = besDAOMock;
timerService1.besDAO = besDAOMock;
timerService.mailService = mailService;
timerService1.mailService = mailService;
timerService.operationDAO = operationDAOMock;
timerService1.operationDAO = operationDAOMock;
timerService.opBean = opBean;
timerService1.opBean = opBean;
timerService.appTimerServiceBean = timerService1;
}
示例12: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setup(TestContainer container) throws Exception {
AESEncrypter.generateKey();
container.addBean(configService = Mockito
.mock(APPConfigurationServiceBean.class));
container.addBean(Mockito.mock(ServiceInstanceDAO.class));
container.addBean(Mockito.mock(APPConcurrencyServiceBean.class));
container.addBean(
Mockito.mock(ProductProvisioningServiceFactoryBean.class));
container.addBean(Mockito.mock(APPCommunicationServiceBean.class));
serviceMock = Mockito.mock(Service.class);
besDAO = Mockito.mock(BesDAO.class);
subcriptionService = Mockito.mock(SubscriptionService.class);
identityService = Mockito.mock(EnhancedIdentityService.class);
Mockito.doReturn(Arrays.asList(new VOUserDetails())).when(besDAO)
.getBESTechnologyManagers(any(ServiceInstance.class));
Mockito.doReturn(identityService).when(besDAO).getBESWebService(
Matchers.eq(IdentityService.class),
any(ServiceInstance.class), any(Optional.class));
Mockito.doNothing().when(besDAO).setUserCredentialsInContext(
any(BindingProvider.class), anyString(),
anyString(), Matchers.anyMap());
Mockito.doReturn(subcriptionService).when(besDAO).getBESWebService(
Matchers.eq(SubscriptionService.class),
any(ServiceInstance.class), any(Optional.class));
Mockito.doNothing().when(subcriptionService).completeAsyncSubscription(
anyString(), anyString(),
any(VOInstanceInfo.class));
Mockito.doNothing().when(subcriptionService).abortAsyncSubscription(
anyString(), anyString(),
Matchers.anyListOf(VOLocalizedText.class));
Mockito.doReturn(subcriptionService).when(serviceMock).getPort(
any(QName.class),
Matchers.eq(SubscriptionService.class));
Mockito.doReturn(serviceMock).when(besDAO).createWebService(
any(URL.class), any(QName.class));
Mockito.doReturn(identityService).when(serviceMock).getPort(
any(QName.class), Matchers.eq(IdentityService.class));
container.addBean(besDAO);
container.addBean(Mockito.mock(OperationDAO.class));
container.addBean(Mockito.mock(ServiceInstanceDAO.class));
container.addBean(Mockito.mock(OperationServiceBean.class));
container.addBean(
authService = Mockito.spy(new APPAuthenticationServiceBean()));
container.addBean(Mockito.mock(OperationServiceBean.class));
container.addBean(new APPlatformServiceBean());
controller = Mockito.mock(APPlatformController.class);
InitialContext context = new InitialContext();
context.bind("bss/app/controller/ess.vmware", controller);
container.addBean(controller);
besDAO = container.get(BesDAO.class);
platformService = container.get(APPlatformServiceBean.class);
em = container.getPersistenceUnit("oscm-app");
defaultAuth = new PasswordAuthentication("user", "password");
}
示例13: getTestBean
import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
* Init and return testing bean
*/
private ConfigurationBean getTestBean() throws Exception {
InitialContext context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
facesContext = Mockito.mock(FacesContext.class);
externalContext = Mockito.mock(ExternalContext.class);
httpSession = Mockito.mock(HttpSession.class);
application = Mockito.mock(Application.class);
controllerAccess = Mockito.mock(ControllerAccess.class);
viewRoot = Mockito.mock(UIViewRoot.class);
Mockito.when(facesContext.getExternalContext()).thenReturn(
externalContext);
Mockito.when(facesContext.getApplication()).thenReturn(application);
Mockito.when(externalContext.getSession(Matchers.anyBoolean()))
.thenReturn(httpSession);
Mockito.when(httpSession.getAttribute(Matchers.anyString()))
.thenReturn("aValue");
Mockito.when(facesContext.getViewRoot()).thenReturn(viewRoot);
Mockito.when(viewRoot.getLocale()).thenReturn(new Locale("en"));
Mockito.when(controllerAccess.getControllerId()).thenReturn(
"ess.common");
Mockito.when(controllerAccess.getControllerParameterKeys()).thenReturn(
TEST_KEYS);
// Init testing bean
ConfigurationBean bean = new ConfigurationBean() {
private static final long serialVersionUID = -1300403486736808608L;
@Override
protected FacesContext getContext() {
return facesContext;
}
};
bean.init();
bean.setControllerAccess(controllerAccess);
bean.resetToken();
bean.setToken(bean.getToken());
return bean;
}
示例14: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected void setup(TestContainer container) throws Exception {
platformService = new APPlatformServiceMockup() {
@Override
public User authenticate(String controllerId,
PasswordAuthentication authentication)
throws AuthenticationException, ConfigurationException,
APPlatformException {
User user = new User();
user.setLocale("en");
if (exception) {
throw new APPlatformException("failed");
}
return user;
}
@Override
public boolean checkToken(String token, String signature) {
return true;
}
};
enableJndiMock();
InitialContext context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
chain = Mockito.mock(FilterChain.class);
config = Mockito.mock(FilterConfig.class);
req = Mockito.mock(HttpServletRequest.class);
resp = Mockito.mock(HttpServletResponse.class);
session = Mockito.mock(HttpSession.class);
Mockito.when(resp.getWriter()).thenReturn(new PrintWriter(responseOut));
Mockito.when(req.getSession()).thenReturn(session);
Mockito.when(req.getLocale()).thenReturn(new Locale("en"));
Mockito.when(config.getInitParameter("exclude-url-pattern")).thenReturn(
"(.*/a4j/.*|.*/img/.*|.*/css/.*|.*/fonts/.*|.*/scripts/.*|.*/faq/.*|.*/org.richfaces.resources|.*/javax.faces.resource/.*|^/public/.*)");
controllerAccess = Mockito.mock(ControllerAccess.class);
Mockito.when(controllerAccess.getControllerId())
.thenReturn("ess.common");
filter = new AuthorizationFilter();
filter.setControllerAccess(controllerAccess);
filter.init(config);
}
示例15: setup
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected void setup(TestContainer container) throws Exception {
MockitoAnnotations.initMocks(this);
// Define controller settings
configSettings = new HashMap<>();
configSettings.put(PropertyHandler.SECRET_KEY_PWD, new Setting(
PropertyHandler.SECRET_KEY_PWD, "secret_key"));
configSettings.put(PropertyHandler.ACCESS_KEY_ID_PWD, new Setting(
PropertyHandler.ACCESS_KEY_ID_PWD, "access_key"));
// Define parameters
parameters = new HashMap<>();
parameters.put(PropertyHandler.REGION, new Setting(
PropertyHandler.REGION, "test"));
parameters.put(PropertyHandler.KEY_PAIR_NAME, new Setting(
PropertyHandler.KEY_PAIR_NAME, "key_pair"));
parameters.put(PropertyHandler.INSTANCE_TYPE, new Setting(
PropertyHandler.INSTANCE_TYPE, "type1"));
parameters.put(PropertyHandler.INSTANCENAME, new Setting(
PropertyHandler.INSTANCENAME, "name1"));
// new data
parameters.put(PropertyHandler.DISK_SIZE, new Setting(
PropertyHandler.DISK_SIZE, DISK_SIZE));
parameters.put(PropertyHandler.SUBNET, new Setting(
PropertyHandler.SUBNET, SUBNET));
parameters.put(PropertyHandler.SECURITY_GROUP_NAMES, new Setting(
PropertyHandler.SECURITY_GROUP_NAMES, SECURITY_GROUP_NAMES));
settings = new ProvisioningSettings(parameters, configSettings, "en");
settings.setOrganizationId("orgId");
settings.setSubscriptionId("subId");
ph = new PropertyHandler(settings) {
@Override
public <T> T getWebService(java.lang.Class<T> serviceClass)
throws Exception {
return mock(serviceClass);
};
};
PropertyHandler.useMock(null);
ec2mock = new EC2Mockup();
ec2 = ec2mock.getEC2();
EC2Communication.useMock(ec2);
ec2mock.createDescribeImagesResult("image1");
ec2mock.createRunInstancesResult("instance1");
// new mock
ec2mock.createDescribeSubnetsResult(SUBNET);
ec2mock.createDescribeSecurityGroupResult(SUBNET, SECURITY_GROUP_NAMES);
ec2mock.createDescribeInstancesResult(INSTANCE_ID, "ok", "1.2.3.4");
platformService = mock(APPlatformService.class);
enableJndiMock();
InitialContext context = new InitialContext();
context.bind(APPlatformService.JNDI_NAME, platformService);
doNothing().when(platformService).sendMail(anyListOf(String.class),
subject.capture(), text.capture());
User user = new User();
user.setLocale("de");
doReturn(user).when(platformService).authenticate(anyString(),
any(PasswordAuthentication.class));
ec2proc = new EC2Processor(ph, "instance1");
doReturn("eventUrl").when(platformService).getEventServiceUrl();
}