Search in sources :

Example 36 with Authority

use of io.github.jhipster.sample.domain.Authority in project jhipster-sample-app-dto by jhipster.

the class UserResourceIntTest method testAuthorityEquals.

@Test
public void testAuthorityEquals() throws Exception {
    Authority authorityA = new Authority();
    assertThat(authorityA).isEqualTo(authorityA);
    assertThat(authorityA).isNotEqualTo(null);
    assertThat(authorityA).isNotEqualTo(new Object());
    assertThat(authorityA.hashCode()).isEqualTo(0);
    assertThat(authorityA.toString()).isNotNull();
    Authority authorityB = new Authority();
    assertThat(authorityA).isEqualTo(authorityB);
    authorityB.setName(AuthoritiesConstants.ADMIN);
    assertThat(authorityA).isNotEqualTo(authorityB);
    authorityA.setName(AuthoritiesConstants.USER);
    assertThat(authorityA).isNotEqualTo(authorityB);
    authorityB.setName(AuthoritiesConstants.USER);
    assertThat(authorityA).isEqualTo(authorityB);
    assertThat(authorityA.hashCode()).isEqualTo(authorityB.hashCode());
}
Also used : Authority(io.github.jhipster.sample.domain.Authority) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with Authority

use of io.github.jhipster.sample.domain.Authority in project jhipster-sample-app-dto by jhipster.

the class UserMapper method userDTOToUser.

public User userDTOToUser(UserDTO userDTO) {
    if (userDTO == null) {
        return null;
    } else {
        User user = new User();
        user.setId(userDTO.getId());
        user.setLogin(userDTO.getLogin());
        user.setFirstName(userDTO.getFirstName());
        user.setLastName(userDTO.getLastName());
        user.setEmail(userDTO.getEmail());
        user.setImageUrl(userDTO.getImageUrl());
        user.setActivated(userDTO.isActivated());
        user.setLangKey(userDTO.getLangKey());
        Set<Authority> authorities = this.authoritiesFromStrings(userDTO.getAuthorities());
        if (authorities != null) {
            user.setAuthorities(authorities);
        }
        return user;
    }
}
Also used : User(io.github.jhipster.sample.domain.User) Authority(io.github.jhipster.sample.domain.Authority)

Aggregations

Authority (io.github.jhipster.sample.domain.Authority)37 User (io.github.jhipster.sample.domain.User)24 Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 UserDTO (io.github.jhipster.sample.service.dto.UserDTO)7 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 ChangeSet (com.github.mongobee.changeset.ChangeSet)2 HashSet (java.util.HashSet)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 Transactional (org.springframework.transaction.annotation.Transactional)1