ItEr08S11HistoriaLaboralTraballador: Change to Criterion mapping, now it has an inmutable business key. Loading of the predefined criterions.

Modified CriterionBootstrap.java to autowire ICriterionTypeProvider classes
 (Javier Moran Rua <jmoran@igalia.com>)
This commit is contained in:
Óscar González Fernández 2009-05-16 17:14:17 +02:00 committed by Javier Moran Rua
parent 661dd40860
commit dcd0f01991
21 changed files with 417 additions and 81 deletions

View file

@ -1,26 +1,45 @@
package org.navalplanner.business.resources.bootstrap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.List;
import java.util.Map.Entry;
import org.navalplanner.business.IDataBootstrap;
import org.navalplanner.business.resources.services.ResourceService;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.ICriterionType;
import org.navalplanner.business.resources.services.CriterionService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* Loads all {@link ICriterionTypeProvider} and if there is any criterion that
* doesn't exist, creates them.<br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
@Component
@Scope("singleton")
public class CriterionsBootstrap implements IDataBootstrap {
private static final Log LOG = LogFactory.getLog(CriterionsBootstrap.class);
@Autowired
private ResourceService resourceService;
private CriterionService criterionService;
@Autowired
private List<ICriterionTypeProvider> providers;
@Override
public void loadRequiredData() {
LOG.info("TODO: load criterions");
assert resourceService != null;
}
for (ICriterionTypeProvider provider: providers) {
for (Entry<ICriterionType<?>, List<Criterion>> entry : provider
.getRequiredCriterions()
.entrySet()) {
for (Criterion criterion : entry.getValue()) {
criterionService.createIfNotExists(criterion);
}
}
}
}
}

View file

@ -0,0 +1,18 @@
package org.navalplanner.business.resources.bootstrap;
import java.util.List;
import java.util.Map;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.ICriterionType;
/**
* Defines a class that can provide some known {@link ICriterionType} along with
* their associated Criterion <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public interface ICriterionTypeProvider {
public Map<ICriterionType<?>, List<Criterion>> getRequiredCriterions();
}

View file

@ -0,0 +1,34 @@
package org.navalplanner.business.resources.bootstrap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.ICriterionType;
import org.navalplanner.business.resources.entities.PredefinedCriterionTypes;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* This class provides the CriterionTypes with their criterions that are known a
* priori<br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
@Component
@Scope("singleton")
public class PredefinedCriterionTypesProvider implements ICriterionTypeProvider {
public PredefinedCriterionTypesProvider() {
}
@Override
public Map<ICriterionType<?>, List<Criterion>> getRequiredCriterions() {
Map<ICriterionType<?>, List<Criterion>> result = new HashMap<ICriterionType<?>, List<Criterion>>();
for (PredefinedCriterionTypes type : PredefinedCriterionTypes.values()) {
result.put(type, type.getPredefined());
}
return result;
}
}

View file

@ -7,6 +7,6 @@ import org.navalplanner.business.resources.entities.Criterion;
* Description goes here. <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public interface ICriterionDAO extends IGenericDao<Criterion, Long> {
public interface ICriterionDAO extends IGenericDao<Criterion, Criterion> {
}

View file

@ -1,14 +1,23 @@
package org.navalplanner.business.resources.daos.impl;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
import org.navalplanner.business.resources.daos.ICriterionDAO;
import org.navalplanner.business.resources.entities.Criterion;
/**
* Description goes here. <br />
* DAO implementation for Criterion. <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class CriterionDAO extends GenericDaoHibernate<Criterion, Long>
public class CriterionDAO extends GenericDaoHibernate<Criterion, Criterion>
implements ICriterionDAO {
@Override
public boolean exists(Criterion criterion) {
return getSession().createCriteria(Criterion.class).add(
Restrictions.eq("name", criterion.getName())).add(
Restrictions.eq("type", criterion.getType()))
.uniqueResult() != null;
}
}

View file

@ -1,24 +1,41 @@
package org.navalplanner.business.resources.entities;
import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.validator.NotEmpty;
/**
* A criterion stored in the database <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class Criterion implements ICriterion {
private Long id;
public class Criterion implements ICriterion, Serializable {
@SuppressWarnings("unused")
private long version;
@NotEmpty
private String name;
@NotEmpty
private String type;
private boolean active;
private boolean active = true;
public Long getId() {
return id;
/**
* Constructor for hibernate. Do not use!
*/
public Criterion() {
}
public Criterion(String name, String type) {
Validate.notNull(name);
Validate.notNull(type);
this.type = type;
this.name = name;
}
@Override
@ -31,4 +48,28 @@ public class Criterion implements ICriterion {
.isEmpty();
}
public String getName() {
return name;
}
public String getType() {
return type;
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(name)
.append(type).toHashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Criterion) {
Criterion other = (Criterion) obj;
return new EqualsBuilder().append(name, other.name).append(type,
other.type).isEquals();
}
return false;
}
}

