Hi nek, how are you? fine? me too.
I try using this extension too and don't have success in my project.
I search the solution and found this discussion of arquillians developers. so arquillian will native supports for Suite class in version 1.2.0.Alpha1 of Core api.
For now I create my solution for this problem (workaround), creating a Suite Class like that:
Suite class api
/**
*
* @author Rafael Jesus
*
* Data de criação: 29/10/2015</br>
*
* Descrição do arquivo ApplicationSuiteAPITest.java:</br> This application suite class is a workaround for suite all arquillian tests that doesn't supports suite</br>
* see more in this <a href="http://discuss.arquillian.org/t/arquillian-core-suite-subsuite-how-to-define-the-suite/163/27">discussion</a></br>
* When this code are merged in 1.2.0.Alpha1 version of core, this interface will be deprecated.
*
* ---------------------------------------------
*
* ---------------------------------------------
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ApplicationSuiteAPITest {
@ArquillianResource
private URL contextPath;
public URL getContextPath() {
return contextPath;
}
public void setContextPath(URL contextPath) {
this.contextPath = contextPath;
}
private List<ISuiteAPITest> tests = null;
@Deployment(testable = true, managed = true, name = "simple")
@OverProtocol("Servlet 2.5")
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "app.war")
.addAsWebInfResource("applicationContext-arquillian-test.xml", "applicationContext.xml" )
... //all files your application needs
.setWebXML("in-container-web.xml");
}
/**
* After load all tests class.
*
* @author Rafael Jesus
*/
@Before
public void setUp() {
tests = loadAllTests();
}
/**
* This code was adapted of following discussion:</br>
* <a href="http://stackoverflow.com/questions/3949260/java-class-isinstance-vs-class-isassignablefrom">Class.isInstance vs Class.isAssignableFrom</a>
* @return List of class for tests with arquillian
* @author Rafael Jesus
*/
private List<ISuiteAPITest> loadAllTests() {
List<ISuiteAPITest> tests = new ArrayList<ISuiteAPITest>();
try {
// create scanner and disable default filters (that is the 'false' argument)
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
false);
// add include filters which matches all the classes (or use your own)
provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(".*")));
// get matching classes defined in the package
final Set<BeanDefinition> classes = provider.findCandidateComponents("com.app.app.api");
// this is how you can load the class type from BeanDefinition instance
for (BeanDefinition bean : classes) {
Class<?> clazz = Class.forName(bean.getBeanClassName());
if (!Modifier.isAbstract(clazz.getModifiers()) && !clazz.isMemberClassa !clazz.isAnonymousClass()) {
Object obj = clazz.newInstance();
if (ISuiteAPITest.class.isInstance(obj)) {
tests.add((ISuiteAPITest) obj);
}
}
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
return tests;
}
/**
* Runing all tests for each test class loaded in List<ISuiteAPITest> before.
*
* @author Rafael Jesus
*/
@Test
public void testApplicationAPI() {
for (ISuiteAPITest test : tests) {
test.setContextPath(getContextPath());
test.runingSetUps();
test.runTests();
test.runningTearDowns();
}
System.out.println("number of api tests running in suite application: " + tests.size());
}
Interface:
/**
*
* @author Rafael Jesus
*
* Data de criação: 29/10/2015</br>
*
* Descrição do arquivo ISuiteAPITest.java:</br> This application suite interface is a workaround for suite all arquillian tests that doesn't supports suite</br>
* see more in this <a href="http://discuss.arquillian.org/t/arquillian-core-suite-subsuite-how-to-define-the-suite/163/27">discussion</a></br>.
* When this code are merged in 1.2.0.Alpha1 version of core, this interface will be deprecated.
*
* ---------------------------------------------
*
* ---------------------------------------------
*/
public interface ISuiteAPITest {
/**
* runing all setUp tests.
*
* @author Rafael Jesus
*/
public void runingSetUps();
/**
* Runing all tests
*
* @author Rafael Jesus
*/
public void runTests();
/**
* runing all tearDown tests.
*
* @author Rafael Jesus
*/
public void runningTearDowns();
/**
* inject contextPath for <b>BaseAPITest</b> class
*
* @author Rafael Jesus
*/
public void setContextPath(URL contextPath);
}
test class example using suite api.
/**
*
* @author Rafael Jesus
*
* Data de criação: 28/04/2015
*
* Descrição do arquivo UserLogControllerAPITest.java: Integration tests for controller UserLogController.java class
*
* ---------------------------------------------
*
*
* ---------------------------------------------
*/
@Ignore
public class UserLogControllerAPITest extends BaseAPITest<UserLogDTO> implements ISuiteAPITest {
private static final String CONTROLLER_PATH = UserLogController.CONTROLLER_PATH;
private Long createdProjectId = null;
@Override
public void injectClazzBaseDTO() {
setClazzBaseDTO(UserLogDTO.class);
}
/**
* Set up all information needed
* @author Rafael Jesus
*/
@Before
public void setUp(){
//all methods needed
}
/**
* retrieves log for project base(BaseAPITest.PROJECT_ID = 36)
* @author Rafael Jesus
*/
@Test
public void testGetUserLogProjectBaseAPI() {
//your test implementation
}
@Override
public boolean requireAuthentication() {
return true;
}
@Override
public void runingSetUps() {
injectClazzBaseDTO();
setUp();
}
@Override
public void runTests() {
testGetUserLogProjectBaseAPI();
}
@Override
public void runningTearDowns() {
}
}