2 Replies Latest reply on Jul 5, 2016 3:39 PM by Magno Ferreira

    how to migrate seamtests (seam 2.2.2) to arquillian?

    Magno Ferreira Newbie

      I only found guides showing the migration of seam 2.3  tests to arquillian.

       

      As I'm migrating from jboss eap 5 to 6, I would like to migrate the tests but it's been complicated to do that from the scenario seam2.2.2/jboss5eap/Ant.

       

      I've tried to use arquillian-seam2 extension but I couldn't make it. I don't know exactly what I have to ship in the createDeployment() method. All examples from the internet seems much different from my prior perspective.

       

      In the tests suit, I need to inject seam objects (with @In) and use new ComponentTest(){...}.run(); from SeamTest.

        • 1. Re: how to migrate seamtests (seam 2.2.2) to arquillian?
          omid pourhadi Apprentice

          I'm using Seam 2.2Final with Arquillian. you can find it here https://github.com/omidp/seam

           

          @RunWith(Arquillian.class)
          public class CriticalPathTest extends JUnitSeamTest
          {
          
              @Deployment()
              @OverProtocol("Servlet 3.0")
              public static WebArchive seamDeployment()
              {
                  WebArchive archive = simpleSeamDeployment();
                  archive.addPackages(true, "org.project.model");
                  archive.addAsResource("nativeQueries.xml");
                  return archive;
              }
          
              @Test
              public void testCPM() throws Exception
              {
                  new ComponentTest() {
          
                      @Override
                      protected void testComponents() throws Exception
                      {
                          EntityManager em = Component.getInstance("entityManager");
                          //your test logic 
                      }
                  }.run();
              }
              
              public static WebArchive simpleSeamDeployment()
              {
                  InputStream is = DeploymentResolver.class.getResourceAsStream("jboss-deployment-structure-test.txt");
                  String deploymentContent = TestUtil.readFile(is);
                  //woodstox xml parser clean up
                  deploymentContent = deploymentContent.replaceAll("[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]", "");
                  WebArchive war = ShrinkWrap.create(WebArchive.class, "web-test.war");
                  war.addAsWebInfResource(new StringAsset(deploymentContent), "jboss-deployment-structure.xml");
                  war.addAsResource("seam.properties").addAsResource("components.properties");
                  war.addAsWebInfResource("WEB-INF/components.xml", "components.xml").addAsWebInfResource("WEB-INF/pages.xml", "pages.xml");
                  war.addAsWebInfResource("WEB-INF/web.xml", "web.xml");
                  war.addAsResource("META-INF/persistence.xml");
                  war.addAsResource("META-INF/ejb-jar.xml");
                  File[] resolveAsFiles = DependencyResolvers.use(MavenDependencyResolver.class).includeDependenciesFromPom("pom_test.xml")
                          .scope("compile").goOffline().resolveAsFiles();
                  for (File file : resolveAsFiles)
                  {
                      System.out.println(file.getName());
                  }
                  war.addAsLibraries(resolveAsFiles);
                  for (ArchivePath path : war.getContent().keySet())
                  {
                      if (path.get().contains("jboss-seam-ui"))
                      {
                          war.delete(path);
                          break;
                      }
                  }
                  System.out.println(war.toString());
                  return war;
              }
              
          
          }
          
          • 2. Re: how to migrate seamtests (seam 2.2.2) to arquillian?
            Magno Ferreira Newbie

            Thanks, that really helped me.

            After overriding some classes from your 2.2.3 seam version,

            I also followed this tip jboss - arquillian + shrinkwrap + seam: how to create deployment package - Stack Overflow

            and that worked.