Search in sources :

Example 36 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method shouldUpdateBuildConfigurationWithDependencies.

/**
 * Reproducer NCL-5686 - update of build configuration with dependencies, with cache enabled, is possible
 *
 * @throws Exception
 */
@Test
@InSequence(60)
public void shouldUpdateBuildConfigurationWithDependencies() throws ClientException {
    // given
    // Create dependency
    BuildConfiguration dependency = createBuildConfigurationAndValidateResults(projectId, environmentId, repositoryConfigurationId, "pnc-1.0.0.DR1", UUID.randomUUID().toString());
    // Create build configuration
    Map<String, BuildConfigurationRef> dependencies = new HashMap<>();
    dependencies.put(dependency.getId(), dependency);
    BuildConfiguration buildConfiguration = createBuildConfigurationWithDependencyAndValidateResults(projectId, environmentId, repositoryConfigurationId, "dependency-analysis-master", UUID.randomUUID().toString(), dependencies);
    final String updatedBuildScript = "mvn clean deploy -DskipTests=true";
    final Instant modificationTime = Instant.ofEpochMilli(155382545038L);
    BuildConfiguration updatedBuildConfiguration = BuildConfiguration.builder().id(buildConfiguration.getId()).name(buildConfiguration.getName()).buildScript(updatedBuildScript).creationTime(buildConfiguration.getCreationTime()).modificationTime(modificationTime).project(buildConfiguration.getProject()).environment(buildConfiguration.getEnvironment()).parameters(buildConfiguration.getParameters()).scmRepository(buildConfiguration.getScmRepository()).buildType(buildConfiguration.getBuildType()).build();
    // when
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    client.update(updatedBuildConfiguration.getId(), updatedBuildConfiguration);
    BuildConfiguration updatedBC = client.getSpecific(updatedBuildConfiguration.getId());
    // then
    assertThat(updatedBC.getId()).isEqualTo(buildConfiguration.getId());
    assertThat(updatedBC.getName()).isEqualTo("dependency-analysis-master");
    assertThat(updatedBC.getBuildScript()).isEqualTo(updatedBuildScript);
    assertThat(updatedBC.getScmRepository().getId()).isEqualTo(repositoryConfigurationId);
    assertThat(updatedBC.getProject().getId()).isEqualTo(projectId);
    assertThat(updatedBC.getEnvironment().getId()).isEqualTo(environmentId);
    assertThat(modificationTime).isNotEqualTo(updatedBC.getModificationTime());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) HashMap(java.util.HashMap) Instant(java.time.Instant) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 37 with BuildConfigurationClient

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

the class BuildConfigurationEndpointTest method shouldNotCreateWithInternalUrlNotMatchingPattern.

@Test
public void shouldNotCreateWithInternalUrlNotMatchingPattern() throws ClientException {
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration bc = client.getSpecific(configurationId);
    BuildConfiguration newBC = BuildConfiguration.builder().name("othername").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/gerrit/newRepo.git").build();
    assertThatThrownBy(() -> client.createWithSCM(request)).hasCauseInstanceOf(BadRequestException.class);
    BuildConfigWithSCMRequest request2 = BuildConfigWithSCMRequest.builder().buildConfig(newBC).scmUrl("ssh://git@github.com:22/foo/newRepo").build();
    assertThatThrownBy(() -> client.createWithSCM(request2)).hasCauseInstanceOf(BadRequestException.class);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigWithSCMRequest(org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 38 with BuildConfigurationClient

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

the class GroupConfigurationEndpointTest method testAddBuildConfig.

@Test
public void testAddBuildConfig() throws ClientException {
    // with
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    BuildConfigurationClient bcClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    String gcId = "100";
    BuildConfiguration buildConfiguration = bcClient.getAll().iterator().next();
    String bcToAddId = buildConfiguration.getId();
    GroupConfiguration groupConfiguration = client.getSpecific(gcId);
    assertThat(groupConfiguration.getBuildConfigs()).doesNotContainKey(bcToAddId);
    // when
    client.addBuildConfig(gcId, buildConfiguration);
    // then
    assertThat(client.getSpecific(gcId).getBuildConfigs()).containsKey(bcToAddId);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 39 with BuildConfigurationClient

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

the class GroupConfigurationEndpointTest method shouldUpdateAllBuildConfigurations.

@Test
public void shouldUpdateAllBuildConfigurations() throws Exception {
    // with
    GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
    BuildConfigurationClient bcClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    String gcId = "101";
    BuildConfiguration bc = bcClient.getAll().iterator().next();
    GroupConfiguration gc = client.getSpecific(gcId);
    String bcId = bc.getId();
    Map<String, BuildConfigurationRef> buildConfigurationMap = new HashMap<>();
    buildConfigurationMap.put(bcId, bc);
    GroupConfiguration updated = gc.toBuilder().buildConfigs(buildConfigurationMap).build();
    assertThat(gc.getBuildConfigs()).doesNotContainKey(bcId);
    // when
    client.update(gc.getId(), updated);
    // then
    assertThat(client.getSpecific(gcId).getBuildConfigs()).containsOnlyKeys(bcId);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) HashMap(java.util.HashMap) GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 40 with BuildConfigurationClient

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

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