.setTarget(new TargetDescription("X")));
Mockito.when(scenario.deployment(new DeploymentTargetDescription("Z"))).thenReturn(deploymentZ);
Mockito.when(scenario.deployment(new DeploymentTargetDescription("X"))).thenReturn(deploymentX);
ContainerContext containerContext = getManager().getContext(ContainerContext.class);
DeploymentContext deploymentContext = getManager().getContext(DeploymentContext.class);
try
{
deploymentContext.activate(deploymentX);
deploymentContext.getObjectStore().add(contextualType, innerType);
deploymentContext.deactivate();
/*
* deploymentZ is left active and should be handled as 'current'.
* The test is to see if the Enricher with Qualifier can activate/deactive and read from X
*/
deploymentContext.activate(deploymentZ);
deploymentContext.getObjectStore().add(contextualType, outerType);
containerContext.activate("TEST");
TestEnricher enricher = new ArquillianResourceTestEnricher();
injector.get().inject(enricher);
X test = enrichType.cast(enrichType.newInstance());
enricher.enrich(test);
return test;
}
catch (RuntimeException e)
{
throw (Exception)e.getCause();
}
finally
{
if(deploymentContext.isActive())
{
Deployment activeContext = deploymentContext.getActiveId();
if(!"Z".equals(activeContext.getDescription().getName()))
{
Assert.fail("Wrong deployment context active, potential leak in Enricher. Active context was " + activeContext.getDescription().getName());
}
}
if(containerContext.isActive())
{
String activeContext = containerContext.getActiveId();
if(!"TEST".equalsIgnoreCase(activeContext))
{
Assert.fail("Wrong container context active, potential leak in Enricher. Active context was " + activeContext);
}
}