1

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.

4

3 回答 3

5

在所有答案之后,我得到了答案,我只想为其他寻找相同问题的人总结一下。

  1. 删除了这一行:.addAsLibraries(mvnResolver.artifact("org.infinispan:infinispan-core:5.2.0.Final").resolveAsFiles())
  2. MANIFEST.MF文件添加到src/test/resource内容Dependencies: org.infinispan export
  3. 将行添加.addAsManifestResource("MANIFEST.MF")到 ShrinkWrap
  4. 将以下内容添加到 JBoss 中的 Standalone.xml/domain.xml 配置文件中:

    <subsystem xmlns="urn:jboss:domain:ee:1.0">
        <global-modules>
            <module name="org.infinispan" slot="main"/>
        </global-modules>
    </subsystem>
    
于 2013-05-29T08:48:19.723 回答
1

您尝试插入的缓存容器是 Hibernate 的二级缓存。您不应该真正尝试访问 Hibernate 2LC 的底层缓存。如果您需要有关此缓存的信息,请启用 2LC 统计信息。

如果您要做的是插入 Infinispan 缓存,请查看Infinispan JBoss AS7 快速入门,您可以在其中了解如何定义自己的缓存容器,并将其插入您的 CDI 应用程序。

于 2013-05-28T08:42:57.063 回答
1

您是否将任何 Infinispan 类与您的 arquillian 部署打包在一起?Infinispan 作为模块与 JBoss 捆绑在一起,无需部署即可使用。类路径中模棱两可的类名可能会导致该问题。

问候

于 2013-05-29T07:35:20.420 回答