Advertisement
aadddrr

Untitled

Aug 7th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.37 KB | None | 0 0
  1. package org.jleaf.erp.inv.bo.test.adjustmentstock;
  2.  
  3. import java.io.PrintWriter;
  4. import java.io.StringWriter;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. import junit.framework.Assert;
  9.  
  10. import org.jleaf.core.BusinessFunction;
  11. import org.jleaf.core.BusinessTransaction;
  12. import org.jleaf.core.CoreException;
  13. import org.jleaf.core.Dto;
  14. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  15. import org.jleaf.erp.inv.dao.InventoryItemDao;
  16. import org.junit.Test;
  17. import org.junit.runner.RunWith;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Qualifier;
  22. import org.springframework.jdbc.core.JdbcTemplate;
  23. import org.springframework.test.context.ContextConfiguration;
  24. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  25. import org.springframework.test.context.transaction.TransactionConfiguration;
  26. import org.springframework.transaction.annotation.Transactional;
  27.  
  28. import com.carbonfive.testutils.spring.dbunit.DataSet;
  29.  
  30. @RunWith(SpringJUnit4ClassRunner.class)
  31. @ContextConfiguration(
  32.         locations = { "classpath:applicationContext.xml" })
  33. @TransactionConfiguration(
  34.         transactionManager = "transactionManager", defaultRollback = true)
  35. @Transactional
  36. public class TestAddAdjustmentStockAmountItemList extends AbstractSpringDbUnitTest{
  37.     private static final Logger log = LoggerFactory.getLogger(TestAddAdjustmentStockAmountItemList.class);
  38.    
  39.     @Autowired
  40.     @Qualifier("addAdjustmentStockAmountItemList")
  41.     BusinessTransaction addAdjustmentStockAmountItemList;
  42.    
  43.     @Autowired
  44.     @Qualifier("getInventoryItemListByInventory")
  45.     BusinessFunction getInventoryItemListByInventory;
  46.  
  47.     @Autowired
  48.     @Qualifier("findInventoryById")
  49.     BusinessFunction findInventoryById;
  50.    
  51.     @Autowired
  52.     @Qualifier("findInventoryItemById")
  53.     BusinessFunction findInventoryItemById;
  54.    
  55.     @Autowired
  56.     JdbcTemplate jdbcTemplate;
  57.    
  58.     @Autowired
  59.     InventoryItemDao inventoryItemDao;
  60.    
  61.     @SuppressWarnings("unchecked")
  62.     @Test
  63.     @DataSet("AddAdjustmentStockAmountItemListPolicyActivityGl.xml"
  64.             + ";AddAdjustmentStockAmountItemListInventory.xml"
  65.             + ";AddAdjustmentStockAmountItemListInventoryItem.xml")
  66.     public void testSuccess(){
  67. //      @Info(name = "adjustmentId", description = "Adjustment stock id", type = Long.class),      
  68. //      @Info(name = "adjustmentVersion", description = "Adjustment stock version", type = Long.class),
  69. //      @Info(name = "adjustmentItemList", description = "Adjustment stock item list (productBalanceId, productCode, productName, serialNumber, productYearMade, expiredDate, adjustQty, baseUomName, currCode, adjustAmount, productStatus)", type = List.class),
  70. //     
  71. //      @Info(name = "tenantLoginId", description = "Tenant login id", type = Long.class),
  72. //      @Info(name = "userLoginId", description = "User login id", type = Long.class),
  73. //      @Info(name = "roleLoginId", description = "Role login id", type = Long.class),
  74. //      @Info(name = "datetime", description = "Datetime", type = Long.class)
  75.        
  76.         List<Dto> adjustmentItemList = new ArrayList<Dto>();
  77.         adjustmentItemList.add(new Dto()
  78.                 .put("productBalanceId", "856")
  79.                 .put("productId", "856")
  80.                 .put("productCode", "01300010")
  81.                 .put("productName", "BB INK EPSON UV DYE 100ML CYAN")
  82.                 .put("serialNumber", "999999")
  83.                 .put("productYearMade", "2013")
  84.                 .put("expiredDate", "20140730")
  85.                 .put("adjustQty", "10")
  86.                 .put("currCode", "IDR")
  87.                 .put("adjustAmount", "10000")
  88.                 .put("productStatus", "BAD")
  89.                 );
  90.         adjustmentItemList.add(new Dto()
  91.                     .put("productBalanceId", "857")
  92.                     .put("productId", "857")
  93.                     .put("productCode", "01300010")
  94.                     .put("productName", "BB INK EPSON UV DYE 100ML L CY")
  95.                     .put("serialNumber", "999999")
  96.                     .put("productYearMade", "2013")
  97.                     .put("expiredDate", "20140730")
  98.                     .put("adjustQty", "10")
  99.                     .put("currCode", "IDR")
  100.                     .put("adjustAmount", "10000")
  101.                     .put("productStatus", "GOOD")
  102.                     );
  103.        
  104.         Dto inputDtoForAddAdjustmentStockAmountItemList = new Dto();
  105.         inputDtoForAddAdjustmentStockAmountItemList.put("adjustmentId", 1L);
  106.         inputDtoForAddAdjustmentStockAmountItemList.put("adjustmentVersion", 0L);
  107.         inputDtoForAddAdjustmentStockAmountItemList.put("adjustmentItemList", adjustmentItemList);
  108.        
  109.         inputDtoForAddAdjustmentStockAmountItemList.put("tenantLoginId", 10L);
  110.         inputDtoForAddAdjustmentStockAmountItemList.put("userLoginId", 10L);
  111.         inputDtoForAddAdjustmentStockAmountItemList.put("roleLoginId", 10L);
  112.         inputDtoForAddAdjustmentStockAmountItemList.put("datetime", "20140720");
  113.        
  114.         try {
  115.             inventoryItemDao.flush();
  116.            
  117.             Dto adjustmentStockDto = findInventoryById.execute(new Dto().put("id", inputDtoForAddAdjustmentStockAmountItemList.get("adjustmentId")));
  118.             log.debug("adjustmentStockDto : "+adjustmentStockDto);
  119.            
  120.             Dto adjustmentStockItemDto =  findInventoryItemById.execute(new Dto().put("id", 1l));
  121.             log.debug("adjustmentStockItemDto : "+adjustmentStockItemDto);
  122.            
  123.             //get start item
  124.             Dto inputDtoForGetInventoryItemListByInventory = new Dto();
  125.             inputDtoForGetInventoryItemListByInventory.put("tenantId", 10L);
  126.             inputDtoForGetInventoryItemListByInventory.put("inventoryId", 1L);
  127.            
  128. //          Long tenantId = 10L;
  129. //          Long inventoryId = 1L;
  130. //         
  131. //          QueryBuilder builder = new QueryBuilder();
  132. //          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*/ "
  133. //                  + " FROM ")
  134. //                 .add(InventoryItem.TABLE_NAME)
  135. //                 .add(" a INNER JOIN ")
  136. //                 .add(Product.TABLE_NAME)
  137. //                 .add(" b ON b.tenant_id = a.tenant_id AND b.product_id = a.product_id ")
  138. //                 .add(" INNER JOIN ")
  139. //                 .add(Uom.TABLE_NAME)
  140. //                 .add(" c ON c.tenant_id = a.tenant_id AND c.uom_id = a.base_uom_id ")
  141. //                 .add(" WHERE a.inventory_id = :inventoryId AND a.tenant_id = :tenantId ORDER BY a.line_no")
  142.                    ;
  143.            
  144. //          Query query = inventoryItemDao.createNativeQuery(builder.toString());
  145. //          query.setParameter("inventoryId", inventoryId);
  146. //          query.setParameter("tenantId", tenantId);
  147.            
  148. //          List<Object[]> result = query.getResultList();
  149. //          for (Object[] objects : result) {
  150. //              log.debug(Arrays.toString(objects));
  151. //          }
  152. //          Dto outputDto = new Dto().putList("inventoryItemList", DtoUtil.createDtoListFromArray(result,
  153. //                  "id", "lineNo", "productId", "productCode", "productName", "productBalanceId", "productStatus", "serialNumber", "productExpiredDate", "productYearMade", "lotNumber", "baseUomId", "baseUomCode", "baseUomName", "qtyRequest", "qtyRealization", "remark", "version", "refItemId","currCode","adjustAmount"));
  154. //          log.debug("outputDto : "+outputDto);
  155.            
  156.             Dto outputDtoForGetInventoryItemListByInventory = getInventoryItemListByInventory.execute(inputDtoForGetInventoryItemListByInventory);
  157.             log.debug("Output GetInventoryItemListByInventory : "+outputDtoForGetInventoryItemListByInventory);
  158.             List<Dto> inventoryItemList = outputDtoForGetInventoryItemListByInventory.getList("inventoryItemList");
  159.             Assert.assertEquals(1, inventoryItemList.size());
  160.                        
  161.             Dto inventoryItemDto = inventoryItemList.get(0);
  162.             Assert.assertEquals(adjustmentItemList.get(0).get("productStatus"), inventoryItemDto.get("productStatus"));
  163.            
  164.             Dto outputDtoForAddAdjustmentStockAmount = addAdjustmentStockAmountItemList.execute(inputDtoForAddAdjustmentStockAmountItemList);
  165.             log.debug("Output AddAdjustmentStockAmount : "+outputDtoForAddAdjustmentStockAmount);
  166.            
  167.             inventoryItemDao.flush();
  168.  
  169.             outputDtoForGetInventoryItemListByInventory = getInventoryItemListByInventory.execute(inputDtoForGetInventoryItemListByInventory);
  170.             log.debug("Output GetInventoryItemListByInventory after edit : "+outputDtoForGetInventoryItemListByInventory);
  171.             inventoryItemList = outputDtoForGetInventoryItemListByInventory.getList("inventoryItemList");
  172.             Assert.assertEquals(3, inventoryItemList.size());
  173.  
  174.            
  175.         } catch (CoreException ce) {
  176.             log.error("",ce);
  177.            
  178.             Assert.fail(ce+"");
  179.         } catch (Exception e) {
  180.             StringWriter sw = new StringWriter();
  181.             PrintWriter pw = new PrintWriter(sw);
  182.             e.printStackTrace(pw);
  183.             log.error("",e);
  184.            
  185.             Assert.fail(sw.toString());
  186.         }
  187.        
  188.     }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement