Commit 4f28d1892f79c8139b1218f3180df1afd74b22e2

Authored by Cleverson Sacramento
1 parent 29296286
Exists in master

Funcionando com o JBoss AS7 Managed mas a cobertura não está funcionando

impl/extension/jpa/pom.xml
... ... @@ -66,10 +66,93 @@
66 66 <url>http://www.serpro.gov.br</url>
67 67 </organization>
68 68  
69   - <!--
70 69 <build>
  70 + <testResources>
  71 + <testResource>
  72 + <directory>src/test/resources</directory>
  73 + <filtering>true</filtering>
  74 + </testResource>
  75 + </testResources>
  76 +
71 77 <plugins>
72 78 <plugin>
  79 + <artifactId>maven-dependency-plugin</artifactId>
  80 + <executions>
  81 + <execution>
  82 + <id>unpack</id>
  83 + <phase>process-test-classes</phase>
  84 + <goals>
  85 + <goal>unpack</goal>
  86 + </goals>
  87 + <configuration>
  88 + <artifactItems>
  89 + <artifactItem>
  90 + <groupId>org.jboss.as</groupId>
  91 + <artifactId>jboss-as-dist</artifactId>
  92 + <version>${jbossas.version}</version>
  93 + <type>zip</type>
  94 + <overWrite>false</overWrite>
  95 + <outputDirectory>target</outputDirectory>
  96 + </artifactItem>
  97 + </artifactItems>
  98 + </configuration>
  99 + </execution>
  100 + </executions>
  101 + </plugin>
  102 + <!--
  103 + <plugin>
  104 + <artifactId>maven-surefire-plugin</artifactId>
  105 + <version>2.12.4</version>
  106 + <configuration>
  107 + <environmentVariables>
  108 + <JBOSS_HOME>${project.build.directory}/jboss-as-${jbossas.version}</JBOSS_HOME>
  109 + </environmentVariables>
  110 + <systemProperties>
  111 + <jboss.version>${jbossas.version}</jboss.version>
  112 + </systemProperties>
  113 + </configuration>
  114 + </plugin>
  115 + <plugin>
  116 + <groupId>org.apache.maven.plugins</groupId>
  117 + <artifactId>maven-dependency-plugin</artifactId>
  118 + <executions>
  119 + <execution>
  120 + <id>unpack</id>
  121 + <phase>process-test-classes</phase>
  122 + <goals>
  123 + <goal>unpack</goal>
  124 + </goals>
  125 + <configuration>
  126 + <artifactItems>
  127 + <artifactItem>
  128 + <groupId>org.jboss.as</groupId>
  129 + <artifactId>jboss-as-dist</artifactId>
  130 + <version>${jbossas.version}</version>
  131 + <type>zip</type>
  132 + <overWrite>false</overWrite>
  133 + <outputDirectory>${project.build.directory}</outputDirectory>
  134 + </artifactItem>
  135 + </artifactItems>
  136 + </configuration>
  137 + </execution>
  138 + </executions>
  139 + </plugin>
  140 + -->
  141 + <!--
  142 + <plugin>
  143 +
  144 + <groupId>org.apache.maven.plugins</groupId>
  145 + <artifactId>maven-surefire-plugin</artifactId>
  146 + <configuration>
  147 + <systemPropertyVariables>
  148 + <tomee.httpPort>-1</tomee.httpPort>
  149 + <tomee.stopPort>-1</tomee.stopPort>
  150 + </systemPropertyVariables>
  151 + </configuration>
  152 + </plugin>
  153 + -->
  154 + <!--
  155 + <plugin>
73 156 <groupId>org.apache.maven.plugins</groupId>
74 157 <artifactId>maven-surefire-plugin</artifactId>
75 158 <version>2.12</version>
... ... @@ -84,9 +167,14 @@
84 167 </systemPropertyVariables>
85 168 </configuration>
86 169 </plugin>
  170 + -->
  171 + <plugin>
  172 + <groupId>org.apache.maven.plugins</groupId>
  173 + <artifactId>maven-surefire-plugin</artifactId>
  174 + <version>2.16</version>
  175 + </plugin>
