Search in sources :

Example 16 with ClientException

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

the class EnvironmentEndpointTest method shouldFailToSaveEnvironmentAsUser.

@Test
@InSequence(30)
public void shouldFailToSaveEnvironmentAsUser() {
    EnvironmentClient client = new EnvironmentClient(RestClientConfiguration.asUser());
    Environment.Builder environmentBuilder = Environment.builder().name("OpenJDK 14.0; Mvn 3.6.5").description("OpenJDK 14.0; Mvn 3.6.5").systemImageId("builder-rhel-8-j14-mvn3.6.5:1.0").systemImageRepositoryUrl("quay.io/rh-newcastle").systemImageType(SystemImageType.DOCKER_IMAGE);
    Exception caught = null;
    try {
        client.createNew(environmentBuilder.build());
    } catch (ClientException e) {
        caught = e;
    }
    Assertions.assertThat(caught).isNotNull();
    Assertions.assertThat(caught.getCause()).isInstanceOf(javax.ws.rs.ForbiddenException.class);
}
Also used : EnvironmentClient(org.jboss.pnc.client.EnvironmentClient) Environment(org.jboss.pnc.dto.Environment) ClientException(org.jboss.pnc.client.ClientException) ClientException(org.jboss.pnc.client.ClientException) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest) InSequence(org.jboss.arquillian.junit.InSequence)

Example 17 with ClientException

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

the class ProductEndpointTest method shouldFailToSaveProductWithSpaceInAbbreviation.

@Test
public void shouldFailToSaveProductWithSpaceInAbbreviation() {
    ProductClient client = new ProductClient(RestClientConfiguration.asUser());
    Product product = Product.builder().name("New Ab re via ted product").abbreviation("abb re viation").description("The newst product of them all. Now with spaces.").build();
    try {
        client.createNew(product);
        fail("Exception should be thrown");
    } catch (ClientException ex) {
    // OK
    }
}
Also used : ProductClient(org.jboss.pnc.client.ProductClient) Product(org.jboss.pnc.dto.Product) ClientException(org.jboss.pnc.client.ClientException) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 18 with ClientException

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

the class SCMRepositoryEndpointTest method testGetBuildConfigurationForARepository.

@Test
public void testGetBuildConfigurationForARepository() throws ClientException {
    BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    SCMRepository scmRepository = repositoryClient.getAll(null, null).iterator().next();
    Iterator<BuildConfiguration> allConfigsIterator = buildConfigurationClient.getAll().iterator();
    BuildConfiguration buildConfiguration1 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
    BuildConfiguration buildConfiguration2 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
    buildConfigurationClient.update(buildConfiguration1.getId(), buildConfiguration1);
    buildConfigurationClient.update(buildConfiguration2.getId(), buildConfiguration2);
    RemoteCollection<BuildConfiguration> buildConfigs = repositoryClient.getBuildConfigs(scmRepository.getId());
    assertThat(buildConfigs).usingElementComparatorIgnoringFields("modificationTime", "creationUser", "modificationUser").contains(buildConfiguration1, buildConfiguration2).allSatisfy((bc -> scmRepository.equals(bc.getScmRepository())));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ClientErrorException(javax.ws.rs.ClientErrorException) RemoteCollection(org.jboss.pnc.client.RemoteCollection) CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BadRequestException(javax.ws.rs.BadRequestException) Deployments(org.jboss.pnc.integration.setup.Deployments) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) SCMRepositoryClient(org.jboss.pnc.client.SCMRepositoryClient) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository) Ignore(org.junit.Ignore) Deployment(org.jboss.arquillian.container.test.api.Deployment) Condition(org.assertj.core.api.Condition) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) SCMRepository(org.jboss.pnc.dto.SCMRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 19 with ClientException

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

the class WebSocketClientTest method groupBuildToFinish.

private Boolean groupBuildToFinish(String groupBuildId) {
    GroupBuild build = null;
    try {
        build = new GroupBuildClient(RestClientConfiguration.asUser()).getSpecific(groupBuildId);
        assertThat(build).isNotNull();
        if (!build.getStatus().isFinal())
            return false;
    } catch (RemoteResourceNotFoundException e) {
        fail(String.format("Group Build with id:%s not present", groupBuildId), e);
    } catch (ClientException e) {
        fail("Client has failed in an unexpected way.", e);
    }
    return true;
}
Also used : RemoteResourceNotFoundException(org.jboss.pnc.client.RemoteResourceNotFoundException) GroupBuild(org.jboss.pnc.dto.GroupBuild) GroupBuildClient(org.jboss.pnc.client.GroupBuildClient) ClientException(org.jboss.pnc.client.ClientException)

Aggregations

ClientException (org.jboss.pnc.client.ClientException)19 GroupBuild (org.jboss.pnc.dto.GroupBuild)6 ContainerTest (org.jboss.pnc.test.category.ContainerTest)6 Test (org.junit.Test)6 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)4 Build (org.jboss.pnc.dto.Build)4 BadRequestException (javax.ws.rs.BadRequestException)3 ClientErrorException (javax.ws.rs.ClientErrorException)3 InSequence (org.jboss.arquillian.junit.InSequence)3 ProductClient (org.jboss.pnc.client.ProductClient)3 RemoteResourceNotFoundException (org.jboss.pnc.client.RemoteResourceNotFoundException)3 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)3 BuildsFilterParameters (org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)3 Iterator (java.util.Iterator)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Condition (org.assertj.core.api.Condition)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 Arquillian (org.jboss.arquillian.junit.Arquillian)2