View file

@ -4,7 +4,7 @@ package org.navalplanner.business.resources.entities;
* Base implementation of {@link ICriterionType} <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public abstract class CriterionTypeBase implements ICriterionType {
public abstract class CriterionTypeBase implements ICriterionType<Criterion> {
private final boolean allowHierarchy;

View file

@ -4,13 +4,13 @@ package org.navalplanner.business.resources.entities;
* Parametrizes the behaviour of some criterions <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public interface ICriterionType {
public interface ICriterionType<C extends ICriterion> {
public boolean allowMultipleActiveCriterionsPerResource();
public boolean allowHierarchy();
public ICriterion createCriterion();
public C createCriterion(String name);
public boolean contains(ICriterion criterion);

View file

@ -0,0 +1,70 @@
package org.navalplanner.business.resources.entities;
import java.util.List;
/**
* This class defines some criterion types known a priori<br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public enum PredefinedCriterionTypes implements ICriterionType<Criterion> {
WORK_RELATIONSHIP(false, false) {
@Override
public List<Criterion> getPredefined() {
return WorkingRelationship.getCriterions();
}
};
private final boolean allowHierarchy;
private final boolean allowMultipleActiveCriterionsPerResource;
private PredefinedCriterionTypes(boolean allowHierarchy,
boolean allowMultipleActiveCriterionsPerResource) {
this.allowHierarchy = allowHierarchy;
this.allowMultipleActiveCriterionsPerResource = allowMultipleActiveCriterionsPerResource;
}
@Override
public boolean allowHierarchy() {
return allowHierarchy;
}
@Override
public boolean allowMultipleActiveCriterionsPerResource() {
return allowMultipleActiveCriterionsPerResource;
}
@Override
public boolean contains(ICriterion criterion) {
if (criterion instanceof Criterion) {
Criterion c = (Criterion) criterion;
return this.getType().equals(c.getType());
} else
return false;
}
@Override
public Criterion createCriterion(String name) {
return new Criterion(name, getType());
}
public abstract List<Criterion> getPredefined();
private String getType() {
return name();
}
public static ICriterionType<Criterion> getType(String type) {
for (PredefinedCriterionTypes predefinedType : PredefinedCriterionTypes
.values()) {
if (predefinedType.name().equals(type))
return predefinedType;
}
throw new RuntimeException("not found "
+ PredefinedCriterionTypes.class.getName() + " type for "
+ type);
}
}

View file

@ -58,7 +58,7 @@ public abstract class Resource {
}
public Collection<CriterionSatisfaction> getSatisfactionsFor(
ICriterionType type) {
ICriterionType<?> type) {
Set<CriterionSatisfaction> allSatisfactions = getAllSatisfactions();
ArrayList<CriterionSatisfaction> result = new ArrayList<CriterionSatisfaction>();
for (CriterionSatisfaction criterionSatisfaction : allSatisfactions) {
@ -70,7 +70,7 @@ public abstract class Resource {
}
public Collection<CriterionSatisfaction> getActiveSatisfactionsFor(
ICriterionType criterionType) {
ICriterionType<?> criterionType) {
Collection<CriterionSatisfaction> satisfactionsFor = getSatisfactionsFor(criterionType);
ArrayList<CriterionSatisfaction> result = new ArrayList<CriterionSatisfaction>();
for (CriterionSatisfaction criterionSatisfaction : satisfactionsFor) {
@ -82,7 +82,7 @@ public abstract class Resource {
}
public Collection<CriterionSatisfaction> getActiveSatisfactionsForIn(
ICriterionType criterionType, Date start, Date end) {
ICriterionType<?> criterionType, Date start, Date end) {
Validate.notNull(criterionType);
Validate.isTrue(start.before(end));
Collection<CriterionSatisfaction> satisfactionsFor = getSatisfactionsFor(criterionType);

View file

@ -0,0 +1,30 @@
package org.navalplanner.business.resources.entities;
import java.util.ArrayList;
import java.util.List;
public enum WorkingRelationship {
HIRED("hiredResourceWorkingRelationship"), FIRED(
"firedResourceWorkingRelationship");
public static List<Criterion> getCriterions() {
ArrayList<Criterion> result = new ArrayList<Criterion>();
for (WorkingRelationship workingRelationship : values()) {
result.add(workingRelationship.criterion());
}
return result;
}
private final String criterionName;
private WorkingRelationship(String name) {
this.criterionName = name;
}
public Criterion criterion() {
return PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(criterionName);
}
}

View file

@ -17,16 +17,10 @@ import org.navalplanner.business.resources.entities.Resource;
*/
public interface CriterionService {
boolean exists(Long id);
Criterion find(Long id) throws InstanceNotFoundException;
List<Criterion> list();
void remove(Criterion criterion) throws InstanceNotFoundException;
void remove(Long id) throws InstanceNotFoundException;
void save(Criterion entity);
void add(CriterionSatisfaction criterionSatisfaction);
@ -37,9 +31,13 @@ public interface CriterionService {
Date begin, Date end);
Collection<CriterionSatisfaction> getSatisfactionsFor(
ICriterionType criterionType);
ICriterionType<?> criterionType);
Collection<CriterionSatisfaction> getSatisfactionsFor(
ICriterionType criterionType, Date begin, Date end);
ICriterionType<?> criterionType, Date begin, Date end);
void createIfNotExists(Criterion criterion);
boolean exists(Criterion criterion);
}

View file

@ -35,12 +35,12 @@ public class CriterionServiceImpl implements CriterionService {
@Autowired
private ResourceService resourceService;
public boolean exists(Long id) {
return criterionDAO.exists(id);
public boolean exists(Criterion criterion) {
return criterionDAO.exists(criterion);
}
public Criterion find(Long id) throws InstanceNotFoundException {
return criterionDAO.find(id);
public Criterion find(Criterion criterion) throws InstanceNotFoundException {
return criterionDAO.find(criterion);
}
public List<Criterion> list() {
@ -48,11 +48,7 @@ public class CriterionServiceImpl implements CriterionService {
}
public void remove(Criterion criterion) throws InstanceNotFoundException {
criterionDAO.remove(criterion.getId());
}
public void remove(Long id) throws InstanceNotFoundException {
criterionDAO.remove(id);
criterionDAO.remove(criterion);
}
public void save(Criterion entity) {
@ -92,7 +88,7 @@ public class CriterionServiceImpl implements CriterionService {
@Override
public Collection<CriterionSatisfaction> getSatisfactionsFor(
ICriterionType criterionType) {
ICriterionType<?> criterionType) {
ArrayList<CriterionSatisfaction> result = new ArrayList<CriterionSatisfaction>();
for (Resource resource : resourceService.getResources()) {
result.addAll(resource.getActiveSatisfactionsFor(criterionType));
@ -102,7 +98,7 @@ public class CriterionServiceImpl implements CriterionService {
@Override
public Collection<CriterionSatisfaction> getSatisfactionsFor(
ICriterionType criterionType, Date start, Date end) {
ICriterionType<?> criterionType, Date start, Date end) {
ArrayList<CriterionSatisfaction> result = new ArrayList<CriterionSatisfaction>();
for (Resource resource : resourceService.getResources()) {
result.addAll(resource.getActiveSatisfactionsForIn(criterionType,
@ -110,4 +106,10 @@ public class CriterionServiceImpl implements CriterionService {
}
return result;
}
@Override
public void createIfNotExists(Criterion criterion) {
if (!exists(criterion))
save(criterion);
}
}

View file

@ -22,14 +22,16 @@
<property name="dailyHours"/>
</joined-subclass>
</class>
<class name="Criterion">
<id access="field" name="id">
<generator class="native"/>
</id>
<composite-id>
<key-property access="field" name="name"/>
<key-property access="field" name="type"/>
</composite-id>
<version access="field" name="version" type="long"/>
<property access="field" name="type"/>
<property access="field" name="active"/>
</class>
<class name="CriterionSatisfaction">
<id access="field" name="id">
<generator class="native"/>
@ -37,7 +39,10 @@
<version access="field" name="version" type="long"/>
<property access="field" name="startDate" not-null="true"/>
<property access="field" name="finishDate"/>
<many-to-one access="field" name="criterion" not-null="true"/>
<many-to-one name="criterion" access="field" not-null="true">
<column name="name" not-null="true"></column>
<column name="type" not-null="true"></column>
</many-to-one>
<many-to-one access="field" column="resource" name="resource" not-null="true"/>
</class>
</hibernate-mapping>

View file

@ -0,0 +1,44 @@
package org.navalplanner.business.test.resources.bootstrap;
import static junit.framework.Assert.assertTrue;
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.navalplanner.business.resources.bootstrap.CriterionsBootstrap;
import org.navalplanner.business.resources.entities.WorkingRelationship;
import org.navalplanner.business.resources.services.CriterionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
BUSINESS_SPRING_CONFIG_TEST_FILE })
@Transactional
public class CriterionsBootstrapTest {
@Autowired
private CriterionsBootstrap criterionsBootstrap;
@Autowired
private CriterionService criterionService;
@Test
public void testBootstrap() throws Exception {
if (criterionService.exists(WorkingRelationship.FIRED.criterion())) {
criterionService.remove(WorkingRelationship.FIRED.criterion());
}
if (criterionService.exists(WorkingRelationship.HIRED.criterion())) {
criterionService.remove(WorkingRelationship.HIRED.criterion());
}
criterionsBootstrap.loadRequiredData();
assertTrue(criterionService.exists(WorkingRelationship.FIRED
.criterion()));
assertTrue(criterionService.exists(WorkingRelationship.HIRED
.criterion()));
}
}

View file

@ -1,6 +1,7 @@
package org.navalplanner.business.test.resources.daos;
import java.util.List;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -16,6 +17,7 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
@ -42,26 +44,20 @@ public class CriterionDAOTest {
public void testSaveCriterions() throws Exception {
Criterion criterion = createValidCriterion();
criterionDAO.save(criterion);
assertNotNull(criterion.getId());
assertTrue(criterionDAO.exists(criterion.getId()));
assertTrue(criterionDAO.exists(criterion));
}
public static Criterion createValidCriterion() {
return new Criterion();
}
@Test(expected = InstanceNotFoundException.class)
public void testRemoveNotExistent() throws InstanceNotFoundException {
criterionDAO.remove(Long.MAX_VALUE);
return new Criterion(UUID.randomUUID().toString(), "pruebaType");
}
@Test
public void testRemove() throws InstanceNotFoundException {
Criterion criterion = createValidCriterion();
criterionDAO.save(criterion);
assertTrue(criterionDAO.exists(criterion.getId()));
criterionDAO.remove(criterion.getId());
assertFalse(criterionDAO.exists(criterion.getId()));
assertTrue(criterionDAO.exists(criterion));
criterionDAO.remove(criterion);
assertFalse(criterionDAO.exists(criterion));
}
@Test

View file

@ -22,6 +22,7 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
@ -84,7 +85,7 @@ public class CriterionSatisfactionDAOTest {
satisfactionDAO.save(satisfaction);
assertTrue(satisfactionDAO.exists(satisfaction.getId()));
satisfactionDAO.remove(satisfaction.getId());
assertFalse(criterionDAO.exists(satisfaction.getId()));
assertFalse(satisfactionDAO.exists(satisfaction.getId()));
}
@Test

View file

@ -1,21 +1,24 @@
package org.navalplanner.business.test.resources.entities;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.navalplanner.business.resources.entities.CriterionCompounder.atom;
import static org.navalplanner.business.resources.entities.CriterionCompounder.build;
import static org.navalplanner.business.resources.entities.CriterionCompounder.not;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import org.junit.Test;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.CriterionCompounder;
import org.navalplanner.business.resources.entities.ICriterion;
import org.navalplanner.business.resources.entities.PredefinedCriterionTypes;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.navalplanner.business.resources.entities.CriterionCompounder.atom;
import static org.navalplanner.business.resources.entities.CriterionCompounder.build;
import static org.navalplanner.business.resources.entities.CriterionCompounder.not;
/**
* Tests for criterion. <br />
* Created at May 12, 2009
@ -23,6 +26,23 @@ import static org.navalplanner.business.resources.entities.CriterionCompounder.n
*/
public class CriterionTest {
@Test
public void testCreateWithAType() throws Exception {
Criterion firedCriterion = PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion("fired");
assertTrue(PredefinedCriterionTypes.WORK_RELATIONSHIP
.contains(firedCriterion));
}
@Test
public void testCriterionNameAndTypeIsInmutableBusinessKey()
throws Exception {
Criterion criterion = new Criterion("name", "type");
Criterion other = new Criterion("name", "type");
assertEquals(criterion.hashCode(), other.hashCode());
}
@Test
public void testCompounding() throws Exception {
Worker worker1 = new Worker();

View file

@ -83,7 +83,7 @@ public class ResourceTest {
otherCriterion, worker);
new CriterionSatisfaction(CriterionSatisfactionDAOTest.year(4000),
criterion, worker);
ICriterionType criterionType = createTypeThatMatches(criterion);
ICriterionType<Criterion> criterionType = createTypeThatMatches(criterion);
assertEquals(2, worker.getSatisfactionsFor(criterionType).size());
assertEquals(1, worker.getActiveSatisfactionsFor(criterionType).size());
}
@ -100,7 +100,7 @@ public class ResourceTest {
}
@Override
public ICriterion createCriterion() {
public Criterion createCriterion(String name) {
return null;
}
};
@ -119,7 +119,7 @@ public class ResourceTest {
new CriterionSatisfaction(CriterionSatisfactionDAOTest.year(2000),
otherCriterion, worker);
ICriterionType criterionType = createTypeThatMatches(criterion);
ICriterionType<Criterion> criterionType = createTypeThatMatches(criterion);
assertEquals(2, worker.getSatisfactionsFor(criterionType).size());
assertEquals(1, worker.getActiveSatisfactionsForIn(criterionType,

View file

@ -1,11 +1,20 @@
package org.navalplanner.business.test.resources.services;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
import java.util.UUID;
import org.hibernate.SessionFactory;
import org.hibernate.validator.InvalidStateException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
import org.navalplanner.business.resources.entities.ICriterionType;
import org.navalplanner.business.resources.entities.PredefinedCriterionTypes;
import org.navalplanner.business.resources.entities.Worker;
import org.navalplanner.business.resources.services.CriterionService;
import org.navalplanner.business.resources.services.ResourceService;
@ -18,10 +27,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import static junit.framework.Assert.assertEquals;
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
/**
* Test cases for {@link CriterionService} <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
@ -41,6 +46,54 @@ public class CriterionServiceTest {
@Autowired
private SessionFactory sessionFactory;
@Test(expected = InvalidStateException.class)
public void testCantSaveCriterionWithoutNameAndType() throws Exception {
Criterion criterion = new Criterion("", "");
criterionService.save(criterion);
sessionFactory.getCurrentSession().flush();
}
@Test
public void testAddCriterion() throws Exception {
String unique = UUID.randomUUID().toString();
Criterion criterion = PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique);
criterionService.save(criterion);
}
@Test(expected = Exception.class)
public void testUniqueNameForCriterion() {
String unique = UUID.randomUUID().toString();
Criterion criterion = PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique);
criterionService.save(criterion);
criterionService.save(PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique));
}
@Test
public void testCreateIfNotExists() {
String unique = UUID.randomUUID().toString();
Criterion criterion = PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique);
criterionService.createIfNotExists(criterion);
assertTrue(criterionService.exists(criterion));
criterionService.createIfNotExists(PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique));
}
@Test
public void testPersistingDoesNotChangeEquality() throws Exception {
String unique = UUID.randomUUID().toString();
Criterion criterion = PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique);
Criterion other = PredefinedCriterionTypes.WORK_RELATIONSHIP
.createCriterion(unique);
assertEquals(criterion, other);
criterionService.save(criterion);
assertEquals(criterion, other);
}
@Test
public void testCreateCriterionSatisfactionButNotSave() {
Criterion criterion = CriterionDAOTest.createValidCriterion();
@ -54,7 +107,7 @@ public class CriterionServiceTest {
/*
* It sends a dataIntegrityViolationException when adding a
* criterionSatisfaction with a resource that doesn't exist yet
* criterionSatisfaction with a criterion that doesn't exist yet
*/
@Test(expected = DataIntegrityViolationException.class)
public void testCreateCriterionSatisfactionOnTransientCriterion()
@ -83,7 +136,7 @@ public class CriterionServiceTest {
Criterion criterion = CriterionDAOTest.createValidCriterion();
criterionService.save(criterion);
Worker worker = new Worker("firstName", "surName", "2333232", 10);
CriterionSatisfaction criterionSatisfaction = new CriterionSatisfaction(
new CriterionSatisfaction(
CriterionSatisfactionDAOTest.year(2000), criterion, worker);
resourceService.saveResource(worker);
assertEquals(1, criterionService.getResourcesSatisfying(criterion)
@ -154,7 +207,7 @@ public class CriterionServiceTest {
criterionService.add(new CriterionSatisfaction(
CriterionSatisfactionDAOTest.year(1998), criterion, worker));
ICriterionType criterionType = ResourceTest
ICriterionType<?> criterionType = ResourceTest
.createTypeThatMatches(criterion);
assertEquals(2, criterionService.getSatisfactionsFor(criterionType,

View file

@ -1,6 +1,5 @@
package org.navalplanner.business.test.resources.services;
import org.hibernate.SessionFactory;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidStateException;
import org.hibernate.validator.InvalidValue;
@ -43,9 +42,6 @@ public class ResourceServiceTest {
@Autowired
private IResourceDao resourceDao;
@Autowired
private SessionFactory sessionFactory;
@Test
public void testRemoveResource() throws InstanceNotFoundException {