Search in sources :

Example 1 with BuildConfigurationPatchBuilder

use of org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder 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 2 with BuildConfigurationPatchBuilder

use of org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder 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 3 with BuildConfigurationPatchBuilder

use of org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder 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

BuildConfigurationPatchBuilder (org.jboss.pnc.client.patch.BuildConfigurationPatchBuilder)3 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)3 Test (org.junit.Test)3 Instant (java.time.Instant)2 InSequence (org.jboss.arquillian.junit.InSequence)2 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)2 ContainerTest (org.jboss.pnc.test.category.ContainerTest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonPatch (com.github.fge.jsonpatch.JsonPatch)1 HashMap (java.util.HashMap)1