use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldNotUpdateWithClosedMilestone.
@Test
public void shouldNotUpdateWithClosedMilestone() throws ClientException {
// given
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
// has closed milestone, from
ProductVersion productVersion = client.getSpecific(productVersionsId);
// DatabaseDataInitializer
// when
ProductVersion toUpdate = productVersion.toBuilder().version("2.0").build();
// then
assertThatThrownBy(() -> client.update(productVersion.getId(), toUpdate)).isInstanceOf(ClientException.class);
}
use of org.jboss.pnc.client.ProductVersionClient 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());
}
use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldUpdateGroupConfigs.
@Test
public void shouldUpdateGroupConfigs() throws ClientException {
// given
GroupConfiguration gc = GroupConfiguration.builder().name("New GC").build();
GroupConfigurationClient gcc = new GroupConfigurationClient(RestClientConfiguration.asUser());
GroupConfiguration gcToAdd = gcc.createNew(gc);
Map<String, GroupConfigurationRef> groupConfis = new HashMap<>();
// when
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
ProductVersion productVersion = client.getSpecific(productVersionsId2);
groupConfis.putAll(productVersion.getGroupConfigs());
groupConfis.put(gcToAdd.getId(), gcToAdd);
ProductVersion toUpdate = productVersion.toBuilder().groupConfigs(groupConfis).build();
client.update(productVersion.getId(), toUpdate);
ProductVersion retrieved = client.getSpecific(productVersion.getId());
// then
assertThat(retrieved.getGroupConfigs()).hasSameSizeAs(groupConfis).containsKey(gcToAdd.getId());
}
use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldFailGracefullyOnNonExistentProduct.
@Test
public void shouldFailGracefullyOnNonExistentProduct() {
// given
String nonExistentProductId = "384583";
ProductVersion productVersion = ProductVersion.builder().product(ProductRef.refBuilder().id(nonExistentProductId).build()).version("42.2").build();
// whenthen
ProductVersionClient client = new ProductVersionClient(RestClientConfiguration.asUser());
assertThatThrownBy(() -> client.createNew(productVersion)).isInstanceOf(ClientException.class);
}
use of org.jboss.pnc.client.ProductVersionClient in project pnc by project-ncl.
the class ProductVersionEndpointTest method shouldNotUpdateGroupConfigsWhenOneIsAlreadyAsssociatedWithAnotherProductVersion.
@Test
public void shouldNotUpdateGroupConfigsWhenOneIsAlreadyAsssociatedWithAnotherProductVersion() throws ClientException {
// 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
ProductVersion productVersion = client.getSpecific(productVersionsId2);
groupConfis.putAll(productVersion.getGroupConfigs());
groupConfis.put(alreadyAssignedGC.getId(), alreadyAssignedGC);
ProductVersion toUpdate = productVersion.toBuilder().groupConfigs(groupConfis).build();
// then
assertThatThrownBy(() -> client.update(productVersion.getId(), toUpdate)).isInstanceOf(ClientException.class);
}
Aggregations