Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.inv.bo.test.adjustmentstock;
- import java.io.PrintWriter;
- import java.io.StringWriter;
- import java.util.ArrayList;
- import java.util.List;
- import junit.framework.Assert;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.Dto;
- import org.jleaf.core.test.AbstractSpringDbUnitTest;
- import org.jleaf.erp.inv.dao.InventoryItemDao;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.transaction.TransactionConfiguration;
- import org.springframework.transaction.annotation.Transactional;
- import com.carbonfive.testutils.spring.dbunit.DataSet;
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(
- locations = { "classpath:applicationContext.xml" })
- @TransactionConfiguration(
- transactionManager = "transactionManager", defaultRollback = true)
- @Transactional
- public class TestAddAdjustmentStockAmountItemList extends AbstractSpringDbUnitTest{
- private static final Logger log = LoggerFactory.getLogger(TestAddAdjustmentStockAmountItemList.class);
- @Autowired
- @Qualifier("addAdjustmentStockAmountItemList")
- BusinessTransaction addAdjustmentStockAmountItemList;
- @Autowired
- @Qualifier("getInventoryItemListByInventory")
- BusinessFunction getInventoryItemListByInventory;
- @Autowired
- @Qualifier("findInventoryById")
- BusinessFunction findInventoryById;
- @Autowired
- @Qualifier("findInventoryItemById")
- BusinessFunction findInventoryItemById;
- @Autowired
- JdbcTemplate jdbcTemplate;
- @Autowired
- InventoryItemDao inventoryItemDao;
- @SuppressWarnings("unchecked")
- @Test
- @DataSet("AddAdjustmentStockAmountItemListPolicyActivityGl.xml"
- + ";AddAdjustmentStockAmountItemListInventory.xml"
- + ";AddAdjustmentStockAmountItemListInventoryItem.xml")
- public void testSuccess(){
- // @Info(name = "adjustmentId", description = "Adjustment stock id", type = Long.class),
- // @Info(name = "adjustmentVersion", description = "Adjustment stock version", type = Long.class),
- // @Info(name = "adjustmentItemList", description = "Adjustment stock item list (productBalanceId, productCode, productName, serialNumber, productYearMade, expiredDate, adjustQty, baseUomName, currCode, adjustAmount, productStatus)", type = List.class),
- //
- // @Info(name = "tenantLoginId", description = "Tenant login id", type = Long.class),
- // @Info(name = "userLoginId", description = "User login id", type = Long.class),
- // @Info(name = "roleLoginId", description = "Role login id", type = Long.class),
- // @Info(name = "datetime", description = "Datetime", type = Long.class)
- List<Dto> adjustmentItemList = new ArrayList<Dto>();
- adjustmentItemList.add(new Dto()
- .put("productBalanceId", "856")
- .put("productId", "856")
- .put("productCode", "01300010")
- .put("productName", "BB INK EPSON UV DYE 100ML CYAN")
- .put("serialNumber", "999999")
- .put("productYearMade", "2013")
- .put("expiredDate", "20140730")
- .put("adjustQty", "10")
- .put("currCode", "IDR")
- .put("adjustAmount", "10000")
- .put("productStatus", "BAD")
- );
- adjustmentItemList.add(new Dto()
- .put("productBalanceId", "857")
- .put("productId", "857")
- .put("productCode", "01300010")
- .put("productName", "BB INK EPSON UV DYE 100ML L CY")
- .put("serialNumber", "999999")
- .put("productYearMade", "2013")
- .put("expiredDate", "20140730")
- .put("adjustQty", "10")
- .put("currCode", "IDR")
- .put("adjustAmount", "10000")
- .put("productStatus", "GOOD")
- );
- Dto inputDtoForAddAdjustmentStockAmountItemList = new Dto();
- inputDtoForAddAdjustmentStockAmountItemList.put("adjustmentId", 1L);
- inputDtoForAddAdjustmentStockAmountItemList.put("adjustmentVersion", 0L);
- inputDtoForAddAdjustmentStockAmountItemList.put("adjustmentItemList", adjustmentItemList);
- inputDtoForAddAdjustmentStockAmountItemList.put("tenantLoginId", 10L);
- inputDtoForAddAdjustmentStockAmountItemList.put("userLoginId", 10L);
- inputDtoForAddAdjustmentStockAmountItemList.put("roleLoginId", 10L);
- inputDtoForAddAdjustmentStockAmountItemList.put("datetime", "20140720");
- try {
- inventoryItemDao.flush();
- Dto adjustmentStockDto = findInventoryById.execute(new Dto().put("id", inputDtoForAddAdjustmentStockAmountItemList.get("adjustmentId")));
- log.debug("adjustmentStockDto : "+adjustmentStockDto);
- Dto adjustmentStockItemDto = findInventoryItemById.execute(new Dto().put("id", 1l));
- log.debug("adjustmentStockItemDto : "+adjustmentStockItemDto);
- //get start item
- Dto inputDtoForGetInventoryItemListByInventory = new Dto();
- inputDtoForGetInventoryItemListByInventory.put("tenantId", 10L);
- inputDtoForGetInventoryItemListByInventory.put("inventoryId", 1L);
- // Long tenantId = 10L;
- // Long inventoryId = 1L;
- //
- // QueryBuilder builder = new QueryBuilder();
- // builder.add(" SELECT * /*a.inventory_item_id, a.line_no, a.product_id, b.product_code, b.product_name, a.product_balance_id, a.product_status, a.serial_number, a.product_expired_date, a.product_year_made, a.lot_number, a.base_uom_id, c.uom_code, c.uom_name, a.qty_request, a.qty_realization, a.remark, a.version, a.ref_item_id,a.curr_code,a.amount*/ "
- // + " FROM ")
- // .add(InventoryItem.TABLE_NAME)
- // .add(" a INNER JOIN ")
- // .add(Product.TABLE_NAME)
- // .add(" b ON b.tenant_id = a.tenant_id AND b.product_id = a.product_id ")
- // .add(" INNER JOIN ")
- // .add(Uom.TABLE_NAME)
- // .add(" c ON c.tenant_id = a.tenant_id AND c.uom_id = a.base_uom_id ")
- // .add(" WHERE a.inventory_id = :inventoryId AND a.tenant_id = :tenantId ORDER BY a.line_no")
- ;
- // Query query = inventoryItemDao.createNativeQuery(builder.toString());
- // query.setParameter("inventoryId", inventoryId);
- // query.setParameter("tenantId", tenantId);
- // List<Object[]> result = query.getResultList();
- // for (Object[] objects : result) {
- // log.debug(Arrays.toString(objects));
- // }
- // Dto outputDto = new Dto().putList("inventoryItemList", DtoUtil.createDtoListFromArray(result,
- // "id", "lineNo", "productId", "productCode", "productName", "productBalanceId", "productStatus", "serialNumber", "productExpiredDate", "productYearMade", "lotNumber", "baseUomId", "baseUomCode", "baseUomName", "qtyRequest", "qtyRealization", "remark", "version", "refItemId","currCode","adjustAmount"));
- // log.debug("outputDto : "+outputDto);
- Dto outputDtoForGetInventoryItemListByInventory = getInventoryItemListByInventory.execute(inputDtoForGetInventoryItemListByInventory);
- log.debug("Output GetInventoryItemListByInventory : "+outputDtoForGetInventoryItemListByInventory);
- List<Dto> inventoryItemList = outputDtoForGetInventoryItemListByInventory.getList("inventoryItemList");
- Assert.assertEquals(1, inventoryItemList.size());
- Dto inventoryItemDto = inventoryItemList.get(0);
- Assert.assertEquals(adjustmentItemList.get(0).get("productStatus"), inventoryItemDto.get("productStatus"));
- Dto outputDtoForAddAdjustmentStockAmount = addAdjustmentStockAmountItemList.execute(inputDtoForAddAdjustmentStockAmountItemList);
- log.debug("Output AddAdjustmentStockAmount : "+outputDtoForAddAdjustmentStockAmount);
- inventoryItemDao.flush();
- outputDtoForGetInventoryItemListByInventory = getInventoryItemListByInventory.execute(inputDtoForGetInventoryItemListByInventory);
- log.debug("Output GetInventoryItemListByInventory after edit : "+outputDtoForGetInventoryItemListByInventory);
- inventoryItemList = outputDtoForGetInventoryItemListByInventory.getList("inventoryItemList");
- Assert.assertEquals(3, inventoryItemList.size());
- } catch (CoreException ce) {
- log.error("",ce);
- Assert.fail(ce+"");
- } catch (Exception e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- log.error("",e);
- Assert.fail(sw.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement