use of org.jboss.pnc.dto.GroupConfigurationRef in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldNotUpdateGroupConfigsWithNonExistantGroupConfig.
@Test
public void shouldNotUpdateGroupConfigsWithNonExistantGroupConfig() throws ClientException {
// given
GroupConfigurationRef notExistingGC = GroupConfigurationRef.refBuilder().id("9999").name("i-dont-exist").build();
Map<String, GroupConfigurationRef> groupConfis = new HashMap<>();
// when
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
ProductVersion productVersion = client.getSpecific(productVersionsId2);
groupConfis.putAll(productVersion.getGroupConfigs());
groupConfis.put(notExistingGC.getId(), notExistingGC);
ProductVersion toUpdate = productVersion.toBuilder().groupConfigs(groupConfis).build();
// then
assertThatThrownBy(() -> client.update(productVersion.getId(), toUpdate)).isInstanceOf(ClientException.class);
}
use of org.jboss.pnc.dto.GroupConfigurationRef in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldUpdateGroupConfigsUsingPatch.
@Test
public void shouldUpdateGroupConfigsUsingPatch() throws PatchBuilderException, RemoteResourceException {
// given
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
GroupConfiguration gc = GroupConfiguration.builder().name("GC patch test").build();
GroupConfigurationClient gcc = new GroupConfigurationClient(RestClientConfiguration.asUser());
GroupConfiguration gcToAdd = gcc.createNew(gc);
ProductVersion productVersion = client.getSpecific(productVersionsId2);
Map<String, GroupConfigurationRef> groupConfigs = productVersion.getGroupConfigs();
// when
ProductVersionPatchBuilder patchBuilder = new ProductVersionPatchBuilder();
ProductVersionPatchBuilder patch = patchBuilder.addGroupConfigs(Collections.singletonMap(gcToAdd.getId(), gcToAdd));
client.patch(productVersionsId2, patch);
// then
groupConfigs.put(gcToAdd.getId(), gcToAdd);
ProductVersion productVersionUpdated = client.getSpecific(productVersionsId2);
assertThat(productVersionUpdated.getGroupConfigs()).containsKeys(groupConfigs.keySet().toArray(new String[groupConfigs.keySet().size()]));
}
use of org.jboss.pnc.dto.GroupConfigurationRef in project bacon by project-ncl.
the class PncBuilder method getCountOfBuildConfigsForGroupBuild.
/**
* Try to get the count of build configs for a group build's group config. Returns -1 if it couldn't do the request
*
* @param groupBuildId
* @return count, -1 if an error happened
*/
int getCountOfBuildConfigsForGroupBuild(String groupBuildId) {
try {
GroupBuild gb = groupBuildClient.getSpecific(groupBuildId);
GroupConfigurationRef gc = gb.getGroupConfig();
return groupConfigClient.getBuildConfigs(gc.getId()).size();
} catch (ClientException e) {
log.warn("Failed to get count of build configs in the group build {}", groupBuildId, e);
return -1;
}
}
use of org.jboss.pnc.dto.GroupConfigurationRef in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldNotUpdateGroupConfigsWhenOneIsAlreadyAsssociatedWithAnotherProductVersionUsingPatch.
@Test
public void shouldNotUpdateGroupConfigsWhenOneIsAlreadyAsssociatedWithAnotherProductVersionUsingPatch() throws ClientException, PatchBuilderException {
// given
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
GroupConfigurationRef alreadyAssignedGC = client.getSpecific(productVersionsId).getGroupConfigs().values().iterator().next();
Map<String, GroupConfigurationRef> groupConfis = new HashMap<>();
assertThat(alreadyAssignedGC).isNotNull();
// when
ProductVersionPatchBuilder patchBuilder = new ProductVersionPatchBuilder();
ProductVersionPatchBuilder patch = patchBuilder.addGroupConfigs(Collections.singletonMap(alreadyAssignedGC.getId(), alreadyAssignedGC));
// then
assertThatThrownBy(() -> client.patch(productVersionsId2, patch)).isInstanceOf(ClientException.class);
}
use of org.jboss.pnc.dto.GroupConfigurationRef in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldAdd2GroupConfigsWithPatch.
@Test
public void shouldAdd2GroupConfigsWithPatch() throws Exception {
// given #1
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
GroupConfigurationClient gcClient = new GroupConfigurationClient(RestClientConfiguration.asUser());
ProductVersion productVersion = client.getSpecific(productVersionsId2);
GroupConfiguration toAdd = gcClient.createNew(GroupConfiguration.builder().name("New GC1").build());
ProductVersionPatchBuilder builder = new ProductVersionPatchBuilder();
Map<String, GroupConfigurationRef> toAddMap = new HashMap<>();
toAddMap.put(toAdd.getId(), toAdd);
builder.addGroupConfigs(toAddMap);
// when #1
client.patch(productVersion.getId(), builder);
// then #1
ProductVersion refresh = client.getSpecific(productVersionsId2);
assertThat(refresh.getGroupConfigs()).containsKey(toAdd.getId());
// given #2 add second GC
GroupConfiguration toAdd2 = gcClient.createNew(GroupConfiguration.builder().name("New GC2").build());
builder = new ProductVersionPatchBuilder();
toAddMap.clear();
toAddMap.put(toAdd2.getId(), toAdd2);
builder.addGroupConfigs(toAddMap);
// when #2
client.patch(productVersion.getId(), builder);
// then #2
refresh = client.getSpecific(productVersionsId2);
assertThat(refresh.getGroupConfigs()).containsKey(toAdd2.getId()).containsKey(toAdd.getId());
}
Aggregations