Skip to content

Commit

Permalink
TCK test for Andy to work with remove method stuff in core test - to …
Browse files Browse the repository at this point in the history
…be removed once Andy is done

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2506 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 18, 2009
1 parent bcbe157 commit 24b9a82
Show file tree
Hide file tree
Showing 25 changed files with 482 additions and 0 deletions.
@@ -0,0 +1,15 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Local;

@Local
public interface AlteStadt
{
public String getPlaceOfInterest();

public void performPostConstructChecks();

public void initializeBean(GutenbergMuseum pointOfInterest);

public GutenbergMuseum getAnotherPlaceOfInterest();
}
@@ -0,0 +1,9 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Stateful;

@Stateful
public class DirectOrderProcessor extends OrderProcessor implements DirectOrderProcessorLocal
{

}
@@ -0,0 +1,9 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Local;

@Local
public interface DirectOrderProcessorLocal
{
void order();
}
@@ -0,0 +1,87 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.context.Context;
import javax.context.CreationalContext;
import javax.context.RequestScoped;
import javax.inject.manager.Bean;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.IntegrationTest;
import org.jboss.testharness.impl.packaging.Packaging;
import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.webbeans.test.AbstractWebBeansTest;
import org.testng.annotations.Test;

/**
* Sections
*
* 6.5. Lifecycle of stateful session beans
* 6.6. Lifecycle of stateless session and singleton beans
* 6.11. Lifecycle of EJBs
*
* Mostly overlapping with other tests...
*
* @author Nicklas Karlsson
* @author David Allen
*
* Spec version: Public Release Draft 2
*
*/
@Artifact
@Packaging(PackagingType.EAR)
@IntegrationTest
public class EnterpriseBeanLifecycleTest extends AbstractWebBeansTest
{

/**
* When the create() method of a Bean object that represents a stateful
* session bean that is called, the container creates and returns a session
* bean proxy, as defined in Section 3.3.9, "Session bean proxies".
*/
@Test(groups = { "enterpriseBeans", "clientProxy", "lifecycle", "integration" })
public void testCreateSFSB()
{
GrossStadt frankfurt = getCurrentManager().getInstanceByType(GrossStadt.class);
Bean<KleinStadt> stadtBean = getCurrentManager().resolveByType(KleinStadt.class).iterator().next();
assert stadtBean != null : "Expected a bean for stateful session bean Kassel";
CreationalContext<KleinStadt> creationalContext = new MockCreationalContext<KleinStadt>();
KleinStadt stadtInstance = stadtBean.create(creationalContext);
assert stadtInstance != null : "Expected instance to be created by container";
//assert frankfurt.isKleinStadtCreated() : "PostConstruct should be invoked when bean instance is created";
frankfurt.resetCreatedFlags();

// Create a second one to make sure create always does create a new session bean
KleinStadt anotherStadtInstance = stadtBean.create(creationalContext);
assert anotherStadtInstance != null : "Expected second instance of session bean";
//assert frankfurt.isKleinStadtCreated();
assert anotherStadtInstance != stadtInstance : "create() should not return same bean as before";

// Verify that the instance returned is a proxy by checking for all local interfaces
Set<Class<?>> interfaces = new HashSet<Class<?>>(Arrays.asList(stadtInstance.getClass().getInterfaces()));
assert interfaces.contains(KleinStadt.class);
assert interfaces.contains(SchoeneStadt.class);
//frankfurt.dispose();
}

@Test(groups = { "enterpriseBeans", "clientProxy", "lifecycle", "integration" })
public void testDestroyRemovesSFSB() throws Exception
{
GrossStadt frankfurt = getCurrentManager().getInstanceByType(GrossStadt.class);
Bean<KleinStadt> stadtBean = getCurrentManager().resolveByType(KleinStadt.class).iterator().next();
assert stadtBean != null : "Expected a bean for stateful session bean Kassel";
Context requestContext = getCurrentManager().getContext(RequestScoped.class);
CreationalContext<KleinStadt> creationalContext = new MockCreationalContext<KleinStadt>();
KleinStadt kassel = requestContext.get(stadtBean, creationalContext);
stadtBean.destroy(kassel);

assert frankfurt.isKleinStadtDestroyed() : "Expected SFSB bean to be destroyed";
kassel = requestContext.get(stadtBean);
assert kassel == null : "SFSB bean should not exist after being destroyed";
//frankfurt.dispose();
}

}
@@ -0,0 +1,62 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.context.RequestScoped;
import javax.ejb.Remove;
import javax.ejb.Stateful;

