Fanadia_Friska

test get ku

Sep 13th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.test.customer.vs.rayon;
  2.  
  3. import java.util.List;
  4.  
  5. import junit.framework.Assert;
  6.  
  7. import org.jleaf.core.BusinessFunction;
  8. import org.jleaf.core.BusinessTransaction;
  9. import org.jleaf.core.Dto;
  10. import org.jleaf.core.GeneralConstants;
  11. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  12. import org.jleaf.util.DateUtil;
  13. import org.junit.Before;
  14. import org.junit.Test;
  15. import org.junit.runner.RunWith;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Qualifier;
  20. import org.springframework.test.context.ContextConfiguration;
  21. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  22. import org.springframework.test.context.transaction.TransactionConfiguration;
  23. import org.springframework.transaction.annotation.Transactional;
  24.  
  25. @RunWith(SpringJUnit4ClassRunner.class)
  26. @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
  27. @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  28. @Transactional
  29. public class TestGetRegionCustomerList extends AbstractSpringDbUnitTest {
  30. private static final Logger log = LoggerFactory
  31. .getLogger(TestGetRegionCustomerList.class);
  32.  
  33. @Autowired
  34. @Qualifier("getRegionCustomerList")
  35. private BusinessFunction getRegionCustomerList;
  36.  
  37. @Before
  38. public void prepareData() {
  39. super.deleteFromTables("m_region_customer", "m_region", "m_partner");
  40. super.executeSqlScript("scripts/TestGetRegionCustomerList.sql", false);
  41. }
  42.  
  43. //region code, dan region_name kosong
  44. @Test
  45. public void Kasus1() throws Exception{
  46.  
  47. Dto input = new Dto();
  48. input.put("tenantId", 10L);
  49. input.put("region_code", "");
  50. input.put("region_name", "");
  51. input.put("active", GeneralConstants.YES);
  52.  
  53. input.put("limit", 10L);
  54. input.put("offset", 0L);
  55.  
  56. try {
  57. Dto output = getRegionCustomerList.execute(input);
  58. log.debug("ini output:" + output);
  59. List<Dto> list = output.getList("regionCustomerList");
  60. Assert.assertEquals(2, list.size());
  61.  
  62. for (int i = 0; i < list.size() - 1; i++) {
  63. Dto listDto = list.get(i);
  64. if (i == 0) {
  65. Assert.assertEquals("1", listDto.getString("id"));
  66. Assert.assertEquals(10L, listDto.getLong("tenantId")
  67. .longValue());
  68. Assert.assertEquals("1", listDto.getString("region_code"));
  69. Assert.assertEquals("SUMATERA",
  70. listDto.getString("region_name"));
  71. } else if (i == 1) {
  72. Assert.assertEquals("2", listDto.getString("id"));
  73. Assert.assertEquals(10L, listDto.getLong("tenantId")
  74. .longValue());
  75. Assert.assertEquals("10", listDto.getString("region_code"));
  76. Assert.assertEquals("10", listDto.getString("region_name"));
  77. }
  78. }
  79.  
  80. } catch (Exception e) {
  81. log.error(e.getMessage(), e);
  82. }
  83.  
  84. }
  85.  
  86. //region_name kosong
  87. @Test
  88. public void Kasus2() {
  89.  
  90. Dto input = new Dto();
  91. input.put("tenantId", 10L);
  92. input.put("region_code", "1");
  93. input.put("region_name", "");
  94. input.put("active", GeneralConstants.YES);
  95.  
  96. input.put("limit", 10L);
  97. input.put("offset", 0L);
  98.  
  99. try {
  100. Dto output = getRegionCustomerList.execute(input);
  101. log.debug("ini output:" + output);
  102. List<Dto> list = output.getList("regionCustomerList");
  103. Dto listDto = list.get(0);
  104. Assert.assertEquals(1, list.size());
  105. Assert.assertEquals("1", listDto.getString("id"));
  106. Assert.assertEquals(10L, listDto.getLong("tenantId").longValue());
  107. Assert.assertEquals("1", listDto.getString("region_code"));
  108. Assert.assertEquals("SUMATERA", listDto.getString("region_name"));
  109.  
  110. } catch (Exception e) {
  111. log.error(e.getMessage(), e);
  112. }
  113.  
  114. }
  115.  
  116. //region_code kosong
  117. @Test
  118. public void Kasus3() {
  119.  
  120. Dto input = new Dto();
  121. input.put("tenantId", 10L);
  122. input.put("region_code", "");
  123. input.put("region_name", "SUMATERA");
  124. input.put("active", GeneralConstants.YES);
  125.  
  126. input.put("limit", 10L);
  127. input.put("offset", 0L);
  128.  
  129. try {
  130. Dto output = getRegionCustomerList.execute(input);
  131. log.debug("ini output:" + output);
  132. List<Dto> list = output.getList("regionCustomerList");
  133. Dto listDto = list.get(0);
  134. Assert.assertEquals(1, list.size());
  135. Assert.assertEquals("1", listDto.getString("id"));
  136. Assert.assertEquals(10L, listDto.getLong("tenantId").longValue());
  137. Assert.assertEquals("1", listDto.getString("region_code"));
  138. Assert.assertEquals("SUMATERA", listDto.getString("region_name"));
  139.  
  140. } catch (Exception e) {
  141. log.error(e.getMessage(), e);
  142. }
  143.  
  144. }
  145.  
  146. //region_code dan region_name kosong dan active YES
  147. // @Test
  148. // public void Kasus4() {
  149. //
  150. // Dto input = new Dto();
  151. // input.put("tenantId", 10L);
  152. // input.put("region_code", "");
  153. // input.put("region_name", "");
  154. // input.put("active", GeneralConstants.YES);
  155. //
  156. // input.put("limit", 10L);
  157. // input.put("offset", 0L);
  158. //
  159. // try {
  160. // Dto output = getRegionCustomerList.execute(input);
  161. // log.debug("ini output:" + output);
  162. // List<Dto> list = output.getList("regionCustomerList");
  163. // // log.debug("Output bf get region customer :" + result);
  164. //
  165. // Dto listDto = list.get(0);
  166. // Assert.assertEquals(1, list.size());
  167. // Assert.assertEquals("1", listDto.getString("id"));
  168. // Assert.assertEquals(10L, listDto.getLong("tenantId").longValue());
  169. // Assert.assertEquals("1", listDto.getString("region_code"));
  170. // Assert.assertEquals("SUMATERA", listDto.getString("region_name"));
  171. //
  172. // } catch (Exception e) {
  173. // log.error(e.getMessage(), e);
  174. // }
  175. //
  176. // }
  177. //
  178. // //region_code kosong dan active NO
  179. // @Test
  180. // public void Kasus5() {
  181. //
  182. // Dto input = new Dto();
  183. // input.put("tenantId", 10L);
  184. // input.put("region_code", "");
  185. // input.put("region_name", "SUMATERA");
  186. // input.put("active", GeneralConstants.NO);
  187. //
  188. // input.put("limit", 10L);
  189. // input.put("offset", 0L);
  190. //
  191. // try {
  192. // Dto output = getRegionCustomerList.execute(input);
  193. // log.debug("ini output:" + output);
  194. // List<Dto> list = output.getList("regionCustomerList");
  195. //
  196. // Dto listDto = list.get(0);
  197. // Assert.assertEquals(1, list.size());
  198. // Assert.assertEquals("1", listDto.getString("id"));
  199. // Assert.assertEquals(10L, listDto.getLong("tenantId").longValue());
  200. // Assert.assertEquals("1", listDto.getString("region_code"));
  201. // Assert.assertEquals("SUMATERA", listDto.getString("region_name"));
  202. //
  203. // } catch (Exception e) {
  204. // log.error(e.getMessage(), e);
  205. // }
  206. //
  207. // }
  208. //
  209. // //region_code tidak ada di tabe , dan region_name kosong
  210. // @Test
  211. // public void Kasus6() {
  212. //
  213. // Dto input = new Dto();
  214. // input.put("tenantId", 10L);
  215. // input.put("region_code", "BGR");
  216. // input.put("region_name", "");
  217. // input.put("active", GeneralConstants.NO);
  218. //
  219. // input.put("limit", 10L);
  220. // input.put("offset", 0L);
  221. //
  222. // try {
  223. // Dto output = getRegionCustomerList.execute(input);
  224. // log.debug("ini output:" + output);
  225. // List<Dto> list = output.getList("regionCustomerList");
  226. //
  227. // Dto listDto = list.get(0);
  228. // Assert.assertEquals(1, list.size());
  229. // Assert.assertEquals("1", listDto.getString("id"));
  230. // Assert.assertEquals(10L, listDto.getLong("tenantId").longValue());
  231. // Assert.assertEquals("1", listDto.getString("region_code"));
  232. // Assert.assertEquals("BGR", listDto.getString("region_name"));
  233. //
  234. // } catch (Exception e) {
  235. // log.error(e.getMessage(), e);
  236. // }
  237. //
  238. // }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment