org.springframework.ui.ExtendedModelMap Java Examples
The following examples show how to use
org.springframework.ui.ExtendedModelMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuditSetUpControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
public void testDisplayPageAuditSiteSetUpWithWrongContractId() { System.out.println("testDisplayPageAuditSiteSetUpWithWrongContractId"); // set-up setUpMockUserDataServiceAndUser(); setUpMockAuthenticationContext(); setUpMockContractDataService(1,"Contract1"); // the contract Id cannot be converted as a Long. An exception is caught try { instance.displaySiteAuditSetUp("Not a number", null, null, new ExtendedModelMap()); assertTrue(false); } catch (ForbiddenPageException fue) { assertTrue(true); } }
Example #2
Source File: CategoryControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void deleteCategory_invalidValidRequest_nullWidgetToDelete(){ Model model = new ExtendedModelMap(); User user = new UserImpl(); String id = "1"; String categoryText = "Social"; CategoryImpl category = new CategoryImpl(); category.setCreatedUserId(user.getId()); category.setText(categoryText); category.setId(id); SessionStatus sessionStatus = createMock(SessionStatus.class); expect(userService.getAuthenticatedUser()).andReturn(user).once(); expect(categoryService.get(id)).andReturn(null).once(); replay(userService, categoryService); String view = controller.deleteCategory(category, validToken, validToken,"true",REFERRER_ID, model, sessionStatus); assertEquals("ViewName match", ViewNames.ADMIN_CATEGORY_DETAIL, view); assertFalse("empty model", model.asMap().isEmpty()); verify(userService, categoryService); }
Example #3
Source File: UserControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void deleteUserDetail_success() { ModelMap modelMap = new ExtendedModelMap(); String userid = "123"; final String email = "[email protected]"; User user = new UserImpl(userid, "john.doe.sr"); user.setPassword("secrect"); user.setConfirmPassword(user.getConfirmPassword()); user.setEmail(email); SessionStatus sessionStatus = createMock(SessionStatus.class); userService.deleteUser(user.getId()); sessionStatus.setComplete(); expectLastCall(); replay(userService, sessionStatus); final String view = controller.deleteUserDetail(user, validToken, validToken, "true",REFERRER_ID, modelMap, sessionStatus); verify(userService, sessionStatus); assertEquals("redirect:/app/admin/users?action=delete&referringPageId=" + REFERRER_ID, view); }
Example #4
Source File: ServletAnnotationControllerHandlerMethodTests.java From java-technology-stack with MIT License | 6 votes |
@Override public ModelAndView resolveModelAndView(Method handlerMethod, Class<?> handlerType, Object returnValue, ExtendedModelMap implicitModel, NativeWebRequest webRequest) { if (returnValue instanceof MySpecialArg) { return new ModelAndView(new View() { @Override public String getContentType() { return "text/html"; } @Override public void render(@Nullable Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.getWriter().write("myValue"); } }); } return UNRESOLVED; }
Example #5
Source File: PageListControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * if the id cannot be converted as Long, the ForbiddenPageException is * caught. * * @throws Exception */ public void testDisplayPageListWithWrongAuditId() throws Exception { System.out.println("testDisplayPageListWithWrongAuditId"); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(TgolKeyStore.AUDIT_ID_KEY, "wrongId"); try { instance.displayPageList( request, new MockHttpServletResponse(), new ExtendedModelMap()); assertTrue(false); } catch (ForbiddenPageException fbe) { assertTrue( StringUtils.equals( "java.lang.NumberFormatException: For input string: \"wrongId\"", fbe.getCause().toString())); } }
Example #6
Source File: PageListControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * The PageList cannot be displayed when the webResource is a Page * instance. The returned view is an access denied in this case. * * @throws Exception */ public void testDisplayPageListWithPageAudit() throws Exception { System.out.println("testDisplayPageListWithPageAudit"); // The audit with Id 1 is associated with a Page instance setUpMockAuditDataService(PAGE_AUDIT_ID); setUpMockUserDataService(); setUpActDataService(false); setUpMockAuthenticationContext(); HttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(TgolKeyStore.AUDIT_ID_KEY, String.valueOf(PAGE_AUDIT_ID)); try { instance.displayPageList(request, response, new ExtendedModelMap()); assertTrue(false); } catch (ForbiddenPageException fbe) { // The exception is caught when testing if audit.getSubject() is // an instance of Page assertTrue(true); } }
Example #7
Source File: PortalPreferenceControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void testEditPreferences() { Model model = new ExtendedModelMap(); Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); expect(service.getPreferencesAsMap()).andReturn(preferenceMap); replay(service); String view = controller.editPreferences(model,REFERRER_ID); assertEquals(ViewNames.ADMIN_PREFERENCE_DETAIL, view); assertTrue(model.asMap().get("preferenceForm") instanceof PortalPreferenceForm); assertTrue(model.containsAttribute(ModelKeys.TOKENCHECK)); assertTrue(model.containsAttribute("topnav")); assertTrue(model.containsAttribute("tabs")); assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID))); }
Example #8
Source File: FileConverQueueTask.java From kkFileViewOfficeEdit with Apache License 2.0 | 6 votes |
@Override public void run() { while (true) { try { final RBlockingQueue<String> queue = redissonClient.getBlockingQueue(FileConverQueueTask.queueTaskName); String url = queue.take(); if(url!=null){ FileAttribute fileAttribute=fileUtils.getFileAttribute(url); logger.info("正在处理转换任务,文件名称【{}】",fileAttribute.getName()); FileType fileType=fileAttribute.getType(); if(fileType.equals(FileType.compress) || fileType.equals(FileType.office)){ FilePreview filePreview=previewFactory.get(url); filePreview.filePreviewHandle(url,new ExtendedModelMap()); } } } catch (Exception e) { try { Thread.sleep(1000*10); }catch (Exception ex){ ex.printStackTrace(); } e.printStackTrace(); } } }
Example #9
Source File: CategoryControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test(expected = SecurityException.class) public void updateCategory_invalidToken(){ Model model = new ExtendedModelMap(); User user = new UserImpl(); String id = "1"; String categoryText = "Social"; String invalidToken = AdminControllerUtil.generateSessionToken(); CategoryImpl category = new CategoryImpl(); category.setCreatedUserId(user.getId()); category.setText(categoryText); category.setId(id); SessionStatus sessionStatus = createMock(SessionStatus.class); expect(userService.getAuthenticatedUser()).andReturn(user).once(); expect(categoryService.get(id)).andReturn(category); expect(categoryService.update(id, categoryText, user)).andReturn(category); sessionStatus.setComplete(); expectLastCall(); replay(userService, categoryService,sessionStatus); String view = controller.updateCategory(category, validToken, invalidToken,REFERRER_ID, model, sessionStatus);assertTrue("Test should catch exception and never hit this test", false); assertTrue("Test should catch exception and never hit this test", false); }
Example #10
Source File: UserControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test(expected = SecurityException.class) public void updateUserDetail_wrongToken() { ModelMap modelMap = new ExtendedModelMap(); UserImpl user = new UserImpl("123", "john.doe.sr"); final BindingResult errors = new BeanPropertyBindingResult(user, "user"); SessionStatus sessionStatus = createMock(SessionStatus.class); sessionStatus.setComplete(); expectLastCall(); replay(sessionStatus); String otherToken = AdminControllerUtil.generateSessionToken(); controller.updateUserDetail(user, errors, validToken, otherToken,REFERRER_ID, modelMap, sessionStatus); verify(sessionStatus); assertFalse("SecurityException", true); }
Example #11
Source File: UserManagementControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * Test of displayAdminPage method, of class UserManagementController. */ public void testDisplayAdminPageWithDeletedUserMessage() { System.out.println("DisplayAdminPageWithDeletedUserMessage"); instance = new UserManagementController(); setUpMockRoleDataService(); setUpMockUserDataService(false, false, false, false, false); setUpMockAuthenticationContext(); instance.setUserDataService(mockUserDataService); HttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.getSession().setAttribute(TgolKeyStore.DELETED_USER_NAME_KEY, "DeletedUserName"); Model model = new ExtendedModelMap(); String result = instance.displayAdminPage(request, response, model); assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result); assertTrue(model.asMap().containsKey(TgolKeyStore.DELETED_USER_NAME_KEY)); assertEquals(model.asMap().get(TgolKeyStore.DELETED_USER_NAME_KEY),"DeletedUserName"); }
Example #12
Source File: AuditSetUpControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
public void testDisplayPageAuditSiteSetUpWithUnauthorisedFunctionality() { System.out.println("testDisplayPageAuditSiteSetUpWithUnauthorisedFunctionality"); setUpMockUserDataServiceAndUser(); setUpMockAuthenticationContext(); setUpMockContractDataService(2,"Contract1"); setUpEmptyViewFunctionalityBindingMap(); // the functionality associated with the contract is not allowed // regarding the viewFunctionalityBindingMap. An exception is caught try { instance.displaySiteAuditSetUp("2", null, null, new ExtendedModelMap()); assertTrue(false); } catch (ForbiddenPageException fue) { assertTrue(true); } }
Example #13
Source File: CommandControllerTest.java From lognavigator with Apache License 2.0 | 6 votes |
@Test public void testExecuteCommand_ModelMap() throws Exception { // given ExtendedModelMap model = new ExtendedModelMap(); String logAccessConfigId ="one-id"; String cmd = "cat file.log"; String encoding = Constants.DEFAULT_ENCODING_OPTION; DisplayType displayType = DisplayType.RAW; // when String viewName = commandController.executeCommand(model, request, logAccessConfigId, cmd, encoding, displayType); // then Assert.assertEquals(Constants.VIEW_RAW, viewName); Assert.assertEquals(true, request.getAttribute(Constants.SHOW_OPTIONS_KEY)); Assert.assertEquals(encoding, request.getAttribute(Constants.ENCODING_KEY)); Assert.assertEquals(displayType, request.getAttribute(Constants.DISPLAY_TYPE_KEY)); Assert.assertNotNull(request.getAttribute(Constants.BREADCRUMBS_KEY)); Assert.assertNotNull(model.get(Constants.RAW_CONTENT_KEY)); }
Example #14
Source File: CategoryControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test(expected = SecurityException.class) public void createCategory_invalidToken(){ Model model = new ExtendedModelMap(); String invalidToken = AdminControllerUtil.generateSessionToken(); User user = new UserImpl(); String categoryText = "Social"; CategoryImpl category = new CategoryImpl(); category.setText(categoryText); SessionStatus sessionStatus = createMock(SessionStatus.class); expect(userService.getAuthenticatedUser()).andReturn(user).once(); expect(categoryService.create(categoryText, user)).andReturn(new CategoryImpl()); sessionStatus.setComplete(); expectLastCall(); replay(userService, categoryService,sessionStatus); String view = controller.createCategory(category, validToken, invalidToken,REFERRER_ID, model, sessionStatus); assertTrue("Test should catch exception and never hit this test", false); }
Example #15
Source File: CategoryControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void createCategory_valid(){ Model model = new ExtendedModelMap(); User user = new UserImpl(); String categoryText = "Social"; CategoryImpl category = new CategoryImpl(); category.setText(categoryText); SessionStatus sessionStatus = createMock(SessionStatus.class); expect(userService.getAuthenticatedUser()).andReturn(user).once(); expect(categoryService.create(categoryText, user)).andReturn(new CategoryImpl()); sessionStatus.setComplete(); expectLastCall(); replay(userService, categoryService,sessionStatus); String view = controller.createCategory(category, validToken, validToken,REFERRER_ID, model, sessionStatus); assertEquals("ViewName match", "redirect:/app/admin/categories?action=create&referringPageId=" +REFERRER_ID, view); assertTrue("empty model", model.asMap().isEmpty()); verify(userService, categoryService, sessionStatus); }
Example #16
Source File: AuditSetUpControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
public void testDisplayPageAuditUploadSetUpWithWrongContractId() { System.out.println("testDisplayPageAuditUploadSetUpWithWrongContractId"); // set-up setUpMockUserDataServiceAndUser(); setUpMockAuthenticationContext(); setUpMockContractDataService(1,"Contract1"); // the contract Id cannot be converted as a Long. An exception is caught try { instance.displayUploadAuditSetUp("Not a number", null, null, new ExtendedModelMap()); assertTrue(false); } catch (ForbiddenPageException fue) { assertTrue(true); } }
Example #17
Source File: WidgetControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void updateWidget_valid() { final String widgetUrl = "http://example.com/widget"; WidgetImpl widget = new WidgetImpl("123", widgetUrl); widget.setTitle("WidgetImpl title"); widget.setType("OpenSocial"); widget.setDescription("Lorem ipsum"); BindingResult errors = new BeanPropertyBindingResult(widget, "widget"); SessionStatus sessionStatus = createMock(SessionStatus.class); ModelMap modelMap = new ExtendedModelMap(); expect(service.getWidgetByUrl(widgetUrl)).andReturn(widget); service.updateWidget(widget); sessionStatus.setComplete(); expectLastCall(); replay(service, sessionStatus); String view = controller.updateWidgetDetail(widget, errors, validToken, validToken,REFERRER_ID, modelMap, sessionStatus); verify(service, sessionStatus); assertFalse("No errors", errors.hasErrors()); assertEquals("redirect:/app/admin/widgets?action=update&referringPageId=" +REFERRER_ID, view); }
Example #18
Source File: WidgetControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void searchWidgets() throws Exception { Model model = new ExtendedModelMap(); String searchTerm = "widget"; String type = "OpenSocial"; String status = "published"; PortalPreferenceService preferenceService = createMock(PortalPreferenceService.class); expect(preferenceService.getPreference(PortalPreferenceKeys.PAGE_SIZE)).andReturn(null); replay(preferenceService); SearchResult<Widget> widgetSearchResult = populateWidgetSearchResult(); expect(service.getWidgetsBySearchCriteria(searchTerm, type, status, DEFAULT_OFFSET, DEFAULT_PAGESIZE)).andReturn(widgetSearchResult); replay(service); String searchView = controller.searchWidgets(searchTerm, type, status, DEFAULT_OFFSET,REFERRER_ID, model); verify(service); assertEquals(ViewNames.ADMIN_WIDGETS, searchView); assertEquals(searchTerm, model.asMap().get(ModelKeys.SEARCH_TERM)); assertEquals(type, model.asMap().get("selectedWidgetType")); assertEquals(status, model.asMap().get("selectedWidgetStatus")); assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID))); }
Example #19
Source File: AuditSetUpControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
public void testDisplayPageAuditSiteSetUp() { System.out.println("testDisplayPageAuditSiteSetUp"); // Set-up setUpMockUserDataServiceAndUser(); setUpMockAuthenticationContext(); setUpMockContractDataService(1,"Contract1"); setUpViewFunctionalityBindingMap(); setUpAuditSetUpCommandFactory(); Model model = new ExtendedModelMap(); String returnedView = instance.displaySiteAuditSetUp("1", null, null, model); // assertions assertEquals(TgolKeyStore.AUDIT_SITE_SET_UP_VIEW_NAME, returnedView); assertEquals("http://www.test1.com", model.asMap().get(TgolKeyStore.URL_KEY)); assertEquals(true, model.asMap().get(TgolKeyStore.DEFAULT_PARAM_SET_KEY)); }
Example #20
Source File: AuditSetUpControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
public void testDisplayPageAuditPageSetUp() { System.out.println("testDisplayPageAuditPageSetUp"); // set-up setUpMockUserDataServiceAndUser(); setUpMockAuthenticationContext(); setUpMockContractDataService(1,"Contract1"); setUpViewFunctionalityBindingMap(); setUpAuditSetUpCommandFactory(); Model model = new ExtendedModelMap(); // test String returnedView = instance.displayPageAuditSetUp("1", null, null, model); // assertions assertEquals(TgolKeyStore.AUDIT_PAGE_SET_UP_VIEW_NAME, returnedView); assertEquals("http://www.test1.com", model.asMap().get(TgolKeyStore.URL_KEY)); assertEquals(false, model.asMap().get(TgolKeyStore.DEFAULT_PARAM_SET_KEY)); // TO DO : write test to control the integrity of data of the AuditSetUpCommand // regarding the option/functionality rules }
Example #21
Source File: HandlerMethodInvoker.java From lams with GNU General Public License v2.0 | 6 votes |
private WebDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam, ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception { // Bind request parameter onto object... String name = attrName; if ("".equals(name)) { name = Conventions.getVariableNameForParameter(methodParam); } Class<?> paramType = methodParam.getParameterType(); Object bindObject; if (implicitModel.containsKey(name)) { bindObject = implicitModel.get(name); } else if (this.methodResolver.isSessionAttribute(name, paramType)) { bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name); if (bindObject == null) { raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session"); } } else { bindObject = BeanUtils.instantiateClass(paramType); } WebDataBinder binder = createBinder(webRequest, bindObject, name); initBinder(handler, name, binder, webRequest); return binder; }
Example #22
Source File: CommandControllerTest.java From lognavigator with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testExecuteCommand_BreadCrumbs_ListTarGzEntry() throws Exception { // given ExtendedModelMap model = new ExtendedModelMap(); String logAccessConfigId ="one-id"; String cmd = "tar -O -zxf backup/apache-access.tar.gz backup/apache-access-3l.log.gz | gzip -dc | tail -1000"; String encoding = Constants.DEFAULT_ENCODING_OPTION; DisplayType displayType = DisplayType.RAW; // when commandController.executeCommand(model, request, logAccessConfigId, cmd, encoding, displayType); // then List<Breadcrumb> breadcrumbs = (List<Breadcrumb>) request.getAttribute(Constants.BREADCRUMBS_KEY); Assert.assertEquals(4, breadcrumbs.size()); Assert.assertEquals(logAccessConfigId, breadcrumbs.get(0).getLabel()); Assert.assertEquals("backup", breadcrumbs.get(1).getLabel()); Assert.assertEquals("apache-access.tar.gz", breadcrumbs.get(2).getLabel()); Assert.assertEquals("apache-access-3l.log.gz", breadcrumbs.get(3).getLabel()); }
Example #23
Source File: PortalPreferenceControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void testUpdatePreferences_invalidPageSizeValue() { ModelMap model = new ExtendedModelMap(); HashMap<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); PortalPreference pageSizePref = new PortalPreferenceImpl(PortalPreferenceKeys.PAGE_SIZE, "invalid"); preferenceMap.put(PortalPreferenceKeys.PAGE_SIZE, pageSizePref); PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap); final BindingResult errors = new BeanPropertyBindingResult(form, "form"); SessionStatus sessionStatus = createMock(SessionStatus.class); replay(service, sessionStatus); String view = controller.updatePreferences(form, errors, validToken, validToken,REFERRER_ID, model, sessionStatus); assertEquals(ViewNames.ADMIN_PREFERENCE_DETAIL, view); assertTrue(errors.hasErrors()); assertTrue(model.containsAttribute("topnav")); assertTrue(model.containsAttribute("tabs")); assertFalse("Model has not been cleared", model.isEmpty()); verify(service, sessionStatus); }
Example #24
Source File: CategoryControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void updateCategory_invalidValidRequest_nullUser(){ Model model = new ExtendedModelMap(); String id = "1"; User user = new UserImpl(); String categoryText = "Social"; CategoryImpl category = new CategoryImpl(); category.setCreatedUserId(user.getId()); category.setText(categoryText); category.setId(id); SessionStatus sessionStatus = createMock(SessionStatus.class); expect(userService.getAuthenticatedUser()).andReturn(user).once(); replay(userService); String view = controller.updateCategory(category, validToken, validToken,REFERRER_ID, model, sessionStatus); assertEquals("ViewName match", ViewNames.ADMIN_CATEGORY_DETAIL, view); assertFalse("empty model", model.asMap().isEmpty()); verify(userService); }
Example #25
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("rawtypes") public ModelAndView resolveModelAndView(Method handlerMethod, Class handlerType, Object returnValue, ExtendedModelMap implicitModel, NativeWebRequest webRequest) { if (returnValue instanceof MySpecialArg) { return new ModelAndView(new View() { @Override public String getContentType() { return "text/html"; } @Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.getWriter().write("myValue"); } }); } return UNRESOLVED; }
Example #26
Source File: PortalPreferenceControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void testViewPreferences_afterUpdate() { Model model = new ExtendedModelMap(); Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); expect(service.getPreferencesAsMap()).andReturn(preferenceMap); replay(service); final String action = "update"; String view = controller.viewPreferences(action,REFERRER_ID, model); assertEquals(ViewNames.ADMIN_PREFERENCES, view); assertEquals(preferenceMap, model.asMap().get("preferenceMap")); assertEquals(action, model.asMap().get("actionresult")); assertTrue(model.containsAttribute("topnav")); assertTrue(model.containsAttribute("tabs")); assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID))); verify(service); }
Example #27
Source File: PageListControllerTest.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * The servlet is supposed to embed the audit id the page is * about. If not, the ForbiddenPageException is caught. * @throws Exception */ public void testDisplayPageListWithoutAuditId() throws Exception { System.out.println("testDisplayPageListWithoutAuditId"); // The servlet is supposed to embed the webresource id the page is // about. If not, the access denied page is returned try { instance.displayPageList( new MockHttpServletRequest(), new MockHttpServletResponse(), new ExtendedModelMap()); assertTrue(false); } catch (AuditParameterMissingException fbe) { assertTrue(true); } }
Example #28
Source File: TwoFactorAuthenticationControllerTest.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void authenticateExceptionTest() { String secretKey = "secretKey"; String verificationCode = "123456"; TwoFactorAuthenticationToken authToken = new TwoFactorAuthenticationToken(verificationCode, null); when(twoFactorAuthenticationProvider.authenticate(authToken)) .thenThrow(new InvalidVerificationCodeException("Invalid verification code entered")); Model model = new ExtendedModelMap(); String viewTemplate = twoFactorAuthenticationController.authenticate(model, verificationCode, secretKey); assertEquals(secretKey, model.asMap().get(ATTRIBUTE_2FA_SECRET_KEY)); assertEquals(model.asMap().get(ERROR_MESSAGE_ATTRIBUTE), "Invalid verification code entered"); assertEquals("view-2fa-activation-modal", viewTemplate); }
Example #29
Source File: CommandControllerTest.java From lognavigator with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testExecuteCommand_BreadCrumbs_TailFile() throws Exception { // given ExtendedModelMap model = new ExtendedModelMap(); String logAccessConfigId ="one-id"; String cmd = "tail -1000 file.log"; String encoding = Constants.DEFAULT_ENCODING_OPTION; DisplayType displayType = DisplayType.RAW; // when commandController.executeCommand(model, request, logAccessConfigId, cmd, encoding, displayType); // then List<Breadcrumb> breadcrumbs = (List<Breadcrumb>) request.getAttribute(Constants.BREADCRUMBS_KEY); Assert.assertEquals(2, breadcrumbs.size()); Assert.assertEquals(logAccessConfigId, breadcrumbs.get(0).getLabel()); Assert.assertEquals("file.log", breadcrumbs.get(1).getLabel()); }
Example #30
Source File: WidgetStoreControllerTest.java From attic-rave with Apache License 2.0 | 6 votes |
@Test public void doAddWidget_existing() { final String widgetUrl = "http://example.com/existingwidget.xml"; final Model model = new ExtendedModelMap(); final WidgetImpl existingWidget = new WidgetImpl(); existingWidget.setId("123"); existingWidget.setTitle("Widget title"); existingWidget.setUrl(widgetUrl); existingWidget.setType("OpenSocial"); final WidgetImpl widget = new WidgetImpl(); widget.setTitle("Widget title"); widget.setUrl(widgetUrl); widget.setType("OpenSocial"); final BindingResult errors = new BeanPropertyBindingResult(widget, "widget"); expect(widgetService.isRegisteredUrl(widgetUrl)).andReturn(true); replay(widgetService); String view = controller.viewAddWidgetResult(widget, errors, model,REFERRER_ID); verify(widgetService); assertEquals(ViewNames.ADD_WIDGET_FORM, view); assertTrue("Valid widget data", errors.hasErrors()); assertNotNull(model.asMap().get(ModelKeys.WIDGET)); }