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());
}
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());
}
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);
}
Aggregations