Fanadia_Friska

TestEditEmployee

Sep 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. package org.jleaf.pos2.test.employee;
  2.  
  3. import org.jleaf.common.CommonExceptionConstants;
  4. import org.jleaf.core.BusinessFunction;
  5. import org.jleaf.core.BusinessTransaction;
  6. import org.jleaf.core.CoreException;
  7. import org.jleaf.core.CoreExceptionConstants;
  8. import org.jleaf.core.Dto;
  9. import org.jleaf.core.GeneralConstants;
  10. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  11. import org.jleaf.pos2.PosMasterExceptionConstants;
  12. import org.jleaf.pos2.test.vehicletype.TestFindVehicleTypeById;
  13. import org.jleaf.util.DateUtil;
  14. import org.junit.Assert;
  15. import org.junit.Before;
  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.test.context.ContextConfiguration;
  23. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  24. import org.springframework.test.context.transaction.TransactionConfiguration;
  25. import org.springframework.transaction.annotation.Transactional;
  26.  
  27. /**
  28. *
  29. * @author Desinta Aditiya, 1 August 2016
  30. *
  31. */
  32.  
  33. @RunWith(SpringJUnit4ClassRunner.class)
  34. @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
  35. @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  36. @Transactional
  37. public class TestEditEmployeeJob extends AbstractSpringDbUnitTest {
  38.  
  39. private static final Logger log = LoggerFactory
  40. .getLogger(TestEditEmployeeJob.class);
  41. @Before
  42. public void prepareData() {
  43. super.deleteFromTables("m_employee_job", "t_user", "t_combo", "t_combo_value");
  44. super.executeSqlScript("scripts/TestEditEmployeeJob.sql", false);
  45.  
  46. }
  47. @Autowired
  48. @Qualifier("editEmployeeJob")
  49. private BusinessTransaction editEmployeeJob;
  50.  
  51. @Autowired
  52. @Qualifier("findEmployeeJobById")
  53. private BusinessFunction findEmployeeJobById;
  54.  
  55.  
  56.  
  57. @Test
  58. public void testSucces() {
  59.  
  60. Dto inputDto = new Dto();
  61.  
  62. String datetime = DateUtil.dateTimeNow();
  63. inputDto.put("partnerCode", "Desinta");
  64. inputDto.put("employeeJob", "PURCH");
  65. //inputDto.put("username", "Desinta");
  66. inputDto.put("version", 1L);
  67. inputDto.put("userLoginName", "Nadia");
  68. inputDto.put("roleLoginId", 20L);
  69. inputDto.put("roleLoginName", "Admin");
  70. inputDto.put("datetime", "20160729000000");
  71.  
  72. try {
  73.  
  74. Dto outputDto = editEmployeeJob.execute(inputDto);
  75.  
  76. log.debug("outputDto:"+outputDto);
  77.  
  78. String newId = outputDto.getString("partnerCode");
  79.  
  80. Assert.assertNotNull(newId);
  81.  
  82. Dto findDto = findEmployeeJobById.execute(new Dto().put("partnerCode",
  83. newId));
  84.  
  85. Assert.assertEquals("DESINTA", findDto.getString("partnerCode"));
  86. Assert.assertEquals("PURCH", findDto.getString("employeeJob"));
  87. Assert.assertEquals("Desinta", findDto.getString("username"));
  88. Assert.assertEquals(2L, findDto.getLong("version").longValue());
  89. Assert.assertEquals("20160729000000", findDto.getString("createDateTime"));
  90. Assert.assertEquals("20160729000000", findDto.getString("updateDateTime"));
  91. Assert.assertEquals("Nadia", findDto.getString("createUsername"));
  92. Assert.assertEquals("Nadia", findDto.getString("updateUsername"));
  93.  
  94. } catch (Exception e) {
  95. log.error("error edit", e);
  96.  
  97. e.printStackTrace();
  98. Assert.fail(e.getMessage());
  99. }
  100.  
  101. }
  102.  
  103.  
  104. @Test
  105. public void testEditFailBecausePartnerCodeNotFound() {
  106.  
  107.  
  108.  
  109. Dto input = new Dto();
  110. String datetime = DateUtil.dateTimeNow();
  111. input.put("partnerCode", "Milla");
  112. input.put("employeeJob", "PURCH");
  113. input.put("username", "Desinta");
  114. input.put("version", 1L);
  115. input.put("userLoginName", "Nadia");
  116. input.put("roleLoginId", 20L);
  117. input.put("roleLoginName", "Admin");
  118. input.put("datetime", datetime);
  119.  
  120. try {
  121. editEmployeeJob.execute(input);
  122.  
  123. System.err.println("dgfdhss");
  124. Assert.fail("Validation Partner code empty failed");
  125. } catch (CoreException e1) {
  126. // untuk masuk ke core exception
  127. log.debug("Masuk core exception");
  128.  
  129. Assert.assertEquals("employee.job.id.not.found", e1.getErrorKey());
  130.  
  131. } catch (Exception e) {
  132. log.error("error", e);
  133. Assert.fail(e.getMessage());
  134. }
  135.  
  136. }
  137.  
  138. @Test
  139. public void testEditFailBecauseemployeeJobNotFound() {
  140.  
  141.  
  142.  
  143. Dto input = new Dto();
  144. String datetime = DateUtil.dateTimeNow();
  145. input.put("partnerCode", "Milla");
  146. input.put("employeeJob", "PROGRAMER");
  147. input.put("username", "Desinta");
  148. input.put("version", 1L);
  149. input.put("userLoginName", "Nadia");
  150. input.put("roleLoginId", 20L);
  151. input.put("roleLoginName", "Admin");
  152. input.put("datetime", datetime);
  153.  
  154.  
  155. try {
  156. editEmployeeJob.execute(input);
  157.  
  158. System.err.println("dgfdhss");
  159. Assert.fail("Validation device merchant name empty failed");
  160. } catch (CoreException e1) {
  161. // untuk masuk ke core exception
  162. log.debug("Masuk core exception");
  163.  
  164. Assert.assertEquals("employee.job.id.not.found", e1.getErrorKey());
  165.  
  166. } catch (Exception e) {
  167. log.error("error", e);
  168. Assert.fail(e.getMessage());
  169. }
  170. }
  171.  
  172.  
  173. @Test
  174. public void testEditFailBecausePartnerCodeNotFilled() throws Exception {
  175.  
  176. String datetime = DateUtil.dateTimeNow();
  177.  
  178. Dto input = new Dto();
  179. input.put("partnerCode", "");
  180. input.put("employeeJob", "PURCH");
  181. input.put("username", "Desinta");
  182. input.put("version", 1L);
  183. input.put("userLoginName", "Nadia");
  184. input.put("roleLoginId", 20L);
  185. input.put("roleLoginName", "Admin");
  186. input.put("datetime", datetime);
  187.  
  188. try {
  189. editEmployeeJob.execute(input);
  190.  
  191. System.err.println("dgfdhss");
  192. Assert.fail("Validation device merchant name empty failed");
  193. } catch (CoreException e1) {
  194. // untuk masuk ke core exception
  195. log.debug("Masuk core exception");
  196.  
  197. Assert.assertEquals("value.cannot.null", e1.getErrorKey());
  198.  
  199. } catch (Exception e) {
  200. log.error("error", e);
  201. Assert.fail(e.getMessage());
  202. }
  203. }
  204.  
  205. @Test
  206. public void tesValueBecausePartnerCodeIsExist(){
  207.  
  208. Dto input = new Dto();
  209.  
  210. String datetime = DateUtil.dateTimeNow();
  211. input.put("partnerCode", "Desinta");
  212. input.put("employeeJob", "PURCH");
  213. input.put("username", "Desinta");
  214. input.put("userLoginName", "Nadia");
  215. input.put("roleLoginId", 20L);
  216. input.put("roleLoginName", "Admin");
  217. input.put("datetime", datetime);
  218.  
  219. try {
  220. editEmployeeJob.execute(input);
  221.  
  222. System.err.println("dgfdhss");
  223. Assert.fail("Validation PartnerCode is Already Exists");
  224. } catch (CoreException e1) {
  225. // untuk masuk ke core exception
  226. log.debug("Masuk core exception");
  227.  
  228. Assert.assertEquals("core.parameter.not.found", e1.getErrorKey());
  229.  
  230. } catch (Exception e) {
  231. log.error("error", e);
  232. Assert.fail(e.getMessage());
  233. }
  234. }
  235.  
  236. }
Advertisement
Add Comment
Please, Sign In to add comment