ItEr39S08CUListaFormulariosCalidade : Creating domain classes, the DAOs and its tests.
This commit is contained in:
parent
7657706772
commit
29631638e8
13 changed files with 959 additions and 0 deletions
|
|
@ -24,6 +24,7 @@ import org.navalplanner.business.advance.daos.IAdvanceTypeDAO;
|
|||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
import org.navalplanner.business.materials.daos.IMaterialCategoryDAO;
|
||||
import org.navalplanner.business.materials.daos.IMaterialDAO;
|
||||
import org.navalplanner.business.qualityforms.daos.IQualityFormDAO;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.daos.IMachineDAO;
|
||||
import org.navalplanner.business.users.daos.IUserDAO;
|
||||
|
|
@ -70,6 +71,9 @@ public class Registry {
|
|||
@Autowired
|
||||
private IMaterialCategoryDAO materialCategoryDAO;
|
||||
|
||||
@Autowired
|
||||
private IQualityFormDAO qualityFormDAO;
|
||||
|
||||
private Registry() {
|
||||
}
|
||||
|
||||
|
|
@ -108,4 +112,8 @@ public class Registry {
|
|||
public static IMaterialCategoryDAO getMaterialCategoryDAO() {
|
||||
return getInstance().materialCategoryDAO;
|
||||
}
|
||||
|
||||
public static IQualityFormDAO getQualityFormDAO() {
|
||||
return getInstance().qualityFormDAO;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.qualityforms.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityForm;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityFormType;
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
public interface IQualityFormDAO extends IGenericDAO<QualityForm, Long> {
|
||||
|
||||
List<QualityForm> getAll();
|
||||
|
||||
QualityForm findByNameAndType(String name, QualityFormType type);
|
||||
|
||||
List<QualityForm> getAllByType(QualityFormType type);
|
||||
|
||||
QualityForm findUniqueByName(String name)
|
||||
throws InstanceNotFoundException, NonUniqueResultException;
|
||||
|
||||
QualityForm findUniqueByName(QualityForm qualityForm)
|
||||
throws InstanceNotFoundException;
|
||||
|
||||
boolean existsOtherWorkReportTypeByName(QualityForm qualityForm);
|
||||
|
||||
boolean existsByNameAnotherTransaction(QualityForm qualityForm);
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.qualityforms.daos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityForm;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityFormType;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* DAO for {@link QualityForm}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class QualityFormDAO extends GenericDAOHibernate<QualityForm, Long>
|
||||
implements IQualityFormDAO {
|
||||
|
||||
@Override
|
||||
public List<QualityForm> getAll() {
|
||||
return list(QualityForm.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QualityForm findByNameAndType(String name, QualityFormType type) {
|
||||
return (QualityForm) getSession().createCriteria(QualityForm.class)
|
||||
.add(Restrictions.eq("name", name)).add(
|
||||
Restrictions.eq("qualityFormType", type))
|
||||
.uniqueResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QualityForm> getAllByType(QualityFormType type) {
|
||||
Criteria c = getSession().createCriteria(QualityForm.class).add(
|
||||
Restrictions.eq("qualityFormType", type));
|
||||
return ((List<QualityForm>) c.list());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QualityForm findUniqueByName(QualityForm qualityForm)
|
||||
throws InstanceNotFoundException {
|
||||
Validate.notNull(qualityForm);
|
||||
return findUniqueByName(qualityForm.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QualityForm findUniqueByName(String name)
|
||||
throws InstanceNotFoundException, NonUniqueResultException {
|
||||
Criteria c = getSession().createCriteria(QualityForm.class);
|
||||
c.add(Restrictions.eq("name", name));
|
||||
QualityForm qualityForm = (QualityForm) c.uniqueResult();
|
||||
|
||||
if (qualityForm == null) {
|
||||
throw new InstanceNotFoundException(null, "QualityForm");
|
||||
}
|
||||
return qualityForm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsOtherWorkReportTypeByName(QualityForm qualityForm) {
|
||||
try {
|
||||
QualityForm t = findUniqueByName(qualityForm);
|
||||
return (t != null && t != qualityForm);
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean existsByNameAnotherTransaction(QualityForm qualityForm) {
|
||||
return existsOtherWorkReportTypeByName(qualityForm);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
package org.navalplanner.business.qualityforms.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.NonUniqueResultException;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.qualityforms.daos.IQualityFormDAO;
|
||||
|
||||
public class QualityForm extends BaseEntity {
|
||||
|
||||
public static QualityForm create() {
|
||||
QualityForm qualityForm = new QualityForm();
|
||||
qualityForm.setNewObject(true);
|
||||
return qualityForm;
|
||||
}
|
||||
|
||||
public static QualityForm create(String name, String description) {
|
||||
QualityForm qualityForm = new QualityForm(name, description);
|
||||
qualityForm.setNewObject(true);
|
||||
return qualityForm;
|
||||
}
|
||||
|
||||
public QualityForm() {
|
||||
|
||||
}
|
||||
|
||||
private QualityForm(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private QualityFormType qualityFormType = QualityFormType.getDefault();
|
||||
|
||||
private List<QualityFormItem> qualityFormItems = new ArrayList<QualityFormItem>();
|
||||
|
||||
@NotEmpty
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public QualityFormType getQualityFormType() {
|
||||
return qualityFormType;
|
||||
}
|
||||
|
||||
public void setQualityFormType(QualityFormType qualityFormType) {
|
||||
this.qualityFormType = qualityFormType;
|
||||
}
|
||||
|
||||
@Valid
|
||||
public List<QualityFormItem> getQualityFormItems() {
|
||||
return Collections.unmodifiableList(qualityFormItems);
|
||||
}
|
||||
|
||||
void setQualityFormItems(List<QualityFormItem> qualityFormItems) {
|
||||
this.qualityFormItems = qualityFormItems;
|
||||
}
|
||||
|
||||
public boolean addQualityFormItemAtEnd(QualityFormItem qualityFormItem) {
|
||||
if (qualityFormItem != null) {
|
||||
Integer position = this.qualityFormItems.size();
|
||||
qualityFormItem.setPosition(position);
|
||||
this.qualityFormItems.add(qualityFormItem);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeQualityFormItem(QualityFormItem qualityFormItem) {
|
||||
this.qualityFormItems.remove(qualityFormItem);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "Quality form name is already being used")
|
||||
public boolean checkConstraintUniqueQualityFormName() {
|
||||
IQualityFormDAO qualityFormDAO = Registry.getQualityFormDAO();
|
||||
if (isNewObject()) {
|
||||
return !qualityFormDAO.existsByNameAnotherTransaction(this);
|
||||
} else {
|
||||
try {
|
||||
QualityForm c = qualityFormDAO.findUniqueByName(name);
|
||||
return c.getId().equals(getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return true;
|
||||
} catch (NonUniqueResultException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "The quality item positions must be uniques, consecutives and corrects in function to the percentage.")
|
||||
public boolean validateTheQualityFormItemPositions() {
|
||||
List<QualityFormItem> result = getListToNull(qualityFormItems);
|
||||
for (QualityFormItem qualityFormItem : qualityFormItems) {
|
||||
// Check if index is out of range
|
||||
Integer index = qualityFormItem.getPosition();
|
||||
|
||||
if (index == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((index.compareTo(0) < 0)
|
||||
|| (index.compareTo(result.size()) >= 0)) {
|
||||
return false;
|
||||
}
|
||||
// Check if index is repeated
|
||||
if (result.get(index) != null) {
|
||||
return false;
|
||||
}
|
||||
result.set(index, qualityFormItem);
|
||||
}
|
||||
|
||||
// Check if the indexs are consecutives
|
||||
for (QualityFormItem item : result) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// check the position is correct in function to the percentage.
|
||||
for (QualityFormItem item : qualityFormItems) {
|
||||
if (!item.getPosition().equals(getCorrectPosition(item))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Integer getCorrectPosition(QualityFormItem itemToFind) {
|
||||
Integer position = 0;
|
||||
for (QualityFormItem item : qualityFormItems) {
|
||||
if ((!itemToFind.equals(item))
|
||||
&& (itemToFind.getPercentage().compareTo(item
|
||||
.getPercentage())) > 0) {
|
||||
position++;
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private List<QualityFormItem> getListToNull(List<QualityFormItem> list) {
|
||||
List<QualityFormItem> result = new ArrayList<QualityFormItem>(list
|
||||
.size());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
result.add(null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
package org.navalplanner.business.qualityforms.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.navalplanner.business.INewObject;
|
||||
|
||||
public class QualityFormItem implements INewObject {
|
||||
|
||||
public static QualityFormItem create() {
|
||||
QualityFormItem qualityFormItem = new QualityFormItem();
|
||||
qualityFormItem.setNewObject(true);
|
||||
return qualityFormItem;
|
||||
}
|
||||
|
||||
public static QualityFormItem create(String name, Integer position,
|
||||
BigDecimal percentage) {
|
||||
QualityFormItem qualityFormItem = new QualityFormItem(name, position,
|
||||
percentage);
|
||||
qualityFormItem.setNewObject(true);
|
||||
return qualityFormItem;
|
||||
}
|
||||
|
||||
public QualityFormItem() {
|
||||
|
||||
}
|
||||
|
||||
private QualityFormItem(String name, Integer position, BigDecimal percentage) {
|
||||
this.name = name;
|
||||
this.position = position;
|
||||
this.percentage = percentage;
|
||||
}
|
||||
|
||||
private boolean newObject = false;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer position;
|
||||
|
||||
private BigDecimal percentage;
|
||||
|
||||
@NotEmpty
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer newPosition) {
|
||||
this.position = newPosition;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BigDecimal getPercentage() {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
public void setPercentage(BigDecimal percentage) {
|
||||
this.percentage = percentage;
|
||||
}
|
||||
|
||||
public boolean isNewObject() {
|
||||
return newObject;
|
||||
}
|
||||
|
||||
private void setNewObject(boolean newObject) {
|
||||
this.newObject = newObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
package org.navalplanner.business.qualityforms.entities;
|
||||
|
||||
public enum QualityFormType {
|
||||
|
||||
BY_PERCENTAGE("By Percentage."), BY_ITEMS("By Items.");
|
||||
|
||||
private String description;
|
||||
|
||||
private QualityFormType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public static QualityFormType getDefault() {
|
||||
return BY_PERCENTAGE;
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +60,9 @@
|
|||
<value>
|
||||
org/navalplanner/business/costcategories/entities/CostCategories.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/qualityforms/entities/QualityForms.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.navalplanner.business.qualityforms.entities" default-access="field">
|
||||
|
||||
<!-- QualityForm -->
|
||||
<class name="QualityForm" table="QUALITY_FORM">
|
||||
<id name="id" type="long" access="property">
|
||||
<generator class="hilo">
|
||||
<param name="max_lo">100</param>
|
||||
</generator>
|
||||
</id>
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="name" access="field" unique="true"/>
|
||||
<property name="description" access="field"/>
|
||||
|
||||
<property name="qualityFormType">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">org.navalplanner.business.qualityforms.entities.QualityFormType</param>
|
||||
</type>
|
||||
</property>
|
||||
|
||||
<list name="qualityFormItems" table="QUALITY_FORM_ITEMS">
|
||||
<key column="QUALITY_FORM_ID"/>
|
||||
<index column="position"/>
|
||||
<composite-element class="org.navalplanner.business.qualityforms.entities.QualityFormItem">
|
||||
<property name="name"/>
|
||||
<property name="percentage"/>
|
||||
</composite-element>
|
||||
</list>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.test.qualityforms.daos;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.navalplanner.business.qualityforms.daos.IQualityFormDAO;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityForm;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityFormItem;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Test for {@QualityDAO}
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public abstract class AbstractQualityFormTest {
|
||||
|
||||
@Autowired
|
||||
IQualityFormDAO qualityFormDAO;
|
||||
|
||||
public QualityForm createValidQualityForm() {
|
||||
QualityForm qualityForm = QualityForm.create(UUID.randomUUID()
|
||||
.toString(), UUID.randomUUID().toString());
|
||||
return qualityForm;
|
||||
}
|
||||
|
||||
public QualityFormItem createValidQualityFormItem() {
|
||||
QualityFormItem qualityFormItem = QualityFormItem.create(UUID
|
||||
.randomUUID().toString(), new Integer(0), new BigDecimal(0));
|
||||
return qualityFormItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.test.qualityforms.daos;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.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.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.qualityforms.daos.IQualityFormDAO;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityForm;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityFormItem;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test for {@QualityDAO}
|
||||
*
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class QualityFormDAOTest extends AbstractQualityFormTest {
|
||||
|
||||
@Autowired
|
||||
IQualityFormDAO qualityFormDAO;
|
||||
|
||||
@Test
|
||||
public void testInSpringContainer() {
|
||||
assertNotNull(qualityFormDAO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveQualityForm() {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
qualityFormDAO.save(qualityForm);
|
||||
assertTrue(qualityForm.getId() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveQualityForm() throws InstanceNotFoundException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
qualityFormDAO.save(qualityForm);
|
||||
qualityFormDAO.remove(qualityForm.getId());
|
||||
assertFalse(qualityFormDAO.exists(qualityForm.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListQualityForm() {
|
||||
int previous = qualityFormDAO.list(QualityForm.class).size();
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
qualityFormDAO.save(qualityForm);
|
||||
List<QualityForm> list = qualityFormDAO.list(QualityForm.class);
|
||||
assertEquals(previous + 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveQualityFormItems() {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
QualityFormItem qualityFormItem = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem);
|
||||
qualityFormDAO.save(qualityForm);
|
||||
|
||||
assertTrue(qualityForm.getId() != null);
|
||||
assertEquals(1, qualityForm.getQualityFormItems().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveAndRemoveQualityFormItem()
|
||||
throws InstanceNotFoundException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
QualityFormItem qualityFormItem = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem);
|
||||
qualityFormDAO.save(qualityForm);
|
||||
|
||||
assertTrue(qualityForm.getId() != null);
|
||||
assertEquals(1, qualityForm.getQualityFormItems().size());
|
||||
|
||||
qualityForm.removeQualityFormItem(qualityFormItem);
|
||||
assertEquals(0, qualityForm.getQualityFormItems().size());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.business.test.qualityforms.entities;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.qualityforms.daos.IQualityFormDAO;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityForm;
|
||||
import org.navalplanner.business.qualityforms.entities.QualityFormItem;
|
||||
import org.navalplanner.business.test.qualityforms.daos.AbstractQualityFormTest;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
@Transactional
|
||||
public class QualityFormTest extends AbstractQualityFormTest {
|
||||
|
||||
@Autowired
|
||||
IQualityFormDAO qualityFormDAO;
|
||||
|
||||
@Test
|
||||
public void checkInvalidNameQualityForm() throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
qualityForm.setName("");
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
|
||||
qualityForm.setName(null);
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkInvalidQualityFormType() throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
qualityForm.setQualityFormType(null);
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkInvalidRepeatedQualityFormItemPosition()
|
||||
throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
|
||||
QualityFormItem qualityFormItem1 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem1);
|
||||
|
||||
QualityFormItem qualityFormItem2 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem2);
|
||||
|
||||
qualityFormItem1.setPosition(0);
|
||||
qualityFormItem2.setPosition(0);
|
||||
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkInvalidNotConsecutivesQualityFormItemPosition()
|
||||
throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
|
||||
QualityFormItem qualityFormItem1 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem1);
|
||||
|
||||
QualityFormItem qualityFormItem2 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem2);
|
||||
|
||||
qualityFormItem1.setPosition(0);
|
||||
qualityFormItem2.setPosition(2);
|
||||
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkInvalidOutOfRangeQualityFormItemPosition()
|
||||
throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
|
||||
QualityFormItem qualityFormItem1 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem1);
|
||||
|
||||
QualityFormItem qualityFormItem2 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem2);
|
||||
|
||||
qualityFormItem1.setPosition(1);
|
||||
qualityFormItem2.setPosition(2);
|
||||
|
||||
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkInvalidPercentageQualityFormItemPosition()
|
||||
throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
|
||||
QualityFormItem qualityFormItem1 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem1);
|
||||
|
||||
QualityFormItem qualityFormItem2 = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem2);
|
||||
|
||||
qualityFormItem1.setPosition(0);
|
||||
qualityFormItem1.setPercentage(new BigDecimal(0));
|
||||
qualityFormItem2.setPosition(1);
|
||||
qualityFormItem2.setPercentage(new BigDecimal(1));
|
||||
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
} catch (ValidationException e) {
|
||||
fail("It shouldn't throw an exception");
|
||||
}
|
||||
|
||||
qualityFormItem1.setPercentage(new BigDecimal(1));
|
||||
qualityFormItem2.setPercentage(new BigDecimal(0));
|
||||
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkInvalidQualityFormItemName() throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
QualityFormItem qualityFormItem = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem);
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
} catch (ValidationException e) {
|
||||
fail("It should throw an exception");
|
||||
}
|
||||
|
||||
qualityFormItem.setName(null);
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
|
||||
qualityFormItem.setName("");
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkNotNullQualityFormItemPosition()
|
||||
throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
QualityFormItem qualityFormItem = createValidQualityFormItem();
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem);
|
||||
qualityFormItem.setPosition(null);
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkNotNullQualityFormItemPercentage()
|
||||
throws ValidationException {
|
||||
QualityForm qualityForm = createValidQualityForm();
|
||||
QualityFormItem qualityFormItem = createValidQualityFormItem();
|
||||
qualityFormItem.setPercentage(null);
|
||||
qualityForm.addQualityFormItemAtEnd(qualityFormItem);
|
||||
try {
|
||||
qualityFormDAO.save(qualityForm);
|
||||
fail("It should throw an exception");
|
||||
} catch (ValidationException e) {
|
||||
// It should throw an exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -72,6 +72,9 @@
|
|||
<value>
|
||||
TestEntities.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/qualityforms/entities/QualityForms.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@
|
|||
<value>
|
||||
org/navalplanner/business/costcategories/entities/CostCategories.hbm.xml
|
||||
</value>
|
||||
<value>
|
||||
org/navalplanner/business/qualityforms/entities/QualityForms.hbm.xml
|
||||
</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue