org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription Java Examples

The following examples show how to use org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FurnaceDeploymentScenarioGenerator.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void addAutomaticDependencies(DeploymentDescription primaryDeployment, Class<?> classUnderTest,
         Method deploymentMethod, Collection<DeploymentDescription> deployments)
{
   for (AddonDependencyEntry dependency : getAddonSet(classUnderTest))
   {
      createAnnotatedDeployment(primaryDeployment,
               classUnderTest,
               deploymentMethod,
               deployments,
               dependency.getName(),
               dependency.getVersionRange().toString(),
               AddonDependency.class.getSimpleName(),
               true,
               dependency.isExported(),
               dependency.isOptional(),
               new Class[0],
               10000,
               TimeUnit.MILLISECONDS,
               NullException.class);
   }
}
 
Example #2
Source File: DeploymentTargetModifier.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void checkTestDeployments(List<DeploymentDescription> descriptions, TestClass testClass, boolean isAdapterTest) {
    for (DeploymentDescription deployment : descriptions) {
        if (deployment.getTarget() != null) {
            String containerQualifier = deployment.getTarget().getName();
            if (AUTH_SERVER_CURRENT.equals(containerQualifier) || (!isAdapterTest && "_DEFAULT_".equals(containerQualifier))) {
                String newAuthServerQualifier = AuthServerTestEnricher.AUTH_SERVER_CONTAINER;
                updateServerQualifier(deployment, testClass, newAuthServerQualifier);
            } else if (containerQualifier.contains(APP_SERVER_CURRENT)) {
                String suffix = containerQualifier.split(APP_SERVER_CURRENT)[1];
                String newAppServerQualifier = ContainerConstants.APP_SERVER_PREFIX  + AppServerTestEnricher.CURRENT_APP_SERVER + "-" + suffix;
                updateServerQualifier(deployment, testClass, newAppServerQualifier);
            } else {
                String newServerQualifier = StringPropertyReplacer.replaceProperties(containerQualifier);
                if (!newServerQualifier.equals(containerQualifier)) {
                    updateServerQualifier(deployment, testClass, newServerQualifier);
                }
            }


        }
    }
}
 
Example #3
Source File: WindupFurnaceAddonDeploymentEnhancer.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@Override public List<DeploymentDescription> enhance(TestClass testClass, List<DeploymentDescription> deployments)
    {
        if(Boolean.getBoolean("maven.surefire.debug")) {
            String version = getWindupVersion(deployments);
            if(version != null) {
//                AddonId id = AddonId.from("org.jboss.windup.rexster:windup-rexster", version);
//                AddonDeploymentArchive archive = ShrinkWrap.create(AddonDeploymentArchive.class).setAddonId(id);
//
//                archive.setDeploymentTimeoutUnit(TimeUnit.MILLISECONDS);
//                archive.setDeploymentTimeoutQuantity(10000);
//
//                DeploymentDescription deploymentDescription = new DeploymentDescription(id.toCoordinates(), archive);
//                deploymentDescription.shouldBeTestable(false);
//                deployments.add(deploymentDescription);
            }
        }
        return deployments;
    }
 
Example #4
Source File: ReporterLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
public void observeBeforeDeploy(@Observes BeforeDeploy event) {
    DeploymentReport deploymentReport = new DeploymentReport();

    DeploymentDescription description = event.getDeployment();

    deploymentReport.setArchiveName(description.getArchive().getName());
    deploymentReport.setName(description.getName());

    int order = description.getOrder();
    if (order > 0) {
        deploymentReport.setOrder(order);
    }

    String protocol = description.getProtocol().getName();
    if (!protocol.equals("_DEFAULT_")) {
        deploymentReport.setProtocol(protocol);
    } else {
        deploymentReport.setProtocol("_DEFAULT_");
    }

    deploymentReport.setTarget(description.getTarget().getName());

    boolean reported = false;

    for (ContainerReport containerReport : reporter.get().getLastTestSuiteReport().getContainerReports()) {
        if (containerReport.getQualifier().equals(deploymentReport.getTarget())) {
            containerReport.getDeploymentReports().add(deploymentReport);
            reported = true;
            break;
        }
    }

    if (!reported) {
        if (reporter.get().getLastTestSuiteReport().getContainerReports().size() == 1) {
            reporter.get().getLastTestSuiteReport().getContainerReports().get(0).getDeploymentReports().add(deploymentReport);
        }
    }

}
 
