+ @DataProvider
+ public static Object[][] isTemplatesExistsByGivenServiceUuid() {
+ return new Object[][]{{"1",TRUE},
+ {"3",FALSE}};
+ }
+
+ @Test(dataProvider = "isTemplatesExistsByGivenServiceUuid")
+ public void setInServicesTemplateValue_givenServiceWithServiceModelId_thenIsTemplateExistsIsEatherTrueOrFalse(String givenUuid, Boolean expectedTemplatesExist){
+
+ Service service = new Service();
+ service.setUuid(givenUuid);
+
+ Service newService = instantiationTemplatesService.setTemplateExistForService(service, ImmutableSet.of("1", "2"));
+ assertThat(newService.getIsInstantiationTemplateExists(), is(expectedTemplatesExist));
+ }
+
+ @Test
+ public void setTemplatesExistance_givenCollection__flagIsActive_thenSameCollectionReturnedWithTemplateExistsProperty(){
+ when(featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(true);
+ when(asyncInstantiationRepository.getAllTemplatesServiceModelIds()).thenReturn(ImmutableSet.of("1", "2"));
+ Collection<Service> actualCollection = instantiationTemplatesService.setOnEachServiceIsTemplateExists(createGivenCollection());
+ assertThat(actualCollection, containsInAnyOrder(
+ allOf(hasProperty("uuid", is("1")), hasProperty("isInstantiationTemplateExists", is(true))),
+ allOf(hasProperty("uuid", is("3")), hasProperty("isInstantiationTemplateExists", is(false)))
+ ));
+ }
+
+ @Test
+ public void setTemplatesExistance_givenCollection_flagIsNotActive_thenTemplatesExistNotAdded(){
+ when(featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(false);
+ Collection<Service> actualCollection = instantiationTemplatesService.setOnEachServiceIsTemplateExists(createGivenCollection());
+ assertThat("was " + actualCollection, actualCollection, containsInAnyOrder(
+ allOf(hasProperty("uuid", is("1")), hasProperty("isInstantiationTemplateExists", nullValue())),
+ allOf(hasProperty("uuid", is("3")), hasProperty("isInstantiationTemplateExists", nullValue()))
+ ));
+ }
+
+ private Collection<Service> createGivenCollection(){
+ Service service1 = new Service();
+ Service service2 = new Service();
+ service1.setUuid("1");
+ service2.setUuid("3");
+ return ImmutableList.of(service1, service2);
+ }
+