87 176 </plugins>
88 177 </build>
89   - -->
90 178  
91 179 <dependencies>
92 180 <dependency>
... ... @@ -115,26 +203,43 @@
115 203 </dependency>
116 204 -->
117 205  
  206 + <dependency>
  207 + <groupId>org.jboss.as</groupId>
  208 + <artifactId>jboss-as-arquillian-container-managed</artifactId>
  209 + <version>${jbossas.version}</version>
  210 + <scope>test</scope>
  211 + </dependency>
  212 + <dependency>
  213 + <groupId>org.jboss.arquillian.protocol</groupId>
  214 + <artifactId>arquillian-protocol-servlet</artifactId>
  215 + </dependency>
  216 +
118 217 <!--
  218 + <dependency>
  219 + <groupId>org.apache.openejb</groupId>
  220 + <artifactId>arquillian-tomee-embedded</artifactId>
  221 + <version>1.5.2</version>
  222 + </dependency>
119 223 -->
  224 +
  225 + <!--
120 226 <dependency>
121 227 <groupId>org.jboss.arquillian.container</groupId>
122 228 <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
123 229 <scope>test</scope>
124 230 </dependency>
125   - <!--
126 231 <dependency>
127 232 <groupId>org.glassfish.main.extras</groupId>
128 233 <artifactId>glassfish-embedded-web</artifactId>
129 234 <scope>test</scope>
130 235 </dependency>
131   - -->
132 236 <dependency>
133 237 <groupId>org.glassfish.main.extras</groupId>
134 238 <artifactId>glassfish-embedded-all</artifactId>
135 239 <version>3.1.2</version>
136 240 <scope>test</scope>
137 241 </dependency>
  242 + -->
138 243  
139 244 <!--
140 245 <dependency>
... ... @@ -149,6 +254,20 @@
149 254 <scope>test</scope>
150 255 </dependency>
151 256 -->
  257 +
  258 + <!--
  259 + <dependency>
  260 + <groupId>org.jboss.as</groupId>
  261 + <artifactId>jboss-as-arquillian-container-managed</artifactId>
  262 + <version>7.1.1.Final</version>
  263 + <scope>test</scope>
  264 + </dependency>
  265 + <dependency>
  266 + <groupId>org.jboss.arquillian.protocol</groupId>
  267 + <artifactId>arquillian-protocol-servlet</artifactId>
  268 + <scope>test</scope>
  269 + </dependency>
  270 + -->
152 271  
153 272 <dependency>
154 273 <groupId>org.jboss.shrinkwrap.resolver</groupId>
... ... @@ -218,7 +337,6 @@
218 337 <artifactId>hibernate-validator</artifactId>
219 338 <scope>test</scope>
220 339 </dependency>
221   -
222 340 -->
223 341 </dependencies>
224 342  
... ... @@ -268,6 +386,8 @@
268 386 <groupId>org.slf4j</groupId>
269 387 <artifactId>slf4j-api</artifactId>
270 388 </exclusion>
  389 + <!--
  390 + -->
271 391 <exclusion>
272 392 <groupId>org.javassist</groupId>
273 393 <artifactId>javassist</artifactId>
... ... @@ -282,4 +402,8 @@
282 402 </dependencies>
283 403 </profile>
284 404 </profiles>
  405 +
  406 + <properties>
  407 + <jbossas.version>7.1.1.Final</jbossas.version>
  408 + </properties>
285 409 </project>
... ...
impl/extension/jpa/src/test/java/transaction/manual/JPATransactionTest.java
... ... @@ -2,6 +2,7 @@ package transaction.manual;
2 2  
3 3 import static junit.framework.Assert.assertEquals;
4 4 import static junit.framework.Assert.assertFalse;
  5 +import static junit.framework.Assert.assertNull;
