|
1 | 1 | package org.javaee7.jpa.converter; |
2 | 2 |
|
| 3 | +import static java.util.Arrays.asList; |
| 4 | +import static org.jboss.shrinkwrap.api.ArchivePaths.create; |
| 5 | +import static org.jboss.shrinkwrap.api.ShrinkWrap.create; |
| 6 | +import static org.jboss.shrinkwrap.api.asset.EmptyAsset.INSTANCE; |
| 7 | +import static org.junit.Assert.assertTrue; |
| 8 | + |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +import javax.inject.Inject; |
| 12 | + |
3 | 13 | import org.jboss.arquillian.container.test.api.Deployment; |
4 | 14 | import org.jboss.arquillian.junit.Arquillian; |
5 | | -import org.jboss.shrinkwrap.api.Archive; |
6 | | -import org.jboss.shrinkwrap.api.Filters; |
7 | | -import org.jboss.shrinkwrap.api.GenericArchive; |
8 | | -import org.jboss.shrinkwrap.api.ShrinkWrap; |
9 | | -import org.jboss.shrinkwrap.api.asset.FileAsset; |
10 | | -import org.jboss.shrinkwrap.api.importer.ExplodedImporter; |
11 | | -import org.jboss.shrinkwrap.api.spec.JavaArchive; |
12 | | -import org.jboss.shrinkwrap.resolver.api.maven.Maven; |
| 15 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
13 | 16 | import org.junit.Test; |
14 | 17 | import org.junit.runner.RunWith; |
15 | 18 |
|
16 | | -import javax.inject.Inject; |
17 | | -import java.io.File; |
18 | | -import java.util.List; |
19 | | - |
20 | | -import static org.assertj.core.api.Assertions.assertThat; |
21 | | - |
22 | 19 | @RunWith(Arquillian.class) |
23 | 20 | public class EmployeeRepositoryTest { |
24 | 21 |
|
25 | 22 | @Deployment |
26 | | - public static Archive<?> createDeployment() { |
27 | | - final File[] assertJ = Maven.resolver().loadPomFromFile("pom.xml") |
28 | | - .resolve("org.assertj:assertj-core") |
29 | | - .withTransitivity() |
30 | | - .asFile(); |
31 | | - |
32 | | - final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "employee-card-converter-sample.jar") |
33 | | - .addPackage(Employee.class.getPackage()) |
34 | | - .addAsManifestResource("test-persistence.xml", "persistence.xml") |
35 | | - .merge(metaInfFolder(), "/META-INF", Filters.include(".*\\.sql")); |
36 | | - mergeDependencies(archive, assertJ); |
37 | | - |
38 | | - return archive; |
39 | | - |
| 23 | + public static WebArchive createDeployment() { |
| 24 | + WebArchive war = create(WebArchive.class) |
| 25 | + .addPackage("org.javaee7.jpa.converter") |
| 26 | + .addAsResource("META-INF/persistence.xml") |
| 27 | + .addAsResource("META-INF/create.sql") |
| 28 | + .addAsResource("META-INF/drop.sql") |
| 29 | + .addAsResource("META-INF/load.sql") |
| 30 | + .addAsWebInfResource(INSTANCE, create("beans.xml")); |
| 31 | + |
| 32 | + System.out.println(war.toString(true)); |
| 33 | + |
| 34 | + return war; |
40 | 35 | } |
41 | 36 |
|
42 | 37 | @Inject |
43 | 38 | private EmployeeRepository repository; |
44 | 39 |
|
45 | 40 | @Test |
46 | 41 | public void should_return_all_employee_records() throws Exception { |
47 | | - // when |
48 | | - final List<Employee> employees = repository.all(); |
| 42 | + |
| 43 | + // When |
| 44 | + final List<Employee> actualEmployees = repository.all(); |
49 | 45 |
|
50 | | - // then |
51 | | - assertThat(employees).hasSize(6) |
52 | | - .contains(employee("Leonard", "11-22-33-44"), employee("Sheldon", "22-33-44-55"), |
53 | | - employee("Penny", "33-44-55-66"), employee("Raj", "44-55-66-77"), |
54 | | - employee("Howard", "55-66-77-88"), employee("Bernadette", "66-77-88-99")); |
| 46 | + // Then |
| 47 | + assertTrue(actualEmployees.size() == 6); |
| 48 | + |
| 49 | + List<Employee> expectedEmployees = asList( |
| 50 | + employee("Leonard", "11-22-33-44"), employee("Sheldon", "22-33-44-55"), |
| 51 | + employee("Penny", "33-44-55-66"), employee("Raj", "44-55-66-77"), |
| 52 | + employee("Howard", "55-66-77-88"), employee("Bernadette", "66-77-88-99")); |
| 53 | + |
| 54 | + for (Employee employee : expectedEmployees) { |
| 55 | + assertTrue(actualEmployees.contains(employee)); |
| 56 | + } |
55 | 57 | } |
56 | 58 |
|
57 | | - // -- Test utility methods |
| 59 | + // -- Test utility method |
58 | 60 |
|
59 | 61 | private static Employee employee(String name, String creditCardNumber) { |
60 | | - final CreditCard creditCard = new CreditCard(creditCardNumber); |
61 | | - return new Employee(name, creditCard); |
62 | | - } |
63 | | - |
64 | | - private static void mergeDependencies(JavaArchive archive, File... dependencies) { |
65 | | - for (File file : dependencies) { |
66 | | - archive.merge(ShrinkWrap.createFromZipFile(JavaArchive.class, file)); |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - private static GenericArchive metaInfFolder() { |
71 | | - return ShrinkWrap.create(GenericArchive.class) |
72 | | - .as(ExplodedImporter.class) |
73 | | - .importDirectory("src/main/resources/META-INF") |
74 | | - .as(GenericArchive.class); |
| 62 | + return new Employee(name, new CreditCard(creditCardNumber)); |
75 | 63 | } |
| 64 | + |
76 | 65 | } |
0 commit comments