ItEr16S12CreacionProxectoPlanificacion: Ensuring OrderLine has an hours group associated when it's added to the orders tree.
This commit is contained in:
parent
27a9b35b5b
commit
cbf7cccd21
4 changed files with 84 additions and 110 deletions
|
|
@ -54,11 +54,18 @@ public class HoursGroup implements Cloneable {
|
||||||
return workingHours;
|
return workingHours;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPercentage(BigDecimal percentage)
|
/**
|
||||||
|
* @param proportion
|
||||||
|
* It's one based, instead of one hundred based
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* if the new sum of percentages in the parent {@link OrderLine}
|
||||||
|
* surpasses one
|
||||||
|
*/
|
||||||
|
public void setPercentage(BigDecimal proportion)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
BigDecimal oldPercentage = this.percentage;
|
BigDecimal oldPercentage = this.percentage;
|
||||||
|
|
||||||
this.percentage = percentage;
|
this.percentage = proportion;
|
||||||
|
|
||||||
if (!parentOrderLine.isPercentageValid()) {
|
if (!parentOrderLine.isPercentageValid()) {
|
||||||
this.percentage = oldPercentage;
|
this.percentage = oldPercentage;
|
||||||
|
|
@ -153,7 +160,7 @@ public class HoursGroup implements Cloneable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTransient() {
|
public boolean isTransient() {
|
||||||
// FIXME Review reattachment
|
// FIXME Review reattachment
|
||||||
return id == null;
|
return id == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,16 @@ import java.util.Set;
|
||||||
|
|
||||||
public class OrderLine extends OrderElement {
|
public class OrderLine extends OrderElement {
|
||||||
|
|
||||||
|
public static OrderLine createOrderLineWithUnfixedHours(int hours) {
|
||||||
|
OrderLine result = new OrderLine();
|
||||||
|
HoursGroup hoursGroup = new HoursGroup();
|
||||||
|
result.addHoursGroup(hoursGroup);
|
||||||
|
hoursGroup.setFixedPercentage(true);
|
||||||
|
hoursGroup.setPercentage(new BigDecimal(1));
|
||||||
|
hoursGroup.setWorkingHours(hours);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private Set<HoursGroup> hoursGroups = new HashSet<HoursGroup>();
|
private Set<HoursGroup> hoursGroups = new HashSet<HoursGroup>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -55,7 +65,6 @@ public class OrderLine extends OrderElement {
|
||||||
/**
|
/**
|
||||||
* Set the total working hours of the {@link OrderLine} taking into account
|
* Set the total working hours of the {@link OrderLine} taking into account
|
||||||
* the {@link HoursGroup} policies.
|
* the {@link HoursGroup} policies.
|
||||||
*
|
|
||||||
* @param workHours
|
* @param workHours
|
||||||
* The desired value to set as total working hours
|
* The desired value to set as total working hours
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
|
|
@ -89,20 +98,13 @@ public class OrderLine extends OrderElement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the needed modifications in hoursGroups attribute in order to set
|
* Makes the needed modifications in hoursGroups attribute in order to set
|
||||||
* the desired value of working hours.
|
* the desired value of working hours. This method takes into account the
|
||||||
*
|
* different {@link HoursGroup} policies: If policy is FIXED_PERCENTAGE the
|
||||||
* This method takes into account the different {@link HoursGroup} policies:
|
* new value is calculated for each {@link HoursGroup} with this policy.
|
||||||
*
|
* Using round down in order to avoid problems. Hours are proportionally
|
||||||
* If policy is FIXED_PERCENTAGE the new value is calculated for each
|
* distributed when there're {@link HoursGroup} with NO_FIXED policy.
|
||||||
* {@link HoursGroup} with this policy. Using round down in order to avoid
|
|
||||||
* problems.
|
|
||||||
*
|
|
||||||
* Hours are proportionally distributed when there're {@link HoursGroup}
|
|
||||||
* with NO_FIXED policy.
|
|
||||||
*
|
|
||||||
* Finally, it creates new {@link HoursGroup} if the're some remaining hours
|
* Finally, it creates new {@link HoursGroup} if the're some remaining hours
|
||||||
* (it could happen because of the round down used for operations).
|
* (it could happen because of the round down used for operations).
|
||||||
*
|
|
||||||
* @param workHours
|
* @param workHours
|
||||||
* The value to set as total working hours
|
* The value to set as total working hours
|
||||||
*/
|
*/
|
||||||
|
|
@ -175,7 +177,6 @@ public class OrderLine extends OrderElement {
|
||||||
/**
|
/**
|
||||||
* Checks if the desired total number of hours is valid taking into account
|
* Checks if the desired total number of hours is valid taking into account
|
||||||
* {@link HoursGroup} policy restrictions.
|
* {@link HoursGroup} policy restrictions.
|
||||||
*
|
|
||||||
* @param total
|
* @param total
|
||||||
* The desired value
|
* The desired value
|
||||||
* @return true if the value is valid
|
* @return true if the value is valid
|
||||||
|
|
@ -202,9 +203,7 @@ public class OrderLine extends OrderElement {
|
||||||
/**
|
/**
|
||||||
* Checks if the percentage is or not valid. That means, if the pertentage
|
* Checks if the percentage is or not valid. That means, if the pertentage
|
||||||
* of all {@link HoursGroup} with FIXED_PERCENTAGE isn't more than 100%.
|
* of all {@link HoursGroup} with FIXED_PERCENTAGE isn't more than 100%.
|
||||||
*
|
|
||||||
* This method is called from setPercentage at {@link HoursGroup} class.
|
* This method is called from setPercentage at {@link HoursGroup} class.
|
||||||
*
|
|
||||||
* @return true if the percentage is valid
|
* @return true if the percentage is valid
|
||||||
*/
|
*/
|
||||||
public boolean isPercentageValid() {
|
public boolean isPercentageValid() {
|
||||||
|
|
@ -227,7 +226,6 @@ public class OrderLine extends OrderElement {
|
||||||
/**
|
/**
|
||||||
* Calculates the total number of working hours in a set of
|
* Calculates the total number of working hours in a set of
|
||||||
* {@link HoursGroup}.
|
* {@link HoursGroup}.
|
||||||
*
|
|
||||||
* @param hoursGroups
|
* @param hoursGroups
|
||||||
* A {@link HoursGroup} set
|
* A {@link HoursGroup} set
|
||||||
* @return The sum of working hours
|
* @return The sum of working hours
|
||||||
|
|
@ -244,7 +242,6 @@ public class OrderLine extends OrderElement {
|
||||||
* Calculates the total number of working hours in a set of
|
* Calculates the total number of working hours in a set of
|
||||||
* {@link HoursGroup} taking into account just {@link HoursGroup} with
|
* {@link HoursGroup} taking into account just {@link HoursGroup} with
|
||||||
* NO_FIXED as policy.
|
* NO_FIXED as policy.
|
||||||
*
|
|
||||||
* @param hoursGroups
|
* @param hoursGroups
|
||||||
* A {@link HoursGroup} set
|
* A {@link HoursGroup} set
|
||||||
* @return The sum of NO_FIXED {@link HoursGroup}
|
* @return The sum of NO_FIXED {@link HoursGroup}
|
||||||
|
|
@ -263,7 +260,6 @@ public class OrderLine extends OrderElement {
|
||||||
* Re-calculates the working hours and percentages in the {@link HoursGroup}
|
* Re-calculates the working hours and percentages in the {@link HoursGroup}
|
||||||
* set of the current {@link OrderLine}, taking into account the policy of
|
* set of the current {@link OrderLine}, taking into account the policy of
|
||||||
* each {@link HoursGroup}.
|
* each {@link HoursGroup}.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public void recalculateHoursGroups() {
|
public void recalculateHoursGroups() {
|
||||||
Integer total = calculateTotalHours(hoursGroups);
|
Integer total = calculateTotalHours(hoursGroups);
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,17 @@ import java.math.BigDecimal;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||||
import org.navalplanner.business.orders.entities.OrderLine;
|
import org.navalplanner.business.orders.entities.OrderLine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OrderLine}. <br />
|
* Tests for {@link OrderLine}. <br />
|
||||||
*
|
|
||||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||||
*/
|
*/
|
||||||
public class OrderLineTest {
|
public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An empty {@link OrderLine} without any {@link HoursGroup}.
|
* An empty {@link OrderLine} without any {@link HoursGroup}. Trying to set
|
||||||
*
|
* work hours of {@link OrderLine} to 100h. Expected: {@link OrderLine} with
|
||||||
* Trying to set work hours of {@link OrderLine} to 100h.
|
* 100h, with one {@link HoursGroup} with 100h NO_FIXED.
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 100h, with one {@link HoursGroup} with
|
|
||||||
* 100h NO_FIXED.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursEmptyOrderLine() {
|
public void testSetWorkHoursHoursEmptyOrderLine() {
|
||||||
|
|
@ -48,11 +45,8 @@ public class OrderLineTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An empty {@link OrderLine} without any {@link HoursGroup}.
|
* An empty {@link OrderLine} without any {@link HoursGroup}. Trying to set
|
||||||
*
|
* work hours of {@link OrderLine} to -100h. Expected: Exception.
|
||||||
* Trying to set work hours of {@link OrderLine} to -100h.
|
|
||||||
*
|
|
||||||
* Expected: Exception.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursEmptyOrderLineIllegal() {
|
public void testSetWorkHoursHoursEmptyOrderLineIllegal() {
|
||||||
|
|
@ -75,10 +69,8 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with just one {@link HoursGroup} of 100h NO_FIXED.
|
* An {@link OrderLine} with just one {@link HoursGroup} of 100h NO_FIXED.
|
||||||
*
|
* Trying to set work hours of {@link OrderLine} to 120h. Expected:
|
||||||
* Trying to set work hours of {@link OrderLine} to 120h.
|
* {@link OrderLine} with 120h. {@link HoursGroup} with 120h.
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 120h. {@link HoursGroup} with 120h.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupNoFixedIncreaseValue() {
|
public void testSetWorkHoursHoursGroupNoFixedIncreaseValue() {
|
||||||
|
|
@ -103,10 +95,8 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with just one {@link HoursGroup} of 100h NO_FIXED.
|
* An {@link OrderLine} with just one {@link HoursGroup} of 100h NO_FIXED.
|
||||||
*
|
* Trying to set work hours of {@link OrderLine} to 75h. Expected:
|
||||||
* Trying to set work hours of {@link OrderLine} to 75h.
|
* {@link OrderLine} with 75h. {@link HoursGroup} with 75h.
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 75h. {@link HoursGroup} with 75h.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupNoFixedDecreaseValue() {
|
public void testSetWorkHoursHoursGroupNoFixedDecreaseValue() {
|
||||||
|
|
@ -132,10 +122,7 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with just one {@link HoursGroup} of 100h 100%
|
* An {@link OrderLine} with just one {@link HoursGroup} of 100h 100%
|
||||||
* FIXED_PERCENTAGE.
|
* FIXED_PERCENTAGE. Trying to set work hours of {@link OrderLine} to 120h.
|
||||||
*
|
|
||||||
* Trying to set work hours of {@link OrderLine} to 120h.
|
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 120h. {@link HoursGroup} with 120h 100%.
|
* Expected: {@link OrderLine} with 120h. {@link HoursGroup} with 120h 100%.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -167,10 +154,7 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with just one {@link HoursGroup} of 100h 100%
|
* An {@link OrderLine} with just one {@link HoursGroup} of 100h 100%
|
||||||
* FIXED_PERCENTAGE.
|
* FIXED_PERCENTAGE. Trying to set work hours of {@link OrderLine} to 75h.
|
||||||
*
|
|
||||||
* Trying to set work hours of {@link OrderLine} to 75h.
|
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 100h. {@link HoursGroup} with 75h 100%.
|
* Expected: {@link OrderLine} with 100h. {@link HoursGroup} with 75h 100%.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -202,10 +186,7 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with two {@link HoursGroup} of 100h and 50h
|
* An {@link OrderLine} with two {@link HoursGroup} of 100h and 50h
|
||||||
* NO_FIXED.
|
* NO_FIXED. Trying to set work hours of {@link OrderLine} to 200h.
|
||||||
*
|
|
||||||
* Trying to set work hours of {@link OrderLine} to 200h.
|
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 200h. {@link HoursGroup} with 133h and
|
* Expected: {@link OrderLine} with 200h. {@link HoursGroup} with 133h and
|
||||||
* HoursGroup with 66h.
|
* HoursGroup with 66h.
|
||||||
*/
|
*/
|
||||||
|
|
@ -237,11 +218,8 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with two {@link HoursGroup} of 100h and 50h
|
* An {@link OrderLine} with two {@link HoursGroup} of 100h and 50h
|
||||||
* NO_FIXED.
|
* NO_FIXED. Trying to set work hours of {@link OrderLine} to 50h. Expected:
|
||||||
*
|
* {@link OrderLine} with 50h. {@link HoursGroup} with 33h and
|
||||||
* Trying to set work hours of {@link OrderLine} to 50h.
|
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 50h. {@link HoursGroup} with 33h and
|
|
||||||
* {@link HoursGroup} with 16h.
|
* {@link HoursGroup} with 16h.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -272,12 +250,9 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75%
|
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75%
|
||||||
* FIXED_PERCENTAGE and 25h NO_FIXED.
|
* FIXED_PERCENTAGE and 25h NO_FIXED. Trying to set work hours of
|
||||||
*
|
* {@link OrderLine} to 200h. Expected: {@link OrderLine} with 200h.
|
||||||
* Trying to set work hours of {@link OrderLine} to 200h.
|
* {@link HoursGroup} with 150h 75% and {@link HoursGroup} with 50h.
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 200h. {@link HoursGroup} with 150h 75%
|
|
||||||
* and {@link HoursGroup} with 50h.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupFixedPercentageAndHoursGroupNoFixedIncreaseValue() {
|
public void testSetWorkHoursHoursGroupFixedPercentageAndHoursGroupNoFixedIncreaseValue() {
|
||||||
|
|
@ -312,12 +287,9 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75%
|
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75%
|
||||||
* FIXED_PERCENTAGE and 25h NO_FIXED.
|
* FIXED_PERCENTAGE and 25h NO_FIXED. Trying to set work hours of
|
||||||
*
|
* {@link OrderLine} to 50h. Expected: {@link OrderLine} with 50h.
|
||||||
* Trying to set work hours of {@link OrderLine} to 50h.
|
* {@link HoursGroup} with 37h 75% and HoursGroup with 13h.
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 50h. {@link HoursGroup} with 37h 75% and
|
|
||||||
* HoursGroup with 13h.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupFixedPercentageAndHoursGroupNoFixedDecreaseValue() {
|
public void testSetWorkHoursHoursGroupFixedPercentageAndHoursGroupNoFixedDecreaseValue() {
|
||||||
|
|
@ -352,10 +324,7 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75% and 25h 25%
|
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75% and 25h 25%
|
||||||
* FIXED_PERCENTAGE.
|
* FIXED_PERCENTAGE. Trying to set work hours of {@link OrderLine} to 200h.
|
||||||
*
|
|
||||||
* Trying to set work hours of {@link OrderLine} to 200h.
|
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 200h. {@link HoursGroup} with 150h 75%
|
* Expected: {@link OrderLine} with 200h. {@link HoursGroup} with 150h 75%
|
||||||
* and {@link HoursGroup} with 50h 25%.
|
* and {@link HoursGroup} with 50h 25%.
|
||||||
*/
|
*/
|
||||||
|
|
@ -396,10 +365,7 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75% and 25h 25%
|
* An {@link OrderLine} with two {@link HoursGroup} of 75h 75% and 25h 25%
|
||||||
* FIXED_PERCENTAGE.
|
* FIXED_PERCENTAGE. Trying to set work hours of {@link OrderLine} to 80h.
|
||||||
*
|
|
||||||
* Trying to set work hours of {@link OrderLine} to 80h.
|
|
||||||
*
|
|
||||||
* Expected: {@link OrderLine} with 80h. {@link HoursGroup} with 60h 75% and
|
* Expected: {@link OrderLine} with 80h. {@link HoursGroup} with 60h 75% and
|
||||||
* {@link HoursGroup} with 20h 25%.
|
* {@link HoursGroup} with 20h 25%.
|
||||||
*/
|
*/
|
||||||
|
|
@ -440,12 +406,10 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with three {@link HoursGroup} of 50h, 50h NO_FIXED
|
* An {@link OrderLine} with three {@link HoursGroup} of 50h, 50h NO_FIXED
|
||||||
* and 100h 50% FIXED_PERCENTAGE.
|
* and 100h 50% FIXED_PERCENTAGE. Trying to set work hours of
|
||||||
*
|
* {@link OrderLine} to 300h. Expected: {@link OrderLine} with 300h.
|
||||||
* Trying to set work hours of {@link OrderLine} to 300h.
|
* {@link HoursGroup} with 75h, {@link HoursGroup} with 75h and
|
||||||
*
|
* {@link HoursGroup} with 150h 50%.
|
||||||
* Expected: {@link OrderLine} with 300h. {@link HoursGroup} with 75h,
|
|
||||||
* {@link HoursGroup} with 75h and {@link HoursGroup} with 150h 50%.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupNoFixedAndHoursGroupFixedPercentageIncreaseValue() {
|
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupNoFixedAndHoursGroupFixedPercentageIncreaseValue() {
|
||||||
|
|
@ -484,12 +448,10 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with three {@link HoursGroup} of 40h, 60h NO_FIXED
|
* An {@link OrderLine} with three {@link HoursGroup} of 40h, 60h NO_FIXED
|
||||||
* and 100h 50% FIXED_PERCENTAGE.
|
* and 100h 50% FIXED_PERCENTAGE. Trying to set work hours of
|
||||||
*
|
* {@link OrderLine} to 100h. Expected: {@link OrderLine} with 100h.
|
||||||
* Trying to set work hours of {@link OrderLine} to 100h.
|
* {@link HoursGroup} with 20h, {@link HoursGroup} with 30h and
|
||||||
*
|
* {@link HoursGroup} with 50h 50%.
|
||||||
* Expected: {@link OrderLine} with 100h. {@link HoursGroup} with 20h,
|
|
||||||
* {@link HoursGroup} with 30h and {@link HoursGroup} with 50h 50%.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupNoFixedAndHoursGroupFixedPercentageDecreaseValue() {
|
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupNoFixedAndHoursGroupFixedPercentageDecreaseValue() {
|
||||||
|
|
@ -528,12 +490,10 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with three {@link HoursGroup} of 50h NO_FIXED, 50h
|
* An {@link OrderLine} with three {@link HoursGroup} of 50h NO_FIXED, 50h
|
||||||
* 25% and 100h 50% FIXED_PERCENTAGE.
|
* 25% and 100h 50% FIXED_PERCENTAGE. Trying to set work hours of
|
||||||
*
|
* {@link OrderLine} to 400h. Expected: {@link OrderLine} with 400h.
|
||||||
* Trying to set work hours of {@link OrderLine} to 400h.
|
* {@link HoursGroup} with 100h, {@link HoursGroup} with 100h 25% and
|
||||||
*
|
* {@link HoursGroup} with 200h 50%.
|
||||||
* Expected: {@link OrderLine} with 400h. {@link HoursGroup} with 100h,
|
|
||||||
* {@link HoursGroup} with 100h 25% and {@link HoursGroup} with 200h 50%.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupFixedPercentageAndHoursGroupFixedPercentageIncreaseValue() {
|
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupFixedPercentageAndHoursGroupFixedPercentageIncreaseValue() {
|
||||||
|
|
@ -576,12 +536,10 @@ public class OrderLineTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link OrderLine} with three {@link HoursGroup} of 50h NO_FIXED, 50h
|
* An {@link OrderLine} with three {@link HoursGroup} of 50h NO_FIXED, 50h
|
||||||
* 25% and 100h 50% FIXED_PERCENTAGE.
|
* 25% and 100h 50% FIXED_PERCENTAGE. Trying to set work hours of
|
||||||
*
|
* {@link OrderLine} to 100h. Expected: {@link OrderLine} with 400h.
|
||||||
* Trying to set work hours of {@link OrderLine} to 100h.
|
* {@link HoursGroup} with 25h, {@link HoursGroup} with 25h 25% and
|
||||||
*
|
* {@link HoursGroup} with 50h 50%.
|
||||||
* Expected: {@link OrderLine} with 400h. {@link HoursGroup} with 25h,
|
|
||||||
* {@link HoursGroup} with 25h 25% and {@link HoursGroup} with 50h 50%.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupFixedPercentageAndHoursGroupFixedPercentageDecreaseValue() {
|
public void testSetWorkHoursHoursGroupNoFixedAndHoursGroupFixedPercentageAndHoursGroupFixedPercentageDecreaseValue() {
|
||||||
|
|
@ -751,4 +709,18 @@ public class OrderLineTest {
|
||||||
assertThat(hoursGroup3.getWorkingHours(), equalTo(114));
|
assertThat(hoursGroup3.getWorkingHours(), equalTo(114));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createOrderLineWithAnHoursGroupTakingAll() {
|
||||||
|
int[] hoursValues = { 0, 100, 10, 30 };
|
||||||
|
for (int hours : hoursValues) {
|
||||||
|
OrderLine orderLine = OrderLine
|
||||||
|
.createOrderLineWithUnfixedHours(hours);
|
||||||
|
assertThat(orderLine.getWorkHours(), equalTo(hours));
|
||||||
|
assertThat(orderLine.getHoursGroups().size(), equalTo(1));
|
||||||
|
orderLine.setWorkHours(20);
|
||||||
|
assertThat(orderLine.getWorkHours(), equalTo(20));
|
||||||
|
assertThat(orderLine.getHoursGroups().size(), equalTo(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import org.zkoss.zul.SimpleTreeNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for a the {@link OrderElement} tree for a {@link Order} <br />
|
* Model for a the {@link OrderElement} tree for a {@link Order} <br />
|
||||||
*
|
|
||||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||||
*/
|
*/
|
||||||
public class OrderElementTreeModel extends SimpleTreeModel {
|
public class OrderElementTreeModel extends SimpleTreeModel {
|
||||||
|
|
@ -28,11 +27,11 @@ public class OrderElementTreeModel extends SimpleTreeModel {
|
||||||
|
|
||||||
private static SimpleTreeNode asNode(OrderElement orderElement) {
|
private static SimpleTreeNode asNode(OrderElement orderElement) {
|
||||||
orderElement.forceLoadHourGroups();
|
orderElement.forceLoadHourGroups();
|
||||||
return new SimpleTreeNode(orderElement, asNodes(orderElement.getChildren()));
|
return new SimpleTreeNode(orderElement, asNodes(orderElement
|
||||||
|
.getChildren()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SimpleTreeNode createRootNodeAndDescendants(
|
private static SimpleTreeNode createRootNodeAndDescendants(Order order) {
|
||||||
Order order) {
|
|
||||||
return new SimpleTreeNode(order, asNodes(order.getOrderElements()));
|
return new SimpleTreeNode(order, asNodes(order.getOrderElements()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,7 +52,8 @@ public class OrderElementTreeModel extends SimpleTreeModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private OrderElement createNewOrderElement() {
|
private OrderElement createNewOrderElement() {
|
||||||
OrderElement newOrderElement = new OrderLine();
|
OrderElement newOrderElement = OrderLine
|
||||||
|
.createOrderLineWithUnfixedHours(0);
|
||||||
newOrderElement.setName("New Order Element");
|
newOrderElement.setName("New Order Element");
|
||||||
return newOrderElement;
|
return newOrderElement;
|
||||||
}
|
}
|
||||||
|
|
@ -82,8 +82,7 @@ public class OrderElementTreeModel extends SimpleTreeModel {
|
||||||
SimpleTreeNode selectedForTurningIntoContainer) {
|
SimpleTreeNode selectedForTurningIntoContainer) {
|
||||||
IOrderLineGroup parentContainer = asOrderLineGroup(getParent(selectedForTurningIntoContainer));
|
IOrderLineGroup parentContainer = asOrderLineGroup(getParent(selectedForTurningIntoContainer));
|
||||||
if (selectedForTurningIntoContainer.getData() instanceof IOrderLineGroup)
|
if (selectedForTurningIntoContainer.getData() instanceof IOrderLineGroup)
|
||||||
return (IOrderLineGroup) selectedForTurningIntoContainer
|
return (IOrderLineGroup) selectedForTurningIntoContainer.getData();
|
||||||
.getData();
|
|
||||||
OrderElement toBeTurned = asOrderLine(selectedForTurningIntoContainer);
|
OrderElement toBeTurned = asOrderLine(selectedForTurningIntoContainer);
|
||||||
OrderLineGroup asContainer = toBeTurned.toContainer();
|
OrderLineGroup asContainer = toBeTurned.toContainer();
|
||||||
parentContainer.replace(toBeTurned, asContainer);
|
parentContainer.replace(toBeTurned, asContainer);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue