BATCH-2110: Updated batch to support Spring 4
* Refactored iBatis based readers and writers to not utilize SqlMapClientTemplate. * Depricated all iBatis based readers and writers in favor of MyBatis's native Spring support. * Updated XStream support to 1.4.4 and Jettison to 1.2 to be in alignment with Spring 4. * Added the PooledEmbeddedDataSource to address the issue outlined in SPR-11372.
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class FutureDateFunctionTests {
|
||||
|
||||
private FutureDateFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new FutureDateFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionWithNonDateValue() {
|
||||
|
||||
//set-up mock argument - set return value to non Date value
|
||||
when(argument.getResult(null)).thenReturn(this);
|
||||
|
||||
//call tested method - exception is expected because non date value
|
||||
try {
|
||||
function.doGetResult(null);
|
||||
fail("Exception was expected.");
|
||||
} catch (Exception e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionWithFutureDate() throws Exception {
|
||||
|
||||
//set-up mock argument - set return value to future Date
|
||||
when(argument.getResult(null)).thenReturn(new Date(Long.MAX_VALUE));
|
||||
|
||||
//vefify result - should be true because of future date
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionWithPastDate() throws Exception {
|
||||
|
||||
//set-up mock argument - set return value to future Date
|
||||
when(argument.getResult(null)).thenReturn(new Date(0));
|
||||
|
||||
//vefify result - should be false because of past date
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class TotalOrderItemsFunctionTests {
|
||||
|
||||
private TotalOrderItemsFunction function;
|
||||
private Function argument2;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
//create mock for first argument - set count to 3
|
||||
Function argument1 = mock(Function.class);
|
||||
when(argument1.getResult(null)).thenReturn(3);
|
||||
|
||||
|
||||
argument2 = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new TotalOrderItemsFunction(new Function[] {argument1, argument2}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionWithNonListValue() {
|
||||
|
||||
when(argument2.getResult(null)).thenReturn(this);
|
||||
|
||||
//call tested method - exception is expected because non list value
|
||||
try {
|
||||
function.doGetResult(null);
|
||||
fail("Exception was expected.");
|
||||
} catch (Exception e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionWithCorrectItemCount() throws Exception {
|
||||
|
||||
//create list with correct item count
|
||||
LineItem item = new LineItem();
|
||||
item.setQuantity(3);
|
||||
List<LineItem> list = new ArrayList<LineItem>();
|
||||
list.add(item);
|
||||
|
||||
when(argument2.getResult(null)).thenReturn(list);
|
||||
|
||||
//vefify result
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionWithIncorrectItemCount() throws Exception {
|
||||
|
||||
//create list with incorrect item count
|
||||
LineItem item = new LineItem();
|
||||
item.setQuantity(99);
|
||||
List<LineItem> list = new ArrayList<LineItem>();
|
||||
list.add(item);
|
||||
|
||||
when(argument2.getResult(null)).thenReturn(list);
|
||||
|
||||
//vefify result
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidateDiscountsFunctionTests {
|
||||
|
||||
private ValidateDiscountsFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidateDiscountsFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscountPercentageMin() throws Exception {
|
||||
|
||||
//create line item with correct discount percentage and zero discount amount
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(1.0));
|
||||
item.setDiscountAmount(new BigDecimal(0.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all discount percentages are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative percentage
|
||||
item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(-1.0));
|
||||
item.setDiscountAmount(new BigDecimal(0.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid discount percentage
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscountPercentageMax() throws Exception {
|
||||
|
||||
//create line item with correct discount percentage and zero discount amount
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(99.0));
|
||||
item.setDiscountAmount(new BigDecimal(0.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all discount percentages are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with discount percentage above 100
|
||||
item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(101.0));
|
||||
item.setDiscountAmount(new BigDecimal(0.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid discount percentage
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscountPriceMin() throws Exception {
|
||||
|
||||
//create line item with correct discount amount and zero discount percentage
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setDiscountAmount(new BigDecimal(10.0));
|
||||
item.setPrice(new BigDecimal(100.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all discount amounts are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative discount amount
|
||||
item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setDiscountAmount(new BigDecimal(-1.0));
|
||||
item.setPrice(new BigDecimal(100.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid discount amount
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscountPriceMax() throws Exception {
|
||||
|
||||
//create line item with correct discount amount and zero discount percentage
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setDiscountAmount(new BigDecimal(99.0));
|
||||
item.setPrice(new BigDecimal(100.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all discount amounts are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with discount amount above item price
|
||||
item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setDiscountAmount(new BigDecimal(101.0));
|
||||
item.setPrice(new BigDecimal(100.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid discount amount
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBothDiscountValuesNonZero() throws Exception {
|
||||
|
||||
//create line item with non-zero discount amount and non-zero discount percentage
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountPerc(new BigDecimal(10.0));
|
||||
item.setDiscountAmount(new BigDecimal(99.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be false - only one of the discount values is empty
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidateHandlingPricesFunctionTests {
|
||||
|
||||
private ValidateHandlingPricesFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidateHandlingPricesFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlingPriceMin() throws Exception {
|
||||
|
||||
//create line item with correct handling price
|
||||
LineItem item = new LineItem();
|
||||
item.setHandlingPrice(new BigDecimal(1.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all handling prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative handling price
|
||||
item = new LineItem();
|
||||
item.setHandlingPrice(new BigDecimal(-1.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid handling price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlingPriceMax() throws Exception {
|
||||
|
||||
//create line item with correct handling price
|
||||
LineItem item = new LineItem();
|
||||
item.setHandlingPrice(new BigDecimal(99999999.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all handling prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with handling price above allowed max
|
||||
item = new LineItem();
|
||||
item.setHandlingPrice(new BigDecimal(100000000.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid handling price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidateIdsFunctionTests {
|
||||
|
||||
private ValidateIdsFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidateIdsFunction(new Function[] {argument}, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdMin() throws Exception {
|
||||
|
||||
//create line item with correct item id
|
||||
LineItem item = new LineItem();
|
||||
item.setItemId(1);
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all ids are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative id
|
||||
item = new LineItem();
|
||||
item.setItemId(-1);
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid id
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdMax() throws Exception {
|
||||
|
||||
//create line item with correct item id
|
||||
LineItem item = new LineItem();
|
||||
item.setItemId(9999999999L);
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all item ids are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with item id above allowed max
|
||||
item = new LineItem();
|
||||
item.setItemId(10000000000L);
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid item id
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidatePricesFunctionTests {
|
||||
|
||||
private ValidatePricesFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidatePricesFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemPriceMin() throws Exception {
|
||||
|
||||
//create line item with correct item price
|
||||
LineItem item = new LineItem();
|
||||
item.setPrice(new BigDecimal(1.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all item prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative item price
|
||||
item = new LineItem();
|
||||
item.setPrice(new BigDecimal(-1.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid item price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemPriceMax() throws Exception {
|
||||
|
||||
//create line item with correct item price
|
||||
LineItem item = new LineItem();
|
||||
item.setPrice(new BigDecimal(99999999.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all item prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with item price above allowed max
|
||||
item = new LineItem();
|
||||
item.setPrice(new BigDecimal(100000000.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid item price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidateQuantitiesFunctionTests {
|
||||
|
||||
private ValidateQuantitiesFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidateQuantitiesFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuantityMin() throws Exception {
|
||||
|
||||
//create line item with correct item quantity
|
||||
LineItem item = new LineItem();
|
||||
item.setQuantity(1);
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all quantities are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative quantity
|
||||
item = new LineItem();
|
||||
item.setQuantity(-1);
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid quantity
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuantityMax() throws Exception {
|
||||
|
||||
//create line item with correct item quantity
|
||||
LineItem item = new LineItem();
|
||||
item.setQuantity(9999);
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all item quantities are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with item quantity above allowed max
|
||||
item = new LineItem();
|
||||
item.setQuantity(10000);
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid item quantity
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidateShippingPricesFunctionTests {
|
||||
|
||||
private ValidateShippingPricesFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidateShippingPricesFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShippingPriceMin() throws Exception {
|
||||
|
||||
//create line item with correct shipping price
|
||||
LineItem item = new LineItem();
|
||||
item.setShippingPrice(new BigDecimal(1.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all shipping prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative shipping price
|
||||
item = new LineItem();
|
||||
item.setShippingPrice(new BigDecimal(-1.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid shipping price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShippingPriceMax() throws Exception {
|
||||
|
||||
//create line item with correct shipping price
|
||||
LineItem item = new LineItem();
|
||||
item.setShippingPrice(new BigDecimal(99999999.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all shipping prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with shipping price above allowed max
|
||||
item = new LineItem();
|
||||
item.setShippingPrice(new BigDecimal(100000000.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid shipping price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.valang;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springmodules.validation.valang.functions.Function;
|
||||
|
||||
public class ValidateTotalPricesFunctionTests {
|
||||
|
||||
private ValidateTotalPricesFunction function;
|
||||
private Function argument;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
argument = mock(Function.class);
|
||||
|
||||
//create function
|
||||
function = new ValidateTotalPricesFunction(new Function[] {argument}, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTotalPriceMin() throws Exception {
|
||||
|
||||
//create line item with correct total price
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountAmount(new BigDecimal(0.0));
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setHandlingPrice(new BigDecimal(0.0));
|
||||
item.setShippingPrice(new BigDecimal(0.0));
|
||||
item.setPrice(new BigDecimal(1.0));
|
||||
item.setQuantity(1);
|
||||
item.setTotalPrice(new BigDecimal(1.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all total prices are correct
|
||||
assertTrue((Boolean) function.doGetResult(null));
|
||||
|
||||
//now add line item with negative item price
|
||||
item = new LineItem();
|
||||
item.setTotalPrice(new BigDecimal(-1.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid total price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTotalPriceMax() throws Exception {
|
||||
|
||||
//create line item with correct total price
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountAmount(new BigDecimal(0.0));
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setHandlingPrice(new BigDecimal(0.0));
|
||||
item.setShippingPrice(new BigDecimal(0.0));
|
||||
item.setPrice(new BigDecimal(99999999.0));
|
||||
item.setQuantity(1);
|
||||
item.setTotalPrice(new BigDecimal(99999999.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all total prices are correct
|
||||
assertEquals(true, function.doGetResult(null));
|
||||
|
||||
//now add line item with total price above allowed max
|
||||
item = new LineItem();
|
||||
item.setTotalPrice(new BigDecimal(100000000.0));
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has invalid total price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTotalPriceCalculation() throws Exception {
|
||||
|
||||
//create line item
|
||||
LineItem item = new LineItem();
|
||||
item.setDiscountAmount(new BigDecimal(5.0));
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setHandlingPrice(new BigDecimal(1.0));
|
||||
item.setShippingPrice(new BigDecimal(2.0));
|
||||
item.setPrice(new BigDecimal(250.0));
|
||||
item.setQuantity(1);
|
||||
item.setTotalPrice(new BigDecimal(248.0));
|
||||
|
||||
//add it to line items list
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(item);
|
||||
|
||||
//set return value for mock argument
|
||||
when(argument.getResult(null)).thenReturn(items);
|
||||
|
||||
//verify result - should be true - all total prices are correct
|
||||
assertEquals(true, function.doGetResult(null));
|
||||
|
||||
//now add line item with incorrect total price
|
||||
item = new LineItem();
|
||||
item.setDiscountAmount(new BigDecimal(5.0));
|
||||
item.setDiscountPerc(new BigDecimal(0.0));
|
||||
item.setHandlingPrice(new BigDecimal(1.0));
|
||||
item.setShippingPrice(new BigDecimal(2.0));
|
||||
item.setPrice(new BigDecimal(250.0));
|
||||
item.setQuantity(1);
|
||||
item.setTotalPrice(new BigDecimal(253.0));
|
||||
|
||||
items.add(item);
|
||||
|
||||
//verify result - should be false - second item has incorrect total price
|
||||
assertFalse((Boolean) function.doGetResult(null));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
package org.springframework.batch.sample.domain.order.internal.validator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.sample.domain.order.Address;
|
||||
import org.springframework.batch.sample.domain.order.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.order.Customer;
|
||||
import org.springframework.batch.sample.domain.order.LineItem;
|
||||
import org.springframework.batch.sample.domain.order.Order;
|
||||
import org.springframework.batch.sample.domain.order.ShippingInfo;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
|
||||
public class OrderValidatorTests {
|
||||
|
||||
private OrderValidator orderValidator;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
orderValidator = new OrderValidator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupports() {
|
||||
assertTrue(orderValidator.supports(Order.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotAnOrder() {
|
||||
String notAnOrder = "order";
|
||||
Errors errors = new BeanPropertyBindingResult(notAnOrder, "validOrder");
|
||||
|
||||
orderValidator.validate(notAnOrder, errors);
|
||||
|
||||
assertEquals(1, errors.getAllErrors().size());
|
||||
assertEquals("Incorrect type", errors.getAllErrors().get(0).getCode());
|
||||
|
||||
errors = new BeanPropertyBindingResult(notAnOrder, "validOrder");
|
||||
|
||||
orderValidator.validate(null, errors);
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidOrder() {
|
||||
Order order = new Order();
|
||||
order.setOrderId(-5);
|
||||
order.setOrderDate(new Date(new Date().getTime() + 1000000000l));
|
||||
order.setTotalLines(10);
|
||||
order.setLineItems(new ArrayList<LineItem>());
|
||||
|
||||
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
|
||||
orderValidator.validateOrder(order, errors);
|
||||
|
||||
assertEquals(3, errors.getAllErrors().size());
|
||||
assertEquals("error.order.id", errors.getFieldError("orderId").getCode());
|
||||
assertEquals("error.order.date.future", errors.getFieldError("orderDate").getCode());
|
||||
assertEquals("error.order.lines.badcount", errors.getFieldError("totalLines").getCode());
|
||||
|
||||
order = new Order();
|
||||
order.setOrderId(Long.MAX_VALUE);
|
||||
order.setOrderDate(new Date(new Date().getTime() - 1000));
|
||||
order.setTotalLines(0);
|
||||
List<LineItem> items = new ArrayList<LineItem>();
|
||||
items.add(new LineItem());
|
||||
order.setLineItems(items);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
|
||||
orderValidator.validateOrder(order, errors);
|
||||
|
||||
assertEquals(2, errors.getAllErrors().size());
|
||||
assertEquals("error.order.id", errors.getFieldError("orderId").getCode());
|
||||
assertEquals("error.order.lines.badcount", errors.getFieldError("totalLines").getCode());
|
||||
|
||||
order = new Order();
|
||||
order.setOrderId(5l);
|
||||
order.setOrderDate(new Date(new Date().getTime() - 1000));
|
||||
order.setTotalLines(1);
|
||||
items = new ArrayList<LineItem>();
|
||||
items.add(new LineItem());
|
||||
order.setLineItems(items);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
|
||||
orderValidator.validateOrder(order, errors);
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidCustomer() {
|
||||
Order order = new Order();
|
||||
Customer customer = new Customer();
|
||||
customer.setRegistered(false);
|
||||
customer.setBusinessCustomer(true);
|
||||
order.setCustomer(customer);
|
||||
|
||||
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateCustomer(customer, errors);
|
||||
|
||||
assertEquals(2, errors.getAllErrors().size());
|
||||
assertEquals("error.customer.registration", errors.getFieldError("customer.registered").getCode());
|
||||
assertEquals("error.customer.companyname", errors.getFieldError("customer.companyName").getCode());
|
||||
|
||||
customer = new Customer();
|
||||
customer.setRegistered(true);
|
||||
customer.setBusinessCustomer(false);
|
||||
customer.setRegistrationId(Long.MIN_VALUE);
|
||||
order.setCustomer(customer);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateCustomer(customer, errors);
|
||||
|
||||
assertEquals(3, errors.getAllErrors().size());
|
||||
assertEquals("error.customer.firstname", errors.getFieldError("customer.firstName").getCode());
|
||||
assertEquals("error.customer.lastname", errors.getFieldError("customer.lastName").getCode());
|
||||
assertEquals("error.customer.registrationid", errors.getFieldError("customer.registrationId").getCode());
|
||||
|
||||
customer = new Customer();
|
||||
customer.setRegistered(true);
|
||||
customer.setBusinessCustomer(false);
|
||||
customer.setRegistrationId(Long.MAX_VALUE);
|
||||
order.setCustomer(customer);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateCustomer(customer, errors);
|
||||
|
||||
assertEquals(3, errors.getAllErrors().size());
|
||||
assertEquals("error.customer.firstname", errors.getFieldError("customer.firstName").getCode());
|
||||
assertEquals("error.customer.lastname", errors.getFieldError("customer.lastName").getCode());
|
||||
assertEquals("error.customer.registrationid", errors.getFieldError("customer.registrationId").getCode());
|
||||
|
||||
customer = new Customer();
|
||||
customer.setRegistered(true);
|
||||
customer.setBusinessCustomer(true);
|
||||
customer.setCompanyName("Acme Inc");
|
||||
customer.setRegistrationId(5l);
|
||||
order.setCustomer(customer);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateCustomer(customer, errors);
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
|
||||
customer = new Customer();
|
||||
customer.setRegistered(true);
|
||||
customer.setBusinessCustomer(false);
|
||||
customer.setFirstName("John");
|
||||
customer.setLastName("Doe");
|
||||
customer.setRegistrationId(5l);
|
||||
order.setCustomer(customer);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateCustomer(customer, errors);
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidAddress() {
|
||||
Order order = new Order();
|
||||
|
||||
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateAddress(null, errors, "billingAddress");
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
|
||||
Address address = new Address();
|
||||
order.setBillingAddress(address);
|
||||
|
||||
orderValidator.validateAddress(address, errors, "billingAddress");
|
||||
|
||||
assertEquals(4, errors.getAllErrors().size());
|
||||
assertEquals("error.baddress.addrline1.length", errors.getFieldError("billingAddress.addrLine1").getCode());
|
||||
assertEquals("error.baddress.city.length", errors.getFieldError("billingAddress.city").getCode());
|
||||
assertEquals("error.baddress.zipcode.length", errors.getFieldError("billingAddress.zipCode").getCode());
|
||||
assertEquals("error.baddress.country.length", errors.getFieldError("billingAddress.country").getCode());
|
||||
|
||||
address = new Address();
|
||||
address.setAddressee("1234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
address.setAddrLine1("123456789012345678901234567890123456789012345678901234567890");
|
||||
address.setAddrLine2("123456789012345678901234567890123456789012345678901234567890");
|
||||
address.setCity("1234567890123456789012345678901234567890");
|
||||
address.setZipCode("1234567890");
|
||||
address.setState("1234567890");
|
||||
address.setCountry("123456789012345678901234567890123456789012345678901234567890");
|
||||
order.setBillingAddress(address);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateAddress(address, errors, "billingAddress");
|
||||
|
||||
assertEquals(8, errors.getAllErrors().size());
|
||||
assertEquals("error.baddress.addresse.length", errors.getFieldError("billingAddress.addressee").getCode());
|
||||
assertEquals("error.baddress.addrline1.length", errors.getFieldError("billingAddress.addrLine1").getCode());
|
||||
assertEquals("error.baddress.addrline2.length", errors.getFieldError("billingAddress.addrLine2").getCode());
|
||||
assertEquals("error.baddress.city.length", errors.getFieldError("billingAddress.city").getCode());
|
||||
assertEquals("error.baddress.state.length", errors.getFieldError("billingAddress.state").getCode());
|
||||
assertEquals("error.baddress.zipcode.length", errors.getFieldErrors("billingAddress.zipCode").get(0).getCode());
|
||||
assertEquals("error.baddress.zipcode.format", errors.getFieldErrors("billingAddress.zipCode").get(1).getCode());
|
||||
assertEquals("error.baddress.country.length", errors.getFieldError("billingAddress.country").getCode());
|
||||
|
||||
address = new Address();
|
||||
address.setAddressee("John Doe");
|
||||
address.setAddrLine1("123 4th Street");
|
||||
address.setCity("Chicago");
|
||||
address.setState("IL");
|
||||
address.setZipCode("60606");
|
||||
address.setCountry("United States");
|
||||
order.setBillingAddress(address);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateAddress(address, errors, "billingAddress");
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidPayment() {
|
||||
Order order = new Order();
|
||||
BillingInfo info = new BillingInfo();
|
||||
info.setPaymentId("INVALID");
|
||||
info.setPaymentDesc("INVALID");
|
||||
order.setBilling(info);
|
||||
|
||||
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validatePayment(info, errors);
|
||||
|
||||
assertEquals(2, errors.getAllErrors().size());
|
||||
assertEquals("error.billing.type", errors.getFieldError("billing.paymentId").getCode());
|
||||
assertEquals("error.billing.desc", errors.getFieldError("billing.paymentDesc").getCode());
|
||||
|
||||
info = new BillingInfo();
|
||||
info.setPaymentId("VISA");
|
||||
info.setPaymentDesc("ADFI-1234567890");
|
||||
order.setBilling(info);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validatePayment(info, errors);
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidShipping() {
|
||||
Order order = new Order();
|
||||
ShippingInfo info = new ShippingInfo();
|
||||
info.setShipperId("INVALID");
|
||||
info.setShippingTypeId("INVALID");
|
||||
order.setShipping(info);
|
||||
|
||||
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateShipping(info, errors);
|
||||
|
||||
assertEquals(2, errors.getAllErrors().size());
|
||||
assertEquals("error.shipping.shipper", errors.getFieldError("shipping.shipperId").getCode());
|
||||
assertEquals("error.shipping.type", errors.getFieldError("shipping.shippingTypeId").getCode());
|
||||
|
||||
info = new ShippingInfo();
|
||||
info.setShipperId("FEDX");
|
||||
info.setShippingTypeId("EXP");
|
||||
info.setShippingInfo("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
order.setShipping(info);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateShipping(info, errors);
|
||||
|
||||
assertEquals(1, errors.getAllErrors().size());
|
||||
assertEquals("error.shipping.shippinginfo.length", errors.getFieldError("shipping.shippingInfo").getCode());
|
||||
|
||||
info = new ShippingInfo();
|
||||
info.setShipperId("FEDX");
|
||||
info.setShippingTypeId("EXP");
|
||||
info.setShippingInfo("Info");
|
||||
order.setShipping(info);
|
||||
|
||||
errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateShipping(info, errors);
|
||||
|
||||
assertEquals(0, errors.getAllErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidLineItems() {
|
||||
Order order = new Order();
|
||||
List<LineItem> lineItems = new ArrayList<LineItem>();
|
||||
lineItems.add(buildLineItem(-5, 5.00, 0, 0, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(Long.MAX_VALUE, 5.00, 0, 0, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, -5.00, 0, 0, 2, 3, 3, 0));
|
||||
lineItems.add(buildLineItem(6, Integer.MAX_VALUE, 0, 0, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 900, 0, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, -90, 0, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 10, 20, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, -10, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 50, 2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, -2, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, Long.MAX_VALUE, 3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, -3, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, Long.MAX_VALUE, 3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, -3, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, Integer.MAX_VALUE, 30));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, 3, -5));
|
||||
lineItems.add(buildLineItem(6, 5.00, 0, 0, 2, 3, 3, Integer.MAX_VALUE));
|
||||
order.setLineItems(lineItems);
|
||||
|
||||
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
|
||||
orderValidator.validateLineItems(lineItems, errors);
|
||||
|
||||
assertEquals(7, errors.getAllErrors().size());
|
||||
assertEquals("error.lineitems.id", errors.getFieldErrors("lineItems").get(0).getCode());
|
||||
assertEquals("error.lineitems.price", errors.getFieldErrors("lineItems").get(1).getCode());
|
||||
assertEquals("error.lineitems.discount", errors.getFieldErrors("lineItems").get(2).getCode());
|
||||
assertEquals("error.lineitems.shipping", errors.getFieldErrors("lineItems").get(3).getCode());
|
||||
assertEquals("error.lineitems.handling", errors.getFieldErrors("lineItems").get(4).getCode());
|
||||
assertEquals("error.lineitems.quantity", errors.getFieldErrors("lineItems").get(5).getCode());
|
||||
assertEquals("error.lineitems.totalprice", errors.getFieldErrors("lineItems").get(6).getCode());
|
||||
}
|
||||
|
||||
private LineItem buildLineItem(long itemId, double price, int discountPercentage, int discountAmount, long shippingPrice, long handlingPrice, int qty, int totalPrice) {
|
||||
LineItem invalidId = new LineItem();
|
||||
invalidId.setItemId(itemId);
|
||||
invalidId.setPrice(new BigDecimal(price));
|
||||
invalidId.setDiscountPerc(new BigDecimal(discountPercentage));
|
||||
invalidId.setDiscountAmount(new BigDecimal(discountAmount));
|
||||
invalidId.setShippingPrice(new BigDecimal(shippingPrice));
|
||||
invalidId.setHandlingPrice(new BigDecimal(handlingPrice));
|
||||
invalidId.setQuantity(qty);
|
||||
invalidId.setTotalPrice(new BigDecimal(totalPrice));
|
||||
return invalidId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user