Advertisement
Guest User

samplejUnit

a guest
Dec 12th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. package gov.bsp.lcmis.internal.test;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4.  
  5. import java.util.HashMap;
  6. import java.util.Map;
  7.  
  8. import javax.naming.NamingException;
  9.  
  10. import org.junit.BeforeClass;
  11. import org.junit.Test;
  12. import org.junit.runner.RunWith;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  17. import org.springframework.mock.jndi.SimpleNamingContextBuilder;
  18. import org.springframework.test.context.ActiveProfiles;
  19. import org.springframework.test.context.ContextConfiguration;
  20. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  21. import org.springframework.test.context.web.WebAppConfiguration;
  22.  
  23. import gov.bsp.lcmis.internal.posting.controller.LedgerPostingController;
  24. import gov.bsp.lcmis.internal.posting.exception.PostingBusinessException;
  25. import gov.bsp.lcmis.internal.user.controller.EmergencyLoanRatesController;
  26. import gov.bsp.lcmis.rates.exception.RatesBusinessException;
  27.  
  28. /**
  29. * This class tests if the context that is setup by dispatcher-servlet.xml is
  30. * complete and will run. Completeness includes : (1) that all bean definitions
  31. * have corresponding classes in the classpath.
  32. *
  33. * Note that the datasource set up here cannot be used to query the database in
  34. * other junit tests. A little tweaking is needed.
  35. *
  36. * @author enrique.feleo
  37. *
  38. */
  39. @RunWith(SpringJUnit4ClassRunner.class)
  40. @WebAppConfiguration
  41. @ContextConfiguration(value = "file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
  42. @ActiveProfiles("test")
  43. public class ApplicationContextsTest {
  44.  
  45. private static Logger logger = LoggerFactory.getLogger(ApplicationContextsTest.class);
  46.  
  47. private static String url = "jdbc:db2://localhost:50000/mydb2";
  48.  
  49. private static String username = "db2admin";
  50.  
  51. private static String password = "password123";
  52.  
  53. @Autowired
  54. LedgerPostingController ledgerPostingController;
  55.  
  56. @Autowired
  57. EmergencyLoanRatesController emergencyLoanRatesController;
  58. //
  59. // @Autowired
  60. // SearchController controller;
  61.  
  62. /*
  63. * @BeforeClass public static void setupClass() { //create the datasource
  64. * DataSource datasource = new AbstractDataSource() {
  65. *
  66. * @Override public Connection getConnection(String username, String
  67. * password) throws SQLException { return null; }
  68. *
  69. * @Override public Connection getConnection() throws SQLException { return
  70. * null; } };
  71. *
  72. * String automationPrefix = System.getProperty("automationTest.suffix"); if
  73. * (automationPrefix == null) { automationPrefix = ""; }
  74. * logger.debug(automationPrefix);
  75. *
  76. * //bind to a jndi string SimpleNamingContextBuilder builder = new
  77. * SimpleNamingContextBuilder(); builder.bind(new
  78. * StringBuilder("lcmisbsp").append(automationPrefix).toString(),
  79. * datasource); builder.bind(new
  80. * StringBuilder("${cfas.jndi.name}").append(automationPrefix).toString(),
  81. * datasource); builder.bind(new
  82. * StringBuilder("${ops.jndi.name}").append(automationPrefix).toString(),
  83. * datasource); try { builder.activate(); } catch (IllegalStateException |
  84. * NamingException e) { logger.error("Error setting up test class, ", e); }
  85. * }
  86. *
  87. * @Test public void test() { assertThat(controller, notNullValue()); }
  88. */
  89.  
  90. @BeforeClass
  91. public static void setupClass() {
  92. // create the datasource
  93. DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
  94. datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
  95.  
  96. // bind to a jndi string
  97. SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
  98. builder.bind("lcmisbsp", datasource);
  99. builder.bind("${cfas.jndi.name}", datasource);
  100. builder.bind("${ops.jndi.name}", datasource);
  101.  
  102. try {
  103. builder.activate();
  104. } catch (IllegalStateException | NamingException e) {
  105. logger.error("Error setting up test class, ", e);
  106. }
  107. }
  108.  
  109. @Test
  110. public void test() {
  111.  
  112. try {
  113. Map<String, Object> map = emergencyLoanRatesController.retrieveEmergencyLoanRateByDate("11/25/2017", 0, -10);
  114. System.out.println(map.get("status"));
  115. System.out.println(map.get("maxDate"));
  116. } catch (RatesBusinessException e) {
  117. // TODO Auto-generated catch block
  118. e.printStackTrace();
  119. }
  120. /*try {
  121. String paymentNumber = "2017077770";
  122. String pnNumber = "";
  123. String type = "INPUT";
  124. int id = 1;
  125. boolean isPosted = ledgerPostingController.postAdjustmentToLedgers(paymentNumber, pnNumber, type, id);
  126. assertEquals(true, isPosted);
  127.  
  128. } catch (PostingBusinessException e) {
  129. logger.error("Error found in testing. ", e);
  130. }*/
  131. }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement