Package org.ngrinder.model

Examples of org.ngrinder.model.User


  @Test
  public void testUserHandlerMethodArgument() throws Exception {

    // create a tmp test user "TEST2_USER" for this test
    User user = new User();
    user.setUserId("TEST2_USER");
    user.setUserName("TEST2_USER");
    user.setEmail("TEST2_USER@nhn.com");
    user.setPassword("123");
    user.setRole(Role.USER);
    user = userRepository.save(user);
    User testUser = getTestUser();
    testUser.setFollowers(Lists.newArrayList(user));
    userRepository.save(testUser);

    resolver = new UserHandlerMethodArgumentResolver() {
      @Override
      Cookie[] getCookies(NativeWebRequest webRequest) {
        return new Cookie[] { new Cookie("switchUser", switchUser) };
      }
    };
    resolver.setUserService(userService);
    MethodParameter parameter = mock(MethodParameter.class);
    final Class<?> class1 = User.class;
    when(parameter.getParameterType()).thenAnswer(new Answer<Class<?>>() {
      @Override
      public Class<?> answer(InvocationOnMock invocation) throws Throwable {
        return class1;
      }
    });
    assertThat(resolver.supportsParameter(parameter), is(true));

    // test1 scenario: general user can not check other user's script
    // has parameter "ownerId", and current user is general, resolved user is "TEST_USER"
    ServletWebRequest webRequest1 = mock(ServletWebRequest.class);
    when(webRequest1.getParameter("ownerId")).thenReturn("TEST2_USER");
    resolver.setUserContext(mockUserContext);
    Object resolveArgument1 = resolver.resolveArgument(parameter, null, webRequest1, null);
    assertThat(((User) resolveArgument1).getUserId(), is(getTestUser().getUserId()));

    // test2 scenario: admin can check other user's script
    // has parameter "ownerId", and current user is Admin, resolved user is "TEST2_USER"
    ServletWebRequest webRequest2 = mock(ServletWebRequest.class);
    when(webRequest2.getParameter("ownerId")).thenReturn("TEST2_USER");
    User adminUser = new User("tmpAdminId", "tmpAdminId", "tmpAdminPwd", "admin@nhn.com", Role.ADMIN);
    MockUserContext adminUserContext = mock(MockUserContext.class);
    when(adminUserContext.getCurrentUser()).thenReturn(adminUser);
    resolver.setUserContext(adminUserContext);
    Object resolveArgument2 = resolver.resolveArgument(parameter, null, webRequest2, null);
    assertThat(((User) resolveArgument2).getUserId(), is("TEST2_USER"));

    // test3 scenario: general user switch to use other's permission
    // has parameter "switchUser", resolved user id is "TEST2_USER"
    ServletWebRequest webRequest3 = mock(ServletWebRequest.class);
    switchUser = "TEST2_USER";
    resolver.setUserContext(mockUserContext);
    User resolveArgument3 = cast(resolver.resolveArgument(parameter, null, webRequest3, null));
    assertThat(((User) resolveArgument3).getUserId(), is("TEST_USER"));
    // current user's owner is "TEST2_USER"
    // assertThat(resolveArgument3.getOwnerUser().getUserId(), is("TEST2_USER"));

    // test4 scenario: general user switch back to its own user permission
View Full Code Here


  private FileEntryService fileEntryService = new FileEntryService();

  @Test
  public void testFileTemplate() {
    User user = new User();
    user.setUserName("JunHo Yoon");
    String content = fileEntryService.loadTemplate(user, new JythonScriptHandler(), "http://helloworld/myname/is",
            "hello");
    assertThat(content, containsString("JunHo Yoon"));
    assertThat(content, containsString("http://helloworld/myname/is"));
  }
View Full Code Here

    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getParameter("user_timezone")).thenReturn("Korean");
    when(req.getParameter("native_language")).thenReturn("KoreanLang");
    HttpServletResponse res = mock(HttpServletResponse.class);
    filter.attemptAuthentication(req, res);
    User findOne = userRepository.findOne(getTestUser().getId());
    assertThat(findOne.getUserLanguage(), is("KoreanLang"));
    assertThat(findOne.getTimeZone(), is("Korean"));

  }
View Full Code Here

public class GroovyMavenProjectScriptHandlerTest {

  @Test
  public void testHandlerMatching() {
    GroovyMavenProjectScriptHandler handler = new GroovyMavenProjectScriptHandler();
    User user = new User("my", "my", "password", Role.ADMIN);
    FileEntryRepository serviceMock = mock(FileEntryRepository.class);
    when(serviceMock.hasOne(user, "/hello/world/pom.xml")).thenReturn(true);
    handler.setFileEntryRepository(serviceMock);

    FileEntry entry = new FileEntry();
View Full Code Here

  @Test
  public void testGetTestListByAdmin() {
    String testName = "new test1";
    createPerfTest(testName, Status.READY, new Date());
    ModelMap model = new ModelMap();
    User testAdmin = new User();
    testAdmin.setUserId("testAdmin");
    testAdmin.setPassword("testAdmin");
    testAdmin.setRole(Role.ADMIN);
    testAdmin.setTimeZone("Asia/Seoul");
    testAdmin = userService.save(testAdmin);

    controller.getAll(testAdmin, null, null, null, new PageRequest(0, 10), model);
    @SuppressWarnings("unchecked")
    Page<PerfTest> testPage = (Page<PerfTest>) model.get("testListPage");
View Full Code Here

    String testName = "new test1";
    PerfTest test = createPerfTest(testName, Status.READY, new Date());

    ModelMap model = new ModelMap();

    User otherTestUser = new User();
    otherTestUser.setUserId("testUser");
    otherTestUser.setPassword("testUser");
    otherTestUser.setRole(Role.USER);
    otherTestUser = userService.save(otherTestUser);
    otherTestUser.setTimeZone("Asia/Seoul");
    controller.getAll(otherTestUser, null, null, null, new PageRequest(0, 10), model);
    @SuppressWarnings("unchecked")
    Page<PerfTest> testPage = (Page<PerfTest>) model.get("testListPage");
    List<PerfTest> testList = testPage.getContent();
View Full Code Here

   * @return "user/detail"
   */
  @RequestMapping("/new")
  @PreAuthorize("hasAnyRole('A') or #user.userId == #userId")
  public String openForm(User user, final ModelMap model) {
    User one = User.createNew();
    model.addAttribute("user", one);
    model.addAttribute("allowUserIdChange", true);
    model.addAttribute("allowPasswordChange", true);
    model.addAttribute("allowRoleChange", false);
    model.addAttribute("newUser", true);
View Full Code Here

   * @return "user/detail"
   */
  @RequestMapping("/{userId}")
  @PreAuthorize("hasAnyRole('A')")
  public String getOne(@PathVariable final String userId, ModelMap model) {
    User one = userService.getOne(userId);
    model.addAttribute("user", one);
    model.addAttribute("allowPasswordChange", true);
    model.addAttribute("allowRoleChange", true);
    model.addAttribute("roleSet", EnumSet.allOf(Role.class));
    model.addAttribute("showPasswordByDefault", false);
View Full Code Here

   * @return "user/info"
   */
  @RequestMapping("/profile")
  public String getOne(User user, ModelMap model) {
    checkNotEmpty(user.getUserId(), "UserID should not be NULL!");
    User one = userService.getOne(user.getUserId());
    model.addAttribute("user", one);
    model.addAttribute("allowPasswordChange", !config.isDemo());
    model.addAttribute("allowRoleChange", false);
    model.addAttribute("showPasswordByDefault", false);
    attachCommonAttribute(one, model);
View Full Code Here

  @PreAuthorize("hasAnyRole('A') or #user.id == #updatedUser.id")
  public String save(User user, @ModelAttribute("user") User updatedUser, ModelMap model) {
    checkArgument(updatedUser.validate());
    if (user.getRole() == Role.USER) {
      // General user can not change their role.
      User updatedUserInDb = userService.getOne(updatedUser.getUserId());
      checkNotNull(updatedUserInDb);
      updatedUser.setRole(updatedUserInDb.getRole());

      // prevent user to modify with other user id
      checkArgument(updatedUserInDb.getId().equals(updatedUser.getId()), "Illegal request to update user:%s",
          updatedUser);
    }
    save(updatedUser);
    model.clear();
    if (user.getId().equals(updatedUser.getId())) {
View Full Code Here

TOP

Related Classes of org.ngrinder.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.