Example #5
Source File: DeploymentTargetModifier.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public List<DeploymentDescription> generate(TestClass testClass) {
    TestContext context = testContext.get();
    if (context.isAdapterTest() && !context.isAdapterContainerEnabled() && !context.isAdapterContainerEnabledCluster()) {
        return new ArrayList<>(); // adapter test will be skipped, no need to genarate dependencies
    }

    List<DeploymentDescription> deployments = super.generate(testClass);

    checkTestDeployments(deployments, testClass, context.isAdapterTest());
    Set<String> appServerQualifiers = getAppServerQualifiers(testClass.getJavaClass());
    if (appServerQualifiers.isEmpty()) return deployments; // no adapter test

    String appServerQualifier = appServerQualifiers.stream()
            .filter(q -> q.contains(AppServerTestEnricher.CURRENT_APP_SERVER))
            .findAny()
            .orElse(null);

    if (appServerQualifier.contains(";")) return deployments;

    if (appServerQualifier != null && !appServerQualifier.isEmpty()) {
        for (DeploymentDescription deployment : deployments) {
            final boolean containerMatches = deployment.getTarget() != null && deployment.getTarget().getName().startsWith(appServerQualifier);

            if (deployment.getTarget() == null || Objects.equals(deployment.getTarget().getName(), "_DEFAULT_")) {
                log.debug("Setting target container for " + deployment.getName() + ": " + appServerQualifier);
                deployment.setTarget(new TargetDescription(appServerQualifier));
            } else if (! containerMatches && !deployment.getArchive().getName().equals("run-on-server-classes.war")) {// run-on-server deployment can have different target
                throw new RuntimeException("Inconsistency found: target container for " + deployment.getName()
                  + " is set to " + deployment.getTarget().getName()
                  + " but the test class targets " + appServerQualifier);
            }
        }
    }
    return deployments;
}
 
Example #6
Source File: WindupFurnaceAddonDeploymentEnhancer.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Take the windup-config version and if not found, take the most frequent version of windup addons.
 * @param deployments
 * @return
 */
private String getWindupVersion(List<DeploymentDescription> deployments) {
    Map<String,Integer> versionOccurences = new HashMap<>();
    for (DeploymentDescription deployment : deployments)
    {

        if(deployment.toString().contains("windup")) {
            String version = deployment.toString().split(",")[1];

            if(deployment.toString().contains("windup-config")) {
                return version;
            }
            if(versionOccurences.containsKey(deployment.toString().split(",")[1])) {
                versionOccurences.put(version,versionOccurences.get(version) +1);
            } else {
                versionOccurences.put(version,1);
            }
        }
    }
    Map.Entry<String, Integer>  maxEntry = null;
    for (Map.Entry<String, Integer> stringIntegerEntry : versionOccurences.entrySet())
    {
        if(maxEntry == null || stringIntegerEntry.getValue() > maxEntry.getValue()) {
            maxEntry = stringIntegerEntry;
        }
    }

    return maxEntry == null ? null : maxEntry.getKey();

}
 
Example #7
Source File: FurnaceDeploymentScenarioGenerator.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public List<DeploymentDescription> generate(TestClass testClass)
{
   List<DeploymentDescription> deployments = new ArrayList<DeploymentDescription>();
   Method[] deploymentMethods = testClass.getMethods(Deployment.class);
   if (deploymentMethods.length == 0)
   {
      // FURNACE-58: Add a default deployment if no deployment is specified
      addDefaultDeployments(testClass, deployments);
   }
   else
   {
      for (Method deploymentMethod : deploymentMethods)
      {
         validate(deploymentMethod);
         DeploymentDescription primaryDeployment = null;
         try
         {
            primaryDeployment = generateDeployment(deploymentMethod);

            if (deploymentMethod.isAnnotationPresent(AddonDeployments.class)
                     || deploymentMethod.isAnnotationPresent(AddonDependencies.class)
                     || deploymentMethod.isAnnotationPresent(Dependencies.class))
            {
               deployments.addAll(generateAnnotatedDeployments(primaryDeployment, testClass.getJavaClass(),
                        deploymentMethod));
            }
         }
         catch (Exception e)
         {
            throw new RuntimeException("Could not generate @Deployment for " + testClass.getName() + "."
                     + deploymentMethod.getName() + "()", e);
         }

         deployments.add(primaryDeployment);
      }
   }
   for (AddonDeploymentScenarioEnhancer enhancer : ServiceLoader.load(AddonDeploymentScenarioEnhancer.class))
   {
      deployments = enhancer.enhance(testClass, deployments);
      Assert.notNull(deployments,
               String.format("Cannot return a null deployment. Check %s for more details",
                        enhancer.getClass()));
   }
   return deployments;
}
 
