1 Reply Latest reply on Nov 24, 2016 7:14 AM by Hans-Michael Rupp

    Arquillian Test CDI Producer Injection

    Hans-Michael Rupp Novice

      Hallo

      I am trying to implement a CDI Producer (which should produce an Object from the Elasticsearch API).

       

      public class TransportClientFactory {

       

        private static final String CLUSTER_NAME = "bla-cluster";

       

        private TransportClient transportClient;

       

       

        public TransportClientFactory() {

        super();

        Settings settings = Settings.builder().put("cluster.name", CLUSTER_NAME).build();

        transportClient = new PreBuiltTransportClient(settings);

        }

       

        @Produces

        public TransportClient getTransportClient() {

        return transportClient;

        }

      }

       

      @RunWith(Arquillian.class)

      public class ProducerTest {

       

        @Deployment

        public static Archive<?> createTestArchive() {

       

        return ShrinkWrap.create(JavaArchive.class, "test.jar")

        .addClasses(TransportClientFactory.class)

        .addAsResource(EmptyAsset.INSTANCE, "META-INF/beans.xml")

        .setManifest("META-INF/MANIFEST.MF");

       

       

        }

       

        @Inject

        TransportClient transportClient;

       

        @Test

        public void test() {

        assertNotNull(transportClient);

        }

      }

       

      <?xml version="1.0" encoding="UTF-8"?>

      <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

      http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">

      </beans>

       

      I get

      org.jboss.arquillian.container.spi.client.container.DeploymentException: Cannot deploy: test.war

        at org.jboss.as.arquillian.container.ArchiveDeployer.deployInternal(ArchiveDeployer.java:83)

        ...

      Caused by: java.lang.Exception: {"WFLYCTL0080: Fehlgeschlagene Dienste" => {"jboss.deployment.unit.\"test.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test.war\".WeldStartService: Failed to start service

          Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type TransportClient with qualifiers @Default

        at injection point [BackedAnnotatedField] @Inject bla.ProducerTest.transportClient

       

      I would be greatful for any suggestions.

      (Why is Arquillian trying to deploy a war? It should be producing a jar)