/* (non-Javadoc)
   * @see org.jboss.arquillian.spi.DeploymentPackager#generateDeployment(org.jboss.arquillian.spi.TestDeployment)
   */
  public Archive<?> generateDeployment(
      TestDeployment testDeployment, Collection<ProtocolArchiveProcessor> processors) {
    WebArchive protocol = new ProtocolDeploymentAppender().createAuxiliaryArchive();

    Archive<?> applicationArchive = testDeployment.getApplicationArchive();
    Collection<Archive<?>> auxiliaryArchives = testDeployment.getAuxiliaryArchives();

    Processor processor = new Processor(testDeployment, processors);

    if (Validate.isArchiveOfType(EnterpriseArchive.class, applicationArchive)) {
      return handleArchive(
          applicationArchive.as(EnterpriseArchive.class),
          auxiliaryArchives,
          protocol,
          processor,
          testDeployment);
    }

    if (Validate.isArchiveOfType(WebArchive.class, applicationArchive)) {
      return handleArchive(
          applicationArchive.as(WebArchive.class), auxiliaryArchives, protocol, processor);
    }

    if (Validate.isArchiveOfType(JavaArchive.class, applicationArchive)) {
      return handleArchive(
          applicationArchive.as(JavaArchive.class), auxiliaryArchives, protocol, processor);
    }

    throw new IllegalArgumentException(
        ServletProtocolDeploymentPackager.class.getName()
            + " can not handle archive of type "
            + applicationArchive.getClass().getName());
  }
  /** Adds Warp archive to the protocol archive to make it available for WARs and EARs. */
  @Override
  public void process(TestDeployment testDeployment, Archive<?> protocolArchive) {
    final TestClass testClass = this.testClass.get();
    final Archive<?> applicationArchive = testDeployment.getApplicationArchive();

    if (WarpCommons.isWarpTest(testClass.getJavaClass())) {
      if (!Validate.isArchiveOfType(WebArchive.class, protocolArchive)) {
        throw new IllegalArgumentException(
            "Protocol archives of type "
                + protocolArchive.getClass()
                + " not supported by Warp. Please use the Servlet 3.0 protocol.");
      }

      addWarpPackageToDeployment(protocolArchive.as(WebArchive.class));

      addWarpExtensionsDeployment(protocolArchive.as(WebArchive.class));

      removeTestClassFromDeployment(applicationArchive, testClass);
    }
  }