Java Code Examples for javax.ejb.embeddable.EJBContainer#getContext()

The following examples show how to use javax.ejb.embeddable.EJBContainer#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSourceCipheredExampleTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test
public void accessDatasource() 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", DATASOURCE_URL);
    properties.setProperty("ProtectedDatasource.UserName", USER);
    properties.setProperty("ProtectedDatasource.Password", "fEroTNXjaL5SOTyRQ92x3DNVS/ksbtgs");
    properties.setProperty("ProtectedDatasource.PasswordCipher", "Static3DES");
    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();
}
 
Example 2
Source File: DataSourceCipheredExampleTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source File: MoviesTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void test() throws Exception {

        final Properties p = new Properties();
        p.put("movieDatabase", "new://Resource?type=DataSource");
        p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

        EJBContainer container = EJBContainer.createEJBContainer(p);
        final Context context = container.getContext();

        Movies movies = (Movies) context.lookup("java:global/injection-of-entitymanager/Movies");

        movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
        movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
        movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));

        List<Movie> list = movies.getMovies();
        assertEquals("List.size()", 3, list.size());

        for (Movie movie : list) {
            movies.deleteMovie(movie);
        }

        assertEquals("Movies.getMovies()", 0, movies.getMovies().size());

        container.close();
    }
 
Example 4
Source File: MoviesTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    final Properties p = new Properties();
    p.put("movieDatabase", "new://Resource?type=DataSource");
    p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
    p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

    final EJBContainer container = EJBContainer.createEJBContainer(p);
    final Context context = container.getContext();
    context.bind("inject", this);

    assertTrue(((ReloadableEntityManagerFactory) emf).getManagedClasses().contains(Movie.class.getName()));

    container.close();
}
 
Example 5
Source File: MoviesTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void test() throws Exception {

        final Properties p = new Properties();
        p.put("movieDatabaseXA", "new://Resource?type=javax.sql.XADataSource&class-name=org.apache.derby.jdbc.EmbeddedXADataSource");
        p.put("movieDatabaseXA.DatabaseName", "test");
        p.put("movieDatabaseXA.CreateDatabase", "create");

        p.put("movieDatabase", "new://Resource?type=DataSource");
        p.put("movieDatabase.DataSourceCreator", "dbcp");
        p.put("movieDatabase.XaDataSource", "movieDatabaseXA");
        p.put("movieDatabase.JtaManaged", "true");
        p.put("movieDatabase.UserName", "admin");
        p.put("movieDatabase.Password", "admin");
        p.put("movieDatabase.MaxActive", "128");
        p.put("movieDatabase.MaxIdle", "25");
        p.put("movieDatabase.MinIdle", "10");
        p.put("movieDatabase.AccessToUnderlyingConnectionAllowed", "true");
        p.put("movieDatabase.TestOnBorrow", "false");
        p.put("movieDatabase.TestWhileIdle", "true");
        p.put("movieDatabase.TimeBetweenEvictionRuns", "1 minute");
        p.put("movieDatabase.MaxWaitTime", "0 seconds");
        p.put("movieDatabase.PoolPreparedStatements", "true");
        p.put("movieDatabase.MaxOpenPreparedStatements", "1024");
        p.put("movieDatabase.ValidationQuery", "values 1");

        p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
        p.put("movieDatabaseUnmanaged.DataSourceCreator", "dbcp");
        p.put("movieDatabaseUnmanaged.JdbcDriver", "org.apache.derby.jdbc.EmbeddedDriver");
        p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:derby:test;create=true");
        p.put("movieDatabaseUnmanaged.UserName", "admin");
        p.put("movieDatabaseUnmanaged.Password", "admin");
        p.put("movieDatabaseUnmanaged.JtaManaged", "false");
        p.put("movieDatabaseUnmanaged.MaxActive", "128");
        p.put("movieDatabaseUnmanaged.MaxIdle", "25");
        p.put("movieDatabaseUnmanaged.MinIdle", "10");
        p.put("movieDatabaseUnmanaged.AccessToUnderlyingConnectionAllowed", "true");
        p.put("movieDatabaseUnmanaged.TestOnBorrow", "false");
        p.put("movieDatabaseUnmanaged.TestWhileIdle", "true");
        p.put("movieDatabaseUnmanaged.TimeBetweenEvictionRuns", "1 minute");
        p.put("movieDatabaseUnmanaged.MaxWaitTime", "0 seconds");
        p.put("movieDatabaseUnmanaged.PoolPreparedStatements", "true");
        p.put("movieDatabaseUnmanaged.MaxOpenPreparedStatements", "1024");
        p.put("movieDatabaseUnmanaged.ValidationQuery", "values 1");

        EJBContainer container = EJBContainer.createEJBContainer(p);
        final Context context = container.getContext();

        Movies movies = (Movies) context.lookup("java:global/xa-datasource/Movies");
        MoviesDirect moviesDirect = (MoviesDirect) context.lookup("java:global/xa-datasource/MoviesDirect");

        movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
        movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
        movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));

        List<Movie> list = movies.getMovies();
        assertEquals("List.size()", 3, list.size());
        assertEquals(3, moviesDirect.count());


        for (Movie movie : list) {
            movies.deleteMovie(movie);
        }

        assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
        assertEquals(0, moviesDirect.count());

        container.close();
    }
 
Example 6
Source File: MoviesTest.java    From tomee with Apache License 2.0 3 votes vote down vote up
public void test() throws Exception {

        final Properties p = new Properties();
        p.put("movieDatabase", "new://Resource?type=DataSource");
        p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

        EJBContainer container = EJBContainer.createEJBContainer(p);
        final Context context = container.getContext();

        final Movies movies = (Movies) context.lookup("java:global/jpa-enumerated/Movies");

        movies.addMovie(new Movie("James Frawley", "The Muppet Movie", 1979, Rating.G));
        movies.addMovie(new Movie("Jim Henson", "The Great Muppet Caper", 1981, Rating.G));
        movies.addMovie(new Movie("Frank Oz", "The Muppets Take Manhattan", 1984, Rating.G));
        movies.addMovie(new Movie("James Bobin", "The Muppets", 2011, Rating.PG));

        assertEquals("List.size()", 4, movies.getMovies().size());

        assertEquals("List.size()", 3, movies.findByRating(Rating.G).size());

        assertEquals("List.size()", 1, movies.findByRating(Rating.PG).size());

        assertEquals("List.size()", 0, movies.findByRating(Rating.R).size());

        container.close();
    }