Advertisement
aadddrr

Sample Test Find

Sep 13th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.99 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.partner.test;
  2.  
  3. import org.jleaf.core.BusinessFunction;
  4. import org.jleaf.core.Dto;
  5. import org.jleaf.core.GeneralConstants;
  6. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  7. import org.junit.Test;
  8. import org.junit.Assert;
  9. import org.junit.Before;
  10. import org.junit.runner.RunWith;
  11. import org.jleaf.core.CoreException;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.beans.factory.annotation.Qualifier;
  16. import org.springframework.test.context.ContextConfiguration;
  17. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  18. import org.springframework.test.context.transaction.TransactionConfiguration;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import org.jleaf.erp.master.MasterExceptionConstants;
  21.  
  22. @RunWith(SpringJUnit4ClassRunner.class)
  23. @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
  24. @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  25. @Transactional
  26. public class TestFindCtgrPartnerById extends AbstractSpringDbUnitTest {
  27.     private static final Logger log = LoggerFactory
  28.             .getLogger(TestFindCtgrPartnerById.class);
  29.     @Autowired
  30.     @Qualifier("findCtgrPartnerById")
  31.     private BusinessFunction findCtgrPartnerById;
  32.    
  33.     @Before
  34.     public void prepare() {
  35.         deleteFromTables("m_ctgr_partner");
  36.         executeSqlScript("classpath:org/jleaf/erp/master/bo/TableBase.sql", false);
  37.         executeSqlScript("classpath:org/jleaf/erp/master/bo/partner/test/TestFindCtgrPartnerById.sql", false);
  38.     }
  39.    
  40.     /*@Test
  41.     public void testValidateNull() {
  42.  
  43.         Dto inputDto = new Dto();
  44.         inputDto.put("id", null);          
  45.         log.debug("inputDto :{}", inputDto);
  46.         try {
  47.             findCtgrPartnerById.execute(inputDto);                             
  48.             Assert.fail("The findCtgrPartnerById should be null");
  49.         }catch(CoreException coreEx){
  50.             log.debug("exception :{}", coreEx.getErrorKey());                      
  51.         }catch(NullPointerException ex){
  52.             Assert.fail("findCtgrPartnerById");
  53.         }catch (Exception e) {         
  54.             Assert.fail("addSample");
  55.         }              
  56.     }
  57.    
  58.     @Test
  59.     public void testValidateDataType() {
  60.         //TODO : Handle Input testValidateDataType
  61.         Dto inputDto = new Dto();
  62.         inputDto.put("id","id");           
  63.         log.debug("inputDto :{}", inputDto);
  64.         try {
  65.             findCtgrPartnerById.execute(inputDto);                             
  66.             Assert.fail("The findCtgrPartnerById should be valid");
  67.         }catch(CoreException coreEx){
  68.             log.debug("exception :{}", coreEx.getErrorKey());                      
  69.         }catch(NumberFormatException ex){
  70.             Assert.fail("findCtgrPartnerById");
  71.         }catch (Exception e) {         
  72.             Assert.fail("addSample");
  73.         }  
  74.     }*/
  75.  
  76.     @Test
  77.     public void testSuccess() {
  78.         //TODO : Handle Input testSuccess
  79.         Long id = 10l;
  80.        
  81.         Dto inputDto = new Dto();
  82.         inputDto.put("id", id);        
  83.                
  84.         try {
  85.            Dto outputDto = findCtgrPartnerById.execute(inputDto);
  86.            // TODO Fill the expected result for assert
  87.            Assert.assertEquals(id, outputDto.get("id"));
  88.            Assert.assertEquals(10L, outputDto.get("tenantId"));
  89.            Assert.assertEquals("GENERAL", outputDto.get("code"));
  90.            Assert.assertEquals("GENERAL", outputDto.get("name"));
  91.            Assert.assertEquals(GeneralConstants.YES, outputDto.get("active"));
  92.            Assert.assertEquals("20130620131317", outputDto.get("activeDateTime"));
  93.            Assert.assertEquals(GeneralConstants.SPACE_VALUE, outputDto.get("nonActiveDateTime"));
  94.            Assert.assertEquals("20130620131317", outputDto.get("createDateTime"));
  95.            Assert.assertEquals(-1L, outputDto.get("createUserId"));
  96.            Assert.assertEquals("20130620131317", outputDto.get("updateDateTime"));
  97.            Assert.assertEquals(-1L, outputDto.get("updateUserId"));
  98.            Assert.assertEquals(0L, outputDto.get("version"));
  99.            log.debug("result : {}", outputDto);                                                                    
  100.         }catch(Exception e){
  101.             log.error("Exception{}",e);                        
  102.         }
  103.        
  104.        
  105.     }
  106.    
  107.     @Test
  108.     public void testFailure() {
  109.         Long id = -99l;
  110.        
  111.         Dto inputDto = new Dto();
  112.         inputDto.put("id", id);        
  113.         log.debug("inputDto : {}",inputDto);
  114.         try{           
  115.             Dto outputDto = findCtgrPartnerById.execute(inputDto);
  116.            
  117.             Assert.fail("This findCtgrPartnerById  should be error: "+outputDto);
  118.         } catch(CoreException e){                      
  119.             log.error("Exception{}",e);    
  120.         } catch (Exception e){
  121.             log.error("Exception{}",e);        
  122.             Assert.fail(e.toString());                     
  123.         }          
  124.     }
  125.    
  126.    
  127.    
  128.     @Test      
  129.     public void testForCtgrPartnerIdNotFound() {
  130.         Long id = -99l;
  131.         Dto inputDto = new Dto();
  132.         inputDto.put("id", id);        
  133.        
  134.         try{           
  135.             Dto outputDto = findCtgrPartnerById.execute(inputDto);         
  136.             Assert.fail("This findCtgrPartnerById  should be error: "+outputDto);
  137.         } catch(CoreException e){                      
  138.             log.error("Category Partner Id {0} is not found", e);
  139.             Assert.assertEquals(1, e.getParamValues().length);
  140.             Assert.assertEquals(MasterExceptionConstants.CTGR_PARTNER_ID_NOT_FOUND, e.getErrorKey());          
  141.         } catch (Exception e){
  142.             log.error("Exception{}",e);        
  143.             Assert.fail(e.toString());                     
  144.         }  
  145.     }  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement