9 Replies Latest reply on Mar 21, 2013 9:03 AM by bmajsak

    CleanupUsingScript execution after class

    smabreu

      Hi,

       

      I would like to know if there is a way to execute the script of the annotation @CleanupUsingScript after all the tests of the class be executed and not after each test of the class.

       

      Att,

      Sérgio Abreu

        • 1. Re: CleanupUsingScript execution after class
          bmajsak

          Heya, welcome on the forum!

           

          Technically speaking it could be possible, but I would rather wait for Arquillian 2.0 with proper metadata and event model improvements.

           

          On the other hand why not doing it at the beginning? To start with the clean state?

          • 2. Re: CleanupUsingScript execution after class
            smabreu

            Thanks for the welcoming

            I've tried using phase=before and @createSchema, but when my tests run the tables is not created. I dont want to create the tables in each test because it slow down the execution of the tests.

            • 3. Re: CleanupUsingScript execution after class
              bmajsak

              Can you give me a bit more details about the db, container and scripts?

              • 4. Re: CleanupUsingScript execution after class
                smabreu

                DB - mySQL 5.1.63-0ubuntu0.11.04.1

                container - jboss-as-7.1.1.Final

                script - @CreateSchema({ "create_database.sql" })

                create_database.sql

                ....

                CREATE TABLE user(id bigint PRIMARY KEY NOT NULL AUTO_INCREMENT, email varchar(255) NOT NULL, name varchar(255) NOT NULL, password varchar(255) NOT NULL, status varchar(50) NOT NULL, id_company bigint NOT NULL, id_client_department bigint, FOREIGN KEY (id_company) REFERENCES company(id), FOREIGN KEY (id_client_department) REFERENCES client_department(id))ENGINE=InnoDB DEFAULT CHARSET=utf8;  

                CREATE UNIQUE INDEX idx_user ON user(id);

                CREATE UNIQUE INDEX idx_user_email ON user(email);

                ....

                 

                 

                @CleanupUsingScript(phase=TestExecutionPhase.BEFORE, value="drop_database.sql")

                drop_database.sql

                ...

                DROP TABLE company;

                DROP TABLE client_department;

                DROP TABLE user;

                ...

                • 5. Re: CleanupUsingScript execution after class
                  bmajsak

                  How does the test look like? Which version of APE are you using?

                  • 6. Re: CleanupUsingScript execution after class
                    smabreu

                    Sorry for taking too long to answer. What's APE? My test looks like this:

                     

                    @Category(SlowTest.class)

                    @CreateSchema({ "create_database.sql" })

                    @CleanupUsingScript(phase=TestExecutionPhase.BEFORE, value="drop_database.sql")

                    @RunWith(Arquillian.class)

                    public class UserManagerBeanTest {

                              @Deployment

                              public static Archive<?> createDeploymentPackage() {

                                        MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom("pom.xml");

                     

                     

                                        return ShrinkWrap ..;

                              }

                     

                     

                              @Test

                              @UsingDataSet("datasets/users.xml")

                              public void findById() {

                                        User adminUser = manager.findById(1, User.FIND_BY_ID);

                     

                                        Assert.assertEquals(adminUser.getEmail(), "admin@admin.com");

                                        Assert.assertEquals(adminUser.getName(), "admin");

                              }

                     

                     

                              @Test

                              @UsingDataSet("datasets/users.xml")

                              public void count() {

                                        Long total = manager.count(User.COUNT_USERS);

                                        Assert.assertEquals(new Long(1), total);

                              }

                    }

                    • 7. Re: CleanupUsingScript execution after class
                      bmajsak

                      APE stands for Arquillian Persistence Extension ;0

                       

                      I would rather put all the cleaning and table creation logic in create schema part. Then you will simply know that for each and every test you start with the clean state. Would it work for you?

                      @CreateSchema({ "drop_database.sql", "create_database.sql" })

                      Optionally you can use DROP IF EXISTS to make it bulletproof

                      • 8. Re: CleanupUsingScript execution after class
                        smabreu

                        It works, thank you!

                        • 9. Re: CleanupUsingScript execution after class
                          bmajsak

                          De nada