下面列出了怎么用javax.ejb.CreateException的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testCreateException() throws Exception {
final String jndiName = "foo";
final CreateException cex = new CreateException();
final MyHome home = mock(MyHome.class);
given(home.create()).willThrow(cex);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) throws NamingException {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
LocalStatelessSessionProxyFactoryBean fb = new LocalStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
fb.setResourceRef(false); // no java:comp/env prefix
fb.setBusinessInterface(MyBusinessMethods.class);
assertEquals(fb.getBusinessInterface(), MyBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
try {
mbm.getValue();
fail("Should have failed to create EJB");
}
catch (EjbAccessException ex) {
assertSame(cex, ex.getCause());
}
}
@Test
public void testCreateExceptionWithLocalBusinessInterface() throws Exception {
final String jndiName = "foo";
final CreateException cex = new CreateException();
final MyHome home = mock(MyHome.class);
given(home.create()).willThrow(cex);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
// rely on default setting of resourceRef=false, no auto addition of java:/comp/env prefix
fb.setBusinessInterface(MyLocalBusinessMethods.class);
assertEquals(fb.getBusinessInterface(), MyLocalBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyLocalBusinessMethods mbm = (MyLocalBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
try {
mbm.getValue();
fail("Should have failed to create EJB");
}
catch (RemoteAccessException ex) {
assertTrue(ex.getCause() == cex);
}
}
@Test
public void testCreateException() throws Exception {
final String jndiName = "foo";
final CreateException cex = new CreateException();
final MyHome home = mock(MyHome.class);
given(home.create()).willThrow(cex);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) throws NamingException {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
LocalStatelessSessionProxyFactoryBean fb = new LocalStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
fb.setResourceRef(false); // no java:comp/env prefix
fb.setBusinessInterface(MyBusinessMethods.class);
assertEquals(fb.getBusinessInterface(), MyBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
try {
mbm.getValue();
fail("Should have failed to create EJB");
}
catch (EjbAccessException ex) {
assertSame(cex, ex.getCause());
}
}
@Test
public void testCreateException() throws Exception {
final String jndiName = "foo";
final CreateException cex = new CreateException();
final MyHome home = mock(MyHome.class);
given(home.create()).willThrow(cex);
JndiTemplate jt = new JndiTemplate() {
@Override
public Object lookup(String name) {
// parameterize
assertTrue(name.equals(jndiName));
return home;
}
};
SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
fb.setJndiName(jndiName);
// rely on default setting of resourceRef=false, no auto addition of java:/comp/env prefix
fb.setBusinessInterface(MyBusinessMethods.class);
assertEquals(fb.getBusinessInterface(), MyBusinessMethods.class);
fb.setJndiTemplate(jt);
// Need lifecycle methods
fb.afterPropertiesSet();
MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
assertTrue(Proxy.isProxyClass(mbm.getClass()));
try {
mbm.getValue();
fail("Should have failed to create EJB");
}
catch (RemoteException ex) {
// expected
}
}
private TestingSessionLocal lookupTestingSessionBeanLocal() {
try {
Context c = new InitialContext();
TestingSessionLocalHome rv = (TestingSessionLocalHome) c.lookup("java:comp/env/TestingSessionBean");
return rv.create();
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
} catch (CreateException ce) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ce);
throw new RuntimeException(ce);
}
}
public java.lang.Long ejbCreate(java.lang.Long key) throws CreateException {
if (key == null) {
throw new CreateException("The field \"key\" must not be null");
}
// TODO add additional validation code, throw CreateException if data is not valid
setPk(key);
return null;
}
public java.lang.Long ejbCreate(java.lang.Long key) throws CreateException {
if (key == null) {
throw new CreateException("The field \"key\" must not be null");
}
// TODO add additional validation code, throw CreateException if data is not valid
setKey(key);
return null;
}
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityRemote create(java.lang.String key) throws javax.ejb.CreateException, java.rmi.RemoteException;
/**
*
*/
test.TestingEntityLocal create(java.lang.String key) throws javax.ejb.CreateException;
LocalInterface create() throws CreateException;
MyBusinessMethods create() throws CreateException;
EJBObject create() throws RemoteException, CreateException;
testGenerateJavaEE14.TestCmpRemote create(java.lang.Long key) throws CreateException, RemoteException;
MyBusinessMethods create() throws CreateException, RemoteException;