Fanadia_Friska

Test Add Henokh

Sep 19th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.test.delivery.tolerance;
  2.  
  3. import org.jleaf.core.BusinessFunction;
  4. import org.jleaf.core.BusinessTransaction;
  5. import org.jleaf.core.CoreException;
  6. import org.jleaf.core.Dto;
  7. import org.jleaf.core.GeneralConstants;
  8. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  9. import org.jleaf.erp.master.MasterExceptionConstantsForDlg;
  10. import org.jleaf.erp.master.bo.test.product.TestAddPurchasePriceProduct;
  11. import org.junit.Assert;
  12. import org.junit.Before;
  13. import org.junit.Test;
  14. import org.junit.runner.RunWith;
  15. import org.slf4j.Logger;
  16. import org.slf4j.LoggerFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.beans.factory.annotation.Qualifier;
  19. import org.springframework.test.context.ContextConfiguration;
  20. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  21. import org.springframework.test.context.transaction.TransactionConfiguration;
  22. import org.springframework.transaction.annotation.Transactional;
  23.  
  24. @RunWith(SpringJUnit4ClassRunner.class)
  25. @ContextConfiguration(locations = {"classpath:applicationContext.xml"})
  26. @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  27. @Transactional
  28. public class TestAddDeliveryTolerance extends AbstractSpringDbUnitTest {
  29. private static final Logger log = LoggerFactory
  30. .getLogger(TestAddDeliveryTolerance.class);
  31.  
  32. @Autowired
  33. @Qualifier("addDeliveryTolerance")
  34. private BusinessTransaction addDeliveryTolerance;
  35.  
  36. @Autowired
  37. @Qualifier("isDeliveryToleranceExistsByIndex")
  38. private BusinessFunction isDeliveryToleranceExistsByIndex;
  39.  
  40. @Autowired
  41. @Qualifier("findDeliveryToleranceById")
  42. private BusinessFunction findDeliveryToleranceById;
  43.  
  44. @Before
  45. public void prepareData(){
  46. super.deleteFromTables("m_delivery_tolerance", "m_city", "m_warehouse");
  47. super.executeSqlScript("scripts/TestAddDeliveryTolerance.sql", true);
  48. }
  49.  
  50. /**
  51. * Test Add Delivery Tolerance
  52. *
  53. * @author Henokh Marjie Rivaldy, September 13, 2016
  54. * @throws Exception
  55. *
  56. */
  57.  
  58. @Test
  59. public void testAddDeliveryTolerance() throws Exception{
  60. Dto input = new Dto();
  61. input.put("tenantLoginId",10L);
  62. input.put("roleLoginId",10L);
  63. input.put("userLoginId",999L);
  64. input.put("datetime","20160815000000");
  65. input.put("warehouseFromId",122L);
  66. input.put("cityToId",898L);
  67. input.put("tolerance",7L);
  68. input.put("active","Y");
  69.  
  70. Dto output = addDeliveryTolerance.execute(input);
  71. Long id = output.getLong("id");
  72.  
  73. Dto deliveryToleranceDto = findDeliveryToleranceById.execute(new Dto().put("id", id));
  74. log.debug("deliveryToleranceDto : "+deliveryToleranceDto);
  75.  
  76. Assert.assertEquals(10L, deliveryToleranceDto.getLong("tenantId").longValue());
  77. Assert.assertEquals(7L, deliveryToleranceDto.getLong("tolerance").longValue());
  78. Assert.assertEquals(122L, deliveryToleranceDto.getLong("warehouseFromId").longValue());
  79. Assert.assertEquals(898L, deliveryToleranceDto.getLong("cityToId").longValue());
  80.  
  81. }
  82.  
  83.  
  84. @Test
  85. public void testAddDeliveryToleranceTapiBukanDeliveryTolerance()
  86. throws Exception {
  87.  
  88. Dto input = new Dto();
  89.  
  90. input.put("tenantLoginId",10L);
  91. input.put("roleLoginId",10L);
  92. input.put("userLoginId",12L);
  93. input.put("datetime","20160809000000");
  94. input.put("warehouseFromId",2L);
  95. input.put("cityToId",5L);
  96. input.put("tolerance",2L);
  97. input.put("active","Y");
  98.  
  99. try {
  100. Dto output = addDeliveryTolerance.execute(input);
  101. Long id = output.getLong("id");
  102.  
  103. Dto deliveryToleranceDto = findDeliveryToleranceById.execute(new Dto().put("id", id));
  104. log.debug("deliveryToleranceDto : "+deliveryToleranceDto);
  105.  
  106. Assert.assertEquals(10L, deliveryToleranceDto.getLong("tenantId").longValue());
  107. Assert.assertEquals(2L, deliveryToleranceDto.getLong("tolerance").longValue());
  108. Assert.assertEquals(2L, deliveryToleranceDto.getLong("warehouseFromId").longValue());
  109. Assert.assertEquals(5L, deliveryToleranceDto.getLong("cityToId").longValue());
  110. Assert.fail("Validasi group partner gagal");
  111. } catch (CoreException e) {
  112. // untuk masuk ke core exception
  113. log.debug("Masuk core exception");
  114.  
  115. Assert.assertEquals(
  116. MasterExceptionConstantsForDlg.DELIVERY_TOLERANCE_ALREADY_EXISTS,
  117. e.getErrorKey());
  118.  
  119. } catch (Exception e) {
  120. log.error(e.getMessage(), e);
  121. }
  122.  
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment