Search in sources :

Example 1 with UserBuilder

use of io.fabric8.openshift.api.model.UserBuilder in project syndesis by syndesisio.

the class UserHandlerTest method successfulWhoAmIWithoutFullName.

@Test
public void successfulWhoAmIWithoutFullName() {
    openShiftServer.expect().get().withPath("/oapi/v1/users/~").andReturn(200, new UserBuilder().withNewMetadata().withName("testuser").and().build()).once();
    SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken("testuser", "doesn'tmatter"));
    UserHandler userHandler = new UserHandler(null, new OpenShiftServiceImpl(openShiftServer.getOpenshiftClient(), null));
    User user = userHandler.whoAmI();
    Assertions.assertThat(user).isNotNull();
    Assertions.assertThat(user.getUsername()).isEqualTo("testuser");
    Assertions.assertThat(user.getFullName()).isEmpty();
}
Also used : User(io.syndesis.common.model.user.User) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) OpenShiftServiceImpl(io.syndesis.server.openshift.OpenShiftServiceImpl) UserBuilder(io.fabric8.openshift.api.model.UserBuilder) Test(org.junit.Test)

Example 2 with UserBuilder

use of io.fabric8.openshift.api.model.UserBuilder in project syndesis by syndesisio.

the class UserHandlerTest method successfulWhoAmI.

@Test
public void successfulWhoAmI() {
    openShiftServer.expect().get().withPath("/oapi/v1/users/~").andReturn(200, new UserBuilder().withFullName("Test User").withNewMetadata().withName("testuser").and().build()).once();
    SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken("testuser", "doesn'tmatter"));
    UserHandler userHandler = new UserHandler(null, new OpenShiftServiceImpl(openShiftServer.getOpenshiftClient(), null));
    User user = userHandler.whoAmI();
    Assertions.assertThat(user).isNotNull();
    Assertions.assertThat(user.getUsername()).isEqualTo("testuser");
    Assertions.assertThat(user.getFullName()).isNotEmpty().hasValue("Test User");
}
Also used : User(io.syndesis.common.model.user.User) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) OpenShiftServiceImpl(io.syndesis.server.openshift.OpenShiftServiceImpl) UserBuilder(io.fabric8.openshift.api.model.UserBuilder) Test(org.junit.Test)

Aggregations

UserBuilder (io.fabric8.openshift.api.model.UserBuilder)2 User (io.syndesis.common.model.user.User)2 OpenShiftServiceImpl (io.syndesis.server.openshift.OpenShiftServiceImpl)2 Test (org.junit.Test)2 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)2