@Stateful
@RequestScoped
public class FrankfurtAmMain implements GrossStadt
{

private boolean kleinStadtCreated = false;
private boolean kleinStadtDestroyed = false;

public boolean isKleinStadtCreated()
{
return kleinStadtCreated;
}

public boolean isKleinStadtDestroyed()
{
return kleinStadtDestroyed;
}

public void kleinStadtCreated()
{
kleinStadtCreated = true;
}

public void kleinStadtDestroyed()
{
kleinStadtDestroyed = true;
}

public void resetCreatedFlags()
{
kleinStadtCreated = false;
}

public void resetDestroyedFlags()
{
kleinStadtDestroyed = false;
}

@Remove
public void dispose()
{
}

private boolean schlossDestroyed = false;

public boolean isSchlossDestroyed()
{
return schlossDestroyed;
}

public void schlossDestroyed()
{
schlossDestroyed = true;
}

}
@@ -0,0 +1,9 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Local;

@Local
public interface GeschichtslosStadt
{

}
@@ -0,0 +1,10 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

public class Giessen implements NeueStadt, GeschichtslosStadt
{

public void mehrBauen()
{
}

}
@@ -0,0 +1,25 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Local;

@Local
public interface GrossStadt
{
public void kleinStadtCreated();

public void kleinStadtDestroyed();

public boolean isKleinStadtCreated();

public boolean isKleinStadtDestroyed();

public void resetCreatedFlags();

public void resetDestroyedFlags();

public void dispose();

public void schlossDestroyed();

public boolean isSchlossDestroyed();
}
@@ -0,0 +1,6 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

public class GutenbergMuseum
{

}
@@ -0,0 +1,9 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Stateful;

@Stateful
public class IndirectOrderProcessor extends IntermediateOrderProcessor implements OrderProcessorLocal
{

}
@@ -0,0 +1,6 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

class IntermediateOrderProcessor extends OrderProcessor
{

}
@@ -0,0 +1,34 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.context.RequestScoped;
import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;

@Stateful
@RequestScoped
public class Kassel implements KleinStadt, SchoeneStadt
{
@EJB
private GrossStadt grossStadt;

@PostConstruct
public void begruendet()
{
grossStadt.kleinStadtCreated();
}

@Remove
public void zustandVergessen()
{
}

@PreDestroy
public void zustandVerloren()
{
grossStadt.kleinStadtDestroyed();
}

}
@@ -0,0 +1,14 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Local;

@Local
public interface KleinStadt
{
public void begruendet();

public void zustandVergessen();

public void zustandVerloren();

}
@@ -0,0 +1,27 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.annotation.PreDestroy;
import javax.context.Dependent;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.inject.Current;

@Stateful
@Dependent
public class LandgraffenSchloss implements Schloss
{
@Current
private GrossStadt biggerCity;

@PreDestroy
public void destructionCallback()
{
biggerCity.schlossDestroyed();
}

@Remove
public void remove()
{
}

}
@@ -0,0 +1,40 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.inject.Current;
import javax.inject.Initializer;

@Stateless
public class Mainz implements AlteStadt
{
@Current
private RoemerPassage placeOfInterest;

private GutenbergMuseum anotherPlaceOfInterest;

private String name;

public String getPlaceOfInterest()
{
return name;
}

@PostConstruct
public void performPostConstructChecks()
{
if ( placeOfInterest != null )
name = placeOfInterest.getName();
}

@Initializer
public void initializeBean(@Current GutenbergMuseum pointOfInterest)
{
this.anotherPlaceOfInterest = pointOfInterest;
}

public GutenbergMuseum getAnotherPlaceOfInterest()
{
return anotherPlaceOfInterest;
}
}
@@ -0,0 +1,18 @@
package org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.inject.Current;

@Stateful
public class Marburg implements UniStadt
{
@Current
private Schloss theCastle;

@Remove
public void removeBean()
{
}

}

0 comments on commit 24b9a82

Please sign in to comment.