Advertisement
Guest User

Untitled

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