-
1. Re: CleanupUsingScript execution after class
bmajsak Mar 14, 2013 2:55 PM (in response to smabreu)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 Mar 14, 2013 4:14 PM (in response to bmajsak)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 Mar 14, 2013 4:38 PM (in response to smabreu)Can you give me a bit more details about the db, container and scripts?
-
4. Re: CleanupUsingScript execution after class
smabreu Mar 15, 2013 8:30 AM (in response to bmajsak)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 Mar 16, 2013 3:51 AM (in response to smabreu)How does the test look like? Which version of APE are you using?
-
6. Re: CleanupUsingScript execution after class
smabreu Mar 20, 2013 8:22 AM (in response to bmajsak)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 Mar 21, 2013 5:47 AM (in response to smabreu)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 Mar 21, 2013 9:00 AM (in response to bmajsak)It works, thank you!
-
9. Re: CleanupUsingScript execution after class
bmajsak Mar 21, 2013 9:03 AM (in response to smabreu)De nada