Example #8
Source File: FurnaceDeploymentScenarioGenerator.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
private void createAnnotatedDeployment(DeploymentDescription primaryDeployment, Class<?> classUnderTest,
         Method deploymentMethod, Collection<DeploymentDescription> deployments, String addonName,
         String addonVersion, String annotationSimpleName, boolean imported, boolean exported, boolean optional,
         Class<? extends DeploymentListener>[] listenerClasses, int timeoutQuantity, TimeUnit timeoutUnit,
         Class<? extends Exception> expectedException)
{
   /*
    * Resolve version of annotated deployment (if possible)f
    */
   String version;
   if (addonVersion.isEmpty())
   {
      version = resolveVersionFromPOM(classUnderTest, addonName);
      if (version == null)
      {
         throw new IllegalStateException("Could not resolve the version for [" + addonName
                  + "]. Either specify the version for this @" + annotationSimpleName
                  + " in [" + classUnderTest.getName() + "] or add it to pom.xml located at ["
                  + getPomFileFor(classUnderTest) + "]");
      }
   }
   else
   {
      version = addonVersion;
   }
   AddonId id = AddonId.from(addonName, version);
   AddonDeploymentArchive archive = ShrinkWrap.create(AddonDeploymentArchive.class).setAddonId(id);

   /*
    * Configure deployment timeout
    */
   archive.setDeploymentTimeoutUnit(timeoutUnit);
   archive.setDeploymentTimeoutQuantity(timeoutQuantity);

   /*
    * Configure target repository
    */
   if (Annotations.isAnnotationPresent(deploymentMethod, DeployToRepository.class))
   {
      archive.setAddonRepository(Annotations.getAnnotation(deploymentMethod, DeployToRepository.class)
               .value());
   }

   /*
    * Configure automatic dependency registration to parent Archive
    */
   if (imported)
   {
      AddonDependencyEntry dependency = AddonDependencyEntry.create(addonName, addonVersion, exported, optional);
      ((AddonArchiveBase<?>) primaryDeployment.getArchive()).addAsAddonDependencies(dependency);
   }

   /*
    * Configure deployment listeners
    */
   for (Class<? extends DeploymentListener> listenerClass : listenerClasses)
   {
      if (DeploymentListener.class.equals(listenerClass))
         continue; // do nothing for the default

      try
      {
         archive.addDeploymentListener(listenerClass.newInstance());
      }
      catch (Exception e)
      {
         throw new RuntimeException("Could not instantiate " + DeploymentListener.class.getSimpleName()
                  + " of type " + listenerClass.getName(), e);
      }
   }

   DeploymentDescription deploymentDescription = new DeploymentDescription(id.toCoordinates(), archive);

   /*
    * Don't package supporting test classes in annotation deployments
    */
   deploymentDescription.shouldBeTestable(false);

   /*
    * Configure expected deployment exception
    */
   if (!NullException.class.isAssignableFrom(expectedException))
      deploymentDescription.setExpectedException(expectedException);

   deployments.add(deploymentDescription);
}
 
Example #9
Source File: MockAddonDeploymentScenarioEnhancer.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public List<DeploymentDescription> enhance(TestClass testClass, List<DeploymentDescription> deployments)
{
   calls++;
   return deployments;
}
 
Example #10
Source File: TomEEContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
protected boolean isTestable(final Archive<?> archive, final DeploymentDescription deploymentDescription) {
    return deploymentDescription != null
            && deploymentDescription.isArchiveDeployment()
            && (deploymentDescription.getArchive() == archive || deploymentDescription.getTestableArchive() == archive)
            && deploymentDescription.testable();
}
 
Example #11
Source File: DeploymentTargetModifier.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private void updateServerQualifier(DeploymentDescription deployment, TestClass testClass, String newServerQualifier) {
    log.infof("Setting target container for deployment %s.%s: %s", testClass.getName(), deployment.getName(), newServerQualifier);
    deployment.setTarget(new TargetDescription(newServerQualifier));
}
 
Example #12
Source File: AddonDeploymentScenarioEnhancer.java    From furnace with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * This method will be called for every single furnace test that has this enhancer implementation on classpath.
 * 
 * For example, it is possible to deploy a default addon for each furnace test.
 * 
 * @param testClass the {@link TestClass} with the calculated {@link DeploymentDescription} list
 * @param deployments the deployments before returned in
 *           {@link DeploymentScenarioGenerator#generate(org.jboss.arquillian.test.spi.TestClass)}
 * @return the deployments to be returned in
 *         {@link FurnaceDeploymentScenarioGenerator#generate(org.jboss.arquillian.test.spi.TestClass)}
 */
List<DeploymentDescription> enhance(TestClass testClass, List<DeploymentDescription> deployments);