Fanadia_Friska

TestGetVehicleList.java

Aug 25th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.60 KB | None | 0 0
  1. package org.jleaf.pos2.test.vehicle;
  2.  
  3. import java.util.List;
  4.  
  5. import junit.framework.Assert;
  6.  
  7. import org.jleaf.core.BusinessFunction;
  8. import org.jleaf.core.CoreException;
  9. import org.jleaf.core.Dto;
  10. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Qualifier;
  18. import org.springframework.test.context.ContextConfiguration;
  19. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  20. import org.springframework.test.context.transaction.TransactionConfiguration;
  21. import org.springframework.transaction.annotation.Transactional;
  22.  
  23. @RunWith(SpringJUnit4ClassRunner.class)
  24. @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
  25. @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
  26. @Transactional
  27. public class TestGetVehicleList extends AbstractSpringDbUnitTest {
  28. private static Logger log = LoggerFactory
  29. .getLogger(TestGetVehicleList.class);
  30. @Autowired
  31. @Qualifier("getVehicleList")
  32. private BusinessFunction getVehicleList;
  33.  
  34. @Before
  35. public void prepareData() {
  36. super.deleteFromTables("m_vehicle", "m_vehicle_group", "m_vehicle_type");
  37. super.executeSqlScript("scripts/TestGetVehicleList.sql", false);
  38. }
  39.  
  40. @SuppressWarnings("unchecked")
  41. @Test
  42. public void testGetListIfKeywordByVehicleCodeAndActiveYes()
  43. throws Exception {
  44.  
  45. Dto input = new Dto();
  46. input.put("keyword","HND");
  47. input.put("limit", 1L);
  48. input.put("offset", 0L);
  49. input.put("active","Y");
  50. log.debug("input>>>>>>"+input);
  51. try {
  52.  
  53. Dto result = getVehicleList.execute(input);
  54. List<Dto> list = result.getList("vehicleList");
  55.  
  56. log.debug("List : " + list.size());
  57.  
  58. Assert.assertEquals(1, list.size());
  59.  
  60. } catch (CoreException e) {
  61. e.printStackTrace();
  62. Assert.fail(e.getMessage());
  63. }
  64.  
  65. }
  66.  
  67. /* @SuppressWarnings("unchecked")
  68. @Test
  69. public void TestGetListIfKeywordByVehicleNameAndActiveYes() throws Exception {
  70. Dto input = new Dto();
  71. input.put("keyword", "HND");
  72. input.put("limit", 7L);
  73. input.put("offset", 0L);
  74. input.put("active", "Y");
  75.  
  76. try {
  77.  
  78. Dto result = getVehicleList.execute(input);
  79.  
  80. List<Dto> list = result.getList("vehicleList");
  81.  
  82. log.debug("List : " + result.getList("vehicleList"));
  83. Assert.assertEquals(1, list.size());
  84.  
  85. } catch (CoreException e) {
  86. e.printStackTrace();
  87.  
  88. Assert.fail(e.getMessage());
  89. }
  90.  
  91. }
  92.  
  93. @SuppressWarnings("unchecked")
  94. @Test
  95. public void testGetListIfKeywordByvehicleCodeAndActiveNo() throws
  96. Exception{
  97.  
  98. Dto input = new Dto();
  99. input.put("keyword", "YMH");
  100. input.put("limit", 7L);
  101. input.put("offset", 0L);
  102. input.put("active", "n");
  103.  
  104. try {
  105.  
  106. Dto result = getVehicleList.execute(input);
  107.  
  108. List<Dto> list = result.getList("vehicleList");
  109.  
  110. log.debug("List : "+result.getList("vehicleList"));
  111.  
  112. Assert.assertEquals(0, list.size());
  113.  
  114.  
  115. }catch(CoreException e){
  116. e.printStackTrace();
  117. Assert.fail(e.getMessage());
  118. }
  119.  
  120. }
  121.  
  122. @SuppressWarnings("unchecked")
  123. @Test
  124. public void testGetListIfKeywordByvehicleNameAndActiveNo() throws
  125. Exception{
  126.  
  127. Dto input = new Dto();
  128. input.put("keyword", "HONDA");
  129. input.put("limit", 7L);
  130. input.put("offset", 0L);
  131. input.put("active", "y");
  132.  
  133. try {
  134.  
  135. Dto result = getVehicleList.execute(input);
  136.  
  137. List<Dto> list = result.getList("vehicleList");
  138.  
  139. log.debug("List : "+result.getList("vehicleList"));
  140.  
  141. Assert.assertEquals(0, list.size());
  142.  
  143. }catch(CoreException e){
  144. e.printStackTrace();
  145.  
  146.  
  147. Assert.fail(e.getMessage());
  148. }
  149.  
  150. }
  151.  
  152. @SuppressWarnings("unchecked")
  153. @Test
  154. public void testSuccessIfKeywordAndActiveEmpty() throws Exception{
  155.  
  156. Dto input = new Dto();
  157. input.put("keyword", "");
  158. input.put("limit", 15L);
  159. input.put("offset", 0L);
  160. input.put("active", "");
  161.  
  162. try {
  163.  
  164. Dto result = getVehicleList.execute(input);
  165.  
  166. List<Dto> list = result.getList("vehicleList");
  167.  
  168. log.debug("List : "+result.getList("vehicleList"));
  169.  
  170. Assert.assertEquals(3, list.size());
  171.  
  172. }catch(Exception ex){
  173. ex.printStackTrace();
  174. Assert.fail(ex.getMessage());
  175. }
  176. }
  177.  
  178. @SuppressWarnings("unchecked")
  179. @Test
  180. public void testSuccessIfKeywordByvehicleCodeAndActiveEmpty() throws
  181. Exception{
  182.  
  183. Dto input = new Dto();
  184. input.put("keyword", "HND");
  185. input.put("limit", 15L);
  186. input.put("offset", 0L);
  187. input.put("active", "");
  188.  
  189. try {
  190.  
  191. Dto result = getVehicleList.execute(input);
  192.  
  193. List<Dto> list = result.getList("vehicleList");
  194.  
  195. log.debug("List : "+list);
  196. Assert.assertEquals(0, list.size());
  197.  
  198. }catch(Exception ex){
  199. ex.printStackTrace();
  200. Assert.fail(ex.getMessage());
  201. }
  202. }
  203.  
  204. @SuppressWarnings("unchecked")
  205. @Test
  206. public void testSuccess() throws Exception{
  207. //IfKeywordByvehicleNameAndActiveEmpty
  208. Dto input = new Dto();
  209. input.put("keyword", "Hnd");
  210. input.put("limit", 15L);
  211. input.put("offset", 0L);
  212. input.put("active", "");
  213.  
  214. try {
  215.  
  216. Dto result = getVehicleList.execute(input);
  217.  
  218. List<Dto> list = result.getList("vehicleList");
  219.  
  220. log.debug("List : "+result.getList("vehicleList"));
  221.  
  222. Assert.assertEquals(1, list.size());
  223.  
  224. }catch(Exception ex){
  225. ex.printStackTrace();
  226. Assert.fail(ex.getMessage());
  227. }
  228. }
  229.  
  230. @Test
  231. public void testSuccessIfKeywordHondaAndActiveEmpty() throws Exception{
  232.  
  233. Dto input = new Dto();
  234. input.put("keyword", "Hnd");
  235. input.put("limit", 15L);
  236. input.put("offset", 0L);
  237. input.put("active", "");
  238.  
  239. try {
  240.  
  241. Dto result = getVehicleList.execute(input);
  242.  
  243. @SuppressWarnings("unchecked")
  244. List<Dto> list = result.getList("vehicleList");
  245.  
  246. log.debug("List : "+result.getList("vehicleList"));
  247.  
  248. Assert.assertEquals(1, list.size());
  249.  
  250. }catch(Exception ex){
  251. ex.printStackTrace();
  252. Assert.fail(ex.getMessage());
  253. }
  254. }
  255.  
  256. @SuppressWarnings("unchecked")
  257. @Test
  258. public void testSuccessIfActiveIsYesAndKeywordIsEmpty() throws Exception{
  259.  
  260. Dto input = new Dto();
  261. input.put("keyword", "");
  262. input.put("limit", 15L);
  263. input.put("offset", 0L);
  264. input.put("active", "y");
  265.  
  266. try {
  267.  
  268. Dto result = getVehicleList.execute(input);
  269.  
  270. List<Dto> list = result.getList("vehicleList");
  271.  
  272. log.debug("List : "+result.getList("vehicleList"));
  273.  
  274. Assert.assertEquals(2, list.size());
  275.  
  276. }catch(Exception ex){
  277. ex.printStackTrace();
  278. Assert.fail(ex.getMessage());
  279. }
  280. }
  281.  
  282.  
  283.  
  284. @SuppressWarnings("unchecked")
  285. @Test
  286. public void testSuccessIfActiveIsNoAndKeywordIsEmpty() throws Exception{
  287.  
  288. Dto input = new Dto();
  289. input.put("keyword", "");
  290. input.put("limit", 15L);
  291. input.put("offset", 0L);
  292. input.put("active", "n");
  293.  
  294. try {
  295.  
  296. Dto result = getVehicleList.execute(input);
  297.  
  298. List<Dto> list = result.getList("vehicleList");
  299.  
  300. Assert.assertEquals(1, list.size());
  301.  
  302. }catch(Exception ex){
  303. ex.printStackTrace();
  304. Assert.fail(ex.getMessage());
  305. }
  306. }
  307.  
  308. @SuppressWarnings("unchecked")
  309. @Test
  310. public void testIfKeywordNotExists() throws Exception{
  311.  
  312. Dto input = new Dto();
  313. input.put("keyword", "SZY");
  314. input.put("limit", 15L);
  315. input.put("offset", 0L);
  316. input.put("active", "y");
  317.  
  318. try {
  319.  
  320. Dto result = getVehicleList.execute(input);
  321.  
  322. List<Dto> list = result.getList("vehicleList");
  323. Assert.assertEquals(0, list.size());
  324. }catch(Exception ex){
  325. ex.printStackTrace();
  326. Assert.fail(ex.getMessage());
  327. }
  328.  
  329. }
  330.  
  331. */
  332.  
  333. }
Advertisement
Add Comment
Please, Sign In to add comment