use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class GuessHowManyMBeanTest method play.
@Test
public void play() throws Exception {
Properties properties = new Properties();
properties.setProperty(LocalMBeanServer.OPENEJB_JMX_ACTIVE, Boolean.TRUE.toString());
EJBContainer container = EJBContainer.createEJBContainer(properties);
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName(OBJECT_NAME);
assertEquals(0, server.getAttribute(objectName, "value"));
server.setAttribute(objectName, new Attribute("value", 3));
assertEquals(3, server.getAttribute(objectName, "value"));
assertEquals("winner", server.invoke(objectName, "tryValue", new Object[] { 3 }, null));
assertEquals("not the correct value, please have another try", server.invoke(objectName, "tryValue", new Object[] { 2 }, null));
container.close();
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class CalculatorTest method test.
@Test
public void test() throws Exception {
ExecutionChannel.getInstance().addObserver(this);
final EJBContainer container = EJBContainer.createEJBContainer();
{
final CalculatorBean calculator = (CalculatorBean) getContext().lookup(JNDI);
Assert.assertEquals(10, calculator.add(4, 6));
//the bean is constructed only when it is used for the first time
Assert.assertEquals("postConstruct", this.received.remove(0));
Assert.assertEquals("add", this.received.remove(0));
Assert.assertEquals(-2, calculator.subtract(4, 6));
Assert.assertEquals("subtract", this.received.remove(0));
Assert.assertEquals(24, calculator.multiply(4, 6));
Assert.assertEquals("multiply", this.received.remove(0));
Assert.assertEquals(2, calculator.divide(12, 6));
Assert.assertEquals("divide", this.received.remove(0));
Assert.assertEquals(4, calculator.remainder(46, 6));
Assert.assertEquals("remainder", this.received.remove(0));
}
{
final CalculatorBean calculator = (CalculatorBean) getContext().lookup(JNDI);
Assert.assertEquals(10, calculator.add(4, 6));
Assert.assertEquals("add", this.received.remove(0));
}
container.close();
Assert.assertEquals("preDestroy", this.received.remove(0));
Assert.assertTrue(this.received.isEmpty());
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class CalculatorTest method call.
@Test
public void call() throws MalformedURLException {
final EJBContainer container = EJBContainer.createEJBContainer(new Properties() {
{
setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
// random port to avoid issue on CI, default is 4204
setProperty("httpejbd.port", "0");
}
});
// get back the random port
final int port = Integer.parseInt(SystemInstance.get().getProperty("httpejbd.port"));
// normal call
final Service service = Service.create(new URL("http://127.0.0.1:" + port + "/webservice-ws-with-resources-config/CalculatorBean?wsdl"), new QName("http://security.ws.superbiz.org/", "CalculatorBeanService"));
final Calculator calculator = service.getPort(Calculator.class);
ClientProxy.getClient(calculator).getOutInterceptors().add(new WSS4JOutInterceptor(new HashMap<String, Object>() {
{
put("action", "UsernameToken");
put("user", "openejb");
put("passwordType", "PasswordText");
put("passwordCallbackRef", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword("tomee");
}
});
}
}));
assertEquals(5, calculator.add(2, 3));
// bad auth
final Calculator calculator2 = service.getPort(Calculator.class);
ClientProxy.getClient(calculator2).getOutInterceptors().add(new WSS4JOutInterceptor(new HashMap<String, Object>() {
{
put("action", "UsernameToken");
put("user", "openejb");
put("passwordType", "PasswordText");
put("passwordCallbackRef", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword("wrong");
}
});
}
}));
try {
assertEquals(5, calculator2.add(2, 3));
} catch (SOAPFaultException sfe) {
assertThat(sfe.getMessage(), CoreMatchers.containsString("A security error was encountered when verifying the message"));
}
container.close();
// valid it passed because all was fine and not because the server config was not here
assertTrue(PasswordCallbackHandler.wasCalled());
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class DataSourceCipheredExampleTest method accessDatasourceWithMyImplementation.
@Test
public void accessDatasourceWithMyImplementation() throws Exception {
// define the datasource
Properties properties = new Properties();
properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource");
properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver");
properties.setProperty("ProtectedDatasource.JdbcUrl", "jdbc:hsqldb:mem:protected");
properties.setProperty("ProtectedDatasource.UserName", USER);
properties.setProperty("ProtectedDatasource.Password", "3MdniFr3v3NLLuoY");
properties.setProperty("ProtectedDatasource.PasswordCipher", "reverse");
properties.setProperty("ProtectedDatasource.JtaManaged", "true");
// start the context and makes junit test injections
EJBContainer container = EJBContainer.createEJBContainer(properties);
Context context = container.getContext();
context.bind("inject", this);
// test the datasource
assertNotNull(dataSource);
assertNotNull(dataSource.getConnection());
// closing the context
container.close();
}
Aggregations