Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARQ-918 Add @ExcludedServices as extensible substitute for @Deployment(testable = false) #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.jboss.arquillian.container.spi.client.deployment;

import java.util.ArrayList;
import java.util.List;

import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;
Expand All @@ -39,6 +42,7 @@ public class DeploymentDescription
private Descriptor descriptor;

private Archive<?> testableArchive;
private List<String> servicesToExclude = new ArrayList<String>();

private Class<? extends Exception> expectedException;

Expand Down Expand Up @@ -153,6 +157,15 @@ public DeploymentDescription shouldBeTestable(boolean testable)
return this;
}

public DeploymentDescription shouldExcludeServices(List<String> servicesToExclude) {
if(!isArchiveDeployment())
{
throw new IllegalArgumentException("Only an Archive deployment can exclude services: " + getName());
}
this.servicesToExclude = servicesToExclude;
return this;
}

/**
* @return the testable
*/
Expand All @@ -161,6 +174,9 @@ public boolean testable()
return testable;
}

public List<String> servicesToExclude() {
return servicesToExclude;
}

/**
* @return the testableArchive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import java.lang.annotation.Target;

/**
* The {@code @Deployment} is used to define which methods should be be considered as deployment producers. Arquillian support
* The {@code @Deployment} is used to define which methods should be be considered as deployment producers. Arquillian supports
* two types of deployment units, a {@link Archive} or a {@link Descriptor}.
* <p>
* A deployment represent the isolation level of your test, that being a single JavaArchive or a multi module EnterpriseArchive.
* A deployment represents the isolation level of your test, that being a single JavaArchive or a multi-module EnterpriseArchive.
* <p>
* The deployment producer will be executed to create the deployment before the Test run, this to detect environment problems as soon as
* The deployment producer will be executed to create the deployment before the Test run to detect environment problems as soon as
* possible.
*
* <p>
Expand All @@ -50,7 +50,7 @@
*/
@Documented
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface Deployment
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.arquillian.container.test.api;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation is used with the {@code @Deployment} annotation to identify which Arquillian services should be left out of
* the test archive.
*
* <p>
* By default, Arquillian adds a collection of services to the {@code Archive} defined by the {@code @Deployment} member, often
* by wrapping it inside another {@code Archive}. The {@code @ExcludeServices} annotation can be used to disable this behavior
* altogether or exclude certain services types using a set of built-in constants defined in {@link ServiceType}. This list of
* service types is extensible so that extensions can honor additional exclusions.
* <p>
*
* <p>
* {@code @ExcludeServices} should be used in place of {@code @Deployment(testable = false)}.
* </p>
*
* <p>
* Usage Example (disable archive modification):<br/>
* <pre><code>
* &#64;Deployment
* &#64;ExcludeServices
* public static WebArchive create() {
* return ShrinkWrap.create(WebArchive.class).addClass(MyComponent.class);
* }
* </code></pre>
* <p>
* Usage Example (exclude support for in-container testing):<br/>
* <pre><code>
* &#64;Deployment
* &#64;ExcludeServices(ServiceType.TEST_RUNNER)
* public static WebArchive create() {
* return ShrinkWrap.create(WebArchive.class).addClass(MyComponent.class);
* }
* </code></pre>
*
* @since 1.0.1.Final
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
* @see Deployment
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface ExcludeServices {
String[] value() default { ServiceType.ALL };
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*/
@Documented
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface OverProtocol
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.arquillian.container.test.api;

/**
* A collection of constants that represent groups of Arquillian services that are
* added to the deployment archive to facilitate or enhance in-container testing.
*
* @since 1.0.1.Final
* @author <a href="http://community.jboss.org/people/dan.j.allen">Dan Allen</a>
* @see Deployment
*/
public interface ServiceType {
/**
* Represents all Arquillian services that are added to a deployment.
*/
public static final String ALL = "*";

/**
* Provides the test runner infrastructure and test class to run tests in-container over the specified protocol.
*/
public static final String TEST_RUNNER = "test-runner";

/**
* Instrumentation services for analyzing and managing code running inside the container.
*
* <p>Instrumentation is the addition of code for the purpose of gathering data to be utilized by tools. Since the changes are
* purely additive, these tools do not modify application state or behavior. Examples include monitoring agents, profilers,
* coverage analyzers, and event loggers.</p>
*
* <p>Not currently honored as an exclusion.</p>
*/
public static final String INSTRUMENTATION = "instrumentation";

/**
* <p>Adds additional component model services to the deployment such as CDI for Servlet containers or Spring libraries.</p>
*
* <p>Not currently honored as an exclusion.</p>
*/
public static final String DEPLOYERS = "deployers";
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
@Documented
@Retention(RUNTIME)
@Target(ElementType.METHOD)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface ShouldThrowException
{
Class<? extends Exception> value();
Expand Down
Loading