How detect that deployment has failed from a test?

api

#1

Hi

My tests are using Arquillian with following extension https://github.com/ingwarsw/arquillian-suite-extension that allows a single deployment to be used by several tests via the ArquillianSuiteDeployment annotation.

That works fine but has one issue - if deployment fails only the FIRST test annotated with OperateOnDeployment actually fails because of the failed deployment. The rest are executed and of course fail but not before doing lots of stuff and wasting lots of time.

I looked around for a solution that would allow me to detect the failed deployment in a @Before method and directly fail the test. In the end I came up with this (very hacky) thing:

  @ArquillianResource(Deployer.class)
  private Deployer deployer;
    
  @Before
  public void setup() throws Exception {
      java.lang.reflect.Field f = deployer.getClass().getDeclaredField("deploymentScenario");
      f.setAccessible(true);
      Object deploymentScenarioInstance = f.get(deployer);
      java.lang.reflect.Method getMethod = deploymentScenarioInstance.getClass().getDeclaredMethod("get");
      Object deploymentScenario = getMethod.invoke(deploymentScenarioInstance);
      java.lang.reflect.Method deploymentsInErrodMethod = deploymentScenario.getClass().getMethod("deploymentsInError");
      java.util.List deploymentsInError = (java.util.List)deploymentsInErrodMethod.invoke(deploymentScenario);
      if (deploymentsInError != null && deploymentsInError.size() > 0) {
        throw new RuntimeException("Cannot execute test - deployment failed!");
      }
   }

Obviously that is VERY ugly, without even mentioning the compatibility issues that I might have.
Still I was not able to find another way.
I attempted using ContainerController.isStarted() but the specific container that I use is always started and it is the deployment that fails.
The Deployer interface only allows me to deploy() and undeploy() stuff but not to check about the status of the deployment. Although this status is obviously available, I see no API method to get it.

Is there a more nice way to do this?

Best regards
Vasil