Info: My Application is a simple JAX-RS Service that stores some values in a cache provided by JBoss 7.1.
I would like to use Arquillian to call the service and test the response. But unfortunately I get this error when I try to run a test:
java.lang.IllegalArgumentException:
Can not set org.infinispan.manager.CacheContainer field
com.company.DataCache.container to
org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager
Here is my DataCache class:
@ManagedBean
public class DataCache<K, V> {
@Resource(lookup="java:jboss/infinispan/container/hibernate")
private CacheContainer container;
private Cache<K, V> cache;
@PostConstruct
public void start() {
this.cache = this.container.getCache();
}
public Cache<K, V> getCache() {
return cache;
}
}
My Testclass looks like that:
@RunWith(Arquillian.class)
@RunAsClient
public class SyncClientServerTest extends RbmlClientServerTest {
@Deployment(testable = false)
public static WebArchive createDeployment() {
MavenDependencyResolver mvnResolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom("pom.xml").goOffline();
return ShrinkWrap
.create(WebArchive.class, "cache-service.war")
.addPackages(true, Filters.exclude(".*ClientServerTest.*"), "com/company")
.addAsLibraries(mvnResolver.artifact("org.infinispan:infinispan-core:5.2.0.Final").resolveAsFiles())
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
public void testStatus() throws Exception {
ClientRequest request = new ClientRequest("localhost:8080/cache-service/cache");
request.accept(MediaType.APPLICATION_JSON_TYPE);
request.body(MediaType.APPLICATION_JSON_TYPE, "");
ClientResponse<String> responseObj = request.post(String.class);
assertEquals(200, responseObj.getStatus());
}
}
Question
- @Resource delivers the right cache from JBoss, is there a way to manipulate that like getting the Resource for a Database?
- Is there a way to Mock up Service calls like getCache()?
All in all I want to use Arquilian for Client testing because I use a lot of Dependency Injection, maybe there is an example project out there that uses @Resource and Infinispan.