@Test
@Transactional
public void testAddAndGetCriterionTypes() {
/* Build criterion type "ct1" (5 constraint violations). */
CriterionDTO ct1c1 = new CriterionDTO(null, true, // Missing criterion
// name.
new ArrayList<CriterionDTO>());
CriterionDTO ct1c2c1 = new CriterionDTO("c2-1", true,
new ArrayList<CriterionDTO>());
List<CriterionDTO> ct1c2Criterions = new ArrayList<CriterionDTO>();
ct1c2Criterions.add(ct1c2c1);
CriterionDTO ct1c2 = new CriterionDTO("c2", true, // Criterion
// hierarchy is not
// allowed in the
// criterion type
// (see above).
ct1c2Criterions);
CriterionDTO ct1c3 = new CriterionDTO("c3", true,
new ArrayList<CriterionDTO>());
CriterionDTO ct1c4 = new CriterionDTO(" C3 ", true,
new ArrayList<CriterionDTO>()); // Repeated criterion name.
CriterionDTO ct1c5 = new CriterionDTO(ct1c3.code, // Repeated criterion
"c4", true, // code inside this criterion type.
new ArrayList<CriterionDTO>());
List<CriterionDTO> ct1Criterions = new ArrayList<CriterionDTO>();
ct1Criterions.add(ct1c1);
ct1Criterions.add(ct1c2);
ct1Criterions.add(ct1c3);
ct1Criterions.add(ct1c4);
ct1Criterions.add(ct1c5);
CriterionTypeDTO ct1 = new CriterionTypeDTO(null, "desc",
false, true, true, ResourceEnumDTO.RESOURCE, // Missing criterion
ct1Criterions); // type name.
/* Build criterion type "ct2" (2 constraint violations). */
CriterionDTO ct2c1 = new CriterionDTO("c1", true, // Its criterion type
new ArrayList<CriterionDTO>()); // is not enabled.
CriterionDTO ct2c2c1 = new CriterionDTO("c2-1",
true, new ArrayList<CriterionDTO>()); // Its criterion father is
// not active.
List<CriterionDTO> ct2c2Criterions = new ArrayList<CriterionDTO>();
ct2c2Criterions.add(ct2c2c1);
CriterionDTO ct2c2 = new CriterionDTO("c2", false,
ct2c2Criterions);
List<CriterionDTO> ct2Criterions = new ArrayList<CriterionDTO>();
ct2Criterions.add(ct2c1);
ct2Criterions.add(ct2c2);
CriterionTypeDTO ct2 = new CriterionTypeDTO(getUniqueName(), "desc",
true, true, false, ResourceEnumDTO.RESOURCE, ct2Criterions);
/* Build criterion type "ct3" (OK). */
CriterionDTO ct3c1 = new CriterionDTO("c1", true,
new ArrayList<CriterionDTO>());
CriterionDTO ct3c2c1 = new CriterionDTO("c2-1",
true, new ArrayList<CriterionDTO>());
List<CriterionDTO> ct3c2Criterions = new ArrayList<CriterionDTO>();
ct3c2Criterions.add(ct3c2c1);
CriterionDTO ct3c2 = new CriterionDTO("c2", true,
ct3c2Criterions);
List<CriterionDTO> ct3Criterions = new ArrayList<CriterionDTO>();
ct3Criterions.add(ct3c1);
ct3Criterions.add(ct3c2);
CriterionTypeDTO ct3 = new CriterionTypeDTO(getUniqueName(), "desc",
true, true, true, ResourceEnumDTO.RESOURCE, ct3Criterions);
/* Build criterion type "ct4" (1 constraint violation). */
CriterionTypeDTO ct4 =
new CriterionTypeDTO( // Repeated criterion
' ' + ct3.name.toUpperCase() + ' ', // type name.
"desc", true, true, true,
ResourceEnumDTO.RESOURCE, new ArrayList<CriterionDTO>());
/* Build criterion type "ct5" (1 constraint violation). */
CriterionDTO ct5c1 = new CriterionDTO(ct3c1.code, // Criterion code
"c1", true, // used by another criterion type.
new ArrayList<CriterionDTO>());
List<CriterionDTO> ct5Criterions = new ArrayList<CriterionDTO>();
ct5Criterions.add(ct5c1);
CriterionTypeDTO ct5 = new CriterionTypeDTO(getUniqueName(), "desc",
true, true, true, ResourceEnumDTO.RESOURCE, ct5Criterions);
/* Build criterion type "ct6" (2 constraint violations). */
CriterionDTO ct6c1 = new CriterionDTO(null, // Missing criterion code.
"c1", true, new ArrayList<CriterionDTO>());
List<CriterionDTO> ct6Criterions = new ArrayList<CriterionDTO>();
ct6Criterions.add(ct6c1);
CriterionTypeDTO ct6 =
new CriterionTypeDTO(null, getUniqueName(), // Missing criterion