5 6 import static junit.framework.Assert.assertTrue;
6 7  
7 8 import javax.inject.Inject;
... ... @@ -53,66 +54,72 @@ public class JPATransactionTest {
53 54 public void commitWithSuccess() {
54 55 Transaction transaction = transactionContext.getCurrentTransaction();
55 56  
56   - MyEntity entity = new MyEntity();
57   - entity.setId(createId("id-1"));
58   - entity.setDescription("desc-1");
  57 + MyEntity1 entity1 = new MyEntity1();
  58 + entity1.setId(createId("id-1"));
  59 + entity1.setDescription("desc-1");
  60 +
  61 + MyEntity2 entity2 = new MyEntity2();
  62 + entity2.setId(createId("id-2"));
  63 + entity2.setDescription("desc-2");
59 64  
60 65 assertFalse(transaction.isActive());
61 66 transaction.begin();
62 67 assertTrue(transaction.isActive());
63 68  
64   - em1.persist(entity);
65   - em2.persist(entity);
  69 + em1.persist(entity1);
  70 + em2.persist(entity2);
66 71 transaction.commit();
67 72 em1.clear();
68 73 em2.clear();
69 74  
70   - MyEntity persisted1 = em1.find(MyEntity.class, createId("id-1"));
71   - MyEntity persisted2 = em2.find(MyEntity.class, createId("id-1"));
  75 + MyEntity1 persisted1 = em1.find(MyEntity1.class, createId("id-1"));
  76 + MyEntity2 persisted2 = em2.find(MyEntity2.class, createId("id-2"));
72 77  
73 78 assertEquals("desc-1", persisted1.getDescription());
74   - assertEquals("desc-1", persisted2.getDescription());
  79 + assertEquals("desc-2", persisted2.getDescription());
75 80 }
76 81  
77 82 @Test(expected = TransactionRequiredException.class)
78 83 public void checkNoTransactionAutomaticallyLoaded() {
79   - MyEntity entity = new MyEntity();
  84 + MyEntity1 entity = new MyEntity1();
80 85 entity.setId(createId("id-2"));
81 86  
82 87 em1.persist(entity);
83 88 em1.flush();
84 89 }
85 90  
86   - //
87   - // @Test
88   - // public void rollbackWithSuccess() {
89   - // Transaction transaction = transactionContext.getCurrentTransaction();
90   - //
91   - // MyEntity entity = new MyEntity();
92   - // entity.setId(createId("id-3"));
93   - //
94   - // assertFalse(transaction.isMarkedRollback());
95   - // transaction.begin();
96   - // assertTrue(transaction.isActive());
97   - //
98   - // em1.persist(entity);
99   - // em2.persist(entity);
100   - // em1.flush();
101   - // em2.flush();
102   - // transaction.setRollbackOnly();
103   - //
104   - // if (transaction.isMarkedRollback()) {
105   - // transaction.rollback();
106   - // }
107   - //
108   - // em1.clear();
109   - // em2.clear();
110   - //
111   - // MyEntity persisted1 = em1.find(MyEntity.class, createId("id-3"));
112   - // MyEntity persisted2 = em2.find(MyEntity.class, createId("id-3"));
113   - // assertNull(persisted1);
114   - // assertNull(persisted2);
115   - // }
  91 + @Test
  92 + public void rollbackWithSuccess() {
  93 + Transaction transaction = transactionContext.getCurrentTransaction();
  94 +
  95 + MyEntity1 entity1 = new MyEntity1();
  96 + entity1.setId(createId("id-3"));
  97 +
  98 + MyEntity2 entity2 = new MyEntity2();
  99 + entity2.setId(createId("id-4"));
  100 +
  101 + assertFalse(transaction.isMarkedRollback());
  102 + transaction.begin();
  103 + assertTrue(transaction.isActive());
  104 +
  105 + em1.persist(entity1);
  106 + em2.persist(entity2);
  107 + em1.flush();
  108 + em2.flush();
  109 + transaction.setRollbackOnly();
  110 +
  111 + if (transaction.isMarkedRollback()) {
  112 + transaction.rollback();
  113 + }
  114 +
  115 + em1.clear();
  116 + em2.clear();
  117 +
  118 + MyEntity1 persisted1 = em1.find(MyEntity1.class, createId("id-3"));
  119 + MyEntity2 persisted2 = em2.find(MyEntity2.class, createId("id-4"));
  120 + assertNull(persisted1);
  121 + assertNull(persisted2);
  122 + }
116 123  
117 124 private String createId(String id) {
118 125 return this.getClass().getName() + "_" + id;
... ...
impl/extension/jpa/src/test/java/transaction/manual/MyEntity.java
... ... @@ -1,29 +0,0 @@
1   -package transaction.manual;
2   -
3   -import javax.persistence.Entity;
4   -import javax.persistence.Id;
5   -
6   -@Entity
7   -public class MyEntity {
8   -
9   - @Id
10   - private String id;
11   -
12   - private String description;
13   -
14   - public String getId() {
15   - return id;
16   - }
17   -
18   - public void setId(String id) {
19   - this.id = id;
20   - }
21   -
22   - public String getDescription() {
23   - return description;
24   - }
25   -
26   - public void setDescription(String description) {
27   - this.description = description;
28   - }
29   -}
impl/extension/jpa/src/test/java/transaction/manual/MyEntity1.java 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +package transaction.manual;
  2 +
  3 +import javax.persistence.Entity;
  4 +import javax.persistence.Id;
  5 +
  6 +@Entity
  7 +public class MyEntity1 {
  8 +
  9 + @Id
  10 + private String id;
  11 +
  12 + private String description;
  13 +
  14 + public String getId() {
  15 + return id;
  16 + }
  17 +
  18 + public void setId(String id) {
  19 + this.id = id;
  20 + }
  21 +
  22 + public String getDescription() {
  23 + return description;
  24 + }
  25 +
  26 + public void setDescription(String description) {
  27 + this.description = description;
  28 + }
  29 +}
... ...
impl/extension/jpa/src/test/java/transaction/manual/MyEntity2.java 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +package transaction.manual;
  2 +
  3 +import javax.persistence.Entity;
  4 +import javax.persistence.Id;
  5 +
  6 +@Entity
  7 +public class MyEntity2 {
  8 +
  9 + @Id
  10 + private String id;
  11 +
  12 + private String description;
  13 +
  14 + public String getId() {
  15 + return id;
  16 + }
  17 +
  18 + public void setId(String id) {
  19 + this.id = id;
  20 + }
  21 +
  22 + public String getDescription() {
  23 + return description;
  24 + }
  25 +
  26 + public void setDescription(String description) {
  27 + this.description = description;
  28 + }
  29 +}
... ...
impl/extension/jpa/src/test/resources/arquillian.xml
... ... @@ -43,6 +43,25 @@
43 43 <property name="deploymentExportPath">target/deployments</property>
44 44 </engine>
45 45  
  46 + <container qualifier="jbossas-managed" default="true">
  47 + <protocol type="Servlet 3.0" />
  48 +
  49 + <configuration>
  50 + <property name="javaHome">/usr/lib/jvm/java-6-serpro/</property>
  51 + <property name="jbossHome">target/jboss-as-${jbossas.version}</property>
  52 + <!--
  53 + <property name="serverConfig">../../../../src/test/resources/standalone.xml</property>
  54 + -->
  55 + </configuration>
  56 + </container>
  57 + <!--
  58 + <container qualifier="jbossas-managed" default="true">
  59 + <configuration>
  60 + <property name="jbossHome">target/jboss-as-${jbossas.version}</property>
  61 + <property name="javaVmArguments">-Djboss.socket.binding.port-offset=10000 -Xmx512m -XX:MaxPermSize=128m</property>
  62 + </configuration>
  63 + </container>
  64 + -->
46 65 <!--
47 66 <container qualifier="jbossas-managed" default="true">
48 67 <configuration>
... ... @@ -53,19 +72,29 @@
53 72 -->
54 73  
55 74 <!--
56   - -->
57 75 <container qualifier="glassfish-embedded" default="true">
58 76 <configuration>
59 77 <property name="resourcesXml">src/test/resources/glassfish-resources.xml</property>
60 78 </configuration>
61 79 </container>
  80 + -->
  81 +
  82 + <!--
  83 + <container qualifier="tomee" default="true">
  84 + <configuration>
  85 + <property name="httpPort">-1</property>
  86 + <property name="stopPort">-1</property>
  87 + </configuration>
  88 + </container>
  89 + -->
62 90  
63 91 <!--
64 92 <container qualifier="jbossas-embedded" default="true">
65 93 <configuration>
66   - <property name="jbossHome">/opt/demoiselle/server/jboss-7.1/</property>
  94 + <property name="bindaddress">127.0.0.1</property>
  95 + <property name="httpport">8081</property>
67 96 </configuration>
68 97 </container>
69 98 -->
70   -
  99 +
71 100 </arquillian>
72 101 \ No newline at end of file
... ...
impl/extension/jpa/src/test/resources/template/persistence.xml
... ... @@ -37,6 +37,7 @@
37 37 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
38 38 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
39 39  
  40 + <!--
40 41 <persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
41 42 <non-jta-data-source>jdbc/arquillian1</non-jta-data-source>
42 43  
... ... @@ -48,8 +49,10 @@
48 49 <property name="eclipselink.logging.parameters" value="true" />
49 50 </properties>
50 51 </persistence-unit>
  52 + -->
51 53  
52 54 <!--
  55 + -->
53 56 <persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
54 57 <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
55 58  
... ... @@ -61,6 +64,5 @@
61 64 <property name="hibernate.hbm2ddl.auto" value="create-drop" />
62 65 </properties>
63 66 </persistence-unit>
64   - -->
65 67  
66 68 </persistence>
67 69 \ No newline at end of file
... ...
impl/extension/jpa/src/test/resources/transaction/manual/persistence.xml
... ... @@ -37,6 +37,7 @@
37 37 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
38 38 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
39 39  
  40 + <!--
40 41 <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL">
41 42 <non-jta-data-source>jdbc/arquillian1</non-jta-data-source>
42 43  
... ... @@ -60,12 +61,15 @@
60 61 <property name="eclipselink.logging.parameters" value="true" />
61 62 </properties>
62 63 </persistence-unit>
  64 + -->
63 65  
64 66 <!--
  67 + -->
65 68 <persistence-unit name="pu1" transaction-type="RESOURCE_LOCAL">
66 69 <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
67 70  
68   - <class>transaction.manual.MyEntity</class>
  71 + <class>transaction.manual.MyEntity1</class>
  72 + <class>transaction.manual.MyEntity2</class>
69 73  
70 74 <properties>
71 75 <property name="hibernate.show_sql" value="true" />
... ... @@ -75,9 +79,10 @@
75 79 </persistence-unit>
76 80  
77 81 <persistence-unit name="pu2" transaction-type="RESOURCE_LOCAL">
78   - <non-jta-data-source>java:jboss/datasources/ExampleDS2</non-jta-data-source>
  82 + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
79 83  
80   - <class>transaction.manual.MyEntity</class>
  84 + <class>transaction.manual.MyEntity1</class>
  85 + <class>transaction.manual.MyEntity2</class>
81 86  
82 87 <properties>
83 88 <property name="hibernate.show_sql" value="true" />
... ... @@ -85,6 +90,5 @@
85 90 <property name="hibernate.hbm2ddl.auto" value="create-drop" />
86 91 </properties>
87 92 </persistence-unit>
88   - -->
89 93  
90 94 </persistence>
91 95 \ No newline at end of file
... ...