Commit 7cda9769 authored by Administrator's avatar Administrator

Completes some tests for better coverage

Some test of the service and rest projects have been updated for better
coverage, achieving a 100% coverage in most of them.
parent 6e691966
......@@ -188,6 +188,7 @@ public class OwnerResourceRestTest {
@CleanupUsingScript({ "cleanup.sql", "cleanup-autoincrement.sql" })
public void afterCreateWithPets() {}
private void testCreateOwner(WebTarget webTarget, Owner newOwner) {
testCreateOwner(webTarget, newOwner, newOwner);
}
......@@ -203,7 +204,6 @@ public class OwnerResourceRestTest {
final Owner owner = responseGet.readEntity(Owner.class);
assertThat(owner, is(equalsToOwner(persistentOwner)));
}
@Test @InSequence(30)
......
......@@ -4,6 +4,7 @@ import static es.uvigo.esei.xcs.domain.entities.IsEqualsToOwner.containsOwnersIn
import static es.uvigo.esei.xcs.domain.entities.IsEqualsToOwner.equalsToOwner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.anyLogin;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.anyOwner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.existentOwner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newOwnerWithFreshPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newOwnerWithPersistentPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.owners;
......@@ -23,6 +24,7 @@ import static org.junit.Assert.assertThat;
import java.net.URI;
import java.util.List;
import javax.persistence.EntityExistsException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
......@@ -157,6 +159,18 @@ public class OwnerResourceUnitTest extends EasyMockSupport {
resource.create(null);
}
@Test(expected = IllegalArgumentException.class)
public void testCreateExistentOwner() {
final Owner existentOwner = existentOwner();
expect(facade.create(existentOwner))
.andThrow(new EntityExistsException());
replayAll();
resource.create(existentOwner);
}
@Test
public void testUpdate() {
final Owner owner = anyOwner();
......
......@@ -174,6 +174,12 @@ public class OwnerServiceIntegrationTest {
asAdmin.call(() -> facade.create(null));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testUpdateNull() {
asAdmin.run(() -> facade.update(null));
}
@Test
@ShouldMatchDataSet("owners-update-password.xml")
public void testUpdatePassword() {
......
......@@ -132,14 +132,24 @@ public class PetServiceIntegrationTest {
final Owner owner = ownerWithoutPets();
principal.setName(owner.getLogin());
final Pet pet = newPet();
final Pet pet = newPetWithOwner(owner);
asOwner.call(() -> facade.create(pet));
}
@Test
@ShouldMatchDataSet({ "owners.xml", "owners-create-pet.xml" })
public void testCreateNullOwner() {
principal.setName(ownerWithoutPets().getLogin());
final Pet pet = newPet();
asOwner.run(() -> facade.create(pet));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet({ "owners.xml" })
public void testCreateNull() {
public void testCreateNullPet() {
principal.setName(ownerWithoutPets().getLogin());
asOwner.run(() -> facade.create(null));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment