tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: @PreDestroy in embedded unit test
Date Fri, 28 May 2010 21:03:57 GMT
Hi Joe,

We didn't previously explicitly destroy beans on shutdown/undeploy, but I've gone ahead and
added that:

  https://issues.apache.org/jira/browse/OPENEJB-1279

I've uploaded new 3.1.3-SNAPSHOT jars to the maven repo at https://repository.apache.org/snapshots/

With those snapshots you should be able to shutdown the container system in your test case
with code like this:

  @Before  
  public void setUp() throws Exception{  
      Properties p = new Properties();  
            
      //Set some other properties like datasources ...         
      p.put("openejb.embedded.initialcontext.close", "destroy");  
            
      context = new InitialContext(p);  
  }  
        
  @After  
  public void tearDown() throws Exception{  
      context.close();  
  } 


Hope this helps!

-David


On May 21, 2010, at 6:26 AM, joe wrote:

> Hi,
> 
> I have a stateless bean which executes some native SQL.
> 
> @PostConstruct
> public void init()
> {
>  try
>  {
>    connection = unmanagedDataSource.getConnection();
>    // create some tables
>  }
>  catch (SQLException e)
>  {
>    throw new RuntimeException(e);
>  }
> }
> 
> @PreDestroy
> public void destroy()
> {
>  try
>  {
>    // drop some tables
>    connection.close();
>  }
>  catch (SQLException e)
>  {
>    throw new RuntimeException(e);
>  }
> }
> 
> public void executeNativeSQL()
> {
>  // some native sql	
> }
> 
> In my unit test the @PreDestroy annotated method is never invoked.
> Is this the expected behaviour?
> So in a unit test i have to call the destroy method manually from the unit test?
> 
> 
> 
> 
> 
> 


Mime
View raw message