1 package org.openecomp.sdc.healing.healers;
3 import org.junit.AfterClass;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.BeforeClass;
7 import org.junit.Ignore;
9 import org.mockito.InjectMocks;
10 import org.mockito.Mock;
11 import org.mockito.Mockito;
12 import org.mockito.MockitoAnnotations;
13 import org.openecomp.core.model.dao.ServiceModelDao;
14 import org.openecomp.core.model.types.ServiceElement;
15 import org.openecomp.sdc.common.togglz.ToggleableFeature;
16 import org.openecomp.sdc.healing.healers.util.TestUtil;
17 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
18 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
19 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
20 import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
21 import org.openecomp.sdc.versioning.dao.types.Version;
22 import org.togglz.testing.TestFeatureManager;
23 import org.togglz.testing.TestFeatureManagerProvider;
25 import java.util.HashMap;
27 import java.util.Optional;
29 import static org.mockito.Matchers.any;
30 import static org.mockito.Matchers.anyObject;
31 import static org.mockito.Matchers.eq;
33 public class ForwarderCapabilityHealerTest {
34 private static final String vspId = "1";
35 private static final Version version = new Version(1, 1);
36 private static final String IN_SUFFIX = "/in";
37 private static final String OUT_SUFFIX = "/out";
38 private static final String BASE_DIRECTORY = "/mock/healers/forwarder";
39 private static final String ENTRY_DEFINITION_SERVICE_TEMPLATE = "MainServiceTemplate.yaml";
40 private static TestFeatureManager manager;
44 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
46 private ToscaAnalyzerService toscaAnalyzerService;
48 private ForwarderCapabilityHealer forwarderCapabilityHealer;
51 public static void enableForwarderFeature(){
52 manager = new TestFeatureManager(ToggleableFeature.class);
53 if (!ToggleableFeature.FORWARDER_CAPABILITY.isActive()) {
54 manager.enable(ToggleableFeature.FORWARDER_CAPABILITY);
59 public static void disableForwarderFeature() {
60 manager.disable(ToggleableFeature.FORWARDER_CAPABILITY);
62 TestFeatureManagerProvider.setFeatureManager(null);
66 public void setUp() throws Exception {
67 MockitoAnnotations.initMocks(ForwarderCapabilityHealerTest.this);
72 public void testHealingSubstitutionMappingsNeutronPort() throws Exception {
74 "/testSubMappingNeutronPort", "org.openecomp.resource.cp.nodes.heat.network.neutron.Port", true);
78 public void testHealingSubstitutionMappingsContrailPort() throws Exception {
80 "/testSubMappingContrailPort", "org.openecomp.resource.cp.nodes.heat.network.contrail.Port", true);
84 public void testHealingSubstitutionMappingsExtNeutronPort() throws Exception {
86 "/testSubMappingExtNeutronPort", "org.openecomp.resource.cp.v2.extNeutronCP", true);
90 public void testHealingSubstitutionMappingsExtContrailPort() throws Exception {
92 "/testSubMappingExtContrailPort", "org.openecomp.resource.cp.v2.extContrailCP", true);
96 public void testHealingGlobalServiceTemplates () throws Exception {
97 testForwarderHealer("/testGlobalServiceTemplates", null, false);
101 public void testHealingNoPorts() throws Exception {
102 testForwarderHealer("/testNoPorts", null, false);
105 private void testForwarderHealer(String testDirectory,
107 boolean needToTestSubMapping) throws Exception {
109 ToscaServiceModel toscaServiceModel = TestUtil.loadToscaServiceModel(
110 BASE_DIRECTORY + testDirectory + IN_SUFFIX, null, ENTRY_DEFINITION_SERVICE_TEMPLATE);
112 Mockito.doReturn(toscaServiceModel)
113 .when(serviceModelDao).getServiceModel(any(), any());
115 if(needToTestSubMapping) {
116 Mockito.doReturn(true)
117 .when(toscaAnalyzerService).isTypeOf(
118 eq(getMockPortNodeTemplate(portType)),
119 eq(ToscaNodeType.NATIVE_NETWORK_PORT),
120 anyObject(), anyObject());
123 validateServiceModelAfterHealing(testDirectory);
126 private void validateServiceModelAfterHealing(String testDirectory) throws Exception {
127 Optional<ToscaServiceModel> serviceModelObject =
128 (Optional<ToscaServiceModel>) forwarderCapabilityHealer.heal(vspId, version);
130 Assert.assertTrue(serviceModelObject.isPresent());
132 .compareToscaServiceModels(
133 BASE_DIRECTORY + testDirectory + OUT_SUFFIX, serviceModelObject.get());
136 private NodeTemplate getMockPortNodeTemplate(String portType) {
137 NodeTemplate nodeTemplate = new NodeTemplate();
138 nodeTemplate.setType(portType);
140 Map<String, Object> properties = new HashMap<>();
141 properties.put("exCP_naming", "port_pd01_port_exCP_naming");
142 nodeTemplate.setProperties(properties);