Java Code Examples for org.springframework.ui.ExtendedModelMap

The following examples show how to use org.springframework.ui.ExtendedModelMap. These examples are extracted from open source projects. 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 Project: attic-rave   Source File: UserControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
Source Project: attic-rave   Source File: CategoryControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: kkFileViewOfficeEdit   Source File: FileConverQueueTask.java    License: Apache License 2.0 6 votes vote down vote up
@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 4
Source Project: attic-rave   Source File: PortalPreferenceControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 5
/**
 * 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 6
/**
 * 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 7
Source Project: attic-rave   Source File: CategoryControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 8
@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 9
Source Project: attic-rave   Source File: CategoryControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void deleteCategory_valid(){
    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(category).anyTimes();
    categoryService.delete(category);
    expectLastCall();
    sessionStatus.setComplete();
    expectLastCall();
    replay(userService, categoryService,sessionStatus);
    String view = controller.deleteCategory(category, validToken, validToken, "true",REFERRER_ID, model,sessionStatus);
    assertEquals("ViewName match", "redirect:/app/admin/categories?action=delete&referringPageId=" + REFERRER_ID, view);
    assertTrue("empty model", model.asMap().isEmpty());
    verify(userService, categoryService, sessionStatus);
}
 
Example 10
Source Project: attic-rave   Source File: CategoryControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 11
Source Project: attic-rave   Source File: CategoryControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 12
Source Project: attic-rave   Source File: WidgetControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 13
Source Project: lams   Source File: HandlerMethodInvoker.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 14
Source Project: attic-rave   Source File: PortalPreferenceControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 15
Source Project: attic-rave   Source File: CategoryControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 16
Source Project: attic-rave   Source File: PortalPreferenceControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 17
/**
 * 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 18
Source Project: lognavigator   Source File: CommandControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 19
Source Project: attic-rave   Source File: WidgetStoreControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 20
@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 21
@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 22
Source Project: lognavigator   Source File: CommandControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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
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 24
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 25
Source Project: attic-rave   Source File: WidgetControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 26
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 27
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 28
Source Project: lognavigator   Source File: CommandControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 29
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 30
Source Project: attic-rave   Source File: UserControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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);

}