ItEr45S14CUActualizarTraballoExportadoPorSubcontrataItEr44S20: Added a basic test for the new report advances service.
This commit is contained in:
parent
b59b77fd74
commit
55d8734ec7
2 changed files with 167 additions and 1 deletions
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* 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.web.test.ws.subcontract;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.web.WebappGlobalNames.WEBAPP_SPRING_CONFIG_FILE;
|
||||
import static org.navalplanner.web.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CONFIG_FILE;
|
||||
import static org.navalplanner.web.test.WebappGlobalNames.WEBAPP_SPRING_CONFIG_TEST_FILE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.IDataBootstrap;
|
||||
import org.navalplanner.business.advance.entities.AdvanceMeasurement;
|
||||
import org.navalplanner.business.advance.entities.DirectAdvanceAssignment;
|
||||
import org.navalplanner.business.common.daos.IConfigurationDAO;
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.orders.entities.OrderLine;
|
||||
import org.navalplanner.ws.common.api.AdvanceMeasurementDTO;
|
||||
import org.navalplanner.ws.subcontract.api.IReportAdvancesService;
|
||||
import org.navalplanner.ws.subcontract.api.OrderElementWithAdvanceMeasurementsDTO;
|
||||
import org.navalplanner.ws.subcontract.api.OrderElementWithAdvanceMeasurementsListDTO;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests for {@link IReportAdvancesService}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE,
|
||||
WEBAPP_SPRING_SECURITY_CONFIG_FILE })
|
||||
@Transactional
|
||||
public class ReportAdvancesServiceTest {
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap defaultAdvanceTypesBootstrapListener;
|
||||
|
||||
@Resource
|
||||
private IDataBootstrap configurationBootstrap;
|
||||
|
||||
@Before
|
||||
public void loadRequiredaData() {
|
||||
defaultAdvanceTypesBootstrapListener.loadRequiredData();
|
||||
configurationBootstrap.loadRequiredData();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private IReportAdvancesService reportAdvancesService;
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Test
|
||||
public void validAdvancesReport() {
|
||||
Order order = givenValidOrderAlreadyStored();
|
||||
String orderElementCode = order.getChildren().get(0).getCode();
|
||||
|
||||
Date date = new Date();
|
||||
BigDecimal value = new BigDecimal(20);
|
||||
OrderElementWithAdvanceMeasurementsListDTO orderElementWithAdvanceMeasurementsListDTO = givenOrderElementWithAdvanceMeasurementsListDTO(
|
||||
orderElementCode, date, value);
|
||||
reportAdvancesService
|
||||
.updateAdvances(orderElementWithAdvanceMeasurementsListDTO);
|
||||
|
||||
Order foundOrder = orderDAO.findExistingEntity(order.getId());
|
||||
assertNotNull(foundOrder);
|
||||
assertThat(foundOrder.getChildren().size(), equalTo(1));
|
||||
|
||||
OrderElement orderElement = foundOrder.getChildren().get(0);
|
||||
assertNotNull(orderElement);
|
||||
|
||||
DirectAdvanceAssignment directAdvanceAssignmentSubcontractor = orderElement
|
||||
.getDirectAdvanceAssignmentSubcontractor();
|
||||
assertNotNull(directAdvanceAssignmentSubcontractor);
|
||||
assertTrue(directAdvanceAssignmentSubcontractor
|
||||
.getReportGlobalAdvance());
|
||||
assertThat(directAdvanceAssignmentSubcontractor
|
||||
.getAdvanceMeasurements().size(), equalTo(1));
|
||||
|
||||
AdvanceMeasurement advanceMeasurement = directAdvanceAssignmentSubcontractor
|
||||
.getAdvanceMeasurements().first();
|
||||
assertThat(advanceMeasurement.getDate(), equalTo(LocalDate
|
||||
.fromDateFields(date)));
|
||||
assertThat(advanceMeasurement.getValue(), equalTo(value));
|
||||
}
|
||||
|
||||
private OrderElementWithAdvanceMeasurementsListDTO givenOrderElementWithAdvanceMeasurementsListDTO(
|
||||
String orderElementCode, Date date, BigDecimal value) {
|
||||
OrderElementWithAdvanceMeasurementsDTO orderElementWithAdvanceMeasurementsDTO = new OrderElementWithAdvanceMeasurementsDTO();
|
||||
orderElementWithAdvanceMeasurementsDTO.code = orderElementCode;
|
||||
|
||||
Set<AdvanceMeasurementDTO> advanceMeasurementDTOs = new HashSet<AdvanceMeasurementDTO>();
|
||||
advanceMeasurementDTOs.add(new AdvanceMeasurementDTO(date, value));
|
||||
orderElementWithAdvanceMeasurementsDTO.advanceMeasurements = advanceMeasurementDTOs;
|
||||
|
||||
return new OrderElementWithAdvanceMeasurementsListDTO(Arrays
|
||||
.asList(orderElementWithAdvanceMeasurementsDTO));
|
||||
}
|
||||
|
||||
private Order givenValidOrderAlreadyStored() {
|
||||
Order order = Order.create();
|
||||
order.setCode(UUID.randomUUID().toString());
|
||||
order.setName("Order name");
|
||||
order.setInitDate(new Date());
|
||||
order.setCalendar(configurationDAO.getConfiguration()
|
||||
.getDefaultCalendar());
|
||||
|
||||
OrderLine orderLine = OrderLine
|
||||
.createOrderLineWithUnfixedPercentage(1000);
|
||||
orderLine.setCode(UUID.randomUUID().toString());
|
||||
orderLine.setName("Order line name");
|
||||
|
||||
order.add(orderLine);
|
||||
|
||||
orderDAO.save(order);
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.IDataBootstrap;
|
||||
import org.navalplanner.business.common.daos.IConfigurationDAO;
|
||||
import org.navalplanner.business.externalcompanies.daos.IExternalCompanyDAO;
|
||||
import org.navalplanner.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
|
|
@ -93,6 +94,9 @@ public class SubcontractServiceTest {
|
|||
@Autowired
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
private OrderLineDTO givenBasicOrderLineDTO(String orderLineCode) {
|
||||
OrderLineDTO orderLineDTO = new OrderLineDTO();
|
||||
orderLineDTO.name = "Test";
|
||||
|
|
@ -204,4 +208,4 @@ public class SubcontractServiceTest {
|
|||
assertThat(children.get(0).getExternalCode(), equalTo(orderLineCode));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue