Package org.apache.rave.model

Examples of org.apache.rave.model.Authority


        verify(template);
    }

    @Test
    public void save_valid(){
        Authority savedAuth = new MongoDbAuthority();
        Authority returnedAuth;
        savedAuth.setAuthority("test");

        expect(template.findOne(query(where("authority").is("test")), CLASS, AUTHORITY_COLLECTION)).andReturn((MongoDbAuthority)savedAuth);
        template.save(isA(Authority.class), eq(AUTHORITY_COLLECTION));
        expectLastCall();

        replay(template);

        returnedAuth = repo.save(savedAuth);
        assertThat(savedAuth.isDefaultForNewUser(), is(equalTo(returnedAuth.isDefaultForNewUser())));
        assertNotNull(template);
        assertThat(savedAuth, is(sameInstance(returnedAuth)));
        verify(template);

    }
View Full Code Here


    }

    @Test
    public void delete(){
        Authority deleted = new MongoDbAuthority();
        deleted.setAuthority("deleted");

        template.remove(isA(Authority.class), eq(AUTHORITY_COLLECTION));
        expectLastCall();
        expect(template.findOne(query(where("authority").is("deleted")), CLASS, AUTHORITY_COLLECTION)).andReturn((MongoDbAuthority)deleted);
        replay(template);
View Full Code Here

        verify(template);
    }

    @Test
    public void getByAuthority(){
        Authority authority = new MongoDbAuthority();
        authority.setAuthority("test");
        Authority result;
        template.save(authority, AUTHORITY_COLLECTION);

        expect(template.findOne(query(where("authority").is("test")), CLASS, AUTHORITY_COLLECTION)).andReturn((MongoDbAuthority)authority);
        replay(template);
View Full Code Here


    @Test
    public void getAll(){
        List<Authority> allAuth = Lists.newLinkedList();
        Authority authority = new MongoDbAuthority();
        authority.setAuthority("test");
        allAuth.add(authority);

        expect(CollectionUtils.<Authority>toBaseTypedList(template.findAll(CLASS, AUTHORITY_COLLECTION))).andReturn(allAuth);
        replay(template);
View Full Code Here

    }

    @Test
    public void getAllDefault(){
        List<Authority> allDefaultAuth = Lists.newLinkedList();
        Authority authority = new MongoDbAuthority();
        authority.setAuthority("test");
        authority.setDefaultForNewUser(true);
        allDefaultAuth.add(authority);

        expect(CollectionUtils.<Authority>toBaseTypedList(template.find(query(where("defaultForNewUser").is(true)), CLASS, AUTHORITY_COLLECTION))).andReturn(allDefaultAuth);
        replay(template);
View Full Code Here


    @Test
    public void getAllDefault_false(){
        List<Authority> allDefaultAuth = Lists.newLinkedList();
        Authority authority = new MongoDbAuthority();
        authority.setDefaultForNewUser(false);
        allDefaultAuth.add(authority);

        expect(CollectionUtils.<Authority>toBaseTypedList(template.find(query(where("defaultForNewUser").is(true)), CLASS, AUTHORITY_COLLECTION))).andReturn(null);
        replay(template);
View Full Code Here

    }

    @Test
    public void getByAuthorityName() {
        String authorityName = "administrator";
        Authority authority = repository.getByAuthority(authorityName);
        assertNotNull(authority);
        assertEquals(authorityName, authority.getAuthority());
        assertTrue(authority.getUsers().isEmpty());
    }
View Full Code Here

    }

    @Test
    public void getUsersByAuthorityName() {
        String authorityName = "administrator";
        Authority authority = repository.getByAuthority(authorityName);
        assertNotNull(authority);
        assertEquals(authorityName, authority.getAuthority());
        assertTrue(authority.getUsers().isEmpty());

        User newUser = new JpaUser();
        newUser.setUsername("adminuser");
        newUser.addAuthority(authority);
        newUser = userRepository.save(newUser);
        assertEquals(authority, newUser.getAuthorities().iterator().next());

        authority = repository.getByAuthority(authorityName);
        assertEquals(1, authority.getUsers().size());
    }
View Full Code Here

    }

    @Test
    public void addOrDeleteAuthorityDoesNotAffectUser() {
        final String authorityName = "guest";
        Authority authority = new JpaAuthority();
        authority.setAuthority(authorityName);
        User user = userRepository.get("1");

        Assert.assertNotNull("User is null", user);
        Assert.assertTrue("User has no authorities", user.getAuthorities().isEmpty());
        assertNull("No authority guest", repository.getByAuthority(authorityName));
View Full Code Here

        assertThat(user.getOpenId(), is(equalTo(OPENID)));
    }

    @Test
    public void addOrDeleteUserDoesNotAffectAuthority() {
        Authority authority = authorityRepository.get("1");
        Assert.assertNotNull("Existing authority", authority);

        int usercount = authority.getUsers().size();
        User user = new JpaUser();
        user.setUsername("dummy");
        authority.addUser(user);
        authorityRepository.save(authority);
        assertNull("Persisting an Authority does not persist an unknown user", repository.getByUsername("dummy"));
        Assert.assertEquals("Authority has 1 more user", usercount + 1, authority.getUsers().size());

        repository.save(user);
        user = repository.getByUsername("dummy");
        Assert.assertNotNull(user);
        Assert.assertEquals("Authority has 1 more user", usercount + 1, authority.getUsers().size());

        repository.delete(user);
        authority = authorityRepository.get("1");
        Assert.assertNotNull("Authority has not been removed after deleting user", authority);
        Assert.assertEquals("Authority has original amount of users", usercount, authority.getUsers().size());
    }
View Full Code Here

TOP

Related Classes of org.apache.rave.model.Authority

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.