Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. package id.co.sts.firebase.bo.device.test;
  2.  
  3. import id.co.sts.firebase.FirebaseExceptionConstants;
  4.  
  5. import org.jleaf.core.BusinessFunction;
  6. import org.jleaf.core.BusinessTransaction;
  7. import org.jleaf.core.CoreException;
  8. import org.jleaf.core.Dto;
  9. import org.jleaf.core.test.AbstractSpringDbUnitTest;
  10. import org.junit.Assert;
  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.  
  28. public class TestInactiveDevice extends AbstractSpringDbUnitTest{
  29.  
  30. private static final Logger log = LoggerFactory.getLogger(TestInactiveDevice.class);
  31.  
  32. @Autowired
  33. @Qualifier("inactiveDevice")
  34. BusinessTransaction inactiveDevice;
  35.  
  36. @Autowired
  37. @Qualifier("findProjectById")
  38. BusinessFunction findProjectById;
  39.  
  40. @Before
  41. public void prepareData(){
  42. log.debug("Prepare data");
  43. super.executeSqlScript("scripts/TestInactiveDevice.sql", false);
  44. }
  45.  
  46. @Test
  47. public void testSuccess(){
  48. log.debug("Test Success");
  49.  
  50. Dto inputDto = new Dto();
  51. inputDto.put("projectId", 50L);
  52. inputDto.put("uuid", "UID1");
  53. inputDto.put("active", "N");
  54.  
  55. log.debug("input : "+inputDto);
  56. try {
  57. log.debug("Call bt inactive device");
  58. Dto outputDto = inactiveDevice.execute(inputDto);
  59. log.debug("output dari inactiveDevice : "+outputDto);
  60.  
  61. Dto inputDtoForFindProjectById = new Dto();
  62. inputDtoForFindProjectById.put("id", outputDto.get("projectId"));
  63.  
  64. Dto deviceDto = findProjectById.execute(inputDtoForFindProjectById);
  65.  
  66. Assert.assertEquals(inputDto.get("projectId"), deviceDto.get("projectId"));
  67. Assert.assertEquals(inputDto.get("uuid"), outputDto.get("uuid"));
  68. Assert.assertEquals(inputDto.get("active"), outputDto.get("active"));
  69. } catch (Exception e) {
  70. // TODO: handle exception
  71. log.error("error inactive device");
  72. Assert.fail(e.toString());
  73. }
  74. }
  75.  
  76. @Test
  77. public void testSuccessNonActive(){
  78. log.debug("Test Success Change Active to N");
  79.  
  80. Dto inputDto = new Dto();
  81. inputDto.put("projectId", 50L);
  82. inputDto.put("uuid", "UID1");
  83. inputDto.put("active", "Y");
  84. log.debug("input : "+inputDto);
  85. try {
  86. log.debug("Call bt inactive device");
  87. Dto outputDto = inactiveDevice.execute(inputDto);
  88. log.debug("output dari inactiveDevice : "+outputDto);
  89.  
  90. Assert.assertEquals(inputDto.get("projectId"), outputDto.get("projectId"));
  91. Assert.assertEquals(inputDto.get("uuid"), outputDto.get("uuid"));
  92. Assert.assertEquals("N", outputDto.get("active"));
  93. } catch (Exception e) {
  94. // TODO: handle exception
  95. log.error("error inactive device");
  96. Assert.fail(e.toString());
  97. }
  98. }
  99.  
  100. @Test
  101. public void testErrorDeviceNotFound(){
  102. log.debug("Test Error Project Not Found");
  103.  
  104. Dto inputDto = new Dto();
  105. inputDto.put("projectId", 92L);
  106. inputDto.put("uuid", "UID1");
  107. inputDto.put("active", "Y");
  108. log.debug("input : "+inputDto);
  109. try {
  110. log.debug("Call bt inactive device");
  111. Dto outputDto = inactiveDevice.execute(inputDto);
  112. Assert.fail("This inactive device should be error : "+outputDto);
  113.  
  114. } catch (CoreException e) {
  115. log.debug("Core Exception");
  116. log.debug(e.getErrorKey());
  117. Assert.assertEquals(FirebaseExceptionConstants.DEVICE_NOT_FOUND, e.getErrorKey());
  118. } catch (Exception e) {
  119. // TODO: handle exception
  120. log.error("error inactive device", e);
  121. Assert.fail(e.toString());
  122. e.printStackTrace();
  123. }
  124.  
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement