Advertisement
aadddrr

Untitled

Oct 18th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.84 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.coa.test;
  2.  
  3. import org.jleaf.common.CommonExceptionConstants;
  4. import org.jleaf.core.BusinessTransaction;
  5. import org.jleaf.core.Dto;
  6. import org.jleaf.core.GeneralConstants;
  7. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  8. import org.junit.Test;
  9. import org.junit.Assert;
  10. import org.junit.Before;
  11. import org.junit.runner.RunWith;
  12. import org.jleaf.core.CoreException;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Qualifier;
  17. import org.springframework.test.context.ContextConfiguration;
  18. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  19. import org.springframework.test.context.transaction.TransactionConfiguration;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.jleaf.erp.master.MasterExceptionConstants;
  22. import org.jleaf.util.DateUtil;
  23.  
  24. /**
  25.  *
  26.  * @author Adrian
  27.  * Jul 4, 2017
  28.  */
  29.  
  30. @RunWith(SpringJUnit4ClassRunner.class)
  31. @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
  32. @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  33. @Transactional
  34. public class TestAddActivity extends AbstractSpringDbUnitTest {
  35.     private static final Logger log = LoggerFactory
  36.             .getLogger(TestAddActivity.class);
  37.     @Autowired
  38.     @Qualifier("addActivity")
  39.     private BusinessTransaction addActivity;
  40.    
  41.     @Before
  42.     public void prepare() {
  43.         deleteFromTables("t_combo_value");
  44.         deleteFromTables("m_coa");
  45.         deleteFromTables("m_activity_gl");
  46.         executeSqlScript("classpath:org/jleaf/erp/master/bo/TableBase.sql", false);
  47.         executeSqlScript("classpath:org/jleaf/erp/master/bo/coa/test/TestAddActivity.sql", false);
  48.     }
  49.    
  50.     /*@Test
  51.     public void testValidateNull() {
  52.  
  53.         Dto inputDto = new Dto();
  54.         inputDto.put("code", null);        
  55.         inputDto.put("name", null);        
  56.         inputDto.put("coaId", null);
  57.         inputDto.put("active", null);          
  58.         inputDto.put("tenantLoginId", null);           
  59.         inputDto.put("userLoginId", null);         
  60.         inputDto.put("roleLoginId", null);         
  61.         inputDto.put("datetime", null);    
  62.         log.debug("inputDto :{}", inputDto);
  63.         try {
  64.             addActivity.execute(inputDto);                             
  65.             Assert.fail("The addActivity should be null");
  66.         }catch(CoreException coreEx){
  67.             log.debug("exception :{}", coreEx.getErrorKey());                      
  68.         }catch(NullPointerException ex){
  69.             Assert.fail("addActivity");
  70.         }catch (Exception e) {         
  71.             Assert.fail("addSample");
  72.         }              
  73.     }
  74.    
  75.     @Test
  76.     public void testValidateDataType() {
  77.         //TODO : Handle Input testValidateDataType
  78.         Dto inputDto = new Dto();
  79.         inputDto.put("code", -99l);        
  80.         inputDto.put("name", -99l);        
  81.         inputDto.put("coaId", "coaId");
  82.         inputDto.put("active", -99l);          
  83.         inputDto.put("tenantLoginId", "tenantLoginId");        
  84.         inputDto.put("userLoginId", "userLoginId");        
  85.         inputDto.put("roleLoginId", "roleLoginId");        
  86.         inputDto.put("datetime", -99l);            
  87.         log.debug("inputDto :{}", inputDto);
  88.         try {
  89.             addActivity.execute(inputDto);                             
  90.             Assert.fail("The addActivity should be valid");
  91.         }catch(CoreException coreEx){
  92.             log.debug("exception :{}", coreEx.getErrorKey());                      
  93.         }catch(NumberFormatException ex){
  94.             Assert.fail("addActivity");
  95.         }catch (Exception e) {         
  96.             Assert.fail("addSample");
  97.         }  
  98.     }*/
  99.  
  100.     @Test
  101.     public void testSuccess() {
  102.         //TODO : Handle Input testSuccess
  103.         String code = "PRE_TAX_30";
  104.         String name = "Prepaid Tax Art 30";
  105.         Long coaId = 8l;
  106.        
  107.         String datetime = DateUtil.dateTimeNow();
  108.         Long tenantLoginId = 10l;
  109.         Long roleLoginId = 1l;
  110.         String active = GeneralConstants.YES;
  111.         Long userLoginId = 1l;
  112.        
  113.         Dto inputDto = new Dto();
  114.         inputDto.put("code", code);        
  115.         inputDto.put("name", name);        
  116.         inputDto.put("coaId", coaId);
  117.         inputDto.put("active", active);        
  118.         inputDto.put("tenantLoginId", tenantLoginId);          
  119.         inputDto.put("userLoginId", userLoginId);          
  120.         inputDto.put("roleLoginId", roleLoginId);          
  121.         inputDto.put("datetime", datetime);        
  122.                
  123.         try {
  124.            Dto outputDto = addActivity.execute(inputDto);
  125.            log.debug("result success : {}", outputDto);                                                                    
  126. //         // TODO Fill the expected result for assert
  127. //         Assert.assertEquals(4L, outputDto.get("id"));
  128.            Assert.assertEquals(tenantLoginId, outputDto.get("tenantId"));
  129.            Assert.assertEquals(code, outputDto.get("code"));
  130.            Assert.assertEquals(name, outputDto.get("name"));
  131.            Assert.assertEquals(coaId, outputDto.get("coaId"));
  132.            Assert.assertEquals(datetime, outputDto.get("activeDateTime"));
  133.            Assert.assertEquals(GeneralConstants.SPACE_VALUE, outputDto.get("nonActiveDateTime"));
  134.            Assert.assertEquals(datetime, outputDto.get("createDateTime"));
  135.            Assert.assertEquals(userLoginId, outputDto.get("createUserId"));
  136.            Assert.assertEquals(datetime, outputDto.get("updateDateTime"));
  137.            Assert.assertEquals(userLoginId, outputDto.get("updateUserId"));
  138.            Assert.assertEquals(0L, outputDto.get("version"));
  139.         }catch(Exception e){
  140.             log.error("Exception{}",e);                        
  141.         }
  142.        
  143.        
  144.     }
  145.    
  146.     @Test
  147.     public void testFailure() {
  148.         String code = "PRE_TAX_29";
  149.         String name = "Prepaid Tax Art 29";
  150.         Long coaId = 8l;
  151.        
  152.         String datetime = DateUtil.dateTimeNow();
  153.         Long tenantLoginId = 10l;
  154.         Long roleLoginId = 1l;
  155.         String active = GeneralConstants.YES;
  156.         Long userLoginId = 1l;
  157.        
  158.         Dto inputDto = new Dto();
  159.         inputDto.put("code", code);        
  160.         inputDto.put("name", name);        
  161.         inputDto.put("coaId", coaId);
  162.         inputDto.put("active", active);        
  163.         inputDto.put("tenantLoginId", tenantLoginId);          
  164.         inputDto.put("userLoginId", userLoginId);          
  165.         inputDto.put("roleLoginId", roleLoginId);          
  166.         inputDto.put("datetime", datetime);            
  167.         log.debug("inputDto : {}",inputDto);
  168.         try{           
  169.             Dto outputDto = addActivity.execute(inputDto);
  170.            
  171.             Assert.fail("This addActivity  should be error: "+outputDto);
  172.         } catch(CoreException e){                      
  173.             log.error("Exception{}",e);    
  174.         } catch (Exception e){
  175.             log.error("Exception{}",e);        
  176.             Assert.fail(e.toString());                     
  177.         }          
  178.     }
  179.    
  180.    
  181.    
  182.     @Test      
  183.     public void testForActivityAlreadyExists() {
  184.         String code = "PRE_TAX_29";
  185.         String name = "Prepaid Tax Art 29";
  186.         Long coaId = 8l;
  187.        
  188.         String datetime = DateUtil.dateTimeNow();
  189.         Long tenantLoginId = 10l;
  190.         Long roleLoginId = 1l;
  191.         String active = GeneralConstants.YES;
  192.         Long userLoginId = 1l;
  193.        
  194.         Dto inputDto = new Dto();
  195.         inputDto.put("code", code);        
  196.         inputDto.put("name", name);        
  197.         inputDto.put("coaId", coaId);
  198.         inputDto.put("active", active);        
  199.         inputDto.put("tenantLoginId", tenantLoginId);          
  200.         inputDto.put("userLoginId", userLoginId);          
  201.         inputDto.put("roleLoginId", roleLoginId);          
  202.         inputDto.put("datetime", datetime);        
  203.        
  204.         try{           
  205.             Dto outputDto = addActivity.execute(inputDto);         
  206.             Assert.fail("This addActivity  should be error: "+outputDto);
  207.         } catch(CoreException e){                      
  208.             log.error("Activity with code {0} is already exists", e);
  209.             Assert.assertEquals(1, e.getParamValues().length);
  210.             Assert.assertEquals(MasterExceptionConstants.ACTIVITY_ALREADY_EXISTS, e.getErrorKey());        
  211.         } catch (Exception e){
  212.             log.error("Exception{}",e);        
  213.             Assert.fail(e.toString());                     
  214.         }  
  215.     }
  216.    
  217.     @Test      
  218.     public void testForTenantLoginCantUsed() {
  219.         String code = "PRE_TAX_29";
  220.         String name = "Prepaid Tax Art 29";
  221.         Long coaId = 8l;
  222.        
  223.         String datetime = DateUtil.dateTimeNow();
  224.         Long tenantLoginId = -1l;
  225.         Long roleLoginId = 1l;
  226.         String active = GeneralConstants.YES;
  227.         Long userLoginId = -1l;
  228.        
  229.         Dto inputDto = new Dto();
  230.         inputDto.put("code", code);        
  231.         inputDto.put("name", name);        
  232.         inputDto.put("coaId", coaId);
  233.         inputDto.put("active", active);        
  234.         inputDto.put("tenantLoginId", tenantLoginId);          
  235.         inputDto.put("userLoginId", userLoginId);          
  236.         inputDto.put("roleLoginId", roleLoginId);          
  237.         inputDto.put("datetime", datetime);
  238.        
  239.         try{           
  240.             Dto outputDto = addActivity.execute(inputDto);         
  241.             Assert.fail("This addActivity  should be error: "+outputDto);
  242.         } catch(CoreException e){                      
  243.             log.error("User Login must choose other tenant, this tenant login cant be used", e);
  244.             //Assert.assertEquals(0, e.getParamValues().length);
  245.             Assert.assertEquals(CommonExceptionConstants.TENANT_LOGIN_CANT_USED, e.getErrorKey());         
  246.         } catch (Exception e){
  247.             log.error("Exception{}",e);        
  248.             Assert.fail(e.toString());                     
  249.         }  
  250.     }  
  251.    
  252.     @Test      
  253.     public void testForDataCantUseDiffTenant() {
  254.         String code = "PRE_TAX_29";
  255.         String name = "Prepaid Tax Art 29";
  256.         Long coaId = 7l;
  257.        
  258.         String datetime = DateUtil.dateTimeNow();
  259.         Long tenantLoginId = 10l;
  260.         Long roleLoginId = 1l;
  261.         String active = GeneralConstants.YES;
  262.         Long userLoginId = 1l;
  263.        
  264.         Dto inputDto = new Dto();
  265.         inputDto.put("code", code);        
  266.         inputDto.put("name", name);        
  267.         inputDto.put("coaId", coaId);
  268.         inputDto.put("active", active);        
  269.         inputDto.put("tenantLoginId", tenantLoginId);          
  270.         inputDto.put("userLoginId", userLoginId);          
  271.         inputDto.put("roleLoginId", roleLoginId);          
  272.         inputDto.put("datetime", datetime);        
  273.        
  274.         try{           
  275.             Dto outputDto = addActivity.execute(inputDto);         
  276.             Assert.fail("This addActivity  should be error: "+outputDto);
  277.         } catch(CoreException e){                      
  278.             log.error("Data {0} cannot use data {1} from different tenant", e);
  279.             Assert.assertEquals(2, e.getParamValues().length);
  280.             Assert.assertEquals(CommonExceptionConstants.DATA_CANT_USE_DIFF_TENANT, e.getErrorKey());          
  281.         } catch (Exception e){
  282.             log.error("Exception{}",e);        
  283.             Assert.fail(e.toString());                     
  284.         }  
  285.     }
  286.    
  287.     @Test      
  288.     public void testForComboValueNotValid() {
  289.         String code = "PRE_TAX_30";
  290.         String name = "Prepaid Tax Art 30";
  291.         Long coaId = 7l;
  292.        
  293.         String datetime = DateUtil.dateTimeNow();
  294.         Long tenantLoginId = 10l;
  295.         Long roleLoginId = 1l;
  296.         String active = "Default text";
  297.         Long userLoginId = 1l;
  298.        
  299.         Dto inputDto = new Dto();
  300.         inputDto.put("code", code);        
  301.         inputDto.put("name", name);        
  302.         inputDto.put("coaId", coaId);
  303.         inputDto.put("active", active);        
  304.         inputDto.put("tenantLoginId", tenantLoginId);          
  305.         inputDto.put("userLoginId", userLoginId);          
  306.         inputDto.put("roleLoginId", roleLoginId);          
  307.         inputDto.put("datetime", datetime);        
  308.        
  309.         try{           
  310.             Dto outputDto = addActivity.execute(inputDto);         
  311.             Assert.fail("This addActivity  should be error: "+outputDto);
  312.         } catch(CoreException e){                      
  313.             log.error("Value {0} is not valid ,should not have values : {1}", e);
  314.             Assert.assertEquals(2, e.getParamValues().length);
  315.             Assert.assertEquals(CommonExceptionConstants.COMBO_VALUE_NOT_VALID, e.getErrorKey());          
  316.         } catch (Exception e){
  317.             log.error("Exception{}",e);        
  318.             Assert.fail(e.toString());                     
  319.         }  
  320.     }
  321.    
  322.     @Test
  323.     public void testForCoaIdNotFound() {
  324.         String code = "PRE_TAX_30";
  325.         String name = "Prepaid Tax Art 30";
  326.         Long coaId = -99l;
  327.        
  328.         String datetime = DateUtil.dateTimeNow();
  329.         Long tenantLoginId = 10l;
  330.         Long roleLoginId = 1l;
  331.         String active = GeneralConstants.YES;
  332.         Long userLoginId = 1l;
  333.        
  334.         Dto inputDto = new Dto();
  335.         inputDto.put("code", code);        
  336.         inputDto.put("name", name);        
  337.         inputDto.put("coaId", coaId);
  338.         inputDto.put("active", active);        
  339.         inputDto.put("tenantLoginId", tenantLoginId);          
  340.         inputDto.put("userLoginId", userLoginId);          
  341.         inputDto.put("roleLoginId", roleLoginId);          
  342.         inputDto.put("datetime", datetime);                    
  343.        
  344.         try{           
  345.             Dto outputDto = addActivity.execute(inputDto);         
  346.             Assert.fail("This addActivity  should be error: "+outputDto);
  347.         } catch(CoreException e){                      
  348.             log.error("Coa Id {0} is not found", e);
  349.             Assert.assertEquals(1, e.getParamValues().length);
  350.             Assert.assertEquals(MasterExceptionConstants.COA_ID_NOT_FOUND, e.getErrorKey());           
  351.         } catch (Exception e){
  352.             log.error("Exception{}",e);        
  353.             Assert.fail(e.toString());                     
  354.         }  
  355.     }
  356.    
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement