Search in sources :

Example 1 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method prepareData.

@SuppressWarnings("unchecked")
@BeforeClass
public static void prepareData() throws Exception {
    BuildConfigurationClient bcc = new BuildConfigurationClient(RestClientConfiguration.asAnonymous());
    Iterator<BuildConfiguration> it = bcc.getAll().iterator();
    configurationId = it.next().getId();
    configuration2Id = it.next().getId();
    configuration3Id = it.next().getId();
    configuration4Id = it.next().getId();
    ProductClient pdc = new ProductClient(RestClientConfiguration.asAnonymous());
    productId = pdc.getAll().iterator().next().getId();
    EnvironmentClient ec = new EnvironmentClient(RestClientConfiguration.asAnonymous());
    environmentId = ec.getAll().iterator().next().getId();
    ProjectClient pjc = new ProjectClient(RestClientConfiguration.asAnonymous());
    projectId = pjc.getAll().iterator().next().getId();
    SCMRepositoryClient scmrc = new SCMRepositoryClient(RestClientConfiguration.asAnonymous());
    final Iterator<SCMRepository> scmrIt = scmrc.getAll(null, null).iterator();
    repositoryConfigurationId = scmrIt.next().getId();
    repositoryConfiguration2Id = scmrIt.next().getId();
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) SCMRepositoryClient(org.jboss.pnc.client.SCMRepositoryClient) ProductClient(org.jboss.pnc.client.ProductClient) EnvironmentClient(org.jboss.pnc.client.EnvironmentClient) ProjectClient(org.jboss.pnc.client.ProjectClient) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) SCMRepository(org.jboss.pnc.dto.SCMRepository) BeforeClass(org.junit.BeforeClass)

Example 2 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method shouldRestoreBuildConfigurationRevision.

@Test
@InSequence(50)
public void shouldRestoreBuildConfigurationRevision() throws Exception {
    // given
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration original = client.getSpecific(configurationId);
    String description = original.getDescription();
    Iterator<BuildConfigurationRevision> it = client.getRevisions(configurationId).iterator();
    // given latest revision
    BuildConfigurationRevision originalRev = it.next();
    while (it.hasNext()) {
        BuildConfigurationRevision candidate = it.next();
        if (candidate.getRev() > originalRev.getRev()) {
            originalRev = candidate;
        }
    }
    // when
    String newDescription = "shouldRestoreBuildConfigurationRevision Updated";
    BuildConfiguration toUpdate = original.toBuilder().description(newDescription).build();
    client.update(configurationId, toUpdate);
    assertThat(toUpdate.getDescription()).isNotEqualTo(description);
    // and when
    BuildConfiguration restored = client.restoreRevision(configurationId, originalRev.getRev());
    BuildConfiguration retrieved = client.getSpecific(configurationId);
    // then
    // we don't audit anymore the description, so it cannot be restored from a previous revision
    assertThat(restored.getDescription()).isEqualTo(toUpdate.getDescription());
    assertThat(restored).isEqualToIgnoringGivenFields(original, "description", "modificationTime", "modificationUser", "creationTime", "creationUser");
    assertThat(retrieved).isEqualToIgnoringGivenFields(restored, "description", "modificationTime", "modificationUser", "creationTime", "creationUser");
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method shouldCreateWithInternalUrlMatchingPattern.

@Test
@InSequence(62)
public void shouldCreateWithInternalUrlMatchingPattern() throws ClientException {
    // given
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration bc = client.getSpecific(configurationId);
    BuildConfiguration newBC = BuildConfiguration.builder().name("othernameforbc").buildScript(bc.getBuildScript()).project(bc.getProject()).environment(bc.getEnvironment()).parameters(bc.getParameters()).buildType(bc.getBuildType()).build();
    BuildConfigWithSCMRequest request = BuildConfigWithSCMRequest.builder().buildConfig(newBC).scmUrl("ssh://git@github.com:22/newUser/newRepo.git").build();
    BuildConfigCreationResponse received = client.createWithSCM(request);
    assertThat(received).isNotNull();
    assertThat(received.getBuildConfig().getId()).isNotNull();
    assertThat(client.getSpecific(received.getBuildConfig().getId())).hasFieldOrPropertyWithValue("name", "othernameforbc");
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) BuildConfigWithSCMRequest(org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 4 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method testRemoveDependency.

@Test
@InSequence(40)
public void testRemoveDependency() throws ClientException {
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    // given
    BuildConfiguration parent = client.getSpecific(configuration3Id);
    Map<String, BuildConfigurationRef> oldDependencies = parent.getDependencies();
    assertThat(oldDependencies).isNotEmpty();
    BuildConfigurationRef toDelete = oldDependencies.values().iterator().next();
    // when
    client.removeDependency(parent.getId(), toDelete.getId());
    // then
    RemoteCollection<BuildConfiguration> all = client.getDependencies(parent.getId());
    oldDependencies.remove(toDelete.getId());
    assertThat(all).extracting(DTOEntity::getId).doesNotContain(toDelete.getId()).containsAll(oldDependencies.keySet().stream().collect(Collectors.toList()));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) DTOEntity(org.jboss.pnc.dto.DTOEntity) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 5 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method shouldGetConflictWhenCreatingNewBuildConfigurationWithTheSameNameAndProjectId.

@Test
public void shouldGetConflictWhenCreatingNewBuildConfigurationWithTheSameNameAndProjectId() throws ClientException {
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration bc = client.getSpecific(configurationId);
    BuildConfiguration duplicate = BuildConfiguration.builder().name(bc.getName()).buildScript(bc.getBuildScript()).project(bc.getProject()).environment(bc.getEnvironment()).parameters(bc.getParameters()).scmRepository(bc.getScmRepository()).buildType(bc.getBuildType()).build();
    assertThatThrownBy(() -> client.createNew(duplicate)).hasCauseInstanceOf(ClientErrorException.class).has(new Condition<Throwable>((e -> ((ClientErrorException) e.getCause()).getResponse().getStatus() == 409), "HTTP 409 Conflict"));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)41 ContainerTest (org.jboss.pnc.test.category.ContainerTest)37 Test (org.junit.Test)37 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)32 InSequence (org.jboss.arquillian.junit.InSequence)16 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)6 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)6 Instant (java.time.Instant)5 Build (org.jboss.pnc.dto.Build)5 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)5 SCMRepositoryClient (org.jboss.pnc.client.SCMRepositoryClient)4 HashMap (java.util.HashMap)3 ClientErrorException (javax.ws.rs.ClientErrorException)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)3 Arquillian (org.jboss.arquillian.junit.Arquillian)3 ClientException (org.jboss.pnc.client.ClientException)3 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)3 BuildConfigurationPatchBuilder (org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder)3