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.LegacyOperationalPolicyController;
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.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.loop.cds.CdsDataInstaller;
+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;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
-@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller")
+@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 LoopTemplatesRepository loopTemplatesRepo;
@Autowired
- ServiceRepository serviceRepository;
+ ServicesRepository serviceRepository;
@Autowired
PolicyModelsRepository policyModelsRepository;
private CsarInstaller csarInstaller;
private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid,
- String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException {
+ String blueprintFilePath, String artifactName,
+ String invariantServiceUuid) throws IOException {
IResourceInstance resource = Mockito.mock(IResourceInstance.class);
Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName);
Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid);
return csarHandler;
}
+ @Test
+ @Transactional
+ public void testPolicyModelAddedAtStartup() {
+ assertThat(policyModelsRepository.findByPolicyModelType(
+ LegacyOperationalPolicyController.OPERATIONAL_POLICY_LEGACY).get(0)).isNotNull();
+ }
+
@Test
@Transactional
public void testGetPolicyModelYaml() throws IOException, SdcToscaParserException, CsarHandlerException {
CsarHandler csarHandler = new CsarHandler(notificationData, "", "");
csarHandler
.setFilePath(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile());
- Optional<String> testyaml = csarHandler.getPolicyModelYaml();
- Assert.assertEquals(testyaml, Optional
+ Assert.assertEquals(csarHandler.getPolicyModelYaml(), Optional
.ofNullable(ResourceFileUtil.getResourceAsString("example/sdc/expected-result/policy-data.yaml")));
}
CsarHandler csar = buildFakeCsarHandler(generatedName);
csarInstaller.installTheCsar(csar);
assertThat(serviceRepository.existsById("63cac700-ab9a-4115-a74f-7eac85e3fce0")).isTrue();
+ // We should have CDS info
+ assertThat(serviceRepository.findById("63cac700-ab9a-4115-a74f-7eac85e3fce0").get().getResourceByType("VF")
+ .getAsJsonObject("vLoadBalancerMS 0").getAsJsonObject(
+ CdsDataInstaller.CONTROLLER_PROPERTIES)).isNotNull();
assertThat(loopTemplatesRepo.existsById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml"))).isTrue();
assertThat(loopTemplatesRepo.existsById(LoopTemplate.generateLoopTemplateName(generatedName, "1.0",
// set
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"),
assertThat(((LoopTemplateLoopElementModel) (loopTemplate.getLoopElementModelsUsed().toArray()[0]))
.getLoopElementModel().getName()).isNotEmpty();
- assertThat(policyModelsRepository.findAll().size()).isEqualByComparingTo(1);
+ 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