0 Replies Latest reply on Nov 3, 2018 9:08 AM by Alexia Alexia

    Arquillian test cannot deploy with class with dependecy injections

    Alexia Alexia Newbie

      When I try to run the test with the SessionController class then I get the following error :

      Tests in error:

        service.SessionTest: Cannot deploy: test.war

       

       

      @RunWith(Arquillian.class)
      public class SessionTest {
      
      
      @Deployment
      public static Archive<?> createTestArchive() {
      return ShrinkWrap.create(WebArchive.class, "test.war")
      .addPackage(Session.class.getPackage())
      .addPackage(SessionController.class.getPackage())
      .addAsDirectory("target/classes")
      // enable JPA
      .addAsResource(new File("src/main/resources/META-INF/persistence.xml"))
      // enable CDI
      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
      // Deploy our test datasource
      .addAsWebInfResource(new File("src/main/webapp/WEB-INF/el-ds.xml"));
      }
      
      @Inject
      Session sess;
      

       

      However when I remove the SessionController and add any other package the tests run fine. I can't find the error in my code. Please help.

      Some bits of code were removed for confidentiality but here is the SessionController class.

      @Singleton
      @Lock(LockType.READ)
      public class SessionController {
      
      
      private Logger logger = Logger.getLogger(this.getClass());
      
      
      @Resource
      TimerService timerService;
      
      
      @PersistenceUnit(unitName = "mssql")
      private EntityManagerFactory emf;
      
      
      @Inject
      private ArchiveService archiveService;
      
      
      @Inject
      private AppConfigService appConfigService;
      
      
      @Inject
      private DateTimeOffsetService dateTimeOffsetService;
      
      
      @Inject
      private AuthenticationService authenticationService;
      
      
      @Inject
      private AuthorisationService authorisationService;
      
      
      @Inject
      private CacheService cacheService;
      
      
      @Inject
      private ActionHandlerService actionHandlerService;
      
      
      @Inject
      private LoginService loginService;
      
      
      @Inject
      private CrmTranscriptService crmTranscriptService;
      
      
      @Inject
      private LockService lockService;
      
      
      public ObjectNode processSession(String sessionId, ObjectNode requestNode, HttpServletRequest httpServletRequest)
      throws IOException {
      
      
      // Get body of the requestNode. This is the HTTP request body.
      // Used for reading only.
      JsonNode requestBodyNode = requestNode.get("body");
      
      
      // Create responseNode to be returned. responseNodeDataNode is nested inside.
      ObjectMapper mapper = new ObjectMapper();
      ObjectNode responseNode = mapper.createObjectNode();
      ObjectNode responseDataNode = mapper.createObjectNode();
      
      
      String sessionType = requestBodyNode.get("sessionType").asText();
      logger.info("Handling sessionType '" + sessionType + "' for sessionId '" + sessionId + "'.");
      Session session = null;
      switch (sessionType) { }
      
      
      }