Advertisement
Guest User

AppContextTest

a guest
Nov 9th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. package gov.bsp.lcmis.internal.test;
  2.  
  3. import javax.naming.NamingException;
  4.  
  5. import org.junit.BeforeClass;
  6. import org.junit.Test;
  7. import org.junit.runner.RunWith;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  12. import org.springframework.mock.jndi.SimpleNamingContextBuilder;
  13. import org.springframework.test.context.ActiveProfiles;
  14. import org.springframework.test.context.ContextConfiguration;
  15. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  16. import org.springframework.test.context.web.WebAppConfiguration;
  17.  
  18. import gov.bsp.lcmis.internal.controller.SearchController;
  19. import gov.bsp.lcmis.internal.user.controller.UserManagementController;
  20. import gov.bsp.lcmis.internal.user.exception.UserBusinessException;
  21. import gov.bsp.lcmis.internal.user.service.RetrieveAllRolesService;
  22. import gov.bsp.lcmis.internal.user.service.RetrieveBspUserAccountProfileService;
  23.  
  24. /**
  25. * This class tests if the context that is setup by dispatcher-servlet.xml is complete and will run.
  26. * Completeness includes :
  27. * (1) that all bean definitions have corresponding classes in the classpath.
  28. *
  29. * Note that the datasource set up here cannot be used to query the database in other junit tests.
  30. * A little tweaking is needed.
  31. *
  32. * @author enrique.feleo
  33. *
  34. */
  35. @RunWith(SpringJUnit4ClassRunner.class)
  36. @WebAppConfiguration
  37. @ContextConfiguration(value="file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
  38. @ActiveProfiles("test")
  39. public class ApplicationContextsTest {
  40.  
  41. private static Logger logger = LoggerFactory.getLogger(ApplicationContextsTest.class);
  42.  
  43. private static String url = "jdbc:db2://localhost:50000/mydb2";
  44.  
  45. private static String username = "db2admin";
  46.  
  47. private static String password = "password123";
  48.  
  49. @Autowired
  50. SearchController controller;
  51.  
  52. @Autowired
  53. RetrieveAllRolesService retrieveAllRolesService;
  54.  
  55. @Autowired
  56. RetrieveBspUserAccountProfileService retrieveBspUserAccountProfileService;
  57.  
  58. @Autowired
  59. UserManagementController userManagementController;
  60.  
  61. @BeforeClass
  62. public static void setupClass() {
  63. //create the datasource
  64. DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
  65. datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
  66.  
  67. //bind to a jndi string
  68. SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
  69. builder.bind("lcmisbsp", datasource);
  70. builder.bind("${cfas.jndi.name}", datasource);
  71. builder.bind("${ops.jndi.name}", datasource);
  72.  
  73. try {
  74. builder.activate();
  75. } catch (IllegalStateException | NamingException e) {
  76. logger.error("Error setting up test class, ", e);
  77. }
  78. }
  79.  
  80. /*@Test
  81. public void test() {
  82. User user = null;
  83. List<Role> roles = null;
  84. int userId = 13;
  85.  
  86. try {
  87. roles = retrieveAllRolesService.retrieveRoles();
  88. logger.info(new StringBuilder("roles.size(): ").append(roles.size()).toString());
  89. //assertThat(controller, notNullValue());
  90.  
  91. user = retrieveBspUserAccountProfileService.retrieveBspUserAccountProfile(userId);
  92. logger.info(new StringBuilder("groupName: ").append(user.getGroup().getGroupName()).toString());
  93. logger.info(new StringBuilder("roles(): ").append(user.getRoles().size()).toString());
  94. logger.info(new StringBuilder("assignedBanks(): ").append(user.getAssignedBanks().size()).toString());
  95. logger.info(new StringBuilder("userGroupsCimm(): ").append(user.getUserGroupMap().get(UserGroupType.CIMM.toString()).size()).toString());
  96. logger.info(new StringBuilder("userGroupsEim(): ").append(user.getUserGroupMap().get(UserGroupType.EIM.toString()).size()).toString());
  97.  
  98. } catch (UserBusinessException e) {
  99. logger.error("Error found in testing ", e);
  100. }
  101. }*/
  102.  
  103. @Test
  104. public void testUserManagementController() {
  105.  
  106. try {
  107. String userId = "13";
  108. userManagementController.viewAddUpdateUser();
  109. } catch (UserBusinessException e) {
  110. logger.error("Error found in testing ", e);
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement