package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-
import javax.transaction.Transactional;
-
import org.apache.commons.lang3.RandomStringUtils;
import org.json.JSONException;
import org.junit.Assert;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.onap.clamp.clds.Application;
+import org.onap.clamp.clds.config.LegacyOperationalPolicy;
+import org.onap.clamp.clds.exception.sdc.controller.BlueprintParserException;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
-import org.onap.clamp.loop.service.ServiceRepository;
-import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.loop.service.ServicesRepository;
+import org.onap.clamp.loop.template.LoopTemplate;
+import org.onap.clamp.loop.template.LoopTemplateLoopElementModel;
+import org.onap.clamp.loop.template.LoopTemplatesRepository;
+import org.onap.clamp.loop.template.PolicyModelId;
+import org.onap.clamp.loop.template.PolicyModelsRepository;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.notification.IResourceInstance;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
-@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller-new")
+@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller,legacy-operational-policy")
public class CsarInstallerItCase {
private static final String CSAR_ARTIFACT_NAME = "example/sdc/service_Vloadbalancerms_csar.csar";
private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2";
@Autowired
- private LoopsRepository loopsRepo;
+ private LoopTemplatesRepository loopTemplatesRepo;
+
+ @Autowired
+ ServicesRepository serviceRepository;
@Autowired
- ServiceRepository serviceRepository;
+ PolicyModelsRepository policyModelsRepository;
@Autowired
@Qualifier("csarInstaller")
return csarHandler;
}
+ @Test
+ @Transactional
+ public void testPolicyModelAddedAtStartup() {
+ assertThat(policyModelsRepository.findByPolicyModelType(
+ LegacyOperationalPolicy.OPERATIONAL_POLICY_LEGACY).get(0)).isNotNull();
+ }
+
@Test
@Transactional
public void testGetPolicyModelYaml() throws IOException, SdcToscaParserException, CsarHandlerException {
@Test
@Transactional
public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException,
- CsarHandlerException, IOException, InterruptedException {
+ CsarHandlerException, IOException, InterruptedException, BlueprintParserException {
String generatedName = RandomStringUtils.randomAlphanumeric(5);
CsarHandler csarHandler = buildFakeCsarHandler(generatedName);
assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isFalse();
@Transactional
@Commit
public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException,
- CsarHandlerException, IOException, JSONException, InterruptedException {
+ CsarHandlerException, IOException, JSONException, InterruptedException, BlueprintParserException {
String generatedName = RandomStringUtils.randomAlphanumeric(5);
CsarHandler csar = buildFakeCsarHandler(generatedName);
csarInstaller.installTheCsar(csar);
- assertThat(serviceRepository
- .existsById("63cac700-ab9a-4115-a74f-7eac85e3fce0")).isTrue();
- assertThat(loopsRepo
- .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")))
- .isTrue();
- assertThat(loopsRepo.existsById(
- Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))).isTrue();
- assertThat(loopsRepo.existsById(
- Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))).isTrue();
+ assertThat(serviceRepository.existsById("63cac700-ab9a-4115-a74f-7eac85e3fce0")).isTrue();
+ assertThat(loopTemplatesRepo.existsById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
+ RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml"))).isTrue();
+ assertThat(loopTemplatesRepo.existsById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
+ RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))).isTrue();
+ assertThat(loopTemplatesRepo.existsById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
+ RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))).isTrue();
// Verify now that policy and json representation, global properties are well
// set
- Loop loop = loopsRepo
- .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml"))
- .get();
- assertThat(loop.getSvgRepresentation()).startsWith("<svg ");
- assertThat(loop.getGlobalPropertiesJson().get("dcaeDeployParameters")).isNotNull();
- assertThat(loop.getMicroServicePolicies()).hasSize(1);
- assertThat(loop.getOperationalPolicies()).hasSize(1);
- assertThat(loop.getModelService().getServiceUuid()).isEqualTo("63cac700-ab9a-4115-a74f-7eac85e3fce0");
+ LoopTemplate loopTemplate = loopTemplatesRepo.findById(LoopTemplate.generateLoopTemplateName(generatedName,
+ "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")).get();
+ assertThat(loopTemplate.getSvgRepresentation()).startsWith("<svg ");
+ assertThat(loopTemplate.getLoopElementModelsUsed()).hasSize(1);
+ assertThat(loopTemplate.getModelService().getServiceUuid()).isEqualTo("63cac700-ab9a-4115-a74f-7eac85e3fce0");
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"),
- JsonUtils.GSON_JPA_MODEL.toJson(loop.getModelService()), true);
+ JsonUtils.GSON_JPA_MODEL.toJson(loopTemplate.getModelService()), true);
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/service-details.json"),
- JsonUtils.GSON_JPA_MODEL.toJson(loop.getModelService().getServiceDetails()), true);
+ JsonUtils.GSON_JPA_MODEL.toJson(loopTemplate.getModelService().getServiceDetails()), true);
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/resource-details.json"),
- JsonUtils.GSON_JPA_MODEL.toJson(loop.getModelService().getResourceDetails()), true);
- assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty();
-
- loop = loopsRepo
- .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))
- .get();
- assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty();
-
- loop = loopsRepo
- .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))
- .get();
- assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty();
- }
-
- @Test(expected = SdcArtifactInstallerException.class)
- @Transactional
- public void shouldThrowSdcArtifactInstallerException()
- throws SdcArtifactInstallerException, SdcToscaParserException, IOException, InterruptedException {
- String generatedName = RandomStringUtils.randomAlphanumeric(5);
- CsarHandler csarHandler = buildFakeCsarHandler(generatedName);
- Mockito.when(csarHandler.getPolicyModelYaml()).thenThrow(IOException.class);
- csarInstaller.installTheCsar(csarHandler);
+ JsonUtils.GSON_JPA_MODEL.toJson(loopTemplate.getModelService().getResourceDetails()), true);
+ assertThat(((LoopTemplateLoopElementModel) (loopTemplate.getLoopElementModelsUsed().toArray()[0]))
+ .getLoopElementModel().getName()).isNotEmpty();
+
+ loopTemplate = loopTemplatesRepo.findById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
+ RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml")).get();
+ assertThat(((LoopTemplateLoopElementModel) (loopTemplate.getLoopElementModelsUsed().toArray()[0]))
+ .getLoopElementModel().getName()).isNotEmpty();
+ assertThat(((LoopTemplateLoopElementModel) (loopTemplate.getLoopElementModelsUsed().toArray()[0]))
+ .getLoopElementModel().getName()).isNotEmpty();
+ assertThat(loopTemplate.getMaximumInstancesAllowed()).isEqualByComparingTo(Integer.valueOf(0));
+ loopTemplate = loopTemplatesRepo.findById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
+ RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml")).get();
+ assertThat(((LoopTemplateLoopElementModel) (loopTemplate.getLoopElementModelsUsed().toArray()[0]))
+ .getLoopElementModel().getName()).isNotEmpty();
+
+ assertThat(policyModelsRepository.findAll().size()).isGreaterThanOrEqualTo(1);
+ assertThat(policyModelsRepository
+ .existsById(new PolicyModelId("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0"))).isTrue();
+ assertThat(policyModelsRepository
+ .getOne((new PolicyModelId("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0")))
+ .getPolicyModelTosca()).isNotBlank();
}
}