Search in sources :

Example 1 with User

use of org.jboss.pnc.dto.User in project pnc by project-ncl.

the class BuildEndpointTest method shouldFilterByBuildConfigurationNameAndUserId.

@Test
public void shouldFilterByBuildConfigurationNameAndUserId() throws Exception {
    BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
    String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
    String username = "pnc-admin";
    String rsql = "user.username==" + username;
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setBuildConfigName(buildConfigName);
    List<Build> builds = new ArrayList<>(client.getAll(filter, null, Optional.empty(), Optional.of(rsql)).getAll());
    assertThat(builds).hasSize(2);
    assertThat(builds.stream().map(Build::getBuildConfigRevision).map(BuildConfigurationRevisionRef::getName).allMatch(name -> name.equals(buildConfigName)));
    assertThat(builds.stream().map(Build::getUser).map(User::getUsername).allMatch(name -> name.equals(username)));
}
Also used : Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) User(org.jboss.pnc.dto.User) BadRequestException(javax.ws.rs.BadRequestException) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) Deployments(org.jboss.pnc.integration.setup.Deployments) ClientBase(org.jboss.pnc.client.ClientBase) BuildRef(org.jboss.pnc.dto.BuildRef) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) BASE_REST_PATH(org.jboss.pnc.integration.setup.RestClientConfiguration.BASE_REST_PATH) Set(java.util.Set) MAX_PAGE_SIZE(org.jboss.pnc.rest.configuration.Constants.MAX_PAGE_SIZE) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) ApacheHttpClient43EngineWithRetry(org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Optional(java.util.Optional) RestAssured.given(io.restassured.RestAssured.given) BeforeClass(org.junit.BeforeClass) BuildClient(org.jboss.pnc.client.BuildClient) Credentials(org.jboss.pnc.integration.setup.Credentials) BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) RunWith(org.junit.runner.RunWith) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ArrayList(java.util.ArrayList) ContainerTest(org.jboss.pnc.test.category.ContainerTest) HashSet(java.util.HashSet) ClientException(org.jboss.pnc.client.ClientException) Configuration(org.jboss.pnc.client.Configuration) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Attributes(org.jboss.pnc.constants.Attributes) Status(javax.ws.rs.core.Response.Status) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) Logger(org.slf4j.Logger) ForbiddenException(javax.ws.rs.ForbiddenException) Iterator(java.util.Iterator) IoUtils(org.jboss.pnc.common.util.IoUtils) DatabaseDataInitializer(org.jboss.pnc.demo.data.DatabaseDataInitializer) Test(org.junit.Test) IOException(java.io.IOException) InSequence(org.jboss.arquillian.junit.InSequence) Artifact(org.jboss.pnc.dto.Artifact) Field(java.lang.reflect.Field) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) Assertions.entry(org.assertj.core.api.Assertions.entry) Build(org.jboss.pnc.dto.Build) Deployment(org.jboss.arquillian.container.test.api.Deployment) ArtifactClient(org.jboss.pnc.client.ArtifactClient) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) BuildCategory(org.jboss.pnc.enums.BuildCategory) Collections(java.util.Collections) InputStream(java.io.InputStream) User(org.jboss.pnc.dto.User) Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) ArrayList(java.util.ArrayList) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with User

use of org.jboss.pnc.dto.User in project pnc by project-ncl.

the class UserEndpointTest method testGetUser.

@Test
public void testGetUser() throws ClientException {
    // when
    UserClient client = new UserClient(RestClientConfiguration.asUser());
    User user = client.getCurrentUser();
    // then
    assertThat(user).isNotNull();
    assertThat(user.getUsername()).isNotNull();
    assertThat(user.getId()).isNotNull();
    // when
    client = new UserClient(RestClientConfiguration.asSystem());
    user = client.getCurrentUser();
    // then
    assertThat(user).isNotNull();
    assertThat(user.getUsername()).isNotNull();
    assertThat(user.getId()).isNotNull();
}
Also used : UserClient(org.jboss.pnc.client.UserClient) User(org.jboss.pnc.dto.User) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 3 with User

use of org.jboss.pnc.dto.User in project pnc by project-ncl.

the class UserEndpointTest method testGetAllBuilds.

@Test
public void testGetAllBuilds() throws ClientException {
    UserClient client = new UserClient(RestClientConfiguration.asUser());
    BuildClient buildClient = new BuildClient(RestClientConfiguration.asAnonymous());
    BuildsFilterParameters params = new BuildsFilterParameters();
    params.setLatest(false);
    params.setRunning(false);
    RemoteCollection<Build> remoteBuilds = buildClient.getAllByStatusAndLogContaining(BuildStatus.SUCCESS, "fox");
    User user = remoteBuilds.iterator().next().getUser();
    RemoteCollection<Build> builds = client.getBuilds(user.getId(), params);
    assertThat(builds).isNotNull();
    assertThat(builds.size()).isGreaterThanOrEqualTo(1);
}
Also used : UserClient(org.jboss.pnc.client.UserClient) User(org.jboss.pnc.dto.User) Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 4 with User

use of org.jboss.pnc.dto.User in project pnc by project-ncl.

the class BuildStatusChangedTest method getBuild.

private Build getBuild() {
    ProjectRef projectRef = ProjectRef.refBuilder().id("1").name("A").description("desc").projectUrl("url1").issueTrackerUrl("url2").build();
    SCMRepository scmRepository = SCMRepository.builder().id("1").internalUrl("url1").externalUrl("url2").preBuildSyncEnabled(true).build();
    Environment buildEnvironment = Environment.builder().id("1").name("jdk8").description("desc").systemImageRepositoryUrl("url").systemImageId("11").systemImageType(SystemImageType.DOCKER_IMAGE).deprecated(true).build();
    User user = User.builder().id("1").username("user").build();
    BuildConfigurationRevisionRef buildConfigurationRevisionRef = BuildConfigurationRevisionRef.refBuilder().id("1").rev(1).name("name").buildScript("true").scmRevision("awqs21").build();
    return Build.builder().project(projectRef).scmRepository(scmRepository).environment(buildEnvironment).user(user).buildConfigRevision(buildConfigurationRevisionRef).status(BuildStatus.BUILDING).buildContentId("build-42").temporaryBuild(true).build();
}
Also used : User(org.jboss.pnc.dto.User) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Environment(org.jboss.pnc.dto.Environment) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Example 5 with User

use of org.jboss.pnc.dto.User in project pnc by project-ncl.

the class ArtifactProviderImpl method store.

@Override
@RolesAllowed(SYSTEM_USER)
public org.jboss.pnc.dto.Artifact store(org.jboss.pnc.dto.Artifact restEntity) throws DTOValidationException {
    org.jboss.pnc.model.User currentUser = userService.currentUser();
    User user = userMapper.toDTO(currentUser);
    Instant now = Instant.now();
    return super.store(restEntity.toBuilder().creationUser(user).modificationUser(user).creationTime(now).modificationTime(now).build());
}
Also used : User(org.jboss.pnc.dto.User) Instant(java.time.Instant) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

User (org.jboss.pnc.dto.User)6 ContainerTest (org.jboss.pnc.test.category.ContainerTest)3 Test (org.junit.Test)3 Instant (java.time.Instant)2 BuildClient (org.jboss.pnc.client.BuildClient)2 UserClient (org.jboss.pnc.client.UserClient)2 RestAssured.given (io.restassured.RestAssured.given)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 BadRequestException (javax.ws.rs.BadRequestException)1