本文整理了Java中javax.naming.Context.close()
方法的一些代码示例,展示了Context.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.close()
方法的具体详情如下:
包路径:javax.naming.Context
类名称:Context
方法名:close
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* Release a JNDI context as obtained from {@link #getContext()}.
* @param ctx the JNDI context to release (may be {@code null})
* @see #getContext
*/
public void releaseContext(@Nullable Context ctx) {
if (ctx != null) {
try {
ctx.close();
}
catch (NamingException ex) {
logger.debug("Could not close JNDI InitialContext", ex);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBind() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
jt.bind(name, o);
verify(context).bind(name, o);
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testRebind() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
jt.rebind(name, o);
verify(context).rebind(name, o);
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testUnbind() throws Exception {
String name = "something";
final Context context = mock(Context.class);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
jt.unbind(name);
verify(context).unbind(name);
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLookupSucceeds() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willReturn(o);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
Object o2 = jt.lookup(name);
assertEquals(o, o2);
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Test that it performs the correct lookup.
*/
@Test
public void testPerformsLookup() throws Exception {
LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.class);
String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
configuredInterceptor(mockContext, jndiName);
verify(mockContext).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLookupFailsWithTypeMismatch() throws Exception {
Object o = new Object();
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willReturn(o);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
try {
jt.lookup(name, String.class);
fail("Should have thrown TypeMismatchNamingException");
}
catch (TypeMismatchNamingException ex) {
// Ok
}
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPerformsLookup() throws Exception {
RemoteInterface ejb = mock(RemoteInterface.class);
String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
configuredProxy(si, RemoteInterface.class);
verify(mockContext).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLookupReturnsNull() throws Exception {
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willReturn(null);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
try {
jt.lookup(name);
fail("Should have thrown NamingException");
}
catch (NameNotFoundException ex) {
// Ok
}
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLookupFails() throws Exception {
NameNotFoundException ne = new NameNotFoundException();
String name = "foo";
final Context context = mock(Context.class);
given(context.lookup(name)).willThrow(ne);
JndiTemplate jt = new JndiTemplate() {
@Override
protected Context createInitialContext() {
return context;
}
};
try {
jt.lookup(name);
fail("Should have thrown NamingException");
}
catch (NameNotFoundException ex) {
// Ok
}
verify(context).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods() throws Exception {
Object retVal = new Object();
LocalInterface ejb = mock(LocalInterface.class);
given(ejb.targetMethod()).willReturn(retVal);
String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
ProxyFactory pf = new ProxyFactory(new Class<?>[] { BusinessMethods.class });
pf.addAdvice(si);
BusinessMethods target = (BusinessMethods) pf.getProxy();
assertTrue(target.targetMethod() == retVal);
verify(mockContext).close();
verify(ejb).remove();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInvokesMethodOnEjbInstance() throws Exception {
Object retVal = new Object();
LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.class);
given(ejb.targetMethod()).willReturn(retVal);
String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
ProxyFactory pf = new ProxyFactory(new Class<?>[] { BusinessMethods.class });
pf.addAdvice(si);
BusinessMethods target = (BusinessMethods) pf.getProxy();
assertTrue(target.targetMethod() == retVal);
verify(mockContext).close();
verify(ejb).remove();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterface() throws Exception {
Object retVal = new Object();
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willReturn(retVal);
final String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
assertTrue(target.targetMethod() == retVal);
verify(mockContext).close();
verify(ejb).remove();
}
代码示例来源:origin: spring-projects/spring-framework
private void testException(Exception expected) throws Exception {
LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.class);
given(ejb.targetMethod()).willThrow(expected);
String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
ProxyFactory pf = new ProxyFactory(new Class<?>[] { LocalInterfaceWithBusinessMethods.class });
pf.addAdvice(si);
LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy();
try {
target.targetMethod();
fail("Should have thrown exception");
}
catch (Exception thrown) {
assertTrue(thrown == expected);
}
verify(mockContext).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testLookupWithExposeAccessContext() throws Exception {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
TestBean tb = new TestBean();
final Context mockCtx = mock(Context.class);
given(mockCtx.lookup("foo")).willReturn(tb);
jof.setJndiTemplate(new JndiTemplate() {
@Override
protected Context createInitialContext() {
return mockCtx;
}
});
jof.setJndiName("foo");
jof.setProxyInterface(ITestBean.class);
jof.setExposeAccessContext(true);
jof.afterPropertiesSet();
assertTrue(jof.getObject() instanceof ITestBean);
ITestBean proxy = (ITestBean) jof.getObject();
assertEquals(0, tb.getAge());
proxy.setAge(99);
assertEquals(99, tb.getAge());
proxy.equals(proxy);
proxy.hashCode();
proxy.toString();
verify(mockCtx, times(2)).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception {
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willThrow(new RemoteException());
final String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class);
try {
target.targetMethod();
fail("Should have thrown RemoteAccessException");
}
catch (RemoteAccessException ex) {
// expected
}
verify(mockContext).close();
verify(ejb).remove();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPerformsLookupWithAccessContext() throws Exception {
RemoteInterface ejb = mock(RemoteInterface.class);
String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
si.setExposeAccessContext(true);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
assertNull(target.targetMethod());
verify(mockContext, times(2)).close();
verify(ejb).targetMethod();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInvokesMethodOnEjbInstanceWithRemoteException() throws Exception {
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willThrow(new RemoteException());
ejb.remove();
final String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
try {
target.targetMethod();
fail("Should have thrown RemoteException");
}
catch (RemoteException ex) {
// expected
}
verify(mockContext).close();
verify(ejb, times(2)).remove();
}
代码示例来源:origin: spring-projects/spring-framework
private void doTestException(Exception expected) throws Exception {
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willThrow(expected);
final String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
try {
target.targetMethod();
fail("Should have thrown remote exception");
}
catch (Exception thrown) {
assertTrue(thrown == expected);
}
verify(mockContext).close();
verify(ejb).remove();
}
代码示例来源:origin: spring-projects/spring-framework
private void doTestInvokesMethodOnEjbInstance(boolean lookupHomeOnStartup, boolean cacheHome) throws Exception {
Object retVal = new Object();
final RemoteInterface ejb = mock(RemoteInterface.class);
given(ejb.targetMethod()).willReturn(retVal);
int lookupCount = 1;
if (!cacheHome) {
lookupCount++;
if (lookupHomeOnStartup) {
lookupCount++;
}
}
final String jndiName= "foobar";
Context mockContext = mockContext(jndiName, ejb);
SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
si.setLookupHomeOnStartup(lookupHomeOnStartup);
si.setCacheHome(cacheHome);
RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class);
assertTrue(target.targetMethod() == retVal);
assertTrue(target.targetMethod() == retVal);
verify(mockContext, times(lookupCount)).close();
verify(ejb, times(2)).remove();
}
内容来源于网络,如有侵权,请联系作者删除!