BAEL-659 (#4489)
* BAEL-1412 add java 8 spring data features * BAEL-21 new HTTP API overview * BAEL-21 fix executor * BAEL-1432 add custom gradle task * BAEL-1567 add samples of cookie and session in serlvet * BAEL-1567 use stream api * BAEL-1567 fix optional * BAEL-1679 add query annotation jpa spring data * BAEL-1679 added new junits * BAEL-1679 use assertJ, use givenWhenThen naming convention * BAEL-1679 move query annotation examples to persistence modules * BAEL-1679 fix formatting * BAEL-659 add junits for repositories * BAEL-659 add one junit * BAEL-659 remove one duplicated dependency * BAEL-659 fix test class name
This commit is contained in:
parent
b24dfc8976
commit
5b1d3d2c32
@ -9,6 +9,13 @@
|
|||||||
<name>deltaspike</name>
|
<name>deltaspike</name>
|
||||||
<description>A starter Java EE 7 webapp which uses DeltaSpike</description>
|
<description>A starter Java EE 7 webapp which uses DeltaSpike</description>
|
||||||
<url>http://wildfly.org</url>
|
<url>http://wildfly.org</url>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-modules</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>Apache License, Version 2.0</name>
|
<name>Apache License, Version 2.0</name>
|
||||||
@ -16,12 +23,12 @@
|
|||||||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
<repositories>
|
||||||
<parent>
|
<repository>
|
||||||
<groupId>com.baeldung</groupId>
|
<id>redhat-repository-techpreview</id>
|
||||||
<artifactId>parent-modules</artifactId>
|
<url>https://maven.repository.redhat.com/techpreview/all/</url>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
</repository>
|
||||||
</parent>
|
</repositories>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -47,6 +54,13 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.deltaspike.distribution</groupId>
|
||||||
|
<artifactId>distributions-bom</artifactId>
|
||||||
|
<version>${deltaspike.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
@ -160,14 +174,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.deltaspike.modules</groupId>
|
<groupId>org.apache.deltaspike.modules</groupId>
|
||||||
<artifactId>deltaspike-data-module-api</artifactId>
|
<artifactId>deltaspike-data-module-api</artifactId>
|
||||||
<version>${deltaspike.version}</version>
|
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.deltaspike.modules</groupId>
|
<groupId>org.apache.deltaspike.modules</groupId>
|
||||||
<artifactId>deltaspike-data-module-impl</artifactId>
|
<artifactId>deltaspike-data-module-impl</artifactId>
|
||||||
<version>${deltaspike.version}</version>
|
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -184,6 +196,71 @@
|
|||||||
<artifactId>querydsl-jpa</artifactId>
|
<artifactId>querydsl-jpa</artifactId>
|
||||||
<version>${querydsl.version}</version>
|
<version>${querydsl.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.deltaspike.modules</groupId>
|
||||||
|
<artifactId>deltaspike-test-control-module-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.deltaspike.modules</groupId>
|
||||||
|
<artifactId>deltaspike-test-control-module-impl</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.deltaspike.cdictrl</groupId>
|
||||||
|
<artifactId>deltaspike-cdictrl-weld</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.weld.se</groupId>
|
||||||
|
<artifactId>weld-se-core</artifactId>
|
||||||
|
<version>${weld.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss</groupId>
|
||||||
|
<artifactId>jandex</artifactId>
|
||||||
|
<version>1.2.5.Final-redhat-1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>1.4.197</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-entitymanager</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Needed for running tests (you may also use TestNG) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Others -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -226,28 +303,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
|
||||||
<!-- The default profile skips all tests, though you can tune it to run
|
|
||||||
just unit tests based on a custom pattern -->
|
|
||||||
<!-- Seperate profiles are provided for running all tests, including Arquillian
|
|
||||||
tests that execute in the specified container -->
|
|
||||||
<id>default</id>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>true</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
|
|
||||||
<!-- An optional Arquillian testing profile that executes tests in your
|
<!-- An optional Arquillian testing profile that executes tests in your
|
||||||
@ -273,15 +328,18 @@
|
|||||||
resources, i.e. build is platform dependent! -->
|
resources, i.e. build is platform dependent! -->
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<querydsl.version>3.7.4</querydsl.version>
|
<querydsl.version>3.7.4</querydsl.version>
|
||||||
<deltaspike.version>1.7.2</deltaspike.version>
|
<deltaspike.version>1.8.2</deltaspike.version>
|
||||||
<!-- JBoss dependency versions -->
|
<!-- JBoss dependency versions -->
|
||||||
<wildfly.maven.plugin.version>1.0.2.Final</wildfly.maven.plugin.version>
|
<wildfly.maven.plugin.version>1.0.2.Final</wildfly.maven.plugin.version>
|
||||||
<!-- Define the version of the JBoss BOMs we want to import to specify
|
<!-- Define the version of the JBoss BOMs we want to import to specify
|
||||||
tested stacks. -->
|
tested stacks. -->
|
||||||
<jboss.bom.version>8.2.2.Final</jboss.bom.version>
|
<jboss.bom.version>8.2.1.Final</jboss.bom.version>
|
||||||
|
<weld.version>2.1.2.Final</weld.version>
|
||||||
<!-- other plugin versions -->
|
<!-- other plugin versions -->
|
||||||
<war.plugin.version>2.6</war.plugin.version>
|
<war.plugin.version>2.6</war.plugin.version>
|
||||||
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package baeldung.controller;
|
package baeldung.controller;
|
||||||
|
|
||||||
|
import baeldung.model.Member;
|
||||||
|
import baeldung.service.MemberRegistration;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.enterprise.inject.Model;
|
import javax.enterprise.inject.Model;
|
||||||
import javax.enterprise.inject.Produces;
|
import javax.enterprise.inject.Produces;
|
||||||
@ -24,9 +27,6 @@ import javax.faces.context.FacesContext;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import baeldung.model.Member;
|
|
||||||
import baeldung.service.MemberRegistration;
|
|
||||||
|
|
||||||
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
|
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
|
||||||
// EL name
|
// EL name
|
||||||
// Read more about the @Model stereotype in this FAQ:
|
// Read more about the @Model stereotype in this FAQ:
|
||||||
@ -34,11 +34,9 @@ import baeldung.service.MemberRegistration;
|
|||||||
@Model
|
@Model
|
||||||
public class MemberController {
|
public class MemberController {
|
||||||
|
|
||||||
@Inject
|
@Inject private FacesContext facesContext;
|
||||||
private FacesContext facesContext;
|
|
||||||
|
|
||||||
@Inject
|
@Inject private MemberRegistration memberRegistration;
|
||||||
private MemberRegistration memberRegistration;
|
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
@Named
|
@Named
|
||||||
|
@ -1,29 +1,18 @@
|
|||||||
package baeldung.data;
|
package baeldung.data;
|
||||||
|
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.enterprise.inject.Default;
|
|
||||||
import javax.enterprise.inject.Disposes;
|
|
||||||
import javax.enterprise.inject.Produces;
|
import javax.enterprise.inject.Produces;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.PersistenceUnit;
|
|
||||||
|
|
||||||
@ApplicationScoped
|
|
||||||
public class EntityManagerProducer {
|
public class EntityManagerProducer {
|
||||||
@PersistenceUnit(unitName = "primary")
|
|
||||||
private EntityManagerFactory entityManagerFactory;
|
|
||||||
|
|
||||||
@Produces
|
@PersistenceContext(unitName = "primary") private EntityManager entityManager;
|
||||||
@Default
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
|
@Produces
|
||||||
public EntityManager create() {
|
public EntityManager create() {
|
||||||
return this.entityManagerFactory.createEntityManager();
|
return entityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose(@Disposes @Default EntityManager entityManager) {
|
|
||||||
if (entityManager.isOpen()) {
|
|
||||||
entityManager.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package baeldung.data;
|
package baeldung.data;
|
||||||
|
|
||||||
|
import baeldung.model.Member;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.enterprise.event.Observes;
|
import javax.enterprise.event.Observes;
|
||||||
@ -25,13 +27,10 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import baeldung.model.Member;
|
|
||||||
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class MemberListProducer {
|
public class MemberListProducer {
|
||||||
|
|
||||||
@Inject
|
@Inject private MemberRepository memberRepository;
|
||||||
private MemberRepository memberRepository;
|
|
||||||
|
|
||||||
private List<Member> members;
|
private List<Member> members;
|
||||||
|
|
||||||
|
@ -18,7 +18,10 @@ package baeldung.data;
|
|||||||
|
|
||||||
import baeldung.model.Member;
|
import baeldung.model.Member;
|
||||||
import baeldung.model.QMember;
|
import baeldung.model.QMember;
|
||||||
import org.apache.deltaspike.data.api.*;
|
import org.apache.deltaspike.data.api.AbstractEntityRepository;
|
||||||
|
import org.apache.deltaspike.data.api.EntityManagerConfig;
|
||||||
|
import org.apache.deltaspike.data.api.Query;
|
||||||
|
import org.apache.deltaspike.data.api.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -35,6 +38,9 @@ public abstract class MemberRepository extends AbstractEntityRepository<Member,
|
|||||||
|
|
||||||
public List<Member> findAllOrderedByNameWithQueryDSL() {
|
public List<Member> findAllOrderedByNameWithQueryDSL() {
|
||||||
final QMember member = QMember.member;
|
final QMember member = QMember.member;
|
||||||
return jpaQuery().from(member).orderBy(member.email.asc()).list(member);
|
return jpaQuery()
|
||||||
|
.from(member)
|
||||||
|
.orderBy(member.email.asc())
|
||||||
|
.list(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
public class QueryDslRepositoryExtension<E> implements QueryDslSupport, DelegateQueryHandler {
|
public class QueryDslRepositoryExtension<E> implements QueryDslSupport, DelegateQueryHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject private QueryInvocationContext context;
|
||||||
private QueryInvocationContext context;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JPAQuery jpaQuery() {
|
public JPAQuery jpaQuery() {
|
||||||
|
@ -2,29 +2,20 @@ package baeldung.data;
|
|||||||
|
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.enterprise.inject.Default;
|
|
||||||
import javax.enterprise.inject.Disposes;
|
|
||||||
import javax.enterprise.inject.Produces;
|
import javax.enterprise.inject.Produces;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.PersistenceUnit;
|
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class SecondaryEntityManagerProducer {
|
public class SecondaryEntityManagerProducer {
|
||||||
@PersistenceUnit(unitName = "secondary")
|
|
||||||
private EntityManagerFactory entityManagerFactory;
|
@PersistenceContext(unitName = "secondary") private EntityManager entityManager;
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
@Default
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@SecondaryPersistenceUnit
|
@SecondaryPersistenceUnit
|
||||||
public EntityManager create() {
|
public EntityManager create() {
|
||||||
return this.entityManagerFactory.createEntityManager();
|
return entityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose(@Disposes @Default EntityManager entityManager) {
|
|
||||||
if (entityManager.isOpen()) {
|
|
||||||
entityManager.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package baeldung.data;
|
||||||
|
|
||||||
|
import baeldung.model.User;
|
||||||
|
import org.apache.deltaspike.data.api.FirstResult;
|
||||||
|
import org.apache.deltaspike.data.api.MaxResults;
|
||||||
|
import org.apache.deltaspike.data.api.Repository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
@Repository(forEntity = User.class)
|
||||||
|
public abstract class SimpleUserRepository {
|
||||||
|
public abstract Collection<User> findAll();
|
||||||
|
|
||||||
|
public abstract Collection<User> findAllOrderByFirstNameAsc(@FirstResult int start, @MaxResults int size);
|
||||||
|
|
||||||
|
public abstract Collection<User> findTop2OrderByFirstNameAsc();
|
||||||
|
|
||||||
|
public abstract Collection<User> findFirst2OrderByFirstNameAsc();
|
||||||
|
|
||||||
|
public abstract List<User> findAllOrderByFirstNameAsc();
|
||||||
|
|
||||||
|
public abstract List<User> findAllOrderByFirstNameAscLastNameDesc();
|
||||||
|
|
||||||
|
public abstract User findById(Long id);
|
||||||
|
|
||||||
|
public abstract Collection<User> findByFirstName(String firstName);
|
||||||
|
|
||||||
|
public abstract User findAnyByLastName(String lastName);
|
||||||
|
|
||||||
|
public abstract Collection<User> findAnyByFirstName(String firstName);
|
||||||
|
|
||||||
|
public abstract Collection<User> findByFirstNameAndLastName(String firstName, String lastName);
|
||||||
|
|
||||||
|
public abstract Collection<User> findByFirstNameOrLastName(String firstName, String lastName);
|
||||||
|
|
||||||
|
public abstract Collection<User> findByAddress_city(String city);
|
||||||
|
|
||||||
|
public abstract int count();
|
||||||
|
|
||||||
|
public abstract void remove(User user);
|
||||||
|
}
|
31
deltaspike/src/main/java/baeldung/data/UserRepository.java
Normal file
31
deltaspike/src/main/java/baeldung/data/UserRepository.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package baeldung.data;
|
||||||
|
|
||||||
|
import baeldung.model.User;
|
||||||
|
import org.apache.deltaspike.data.api.AbstractEntityRepository;
|
||||||
|
import org.apache.deltaspike.data.api.Query;
|
||||||
|
import org.apache.deltaspike.data.api.Repository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public abstract class UserRepository extends AbstractEntityRepository<User, Long> {
|
||||||
|
|
||||||
|
public List<User> findByFirstName(String firstName) {
|
||||||
|
return typedQuery("select u from User u where u.firstName = ?1")
|
||||||
|
.setParameter(1, firstName)
|
||||||
|
.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<User> findByLastName(String lastName);
|
||||||
|
|
||||||
|
@Query("select u from User u where u.firstName = ?1")
|
||||||
|
public abstract Collection<User> findUsersWithFirstName(String firstName);
|
||||||
|
|
||||||
|
@Query(value = "select * from User where firstName = ?1", isNative = true)
|
||||||
|
public abstract Collection<User> findUsersWithFirstNameNative(String firstName);
|
||||||
|
|
||||||
|
}
|
51
deltaspike/src/main/java/baeldung/model/Address.java
Normal file
51
deltaspike/src/main/java/baeldung/model/Address.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package baeldung.model;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Address {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
private String street;
|
||||||
|
private String city;
|
||||||
|
private String postCode;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStreet() {
|
||||||
|
return street;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreet(String street) {
|
||||||
|
this.street = street;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPostCode() {
|
||||||
|
return postCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostCode(String postCode) {
|
||||||
|
this.postCode = postCode;
|
||||||
|
}
|
||||||
|
}
|
@ -16,22 +16,16 @@
|
|||||||
*/
|
*/
|
||||||
package baeldung.model;
|
package baeldung.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.hibernate.validator.constraints.Email;
|
||||||
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.persistence.UniqueConstraint;
|
|
||||||
import javax.validation.constraints.Digits;
|
import javax.validation.constraints.Digits;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Pattern;
|
import javax.validation.constraints.Pattern;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.io.Serializable;
|
||||||
import org.hibernate.validator.constraints.Email;
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Entity
|
@Entity
|
||||||
|
52
deltaspike/src/main/java/baeldung/model/User.java
Normal file
52
deltaspike/src/main/java/baeldung/model/User.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package baeldung.model;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
@OneToOne private Address address;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(Address address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
}
|
5
deltaspike/src/main/resources/META-INF/beans.xml
Normal file
5
deltaspike/src/main/resources/META-INF/beans.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
|
||||||
|
</beans>
|
21
deltaspike/src/test/java/baeldung/ValidatorProducer.java
Normal file
21
deltaspike/src/test/java/baeldung/ValidatorProducer.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package baeldung;
|
||||||
|
|
||||||
|
import javax.enterprise.inject.Produces;
|
||||||
|
import javax.validation.Validation;
|
||||||
|
import javax.validation.Validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
public class ValidatorProducer {
|
||||||
|
|
||||||
|
@Produces
|
||||||
|
public Validator createValidator() {
|
||||||
|
return Validation
|
||||||
|
.byDefaultProvider()
|
||||||
|
.configure()
|
||||||
|
.buildValidatorFactory()
|
||||||
|
.getValidator();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package baeldung.data;
|
||||||
|
|
||||||
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
|
import javax.enterprise.inject.Produces;
|
||||||
|
import javax.enterprise.inject.Specializes;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.Persistence;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
public class TestEntityManagerProducer extends EntityManagerProducer {
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
@Produces
|
||||||
|
@Specializes
|
||||||
|
public EntityManager create() {
|
||||||
|
return Persistence
|
||||||
|
.createEntityManagerFactory("pu-test")
|
||||||
|
.createEntityManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,19 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package baeldung.test;
|
package baeldung.test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import baeldung.data.*;
|
import baeldung.data.*;
|
||||||
import org.jboss.arquillian.container.test.api.Deployment;
|
|
||||||
import org.jboss.arquillian.junit.Arquillian;
|
|
||||||
import baeldung.model.Member;
|
import baeldung.model.Member;
|
||||||
import baeldung.service.MemberRegistration;
|
import baeldung.service.MemberRegistration;
|
||||||
import baeldung.util.Resources;
|
import baeldung.util.Resources;
|
||||||
|
import org.jboss.arquillian.container.test.api.Deployment;
|
||||||
|
import org.jboss.arquillian.junit.Arquillian;
|
||||||
import org.jboss.shrinkwrap.api.Archive;
|
import org.jboss.shrinkwrap.api.Archive;
|
||||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||||
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
||||||
@ -37,24 +30,39 @@ import org.jboss.shrinkwrap.resolver.api.maven.Maven;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(Arquillian.class)
|
@RunWith(Arquillian.class)
|
||||||
public class MemberRegistrationIntegrationTest {
|
public class MemberRegistrationIntegrationTest {
|
||||||
@Deployment
|
@Deployment
|
||||||
public static Archive<?> createTestArchive() {
|
public static Archive<?> createTestArchive() {
|
||||||
File[] files = Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile();
|
File[] files = Maven
|
||||||
|
.resolver()
|
||||||
|
.loadPomFromFile("pom.xml")
|
||||||
|
.importRuntimeDependencies()
|
||||||
|
.resolve()
|
||||||
|
.withTransitivity()
|
||||||
|
.asFile();
|
||||||
|
|
||||||
return ShrinkWrap.create(WebArchive.class, "test.war")
|
return ShrinkWrap
|
||||||
.addClasses(EntityManagerProducer.class, Member.class, MemberRegistration.class, MemberRepository.class, Resources.class, QueryDslRepositoryExtension.class, QueryDslSupport.class, SecondaryPersistenceUnit.class,
|
.create(WebArchive.class, "test.war")
|
||||||
SecondaryEntityManagerProducer.class, SecondaryEntityManagerResolver.class)
|
.addClasses(EntityManagerProducer.class, Member.class, MemberRegistration.class, MemberRepository.class, Resources.class, QueryDslRepositoryExtension.class, QueryDslSupport.class, SecondaryPersistenceUnit.class, SecondaryEntityManagerProducer.class,
|
||||||
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml").addAsResource("META-INF/apache-deltaspike.properties").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml").addAsWebInfResource("test-ds.xml")
|
SecondaryEntityManagerResolver.class)
|
||||||
.addAsWebInfResource("test-secondary-ds.xml").addAsLibraries(files);
|
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
|
||||||
|
.addAsResource("META-INF/apache-deltaspike.properties")
|
||||||
|
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
|
||||||
|
.addAsWebInfResource("test-ds.xml")
|
||||||
|
.addAsWebInfResource("test-secondary-ds.xml")
|
||||||
|
.addAsLibraries(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject MemberRegistration memberRegistration;
|
||||||
MemberRegistration memberRegistration;
|
|
||||||
|
|
||||||
@Inject
|
@Inject Logger log;
|
||||||
Logger log;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegister() throws Exception {
|
public void testRegister() throws Exception {
|
||||||
|
@ -0,0 +1,133 @@
|
|||||||
|
package baeldung.test;
|
||||||
|
|
||||||
|
import baeldung.data.SimpleUserRepository;
|
||||||
|
import baeldung.model.User;
|
||||||
|
import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
@RunWith(CdiTestRunner.class)
|
||||||
|
public class SimpleUserRepositoryUnitTest {
|
||||||
|
|
||||||
|
@Inject private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Inject private SimpleUserRepository simpleUserRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFourUsersWhenFindAllShouldReturnFourUsers() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findAll()
|
||||||
|
.size(), equalTo(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenFindByFirstNameShouldReturnTwoUsers() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findByFirstName("Adam")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenFindAnyByFirstNameShouldReturnTwoUsers() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findAnyByFirstName("Adam")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenCountByFirstNameShouldReturnSizeTwo() {
|
||||||
|
assertThat(simpleUserRepository.count(), equalTo(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenRemoveByFirstNameShouldReturnSizeTwo() {
|
||||||
|
simpleUserRepository.remove(entityManager.merge(simpleUserRepository.findById(1L)));
|
||||||
|
assertThat(entityManager.find(User.class, 1L), nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOneUserWithSpecifiedFirstNameAndLastNameWhenFindByFirstNameAndLastNameShouldReturnOneUser() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findByFirstNameAndLastName("Adam", "LastName1")
|
||||||
|
.size(), equalTo(1));
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findByFirstNameAndLastName("David", "LastName2")
|
||||||
|
.size(), equalTo(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOneUserWithSpecifiedLastNameWhenFindAnyByLastNameShouldReturnOneUser() {
|
||||||
|
assertThat(simpleUserRepository.findAnyByLastName("LastName1"), notNullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOneUserWithSpecifiedAddressCityWhenFindByCityShouldReturnOneUser() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findByAddress_city("London")
|
||||||
|
.size(), equalTo(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUsersWithSpecifiedFirstOrLastNameWhenFindByFirstNameOrLastNameShouldReturnTwoUsers() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findByFirstNameOrLastName("David", "LastName1")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUsersWhenFindAllOrderByFirstNameAscShouldReturnFirstAdamLastPeter() {
|
||||||
|
List<User> users = simpleUserRepository.findAllOrderByFirstNameAsc();
|
||||||
|
assertThat(users
|
||||||
|
.get(0)
|
||||||
|
.getFirstName(), equalTo("Adam"));
|
||||||
|
assertThat(users
|
||||||
|
.get(3)
|
||||||
|
.getFirstName(), equalTo("Peter"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUsersWhenFindAllOrderByFirstNameAscLastNameDescShouldReturnFirstAdamLastPeter() {
|
||||||
|
List<User> users = simpleUserRepository.findAllOrderByFirstNameAscLastNameDesc();
|
||||||
|
assertThat(users
|
||||||
|
.get(0)
|
||||||
|
.getFirstName(), equalTo("Adam"));
|
||||||
|
assertThat(users
|
||||||
|
.get(3)
|
||||||
|
.getFirstName(), equalTo("Peter"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUsersWhenFindTop2ShouldReturnTwoUsers() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findTop2OrderByFirstNameAsc()
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUsersWhenFindFirst2ShouldReturnTwoUsers() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findFirst2OrderByFirstNameAsc()
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenPagesWithSizeTwoWhenFindAllOrderByFirstNameAscShouldReturnTwoPages() {
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findAllOrderByFirstNameAsc(0, 2)
|
||||||
|
.size(), equalTo(2));
|
||||||
|
assertThat(simpleUserRepository
|
||||||
|
.findAllOrderByFirstNameAsc(2, 4)
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package baeldung.test;
|
||||||
|
|
||||||
|
import baeldung.data.UserRepository;
|
||||||
|
import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adam.
|
||||||
|
*/
|
||||||
|
@RunWith(CdiTestRunner.class)
|
||||||
|
public class UserRepositoryUnitTest {
|
||||||
|
|
||||||
|
@Inject private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFourUsersWhenFindAllShouldReturnFourUsers() {
|
||||||
|
assertThat(userRepository
|
||||||
|
.findAll()
|
||||||
|
.size(), equalTo(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenFindByFirstNameShouldReturnTwoUsers() {
|
||||||
|
assertThat(userRepository
|
||||||
|
.findByFirstName("Adam")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenFindUsersWithFirstNameShouldReturnTwoUsers() {
|
||||||
|
assertThat(userRepository
|
||||||
|
.findUsersWithFirstName("Adam")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedNameWhenFindUsersWithFirstNameNativeShouldReturnTwoUsers() {
|
||||||
|
assertThat(userRepository
|
||||||
|
.findUsersWithFirstNameNative("Adam")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoUsersWithSpecifiedLastNameWhenFindByLastNameShouldReturnTwoUsers() {
|
||||||
|
assertThat(userRepository
|
||||||
|
.findByLastName("LastName3")
|
||||||
|
.size(), equalTo(2));
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1,3 @@
|
|||||||
globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy
|
globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy
|
||||||
|
org.apache.deltaspike.ProjectStage=UnitTest
|
||||||
|
deltaspike.testcontrol.stop_container=false
|
18
deltaspike/src/test/resources/META-INF/beans.xml
Normal file
18
deltaspike/src/test/resources/META-INF/beans.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!--<?xml version="1.0" encoding="UTF-8"?>-->
|
||||||
|
<!--<!– JBoss, Home of Professional Open Source Copyright 2013, Red Hat, Inc. -->
|
||||||
|
<!--and/or its affiliates, and individual contributors by the @authors tag. 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. –>-->
|
||||||
|
<!--<!– Marker file indicating CDI should be enabled –>-->
|
||||||
|
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee
|
||||||
|
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
|
||||||
|
|
||||||
|
</beans>
|
@ -11,6 +11,7 @@
|
|||||||
<property name="hibernate.show_sql" value="false" />
|
<property name="hibernate.show_sql" value="false" />
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
<persistence-unit name="secondary">
|
<persistence-unit name="secondary">
|
||||||
<jta-data-source>java:jboss/datasources/baeldung-jee7-seedTestSecondaryDS</jta-data-source>
|
<jta-data-source>java:jboss/datasources/baeldung-jee7-seedTestSecondaryDS</jta-data-source>
|
||||||
<properties>
|
<properties>
|
||||||
@ -18,4 +19,23 @@
|
|||||||
<property name="hibernate.show_sql" value="false" />
|
<property name="hibernate.show_sql" value="false" />
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
<persistence-unit name="pu-test" transaction-type="RESOURCE_LOCAL">
|
||||||
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
<!-- add classes -->
|
||||||
|
<class>baeldung.model.User</class>
|
||||||
|
<class>baeldung.model.Address</class>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- Configuring JDBC properties -->
|
||||||
|
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test"/>
|
||||||
|
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||||
|
|
||||||
|
<!-- Hibernate properties -->
|
||||||
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
|
||||||
|
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
|
||||||
|
<property name="hibernate.format_sql" value="false"/>
|
||||||
|
<property name="hibernate.show_sql" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
@ -28,12 +28,4 @@
|
|||||||
<!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
|
<!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
|
||||||
<defaultProtocol type="Servlet 3.0" />
|
<defaultProtocol type="Servlet 3.0" />
|
||||||
|
|
||||||
<!-- Example configuration for a remote WildFly instance -->
|
|
||||||
<container qualifier="jboss" default="true">
|
|
||||||
<!-- By default, arquillian will use the JBOSS_HOME environment variable. Alternatively, the configuration below can be uncommented. -->
|
|
||||||
<configuration>
|
|
||||||
<property name="jbossHome">target\wildfly-run\wildfly-10.0.0.Final</property>
|
|
||||||
</configuration>
|
|
||||||
</container>
|
|
||||||
|
|
||||||
</arquillian>
|
</arquillian>
|
||||||
|
6
deltaspike/src/test/resources/import.sql
Normal file
6
deltaspike/src/test/resources/import.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
INSERT INTO ADDRESS(ID, STREET, CITY, POSTCODE) VALUES (1, 'Oxford', 'London', 'N121');
|
||||||
|
|
||||||
|
INSERT INTO USER(ID, FIRSTNAME, LASTNAME, ADDRESS_ID) VALUES (1, 'Adam', 'LastName1', null);
|
||||||
|
INSERT INTO USER(ID, FIRSTNAME, LASTNAME, ADDRESS_ID) VALUES (2, 'David', 'LastName2', null);
|
||||||
|
INSERT INTO USER(ID, FIRSTNAME, LASTNAME, ADDRESS_ID) VALUES (3, 'Adam', 'LastName3', null);
|
||||||
|
INSERT INTO USER(ID, FIRSTNAME, LASTNAME, ADDRESS_ID) VALUES (4, 'Peter', 'LastName3', 1);
|
Loading…
x
Reference in New Issue
Block a user