Commit 7fe00cf8 authored by Administrator's avatar Administrator

Adds the service layer implementation

This commit adds the OwnerService and PetService EJBs to the
implementation. This commit also includes the tests for this EJBs with
two different Wildfly profiles: a H2 profile and a MySQL profile.
parent 13caa3fc
This diff is collapsed.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>es.uvigo.esei.xcs</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>service</artifactId>
<packaging>jar</packaging>
<name>Service</name>
<description>XCS Sample - Service</description>
<dependencies>
<!-- General -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>es.uvigo.esei.xcs</groupId>
<artifactId>domain</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-persistence-dbunit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package es.uvigo.esei.xcs.service;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.security.RolesAllowed;
import javax.ejb.Stateless;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.Pet;
/**
* EJB for the Owners. Only administrators have access to this class.
*
* @author Miguel Reboiro Jato
*/
@Stateless
@RolesAllowed("ADMIN")
public class OwnerService {
@PersistenceContext
private EntityManager em;
/**
* Returns the owner identified by {@code login}. If there is no owner with
* the specified login, {@code null} will be returned.
*
* @param login the login of an owner.
* @return the owner with the provided login or {@code null} if there is no
* owner with the specified login.
* @throws IllegalArgumentException if {@code login} is {@code null} or it
* does not identifies a valid owner.
*/
public Owner get(String login) {
return em.find(Owner.class, login);
}
/**
* Returns the complete list of owners.
*
* @return the complete list of owners.
*/
public List<Owner> list() {
return em.createQuery("SELECT o FROM Owner o", Owner.class)
.getResultList();
}
/**
* Returns the list of owners that have a pet with the specified name.
*
* @param petName a pet's name.
* @return the list of owners that have a pet with the specified name. The
* list may be empty if any owner has a pet with the specified name.
* @throws IllegalArgumentException if {@code petName} is {@code null}.
*/
public List<Owner> findByPetName(String petName) {
if (petName == null)
throw new IllegalArgumentException("petName can't be null");
final String query = "SELECT o FROM Owner o JOIN o.pets p " +
"WHERE p.name = :petName";
return em.createQuery(query, Owner.class)
.setParameter("petName", petName)
.getResultList();
}
/**
* Creates a new owner. If the owner already has pets, they will be created
* too.
*
* @param owner a new owner to be stored.
* @return the persistent version of the owner created.
* @throws IllegalArgumentException if {@code owner} is {@code null}.
* @throws EntityExistsException if an owner with the same login already
* exists.
*/
public Owner create(Owner owner) {
if (owner == null)
throw new IllegalArgumentException("owner can't be null");
this.em.persist(owner);
return owner;
}
/**
* Updates a new owner. If the owner is not stored, it will be persisted.
*
* @param owner an owner to be updated.
* @throws IllegalArgumentException if {@code owner} is {@code null}.
*/
public Owner update(Owner owner) {
if (owner == null)
throw new IllegalArgumentException("owner can't be null");
return em.merge(owner);
}
/**
* Deletes an owner.
*
* @param login the login of the owner to be deleted.
* @throws IllegalArgumentException if {@code login} is {@code null} or if
* it does not identifies a valid owner.
*/
public void remove(String login) {
em.remove(this.get(login));
}
/**
* Returns the list of pets of an owner.
*
* @param login the login of the owner that owns the pets.
* @return the list of pets of an owner.
* @throws IllegalArgumentException if {@code login} is {@code null} or it
* does not identifies a valid owner.
*/
public List<Pet> getPets(String login) {
return new ArrayList<>(this.get(login).getPets());
}
}
package es.uvigo.esei.xcs.service;
import java.security.Principal;
import java.util.List;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJBAccessException;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.Pet;
/**
* EJB for the Pets. Only owners have access to this class, and only to their
* own pets.
*
* @author Miguel Reboiro Jato
*/
@Stateless
@RolesAllowed("OWNER")
public class PetService {
@Inject
private Principal currentOwner;
@PersistenceContext
private EntityManager em;
/**
* Returns a pet identified by the provided id. If an owner tries to access
* a pet that does now own, an {@link EJBAccessException} will be thrown.
*
* @param id the identified of a pet.
* @return a pet identified by the provided identifier or {@code null} if no
* pet exists with the provided identifier.
* @throws EJBAccessException if the current owner does not owns the pet.
*/
public Pet get(int id) {
final Pet pet = em.find(Pet.class, id);
if (pet == null) {
return null;
} else if (pet.getOwner().getLogin().equals(this.currentOwner.getName())) {
return pet;
} else {
throw new EJBAccessException("Pet's owner is not the current principal");
}
}
/**
* Returns the complete list of pets of the current owner.
*
* @return the complete list of pets of the current owner.
*/
public List<Pet> list() {
return em.createQuery("SELECT p FROM Pet p WHERE p.owner.login = :login", Pet.class)
.setParameter("login", currentOwner.getName())
.getResultList();
}
/**
* Creates a new pet owned by the current user.
*
* @param pet a new pet to be stored.
* @return the persistent version of the pet created.
* @throws EJBAccessException if the pet already has an owner and it is not
* the current user. If the pet has no owner, this exception will be never
* thrown.
* @throws IllegalArgumentException if a pet with the same identifier
* already exists.
*/
public Pet create(Pet pet) {
final Owner owner = em.find(Owner.class, currentOwner.getName());
if (pet.getOwner() != null && !pet.getOwner().getLogin().equals(owner.getLogin())) {
throw new EJBAccessException("Pet's owner is not the current principal");
} else {
pet.setOwner(owner);
this.em.persist(pet);
return pet;
}
}
/**
* Updates the information of a pet. If the pet is not stored, it will be
* created.
*
* @param pet the pet to be updated.
* @throws IllegalArgumentException if the pet has no owner.
* @throws EJBAccessException if the pet's owner is not the current user.
*/
public Pet update(Pet pet) {
if (pet.getOwner() == null)
throw new IllegalArgumentException("Pet must have an owner");
if (pet.getOwner().getLogin().equals(this.currentOwner.getName())) {
return em.merge(pet);
} else {
throw new EJBAccessException("Pet's owner is not the current principal");
}
}
/**
* Deletes a pet.
*
* @param id the identifier of the pet to be deleted.
* @throws IllegalArgumentException if there is no pet with the provided
* identifier.
* @throws EJBAccessException if the pet's owner is not the current user.
*/
public void remove(int id) {
final Pet pet = this.get(id);
pet.setOwner(null);
em.remove(pet);
}
}
......@@ -74,6 +74,10 @@ public class OwnersDataset {
);
}
public static Owner anyOwner() {
return ownerWithPets();
}
public static Owner ownerWithPets() {
return owners()[1];
}
......@@ -82,7 +86,31 @@ public class OwnersDataset {
return owners()[3];
}
public static Pet anyPet() {
return pet(existentPetId());
}
public static Pet newPet() {
return new Pet("Lorenacat", AnimalType.CAT, new Date(946684861000L));
return newPetWithOwner(null);
}
public static Pet newPetWithOwner(Owner owner) {
return new Pet("Lorenacat", AnimalType.CAT, new Date(946684861000L), owner);
}
public static String existentLogin() {
return "pepe";
}
public static String existentPetName() {
return "Pepecat";
}
public static int existentPetId() {
return 2;
}
public static int nonExistentPetId() {
return 1000000;
}
}
package es.uvigo.esei.xcs.service;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.anyOwner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.existentLogin;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.existentPetName;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newOwnerWithoutPets;
import javax.ejb.EJB;
import javax.ejb.EJBAccessException;
import javax.ejb.EJBTransactionRolledbackException;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.persistence.CleanupUsingScript;
import org.jboss.arquillian.persistence.ShouldMatchDataSet;
import org.jboss.arquillian.persistence.TestExecutionPhase;
import org.jboss.arquillian.persistence.UsingDataSet;
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;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.OwnersDataset;
import es.uvigo.esei.xcs.service.util.security.RoleCaller;
@RunWith(Arquillian.class)
@UsingDataSet("owners.xml")
@ShouldMatchDataSet("owners.xml")
@CleanupUsingScript(phase = TestExecutionPhase.BEFORE, value = { "cleanup.sql", "cleanup-autoincrement.sql" })
public class OwnerServiceIllegalAccessIntegrationTest {
@Inject
private OwnerService facade;
@EJB(beanName = "owner-caller")
private RoleCaller owner;
@Deployment
public static Archive<?> createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(OwnerService.class, OwnersDataset.class)
.addPackage(RoleCaller.class.getPackage())
.addPackage(Owner.class.getPackage())
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource("jboss-web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return archive;
}
@Test(expected = EJBAccessException.class)
public void testGetNoRole() {
facade.get(existentLogin());
}
@Test(expected = EJBAccessException.class)
public void testListNoRole() {
facade.list();
}
@Test(expected = EJBAccessException.class)
public void testFindByPetNameNoRole() {
facade.findByPetName(existentPetName());
}
@Test(expected = EJBAccessException.class)
public void testCreateNoRole() {
facade.create(newOwnerWithoutPets());
}
@Test(expected = EJBAccessException.class)
public void testUpdateNoRole() {
facade.update(anyOwner());
}
@Test(expected = EJBAccessException.class)
public void testRemoveNoRole() {
facade.remove(existentLogin());
}
@Test(expected = EJBAccessException.class)
public void testGetPetsNoRole() {
facade.getPets(existentLogin());
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testGetRoleOwner() {
this.owner.run(this::testGetNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testListRoleOwner() {
this.owner.run(this::testListNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testFindByPetNameRoleOwner() {
this.owner.run(this::testFindByPetNameNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testCreateRoleOwner() {
this.owner.run(this::testCreateNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testUpdateRoleOwner() {
this.owner.run(this::testUpdateNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testRemoveRoleOwner() {
this.owner.run(this::testRemoveNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testGetPetsRoleOwner() {
this.owner.run(this::testGetPetsNoRole);
}
}
package es.uvigo.esei.xcs.service;
import static es.uvigo.esei.xcs.domain.entities.IsEqualsToOwner.containsOwnersInAnyOrder;
import static es.uvigo.esei.xcs.domain.entities.IsEqualsToOwner.equalsToOwner;
import static es.uvigo.esei.xcs.domain.entities.IsEqualsToPet.containsPetsInAnyOrder;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.anyOwner;
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.newOwnerWithoutPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.nonExistentLogin;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.nonExistentPetName;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.owner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.ownerWithPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.ownerWithoutPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.owners;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertThat;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.EJBTransactionRolledbackException;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.persistence.CleanupUsingScript;
import org.jboss.arquillian.persistence.ShouldMatchDataSet;
import org.jboss.arquillian.persistence.UsingDataSet;
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;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.OwnersDataset;
import es.uvigo.esei.xcs.domain.entities.Pet;
import es.uvigo.esei.xcs.service.util.security.RoleCaller;
@RunWith(Arquillian.class)
@UsingDataSet("owners.xml")
@CleanupUsingScript({ "cleanup.sql", "cleanup-autoincrement.sql" })
public class OwnerServiceIntegrationTest {
@Inject
private OwnerService facade;
@EJB(beanName = "admin-caller")
private RoleCaller admin;
@Deployment
public static Archive<?> createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(OwnerService.class, OwnersDataset.class)
.addPackage(RoleCaller.class.getPackage())
.addPackage(Owner.class.getPackage())
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource("jboss-web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return archive;
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testGetOwner() {
final String login = "pepe";
final Owner pepe = owner(login);
final Owner actual = admin.call(() -> facade.get(login));
assertThat(actual, is(equalsToOwner(pepe)));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testGetOwnerNonExistent() {
final String login = nonExistentLogin();
final Owner actual = admin.call(() -> facade.get(login));
assertThat(actual, is(nullValue()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testGetOwnerNull() {
admin.call(() -> facade.get(null));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testList() {
final List<Owner> actual = admin.call(() -> facade.list());
assertThat(actual, is(containsOwnersInAnyOrder(owners())));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testFindByPetName() {
final String pet = "Juandog";
final List<Owner> owners = admin.call(() -> facade.findByPetName(pet));
final Owner owner = owners.get(0);
final Owner juan = owner("juan");
assertThat(owner, is(equalsToOwner(juan)));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testFindByPetNameMultipleOwners() {
final String pet = "Max";
final List<Owner> owners = admin.call(() -> facade.findByPetName(pet));
final Owner[] expectedOwners = owners("juan", "ana");
assertThat(owners, containsOwnersInAnyOrder(expectedOwners));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testFindByPetNameNoPet() {
final String pet = nonExistentPetName();
final List<Owner> owners = admin.call(() -> facade.findByPetName(pet));
assertThat(owners, is(empty()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testFindByPetNameNull() {
admin.run(() -> facade.findByPetName(null));
}
@Test
@ShouldMatchDataSet({"owners.xml", "owners-create-without-pets.xml"})
public void testCreateWithoutPets() {
final Owner newOwner = newOwnerWithoutPets();
final Owner actual = admin.call(() -> facade.create(newOwner));
assertThat(actual, is(equalsToOwner(newOwner)));
}
@Test
@ShouldMatchDataSet({"owners.xml", "owners-create-with-pets.xml"})
public void testCreateWithPets() {
final Owner actual = admin.call(() -> facade.create(newOwnerWithFreshPets()));
assertThat(actual, is(equalsToOwner(newOwnerWithPersistentPets())));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testCreateExistentLogin() {
admin.run(() -> facade.create(anyOwner()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testCreateNull() {
admin.call(() -> facade.create(null));
}
@Test
@ShouldMatchDataSet("owners-update-password.xml")
public void testUpdatePassword() {
final Owner owner = anyOwner();
owner.changePassword("newpassword");
admin.run(() -> facade.update(owner));
}
@Test
@ShouldMatchDataSet({"owners.xml", "owners-create-without-pets.xml"})
public void testUpdateNewOwnerWithoutPets() {
final Owner newOwner = newOwnerWithoutPets();
final Owner actual = admin.call(() -> facade.update(newOwner));
assertThat(actual, is(equalsToOwner(newOwner)));
}
@Test
@ShouldMatchDataSet({"owners.xml", "owners-create-with-pets.xml"})
public void testUpdateNewOwnerWithPets() {
final Owner actual = admin.call(() -> facade.update(newOwnerWithFreshPets()));
assertThat(actual, is(equalsToOwner(newOwnerWithPersistentPets())));
}
@Test
@ShouldMatchDataSet("owners-remove-without-pets.xml")
public void testRemoveWithoutPets() {
admin.run(() -> facade.remove(ownerWithoutPets().getLogin()));
}
@Test
@ShouldMatchDataSet("owners-remove-with-pets.xml")
public void testRemoveWithPets() {
admin.run(() -> facade.remove(ownerWithPets().getLogin()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testRemoveNonExistentOwner() {
admin.run(() -> facade.remove(nonExistentLogin()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testRemoveNull() {
admin.run(() -> facade.remove(null));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testGetPets() {
final Owner owner = ownerWithPets();
final Pet[] ownedPets = owner.getPets().toArray(new Pet[0]);
final List<Pet> pets = admin.call(() -> facade.getPets(owner.getLogin()));
assertThat(pets, containsPetsInAnyOrder(ownedPets));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testGetPetsNoPets() {
final Owner owner = ownerWithoutPets();
final List<Pet> pets = admin.call(() -> facade.getPets(owner.getLogin()));
assertThat(pets, is(empty()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testGetPetsNonExistentOwner() {
admin.call(() -> facade.getPets(nonExistentLogin()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testGetPetsNull() {
admin.call(() -> facade.getPets(null));
}
}
package es.uvigo.esei.xcs.service;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.anyPet;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.existentPetId;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newPet;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newPetWithOwner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.owners;
import javax.ejb.EJB;
import javax.ejb.EJBAccessException;
import javax.ejb.EJBTransactionRolledbackException;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.persistence.CleanupUsingScript;
import org.jboss.arquillian.persistence.ShouldMatchDataSet;
import org.jboss.arquillian.persistence.TestExecutionPhase;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.OwnersDataset;
import es.uvigo.esei.xcs.domain.entities.Pet;
import es.uvigo.esei.xcs.service.util.security.RoleCaller;
import es.uvigo.esei.xcs.service.util.security.TestPrincipal;
@RunWith(Arquillian.class)
@UsingDataSet("owners.xml")
@ShouldMatchDataSet("owners.xml")
@CleanupUsingScript(phase = TestExecutionPhase.BEFORE, value = { "cleanup.sql", "cleanup-autoincrement.sql" })
public class PetServiceIllegalAccessIntegrationTest {
@Inject
private PetService facade;
@Inject
private TestPrincipal principal;
@EJB(beanName = "admin-caller")
private RoleCaller admin;
@EJB(beanName = "owner-caller")
private RoleCaller owner;
@Deployment
public static Archive<?> createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(PetService.class, OwnersDataset.class)
.addPackage(RoleCaller.class.getPackage())
.addPackage(Pet.class.getPackage())
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource("jboss-web.xml")
.addAsWebInfResource("beans.xml", "beans.xml");
return archive;
}
@Test(expected = EJBAccessException.class)
public void testGetNoRole() {
facade.get(existentPetId());
}
@Test(expected = EJBAccessException.class)
public void testListNoRole() {
facade.list();
}
@Test(expected = EJBAccessException.class)
public void testCreateNoRole() {
facade.create(newPet());
}
@Test(expected = EJBAccessException.class)
public void testUpdateNoRole() {
facade.update(anyPet());
}
@Test(expected = EJBAccessException.class)
public void testRemoveNoRole() {
facade.remove(existentPetId());
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testGetRoleAdmin() {
this.admin.run(this::testGetNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testListRoleAdmin() {
this.admin.run(this::testListNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testCreateRoleAdmin() {
this.admin.run(this::testCreateNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testUpdateRoleAdmin() {
this.admin.run(this::testUpdateNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testRemoveRoleAdmin() {
this.admin.run(this::testRemoveNoRole);
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testGetRoleOwner() {
final Owner[] owners = owners();
final Owner owner1 = owners[0];
final Owner owner2 = owners[1];
final Pet pet1 = owner1.getPets().iterator().next();
principal.setName(owner2.getLogin());
this.owner.run(() -> this.facade.get(pet1.getId()));
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testCreateRoleOwner() {
final Owner[] owners = owners();
final Owner owner1 = owners[0];
final Owner owner2 = owners[1];
final Pet pet = newPetWithOwner(owner1);
principal.setName(owner2.getLogin());
this.owner.run(() -> this.facade.create(pet));
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testUpdateRoleOwner() {
final Owner[] owners = owners();
final Owner owner1 = owners[0];
final Owner owner2 = owners[1];
final Pet pet1 = owner1.getPets().iterator().next();
pet1.setName("Owner2 Pet");
principal.setName(owner2.getLogin());
this.owner.run(() -> this.facade.update(pet1));
}
@Test(expected = EJBTransactionRolledbackException.class)
public void testRemoveRoleOwner() {
final Owner[] owners = owners();
final Owner owner1 = owners[0];
final Owner owner2 = owners[1];
final Pet pet1 = owner1.getPets().iterator().next();
principal.setName(owner2.getLogin());
this.owner.run(() -> this.facade.remove(pet1.getId()));
}
}
package es.uvigo.esei.xcs.service;
import static es.uvigo.esei.xcs.domain.entities.IsEqualsToPet.containsPetsInAnyOrder;
import static es.uvigo.esei.xcs.domain.entities.IsEqualsToPet.equalsToPet;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.existentPetId;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newPet;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.newPetWithOwner;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.nonExistentPetId;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.ownerWithPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.ownerWithoutPets;
import static es.uvigo.esei.xcs.domain.entities.OwnersDataset.pet;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertThat;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.EJBTransactionRolledbackException;
import javax.inject.Inject;
import javax.security.auth.login.LoginException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.persistence.CleanupUsingScript;
import org.jboss.arquillian.persistence.ShouldMatchDataSet;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import es.uvigo.esei.xcs.domain.entities.AnimalType;
import es.uvigo.esei.xcs.domain.entities.Owner;
import es.uvigo.esei.xcs.domain.entities.OwnersDataset;
import es.uvigo.esei.xcs.domain.entities.Pet;
import es.uvigo.esei.xcs.service.util.security.RoleCaller;
import es.uvigo.esei.xcs.service.util.security.TestPrincipal;
@RunWith(Arquillian.class)
@UsingDataSet("owners.xml")
@CleanupUsingScript({ "cleanup.sql", "cleanup-autoincrement.sql" })
public class PetServiceIntegrationTest {
@Inject
private PetService facade;
@EJB(beanName = "owner-caller")
private RoleCaller owner;
@Inject
private TestPrincipal principal;
@Deployment
public static Archive<?> createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(PetService.class, OwnersDataset.class)
.addPackage(RoleCaller.class.getPackage())
.addPackage(Pet.class.getPackage())
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource("jboss-web.xml")
.addAsWebInfResource("beans.xml", "beans.xml");
return archive;
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testGet() throws LoginException {
final int id = existentPetId();
final Pet pet = pet(id);
this.principal.setName(pet.getOwner().getLogin());
final Pet actual = this.owner.call(() -> facade.get(id));
assertThat(actual, equalsToPet(pet));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testGetBadId() throws LoginException {
final int id = nonExistentPetId();
this.principal.setName(ownerWithoutPets().getLogin());
final Pet actual = this.owner.call(() -> facade.get(id));
assertThat(actual, is(nullValue()));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testGetOthersPetId() throws LoginException {
final Owner ownerWithoutPets = ownerWithoutPets();
final Owner ownerWithPets = ownerWithPets();
final int petId = ownerWithPets.getPets().iterator().next().getId();
this.principal.setName(ownerWithoutPets.getLogin());
this.owner.run(() -> facade.get(petId));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testList() throws LoginException {
final Owner owner = ownerWithPets();
final Pet[] ownedPets = owner.getPets().toArray(new Pet[0]);
this.principal.setName(owner.getLogin());
final List<Pet> pets = this.owner.call(() -> facade.list());
assertThat(pets, containsPetsInAnyOrder(ownedPets));
}
@Test
@ShouldMatchDataSet("owners.xml")
public void testListNoPets() throws LoginException {
final Owner owner = ownerWithoutPets();
this.principal.setName(owner.getLogin());
final List<Pet> pets = this.owner.call(() -> facade.list());
assertThat(pets, is(empty()));
}
@Test
@ShouldMatchDataSet({ "owners.xml", "owners-create-pet.xml" })
public void testCreate() {
final Owner owner = ownerWithoutPets();
this.principal.setName(owner.getLogin());
final Pet pet = newPet();
this.owner.call(() -> facade.create(pet));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet({ "owners.xml" })
public void testCreateNull() {
this.principal.setName(ownerWithoutPets().getLogin());
this.owner.run(() -> facade.create(null));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet({ "owners.xml" })
public void testCreateWrongOwner() {
final Owner owner = ownerWithoutPets();
final Owner otherOwner = ownerWithPets();
this.principal.setName(owner.getLogin());
final Pet pet = newPetWithOwner(otherOwner);
this.owner.run(() -> facade.create(pet));
}
@Test
@ShouldMatchDataSet("owners-update-pet.xml")
public void testUpdate() throws LoginException {
final int id = existentPetId();
final Pet pet = pet(id);
this.principal.setName(pet.getOwner().getLogin());
pet.setName("UpdateName");
pet.setAnimal(AnimalType.BIRD);
pet.setBirth(new Date(946771261000L));
this.owner.run(() -> facade.update(pet));
}
@Test
@ShouldMatchDataSet({ "owners.xml", "owners-create-pet.xml" })
public void testUpdateNewPetWithOwner() {
final Owner owner = ownerWithoutPets();
this.principal.setName(owner.getLogin());
final Pet pet = newPetWithOwner(owner);
this.owner.call(() -> facade.update(pet));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testUpdateNull() throws LoginException {
this.owner.run(() -> facade.update(null));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet({ "owners.xml" })
public void testUpdateWrongOwner() {
final Owner owner = ownerWithoutPets();
final Owner otherOwner = ownerWithPets();
this.principal.setName(owner.getLogin());
final Pet pet = otherOwner.getPets().iterator().next();
this.owner.run(() -> facade.update(pet));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet({ "owners.xml", "owners-create-pet.xml" })
public void testUpdatePetNoOwner() {
final int id = existentPetId();
final Pet pet = pet(id);
this.principal.setName(pet.getOwner().getLogin());
pet.setOwner(null);
this.owner.run(() -> facade.update(pet));
}
@Test
@ShouldMatchDataSet("owners-remove-pet.xml")
public void testRemove() throws LoginException {
final int id = existentPetId();
final Pet pet = pet(id);
this.principal.setName(pet.getOwner().getLogin());
this.owner.run(() -> facade.remove(id));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testRemoveBadId() throws LoginException {
final int id = nonExistentPetId();
this.principal.setName(ownerWithoutPets().getLogin());
this.owner.run(() -> facade.remove(id));
}
@Test(expected = EJBTransactionRolledbackException.class)
@ShouldMatchDataSet("owners.xml")
public void testRemoveOthersPetId() throws LoginException {
final Owner ownerWithoutPets = ownerWithoutPets();
final Owner ownerWithPets = ownerWithPets();
final int petId = ownerWithPets.getPets().iterator().next().getId();
this.principal.setName(ownerWithoutPets.getLogin());
this.owner.run(() -> facade.remove(petId));
}
}
package es.uvigo.esei.xcs.service;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
OwnerServiceIntegrationTest.class,
OwnerServiceIllegalAccessIntegrationTest.class,
PetServiceIntegrationTest.class,
PetServiceIllegalAccessIntegrationTest.class
})
public class ServiceIntegrationTestSuite {
}
package es.uvigo.esei.xcs.service.util.security;
import java.util.function.Supplier;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RunAs;
import javax.ejb.Stateless;
@Stateless(name = "admin-caller")
@RunAs("ADMIN")
@PermitAll
public class AdminRoleCaller implements RoleCaller {
public <V> V call(Supplier<V> supplier) {
return supplier.get();
}
public void run(Runnable run) {
run.run();
}
public <V> V throwingCall(ThrowingSupplier<V> supplier) throws Throwable {
return supplier.get();
}
public void throwingRun(ThrowingRunnable run) throws Throwable{
run.run();
}
}
package es.uvigo.esei.xcs.service.util.security;
import java.util.function.Supplier;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RunAs;
import javax.ejb.Stateless;
@Stateless(name = "owner-caller")
@RunAs("OWNER")
@PermitAll
public class OwnerRoleCaller implements RoleCaller {
public <V> V call(Supplier<V> supplier) {
return supplier.get();
}
public void run(Runnable run) {
run.run();
}
public <V> V throwingCall(ThrowingSupplier<V> supplier) throws Throwable {
return supplier.get();
}
public void throwingRun(ThrowingRunnable run) throws Throwable{
run.run();
}
}
package es.uvigo.esei.xcs.service.util.security;
import java.util.function.Supplier;
public interface RoleCaller {
public <V> V call(Supplier<V> supplier);
public void run(Runnable run);
public <V> V throwingCall(ThrowingSupplier<V> supplier) throws Throwable;
public void throwingRun(ThrowingRunnable run) throws Throwable;
public interface ThrowingRunnable {
public void run() throws Throwable;
}
public interface ThrowingSupplier<V> {
public V get() throws Throwable;
}
}
package es.uvigo.esei.xcs.service.util.security;
import java.security.Principal;
import javax.enterprise.inject.Alternative;
import javax.inject.Singleton;
@Alternative
@Singleton
public class TestPrincipal implements Principal {
private String name;
public TestPrincipal() {}
public TestPrincipal(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<alternatives>
<class>es.uvigo.esei.xcs.service.util.security.TestPrincipal</class>
</alternatives>
</beans>
ALTER TABLE Pet ALTER COLUMN id RESTART WITH 1;
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>xcs-sample-security-domain</security-domain>
</jboss-web>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="test">
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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">
<alternatives>
<class>es.uvigo.esei.xcs.service.util.security.TestPrincipal</class>
</alternatives>
</beans>
ALTER TABLE Pet AUTO_INCREMENT = 1;
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>xcs-sample-security-domain</security-domain>
</jboss-web>
\ No newline at end of file
<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ironjacamar.org/doc/schema"
xsi:schemaLocation="http://www.ironjacamar.org/doc/schema http://www.ironjacamar.org/doc/schema/datasources_1_1.xsd">
<datasource jndi-name="java:jboss/datasources/xcs" pool-name="MySQLPool">
<connection-url>jdbc:mysql://localhost:3306/xcs</connection-url>
<driver>mysql-connector-java-${mysql.version}.jar</driver>
<pool>
<max-pool-size>30</max-pool-size>
</pool>
<security>
<user-name>xcs</user-name>
<password>xcs</password>
</security>
</datasource>
</datasources>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="test">
<jta-data-source>java:jboss/datasources/xcs</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<extension qualifier="persistence">
<property name="defaultDataSeedStrategy">CLEAN_INSERT</property>
</extension>
<container qualifier="wildfly-embedded-h2" default="true">
<configuration>
<property name="jbossHome">target/wildfly-${wildfly.version}</property>
<property name="modulePath">target/wildfly-${wildfly.version}/modules</property>
</configuration>
</container>
<container qualifier="wildfly-embedded-mysql">
<configuration>
<property name="jbossHome">target/wildfly-${wildfly.version}</property>
<property name="modulePath">target/wildfly-${wildfly.version}/modules</property>
</configuration>
</container>
</arquillian>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<Pet id="7" name="Lorenacat" animal="CAT" birth="2000-01-01 01:01:01" owner="lorena"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jacinto" password="69ED0B54C2B179E20F784370EAE8CB46" role="OWNER" />
<Pet id="7" name="Jacintocat" animal="CAT" birth="2000-01-01 01:01:01" owner="jacinto"/>
<Pet id="8" name="Jacintodo" animal="DOG" birth="2000-01-01 01:01:01" owner="jacinto"/>
<Pet id="9" name="Jacintobird" animal="BIRD" birth="2000-01-01 01:01:01" owner="jacinto"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jacinto" password="69ED0B54C2B179E20F784370EAE8CB46" role="OWNER" />
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jose" password="A3F6F4B40B24E2FD61F08923ED452F34" role="ADMIN"/>
<User login="pepe" password="B43B4D046860B2BD945BCA2597BF9F07" role="OWNER"/>
<User login="juan" password="B4FBB95580592697DC71488A1F19277E" role="OWNER"/>
<User login="ana" password="22BEEAE33E9B2657F9610621502CD7A4" role="OWNER"/>
<User login="lorena" password="05009E420932C21E5A68F5EF1AADD530" role="OWNER"/>
<Pet id="1" name="Pepecat" animal="CAT" birth="2000-01-01 01:01:01" owner="pepe"/>
<Pet id="3" name="Juandog" animal="DOG" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="4" name="Anacat" animal="CAT" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="5" name="Max" animal="DOG" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="6" name="Anabird" animal="BIRD" birth="2000-01-01 01:01:01" owner="ana"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jose" password="A3F6F4B40B24E2FD61F08923ED452F34" role="ADMIN"/>
<User login="pepe" password="B43B4D046860B2BD945BCA2597BF9F07" role="OWNER"/>
<User login="ana" password="22BEEAE33E9B2657F9610621502CD7A4" role="OWNER"/>
<User login="lorena" password="05009E420932C21E5A68F5EF1AADD530" role="OWNER"/>
<Pet id="1" name="Pepecat" animal="CAT" birth="2000-01-01 01:01:01" owner="pepe"/>
<Pet id="4" name="Anacat" animal="CAT" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="5" name="Max" animal="DOG" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="6" name="Anabird" animal="BIRD" birth="2000-01-01 01:01:01" owner="ana"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jose" password="A3F6F4B40B24E2FD61F08923ED452F34" role="ADMIN"/>
<User login="pepe" password="B43B4D046860B2BD945BCA2597BF9F07" role="OWNER"/>
<User login="juan" password="B4FBB95580592697DC71488A1F19277E" role="OWNER"/>
<User login="ana" password="22BEEAE33E9B2657F9610621502CD7A4" role="OWNER"/>
<Pet id="1" name="Pepecat" animal="CAT" birth="2000-01-01 01:01:01" owner="pepe"/>
<Pet id="2" name="Max" animal="CAT" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="3" name="Juandog" animal="DOG" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="4" name="Anacat" animal="CAT" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="5" name="Max" animal="DOG" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="6" name="Anabird" animal="BIRD" birth="2000-01-01 01:01:01" owner="ana"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jose" password="A3F6F4B40B24E2FD61F08923ED452F34" role="ADMIN"/>
<User login="pepe" password="B43B4D046860B2BD945BCA2597BF9F07" role="OWNER"/>
<User login="juan" password="5E9D11A14AD1C8DD77E98EF9B53FD1BA" role="OWNER"/>
<User login="ana" password="22BEEAE33E9B2657F9610621502CD7A4" role="OWNER"/>
<User login="lorena" password="05009E420932C21E5A68F5EF1AADD530" role="OWNER"/>
<Pet id="1" name="Pepecat" animal="CAT" birth="2000-01-01 01:01:01" owner="pepe"/>
<Pet id="2" name="Max" animal="CAT" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="3" name="Juandog" animal="DOG" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="4" name="Anacat" animal="CAT" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="5" name="Max" animal="DOG" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="6" name="Anabird" animal="BIRD" birth="2000-01-01 01:01:01" owner="ana"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jose" password="A3F6F4B40B24E2FD61F08923ED452F34" role="ADMIN"/>
<User login="pepe" password="B43B4D046860B2BD945BCA2597BF9F07" role="OWNER"/>
<User login="juan" password="B4FBB95580592697DC71488A1F19277E" role="OWNER"/>
<User login="ana" password="22BEEAE33E9B2657F9610621502CD7A4" role="OWNER"/>
<User login="lorena" password="05009E420932C21E5A68F5EF1AADD530" role="OWNER"/>
<Pet id="1" name="Pepecat" animal="CAT" birth="2000-01-01 01:01:01" owner="pepe"/>
<Pet id="2" name="UpdateName" animal="BIRD" birth="2000-01-02 01:01:01" owner="juan"/>
<Pet id="3" name="Juandog" animal="DOG" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="4" name="Anacat" animal="CAT" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="5" name="Max" animal="DOG" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="6" name="Anabird" animal="BIRD" birth="2000-01-01 01:01:01" owner="ana"/>
</dataset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<User login="jose" password="A3F6F4B40B24E2FD61F08923ED452F34" role="ADMIN"/>
<User login="pepe" password="B43B4D046860B2BD945BCA2597BF9F07" role="OWNER"/>
<User login="juan" password="B4FBB95580592697DC71488A1F19277E" role="OWNER"/>
<User login="ana" password="22BEEAE33E9B2657F9610621502CD7A4" role="OWNER"/>
<User login="lorena" password="05009E420932C21E5A68F5EF1AADD530" role="OWNER"/>
<Pet id="1" name="Pepecat" animal="CAT" birth="2000-01-01 01:01:01" owner="pepe"/>
<Pet id="2" name="Max" animal="CAT" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="3" name="Juandog" animal="DOG" birth="2000-01-01 01:01:01" owner="juan"/>
<Pet id="4" name="Anacat" animal="CAT" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="5" name="Max" animal="DOG" birth="2000-01-01 01:01:01" owner="ana"/>
<Pet id="6" name="Anabird" animal="BIRD" birth="2000-01-01 01:01:01" owner="ana"/>
</dataset>
\ No newline at end of file
DELETE FROM Pet;
DELETE FROM User;
\ No newline at end of file
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