Search in sources :

Example 1 with BuildClient

use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.

the class BuildEndpointTest method shouldSortResults.

@Test
public void shouldSortResults() throws Exception {
    BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
    String sort = "=asc=submitTime";
    List<Long> notSorted = bc.getAll(null, null).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
    List<Long> sorted = bc.getAll(null, null, Optional.of(sort), Optional.empty()).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
    assertThat(notSorted).isNotEqualTo(sorted);
    assertThat(sorted).isSorted();
}
Also used : BuildRef(org.jboss.pnc.dto.BuildRef) BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with BuildClient

use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.

the class BuildEndpointTest method shouldFailAsRegularUser.

@Test
public void shouldFailAsRegularUser() {
    BuildClient client = new BuildClient(RestClientConfiguration.asUser());
    String buildRecordId = buildId;
    assertThatThrownBy(() -> client.setBuiltArtifacts(buildRecordId, Collections.emptyList())).hasCauseInstanceOf(ForbiddenException.class);
    assertThatThrownBy(() -> client.setDependentArtifacts(buildRecordId, Collections.emptyList())).hasCauseInstanceOf(ForbiddenException.class);
    assertThatThrownBy(() -> client.update(buildRecordId, Build.builder().build())).hasCauseInstanceOf(ForbiddenException.class);
}
Also used : BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with BuildClient

use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.

the class BuildEndpointTest method shouldBeAbleToReachAllBuildsWhenPaging.

@Test
public void shouldBeAbleToReachAllBuildsWhenPaging() throws Exception {
    BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
    List<String> buildIds = bc.getAll(null, null).getAll().stream().map(Build::getId).collect(Collectors.toList());
    List<String> pagedBuildIds = new ArrayList<>();
    int pageSize = 1;
    for (int pageIndex = 0; pageIndex < buildIds.size(); pageIndex++) {
        final io.restassured.response.Response response = given().redirects().follow(false).port(8080).when().get(String.format(BASE_REST_PATH + "/builds/?pageIndex=%d&pageSize=%d", pageIndex, pageSize));
        List<Build> builds = response.getBody().jsonPath().getList("content", Build.class);
        pagedBuildIds.add(builds.get(0).getId());
    }
    assertThat(pagedBuildIds).containsExactlyInAnyOrderElementsOf(buildIds);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) ArrayList(java.util.ArrayList) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with BuildClient

use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.

the class BuildEndpointTest method shouldFilterByBuildConfigurationName.

@Test
public void shouldFilterByBuildConfigurationName() throws Exception {
    BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
    String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setBuildConfigName(buildConfigName);
    List<String> buildConfigNames = client.getAll(filter, null).getAll().stream().map(Build::getBuildConfigRevision).map(BuildConfigurationRevisionRef::getName).collect(Collectors.toList());
    // from DatabaseDataInitializer
    assertThat(buildConfigNames).hasSize(2);
    assertThat(buildConfigNames).containsOnly(buildConfigName);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with BuildClient

use of org.jboss.pnc.client.BuildClient 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)

Aggregations

BuildClient (org.jboss.pnc.client.BuildClient)37 ContainerTest (org.jboss.pnc.test.category.ContainerTest)33 Test (org.junit.Test)33 Build (org.jboss.pnc.dto.Build)20 BuildsFilterParameters (org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)7 InputStream (java.io.InputStream)5 Artifact (org.jboss.pnc.dto.Artifact)5 InSequence (org.jboss.arquillian.junit.InSequence)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 ArtifactClient (org.jboss.pnc.client.ArtifactClient)3 BuildPushParameters (org.jboss.pnc.dto.requests.BuildPushParameters)3 Field (java.lang.reflect.Field)2 ApacheHttpClient43EngineWithRetry (org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry)2 ClientException (org.jboss.pnc.client.ClientException)2 Configuration (org.jboss.pnc.client.Configuration)2 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)2 BuildRef (org.jboss.pnc.dto.BuildRef)2 BeforeClass (org.junit.BeforeClass)2