Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gov.bsp.lcmis.internal.test;
- import javax.naming.NamingException;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.mock.jndi.SimpleNamingContextBuilder;
- import org.springframework.test.context.ActiveProfiles;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.web.WebAppConfiguration;
- import gov.bsp.lcmis.internal.controller.SearchController;
- import gov.bsp.lcmis.internal.user.controller.UserManagementController;
- import gov.bsp.lcmis.internal.user.exception.UserBusinessException;
- import gov.bsp.lcmis.internal.user.service.RetrieveAllRolesService;
- import gov.bsp.lcmis.internal.user.service.RetrieveBspUserAccountProfileService;
- /**
- * This class tests if the context that is setup by dispatcher-servlet.xml is complete and will run.
- * Completeness includes :
- * (1) that all bean definitions have corresponding classes in the classpath.
- *
- * Note that the datasource set up here cannot be used to query the database in other junit tests.
- * A little tweaking is needed.
- *
- * @author enrique.feleo
- *
- */
- @RunWith(SpringJUnit4ClassRunner.class)
- @WebAppConfiguration
- @ContextConfiguration(value="file:src/main/webapp/WEB-INF/dispatcher-servlet.xml")
- @ActiveProfiles("test")
- public class ApplicationContextsTest {
- private static Logger logger = LoggerFactory.getLogger(ApplicationContextsTest.class);
- private static String url = "jdbc:db2://localhost:50000/mydb2";
- private static String username = "db2admin";
- private static String password = "password123";
- @Autowired
- SearchController controller;
- @Autowired
- RetrieveAllRolesService retrieveAllRolesService;
- @Autowired
- RetrieveBspUserAccountProfileService retrieveBspUserAccountProfileService;
- @Autowired
- UserManagementController userManagementController;
- @BeforeClass
- public static void setupClass() {
- //create the datasource
- DriverManagerDataSource datasource = new DriverManagerDataSource(url, username, password);
- datasource.setDriverClassName("com.ibm.db2.jcc.DB2Driver");
- //bind to a jndi string
- SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
- builder.bind("lcmisbsp", datasource);
- builder.bind("${cfas.jndi.name}", datasource);
- builder.bind("${ops.jndi.name}", datasource);
- try {
- builder.activate();
- } catch (IllegalStateException | NamingException e) {
- logger.error("Error setting up test class, ", e);
- }
- }
- /*@Test
- public void test() {
- User user = null;
- List<Role> roles = null;
- int userId = 13;
- try {
- roles = retrieveAllRolesService.retrieveRoles();
- logger.info(new StringBuilder("roles.size(): ").append(roles.size()).toString());
- //assertThat(controller, notNullValue());
- user = retrieveBspUserAccountProfileService.retrieveBspUserAccountProfile(userId);
- logger.info(new StringBuilder("groupName: ").append(user.getGroup().getGroupName()).toString());
- logger.info(new StringBuilder("roles(): ").append(user.getRoles().size()).toString());
- logger.info(new StringBuilder("assignedBanks(): ").append(user.getAssignedBanks().size()).toString());
- logger.info(new StringBuilder("userGroupsCimm(): ").append(user.getUserGroupMap().get(UserGroupType.CIMM.toString()).size()).toString());
- logger.info(new StringBuilder("userGroupsEim(): ").append(user.getUserGroupMap().get(UserGroupType.EIM.toString()).size()).toString());
- } catch (UserBusinessException e) {
- logger.error("Error found in testing ", e);
- }
- }*/
- @Test
- public void testUserManagementController() {
- try {
- String userId = "13";
- userManagementController.viewAddUpdateUser();
- } catch (UserBusinessException e) {
- logger.error("Error found in testing ", e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement