Search in sources :

Example 61 with BuildConfiguration

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

the class BuildConfigurationEndpointTest method shouldPatchBuildConfiguration.

@Test
@InSequence(20)
public void shouldPatchBuildConfiguration() throws ClientException, PatchBuilderException {
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration buildConfiguration = client.getAll().iterator().next();
    String newDescription = "Testing patch support.";
    Instant modTime = buildConfiguration.getModificationTime();
    String id = buildConfiguration.getId();
    Map<String, String> addElements = Collections.singletonMap("newKey", "newValue");
    BuildConfigurationPatchBuilder builder = new BuildConfigurationPatchBuilder().replaceDescription(newDescription).addParameters(addElements);
    BuildConfiguration updated = client.patch(id, builder);
    Assert.assertEquals(newDescription, updated.getDescription());
    Assert.assertNotEquals(modTime, updated.getModificationTime());
    Assertions.assertThat(updated.getParameters()).contains(addElements.entrySet().toArray(new Map.Entry[1]));
    String newDescription2 = "Testing patch support 2.";
    BuildConfigurationPatchBuilder builder2 = new BuildConfigurationPatchBuilder().replaceDescription(newDescription2);
    BuildConfiguration updated2 = client.patch(id, builder2.getJsonPatch(), BuildConfiguration.class);
    Assert.assertEquals(newDescription2, updated2.getDescription());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationPatchBuilder(org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder) 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 62 with BuildConfiguration

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

the class BuildConfigurationEndpointTest method shouldUpdateBuildConfiguration.

/**
 * Reproducer NCL-2615 - big generic parameters cannot be ubdated in the BuildConfiguration
 *
 * @throws ClientException
 */
@Test
@InSequence(30)
public void shouldUpdateBuildConfiguration() throws ClientException {
    // given
    final String updatedBuildScript = "mvn clean deploy -Dmaven.test.skip=true";
    final String updatedName = UUID.randomUUID().toString();
    final String updatedProjectId = String.valueOf(projectId);
    final String updatedGenParamValue = PME_PARAMS_LONG;
    final Instant modificationTime = Instant.ofEpochMilli(155382545038L);
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().id(configurationId).name(updatedName).buildScript(updatedBuildScript).creationTime(Instant.ofEpochMilli(1518382545038L)).modificationTime(modificationTime).project(ProjectRef.refBuilder().id(updatedProjectId).build()).environment(Environment.builder().id(environmentId).build()).parameters(Collections.singletonMap(PARAMETER_KEY, updatedGenParamValue)).scmRepository(SCMRepository.builder().id(repositoryConfigurationId).build()).buildType(BuildType.MVN).brewPullActive(true).build();
    // when
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    client.update(configurationId, buildConfiguration);
    BuildConfiguration updatedBC = client.getSpecific(configurationId);
    // then
    assertThat(updatedBC.getId()).isEqualTo(configurationId);
    assertThat(updatedBC.getName()).isEqualTo(updatedName);
    assertThat(updatedBC.getBuildScript()).isEqualTo(updatedBuildScript);
    assertThat(updatedBC.getScmRepository().getId()).isEqualTo(repositoryConfigurationId);
    assertThat(updatedBC.getProject().getId()).isEqualTo(updatedProjectId);
    assertThat(updatedBC.getParameters().get(PARAMETER_KEY)).isEqualTo(updatedGenParamValue);
    assertThat(updatedBC.getEnvironment().getId()).isEqualTo(environmentId);
    assertThat(modificationTime).isNotEqualTo(updatedBC.getModificationTime());
    assertThat(updatedBC.getBrewPullActive()).isTrue();
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) 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 63 with BuildConfiguration

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

the class BuildConfigurationEndpointTest method shouldCloneBuildConfiguration.

@Test
@InSequence(20)
public void shouldCloneBuildConfiguration() throws ClientException {
    // given
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration original = client.getSpecific(configurationId);
    assertThat(original.getProductVersion()).isNotNull();
    assertThat(original.getGroupConfigs()).isNotEmpty();
    BuildConfiguration parent = client.getSpecific(configuration4Id);
    assertThat(parent.getDependencies()).containsKey(configurationId);
    // when
    BuildConfiguration clone = client.clone(original.getId());
    // then
    assertThat(clone.getId()).isNotEmpty();
    assertThat(clone.getProductVersion()).isNull();
    assertThat(clone.getGroupConfigs()).isEmpty();
    BuildConfiguration retrieved = client.getSpecific(clone.getId());
    BuildConfiguration retrivedParent = client.getSpecific(configuration4Id);
    assertThat(retrivedParent.getDependencies()).containsKey(configurationId);
    assertThat(retrivedParent.getDependencies()).doesNotContainKey(clone.getId());
    assertThat(clone).isEqualToIgnoringGivenFields(original, "id", "name", "groupConfigs", "creationTime", "modificationTime", "modificationTime", "productVersion", "creationUser", "modificationUser");
    assertThat(retrieved).isEqualToIgnoringGivenFields(clone, "modificationTime", "creationUser", // close
    "modificationUser");
// of
// transaction
// changes
// the modification time -
// WONTFIX
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 64 with BuildConfiguration

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

the class BuildConfigurationEndpointTest method shouldDeleteDependencyWithPatch.

@Test
@InSequence(100)
public void shouldDeleteDependencyWithPatch() throws Exception {
    // given
    BuildConfigurationClient bcClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration gc = null;
    for (BuildConfiguration bc1 : bcClient.getAll()) {
        if (!bc1.getDependencies().isEmpty()) {
            gc = bc1;
            break;
        }
    }
    assertThat(gc).isNotNull();
    BuildConfiguration toRemove = bcClient.getSpecific(gc.getDependencies().keySet().iterator().next());
    BuildConfigurationPatchBuilder builder = new BuildConfigurationPatchBuilder();
    builder.removeDependencies(Collections.singletonList(toRemove.getId()));
    // when
    bcClient.patch(gc.getId(), builder);
    // then
    BuildConfiguration refresh = bcClient.getSpecific(gc.getId());
    assertThat(refresh.getDependencies().keySet()).doesNotContain(toRemove.getId());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationPatchBuilder(org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 65 with BuildConfiguration

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

the class BuildConfigurationSerializationTest method shouldPatchBuildConfiguration.

@Test
public void shouldPatchBuildConfiguration() throws PatchBuilderException, IOException, JsonPatchException {
    ObjectMapper mapper = ObjectMapperProvider.getInstance();
    // given
    Instant now = Instant.now();
    Map<String, String> initialParameters = Collections.singletonMap("KEY", "VALUE");
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").name("name").creationTime(now).parameters(initialParameters).build();
    // when
    BuildConfigurationPatchBuilder patchBuilder = new BuildConfigurationPatchBuilder();
    patchBuilder.replaceName("new name");
    Map<String, String> newParameter = Collections.singletonMap("KEY 2", "VALUE 2");
    patchBuilder.addParameters(newParameter);
    JsonNode targetJson = mapper.valueToTree(buildConfiguration);
    JsonPatch patch = JsonPatch.fromJson(mapper.readValue(patchBuilder.getJsonPatch(), JsonNode.class));
    JsonNode result = patch.apply(targetJson);
    // then
    BuildConfiguration deserialized = mapper.treeToValue(result, BuildConfiguration.class);
    Assert.assertEquals(now, deserialized.getCreationTime());
    Assert.assertEquals("new name", deserialized.getName());
    Map<String, String> finalParameters = new HashMap<>(initialParameters);
    finalParameters.putAll(newParameter);
    assertThat(deserialized.getParameters()).containsAllEntriesOf(finalParameters);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationPatchBuilder(org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder) HashMap(java.util.HashMap) Instant(java.time.Instant) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPatch(com.github.fge.jsonpatch.JsonPatch) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)90 Test (org.junit.Test)65 ContainerTest (org.jboss.pnc.test.category.ContainerTest)45 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)31 HashMap (java.util.HashMap)17 InSequence (org.jboss.arquillian.junit.InSequence)17 Build (org.jboss.pnc.dto.Build)13 GroupBuild (org.jboss.pnc.dto.GroupBuild)12 SCMRepository (org.jboss.pnc.dto.SCMRepository)10 Test (org.junit.jupiter.api.Test)10 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)9 Instant (java.time.Instant)8 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)7 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ArrayList (java.util.ArrayList)4 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)4 HashSet (java.util.HashSet)3