added more test cases
This commit is contained in:
parent
fb34b40870
commit
344846c9ca
|
@ -15,10 +15,6 @@ public class ExtendedPersistenceContextUserService {
|
|||
@PersistenceContext(type = PersistenceContextType.EXTENDED)
|
||||
private EntityManager entityManager;
|
||||
|
||||
public EntityManager getEntityManager() {
|
||||
return entityManager;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public User insertWithTransaction(User user) {
|
||||
entityManager.persist(user);
|
||||
|
|
|
@ -15,10 +15,6 @@ public class TransctionPersistenceContextUserService {
|
|||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
public EntityManager getEntityManager() {
|
||||
return entityManager;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public User insertWithTransaction(User user) {
|
||||
entityManager.persist(user);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class PersistenceContextIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(expected = HttpServerErrorException.class)
|
||||
public void testThatWhenUserSaveWithOutTransactionInPersistenceContextTypeTransactionThenShouldFailOnPersist() {
|
||||
public void testThatWhenUserSaveWithOutTransactionInPersistenceContextTypeTransactionThenShouldWhtowTransactionRequiredExceptionOnPersist() {
|
||||
User user = new User(122L, "Devender", "admin");
|
||||
restTemplate.postForEntity(buildRequestUrl("v4/user/"), user, User.class);
|
||||
}
|
||||
|
@ -55,6 +55,21 @@ public class PersistenceContextIntegrationTest {
|
|||
assertThat(userFromTransctionPersistenceContext, Is.is(IsNull.nullValue()));
|
||||
}
|
||||
|
||||
@Test(expected = HttpServerErrorException.class)
|
||||
public void testThatWhenAddUserWithSameIdentifierInPersistenceContextThenShouldThrowException() {
|
||||
User user = new User(126L, "Devender", "admin");
|
||||
restTemplate.postForEntity(buildRequestUrl("v2/user/"), user, User.class);
|
||||
restTemplate.postForEntity(buildRequestUrl("v2/user/"), user, User.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatWhenUserSavedWithExtendedPersistenceContextWithTransactionThenUserShouldSaveEntityIntoDB() {
|
||||
User user = new User(127L, "Devender", "admin");
|
||||
restTemplate.postForEntity(buildRequestUrl("v3/user/"), user, User.class);
|
||||
User userFromDB = restTemplate.getForObject(buildRequestUrl("v1/user/127"), User.class);
|
||||
assertThat(userFromDB, Is.is(IsNull.notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatWhenUserSavedWithExtendedPersistenceContextWithTransactionThenUserShouldFlushCachedEntityIntoDB() {
|
||||
User user = new User(124L, "Devender", "admin");
|
||||
|
|
Loading…
Reference in New Issue