Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ARQ-752] Fixed test archive enrichment. Updated Arquillian Core to CR7.

  • Loading branch information...
commit 3552ac41e05289b3ad1ac3e25e86930bdce55679 1 parent fc929b6
@bartoszmajsak bartoszmajsak authored
View
6 ...boss/arquillian/persistence/deployment/PersistenceExtensionDynamicDependencyAppender.java
@@ -53,7 +53,11 @@
@Override
public void process(Archive<?> applicationArchive, TestClass testClass)
{
- addResources(applicationArchive, toJavaArchive(fetchAllDataResources(testClass)));
+ final Set<ResourceDescriptor<?>> allDataResources = fetchAllDataResources(testClass);
+ if (!allDataResources.isEmpty())
+ {
+ addResources(applicationArchive, toJavaArchive(allDataResources));
+ }
addSqlScriptAsResource(applicationArchive, configuration.get().getCleanupStatement());
addSqlScriptAsResource(applicationArchive, configuration.get().getInitStatement());
}
View
13 int-tests/src/test/java/org/jboss/arquillian/example/NonDeployableUserPersistenceTest.java
@@ -189,7 +189,7 @@ public void shouldPersistUsersWithinTransaction() throws Exception
// then
@SuppressWarnings("unchecked")
- List<UserAccount> savedUserAccounts = em.createQuery(selectAllInJPQL(UserAccount.class)).getResultList();
+ List<UserAccount> savedUserAccounts = em.createQuery(Query.selectAllInJPQL(UserAccount.class)).getResultList();
assertThat(savedUserAccounts).hasSize(2);
}
@@ -209,7 +209,7 @@ public void shouldPersistUsersAndRollbackTransactionAfterTestExecution() throws
// then
@SuppressWarnings("unchecked")
- List<UserAccount> savedUserAccounts = em.createQuery(selectAllInJPQL(UserAccount.class)).getResultList();
+ List<UserAccount> savedUserAccounts = em.createQuery(Query.selectAllInJPQL(UserAccount.class)).getResultList();
assertThat(savedUserAccounts).hasSize(2);
}
@@ -241,7 +241,7 @@ public void shouldFindTwoUsersUsingFlatXmlDataSet() throws Exception
// when
@SuppressWarnings("unchecked")
- List<UserAccount> userAccounts = em.createQuery(selectAllInJPQL(UserAccount.class)).getResultList();
+ List<UserAccount> userAccounts = em.createQuery(Query.selectAllInJPQL(UserAccount.class)).getResultList();
// then
assertThat(userAccounts).hasSize(expectedUserAmount);
@@ -298,11 +298,4 @@ public void shouldCompareNullValueDefinedInJsonDataSet() throws Exception
// verified by DataSet comparision
}
- // Private helper methods
-
- private String selectAllInJPQL(Class<?> clazz)
- {
- return "SELECT entity FROM " + clazz.getSimpleName() + " entity";
- }
-
}
View
28 int-tests/src/test/java/org/jboss/arquillian/example/Query.java
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.arquillian.example;
+
+public class Query
+{
+
+ public static String selectAllInJPQL(final Class<UserAccount> c)
+ {
+ return "SELECT entity FROM " + c.getSimpleName() + " entity";
+ }
+
+}
View
82 int-tests/src/test/java/org/jboss/arquillian/example/TransactionalUserPersistenceTest.java
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.arquillian.example;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.persistence.Transactional;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * All tests are wrapped in transaction.
+ *
+ * @author <a href="mailto:bartosz.majsak@gmail.com">Bartosz Majsak</a>
+ *
+ */
+@RunWith(Arquillian.class)
+@Transactional
+public class TransactionalUserPersistenceTest
+{
+
+ @Deployment
+ public static Archive<?> createDeploymentPackage()
+ {
+ return ShrinkWrap.create(WebArchive.class, "test.war")
+ .addPackage(UserAccount.class.getPackage())
+ // required for remote containers in order to run tests with FEST-Asserts
+ .addPackages(true, "org.fest")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addAsResource("test-persistence.xml", "META-INF/persistence.xml");
+ }
+
+ @PersistenceContext
+ EntityManager em;
+
+ @Test
+ public void shouldPersistUsersWithinTransaction() throws Exception
+ {
+ // given
+ UserAccount johnSmith = new UserAccount("John", "Smith", "doovde", "password");
+ UserAccount clarkKent = new UserAccount("Clark", "Kent", "superman", "LexLuthor");
+
+ // when
+ em.persist(johnSmith);
+ em.persist(clarkKent);
+ em.flush();
+ em.clear();
+
+ // then
+ @SuppressWarnings("unchecked")
+ List<UserAccount> savedUserAccounts = em.createQuery(Query.selectAllInJPQL(UserAccount.class)).getResultList();
+ assertThat(savedUserAccounts).hasSize(2);
+ }
+
+}
View
84 int-tests/src/test/java/org/jboss/arquillian/example/UserPersistenceTest.java
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.arquillian.example;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.persistence.PersistenceTest;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ *
+ * This test is using {@link PersistenceTest} annotation which is marker
+ * annotation for triggering persistence extension. All tests within
+ * marked test class are wrapped in transaction.
+ *
+ * @author <a href="mailto:bartosz.majsak@gmail.com">Bartosz Majsak</a>
+ *
+ */
+@RunWith(Arquillian.class)
+@PersistenceTest
+public class UserPersistenceTest
+{
+
+ @Deployment
+ public static Archive<?> createDeploymentPackage()
+ {
+ return ShrinkWrap.create(WebArchive.class, "test.war")
+ .addPackage(UserAccount.class.getPackage())
+ // required for remote containers in order to run tests with FEST-Asserts
+ .addPackages(true, "org.fest")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addAsResource("test-persistence.xml", "META-INF/persistence.xml");
+ }
+
+ @PersistenceContext
+ EntityManager em;
+
+ @Test
+ public void shouldPersistUsersWithinTransaction() throws Exception
+ {
+ // given
+ UserAccount johnSmith = new UserAccount("John", "Smith", "doovde", "password");
+ UserAccount clarkKent = new UserAccount("Clark", "Kent", "superman", "LexLuthor");
+
+ // when
+ em.persist(johnSmith);
+ em.persist(clarkKent);
+ em.flush();
+ em.clear();
+
+ // then
+ @SuppressWarnings("unchecked")
+ List<UserAccount> savedUserAccounts = em.createQuery(Query.selectAllInJPQL(UserAccount.class)).getResultList();
+ assertThat(savedUserAccounts).hasSize(2);
+ }
+
+}
View
2  pom.xml
@@ -25,7 +25,7 @@
<!-- Properties -->
<properties>
<!-- Versioning -->
- <version.arquillian_core>1.0.0.CR6</version.arquillian_core>
+ <version.arquillian_core>1.0.0.CR7</version.arquillian_core>
<!-- override from parent -->
<maven.compiler.argument.target>1.5</maven.compiler.argument.target>
Please sign in to comment.
Something went wrong with that request. Please try again.