diff options
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test')
15 files changed, 0 insertions, 1943 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java deleted file mode 100644 index 1a89f75a70..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows; - -import static org.camunda.bpm.engine.history.HistoricProcessInstance.STATE_ACTIVE; -import static org.slf4j.LoggerFactory.getLogger; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import org.camunda.bpm.engine.HistoryService; -import org.camunda.bpm.engine.RuntimeService; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.camunda.bpm.engine.history.HistoricVariableInstance; -import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.junit.runner.RunWith; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; -import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import com.github.tomakehurst.wiremock.WireMockServer; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -@ContextConfiguration -@AutoConfigureWireMock(port = 0) -public abstract class BaseTest { - protected static final String ETSI_CATALOG_URL = "http://modeling-etsicatalog.onap:8806/api"; - protected static final String SOL003_ADAPTER_ENDPOINT_URL = "https://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1"; - protected static final String GLOBAL_CUSTOMER_ID = UUID.randomUUID().toString(); - protected static final String NSD_INVARIANT_ID = UUID.randomUUID().toString(); - protected static final String SERVICE_TYPE = "NetworkService"; - protected static final String UUID_REGEX = - "[0-9a-zA-Z]{8}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{12}"; - protected static final String RANDOM_JOB_ID = UUID.randomUUID().toString(); - - protected static final Logger logger = getLogger(BaseTest.class); - - private static final long TIME_OUT_IN_SECONDS = 120; - private static final int SLEEP_TIME_IN_SECONDS = 5; - - @Autowired - private HistoryService historyService; - - @Autowired - private RuntimeService runtimeService; - - @Autowired - protected DatabaseServiceProvider databaseServiceProvider; - - @Autowired - protected WireMockServer wireMockServer; - - public NfvoJob createNewNfvoJob(final String jobAction, final String nsdId, final String nsName) { - final NfvoJob newJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(JobAction.CREATE) - .status(JobStatusEnum.STARTING).resourceId(nsdId).resourceName(nsName); - databaseServiceProvider.addJob(newJob); - return newJob; - } - - public Optional<NfvoJob> getNfvoJob(final String jobId) { - return databaseServiceProvider.getJob(jobId); - } - - public Optional<NfvoJob> getJobByResourceId(final String resourceId) { - return databaseServiceProvider.getJobByResourceId(resourceId); - } - - public ProcessInstance executeWorkflow(final String processDefinitionKey, final String businessKey, - final Map<String, Object> variables) { - return runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables); - } - - public HistoricProcessInstance getHistoricProcessInstance(final String processInstanceId) { - return historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); - } - - public HistoricVariableInstance getVariable(final String processInstanceId, final String name) { - return historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId) - .variableName(name).singleResult(); - } - - public List<HistoricVariableInstance> getVariables(final String processInstanceId) { - return historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list(); - } - - public boolean waitForProcessInstanceToFinish(final String processInstanceId) throws InterruptedException { - final long startTimeInMillis = System.currentTimeMillis(); - final long timeOutTime = startTimeInMillis + TimeUnit.SECONDS.toMillis(TIME_OUT_IN_SECONDS); - while (timeOutTime > System.currentTimeMillis()) { - - if (isProcessEndedByProcessInstanceId(processInstanceId)) { - logger.info("processInstanceId: {} is finished", processInstanceId); - return true; - } - logger.info("processInstanceId: {} is still running", processInstanceId); - logger.info("Process instance {} not finished yet, will try again in {} seconds", processInstanceId, - SLEEP_TIME_IN_SECONDS); - TimeUnit.SECONDS.sleep(SLEEP_TIME_IN_SECONDS); - } - logger.warn("Timeout {} process didn't finished ", processInstanceId); - return false; - } - - - public boolean isProcessEndedByProcessInstanceId(final String processInstanceId) { - return !isProcessInstanceActive(processInstanceId) && isProcessInstanceEnded(processInstanceId); - } - - private boolean isProcessInstanceActive(final String processInstanceId) { - final HistoricProcessInstance processInstance = getHistoricProcessInstance(processInstanceId); - return processInstance != null && STATE_ACTIVE.equalsIgnoreCase(processInstance.getState()); - } - - private boolean isProcessInstanceEnded(final String processInstanceId) { - return runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null; - } - - protected String getAaiServiceInstanceEndPoint() { - return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID - + "/service-subscriptions/service-subscription/" + SERVICE_TYPE - + "/service-instances/service-instance/.*"; - } -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/DefaultToShortClassNameBeanNameGenerator.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/DefaultToShortClassNameBeanNameGenerator.java deleted file mode 100644 index f91cf9d0c3..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/DefaultToShortClassNameBeanNameGenerator.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.AnnotationBeanNameGenerator; -import org.springframework.util.ClassUtils; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class DefaultToShortClassNameBeanNameGenerator extends AnnotationBeanNameGenerator { - - @Override - protected String buildDefaultBeanName(final BeanDefinition definition) { - return ClassUtils.getShortName(definition.getBeanClassName()); - } -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java deleted file mode 100644 index edfb20afd2..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows; - -import java.util.Arrays; -import java.util.List; -import org.junit.Test; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction; -import org.onap.so.openpojo.rules.ToStringTester; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class PojoClassesTests { - - @Test - public void test_nsd_parser_pojo_classes() throws ClassNotFoundException { - - final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) - .with(new ToStringTester()).build(); - validator.validate(FileEntry.class.getPackageName(), new FilterPackageInfo()); - } - - - @Test - public void test_nsd_parser_pojo_classes_equalAndHashMethod() throws ClassNotFoundException { - final List<Class<?>> classes = Arrays.asList(FileEntry.class, NetworkServiceDescriptor.class, - ToscaMetadata.class, VirtualNetworkFunction.class); - for (final Class<?> clazz : classes) { - EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, - Warning.INHERITED_DIRECTLY_FROM_OBJECT).verify(); - } - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/TestApplication.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/TestApplication.java deleted file mode 100644 index 18d601930c..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/TestApplication.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; -import org.springframework.context.annotation.ComponentScan.Filter; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@SpringBootApplication(scanBasePackages = {"org.onap.so"}) -@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) -@ComponentScan(basePackages = {"org.onap"}, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class, - excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) -public class TestApplication { - - public static void main(final String[] args) { - new SpringApplication(TestApplication.class).run(args); - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java deleted file mode 100644 index 4a8c715e5c..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Map; -import java.util.Optional; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.TestApplication; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser.NetworkServiceDescriptorParser; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -public class NetworkServiceDescriptorParserTest { - - private static final String VALID_ETSI_NSD_FILE = "src/test/resources/ns.csar"; - private static final String INVALID_ETSI_NSD_FILE = "src/test/resources/invalid_ns.csar"; - - @Autowired - private NetworkServiceDescriptorParser objUnderTest; - - @Test - public void testValidEtsiNsd_ableToParseIt() throws IOException { - final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE))); - final Optional<NetworkServiceDescriptor> optional = objUnderTest.parse(zipBytes); - assertTrue(optional.isPresent()); - final NetworkServiceDescriptor actualNsd = optional.get(); - assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType()); - assertFalse(actualNsd.getProperties().isEmpty()); - - final Map<String, Object> actualNsdProperties = actualNsd.getProperties(); - assertEquals(5, actualNsdProperties.size()); - assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id")); - assertEquals(5, actualNsd.getVnfs().size()); - - } - - @Test - public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException { - assertFalse(objUnderTest.parse(new byte[] {}).isPresent()); - } - - @Test - public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException { - final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE))); - assertFalse(objUnderTest.parse(zipBytes).isPresent()); - } - - private String getAbsolutePath(final String path) { - final File file = new File(path); - return file.getAbsolutePath(); - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java deleted file mode 100644 index 3686cd620d..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java +++ /dev/null @@ -1,381 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.notFound; -import static com.github.tomakehurst.wiremock.client.WireMock.ok; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.camunda.bpm.engine.history.HistoricVariableInstance; -import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.WorkflowQueryService; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; -import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest; -import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; -import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; -import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance.NsStateEnum; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.RestTemplate; -import com.github.tomakehurst.wiremock.client.WireMock; -import com.google.gson.Gson; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class CreateNsTaskTest extends BaseTest { - private static final String NSD_ID = UUID.randomUUID().toString(); - private static final String NS_NAME = "CreateNetworkService-" + NSD_ID; - private static final String CREATE_NS_WORKFLOW_NAME = "CreateNs"; - - @Autowired - @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) - private RestTemplate restTemplate; - - @Autowired - private GsonProvider gsonProvider; - - @Autowired - private JobExecutorService objUnderTest; - - @Autowired - private WorkflowQueryService workflowQueryService; - - private MockRestServiceServer mockRestServiceServer; - - private Gson gson; - - @Before - public void before() { - wireMockServer.resetAll(); - final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate); - builder.ignoreExpectOrder(true); - mockRestServiceServer = builder.build(); - gson = gsonProvider.getGson(); - restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } - - @After - public void after() { - wireMockServer.resetAll(); - mockRestServiceServer.reset(); - } - - @Test - public void testCreateNsWorkflow_SuccessfullCase() throws InterruptedException { - final CreateNsRequest createNsRequest = getCreateNsRequest(); - - mockEtsiCatalogEndpoints(); - mockAAIEndpoints(createNsRequest); - - final NsInstancesNsInstance nsResponse = - objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); - assertNotNull(nsResponse); - assertNotNull(nsResponse.getId()); - - final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - - assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); - - mockRestServiceServer.verify(); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - assertTrue(databaseServiceProvider.isNsInstExists(createNsRequest.getNsName())); - - final NfvoJob actualJob = optional.get(); - assertEquals(JobStatusEnum.FINISHED, actualJob.getStatus()); - - assertEquals(NS_NAME, nsResponse.getNsInstanceName()); - assertEquals(NsStateEnum.NOT_INSTANTIATED, nsResponse.getNsState()); - - final HistoricVariableInstance doesNsPackageExistsVar = - getVariable(nfvoJob.getProcessInstanceId(), "doesNsPackageExists"); - assertNotNull(doesNsPackageExistsVar); - assertTrue((boolean) doesNsPackageExistsVar.getValue()); - - final HistoricVariableInstance doesNsInstanceExistsVar = - getVariable(nfvoJob.getProcessInstanceId(), "doesNsInstanceExists"); - assertNotNull(doesNsInstanceExistsVar); - assertFalse((boolean) doesNsInstanceExistsVar.getValue()); - - } - - @Test - public void testCreateNsWorkflow_FailsToGetNsPackage() throws InterruptedException { - final String nsdId = UUID.randomUUID().toString(); - final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); - final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); - - mockRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) - .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND)); - - try { - objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); - fail("runCreateNsJob should throw exception"); - } catch (final Exception exception) { - assertEquals(NsRequestProcessingException.class, exception.getClass()); - } - - final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - assertEquals(JobStatusEnum.ERROR, nfvoJob.getStatus()); - - assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); - - mockRestServiceServer.verify(); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - - final HistoricVariableInstance nsResponseVariable = - getVariable(nfvoJob.getProcessInstanceId(), CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME); - assertNull(nsResponseVariable); - - final Optional<InlineResponse400> problemDetailsOptional = - workflowQueryService.getProblemDetails(nfvoJob.getProcessInstanceId()); - assertTrue(problemDetailsOptional.isPresent()); - - final InlineResponse400 problemDetails = problemDetailsOptional.get(); - assertNotNull(problemDetails); - assertNotNull(problemDetails.getDetail()); - - final HistoricVariableInstance doesNsPackageExistsVar = - getVariable(nfvoJob.getProcessInstanceId(), "doesNsPackageExists"); - assertNotNull(doesNsPackageExistsVar); - assertFalse((boolean) doesNsPackageExistsVar.getValue()); - assertEquals("Unexpected exception occured while getting ns package using nsdId: " + nsdId, - problemDetails.getDetail()); - } - - @Test - public void testCreateNsWorkflow_FailsToFindJobUsingJobId() throws InterruptedException { - final String nsdId = UUID.randomUUID().toString(); - final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); - final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); - - final String randomJobId = UUID.randomUUID().toString(); - final ProcessInstance processInstance = - executeWorkflow(CREATE_NS_WORKFLOW_NAME, randomJobId, getVariables(randomJobId, createNsRequest)); - assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); - - mockRestServiceServer.verify(); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(processInstance.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME); - - assertNull(nsResponseVariable); - - final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); - - final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); - assertNotNull(problemDetails); - assertNotNull(problemDetails.getDetail()); - assertEquals("Unable to find job using job id: " + randomJobId, problemDetails.getDetail()); - - } - - @Test - public void testCreateNsWorkflow_NsInstanceExistsInDb() throws InterruptedException { - final String nsdId = UUID.randomUUID().toString(); - final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); - final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); - - databaseServiceProvider.saveNfvoNsInst(new NfvoNsInst().nsInstId(nsdId).name(createNsRequest.getNsName()) - .nsPackageId(UUID.randomUUID().toString()).nsdId(nsdId).nsdInvariantId(nsdId) - .description(createNsRequest.getNsDescription()).status(State.INSTANTIATED) - .statusUpdatedTime(LocalDateTime.now()).globalCustomerId(GLOBAL_CUSTOMER_ID).serviceType(SERVICE_TYPE)); - - mockEtsiCatalogEndpoints(nsdId); - - try { - objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); - fail("runCreateNsJob should throw exception"); - } catch (final Exception exception) { - assertEquals(NsRequestProcessingException.class, exception.getClass()); - } - - final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - assertEquals(JobStatusEnum.ERROR, nfvoJob.getStatus()); - - assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); - - mockRestServiceServer.verify(); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - assertTrue(databaseServiceProvider.isNsInstExists(createNsRequest.getNsName())); - - final HistoricVariableInstance historicVariableInstance = - getVariable(nfvoJob.getProcessInstanceId(), CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME); - - assertNull(historicVariableInstance); - - final Optional<InlineResponse400> problemDetailsOptional = - workflowQueryService.getProblemDetails(nfvoJob.getProcessInstanceId()); - - final InlineResponse400 problemDetails = problemDetailsOptional.get(); - assertNotNull(problemDetails); - assertNotNull(problemDetails.getDetail()); - assertTrue(problemDetails.getDetail().startsWith("Ns Instance already exists in database")); - - final HistoricVariableInstance doesNsInstanceExistsVar = - getVariable(nfvoJob.getProcessInstanceId(), "doesNsInstanceExists"); - assertNotNull(doesNsInstanceExistsVar); - assertTrue((boolean) doesNsInstanceExistsVar.getValue()); - - } - - @Test - public void testCreateNsWorkflow_FailToCreateResouceInAai() throws InterruptedException { - final String nsdId = UUID.randomUUID().toString(); - final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); - final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); - - mockEtsiCatalogEndpoints(nsdId); - - final String modelEndpoint = getAaiServiceInstanceEndPoint(); - wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); - wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); - - try { - objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); - fail("runCreateNsJob should throw exception"); - } catch (final Exception exception) { - assertEquals(NsRequestProcessingException.class, exception.getClass()); - } - final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - assertEquals(JobStatusEnum.ERROR, nfvoJob.getStatus()); - - mockRestServiceServer.verify(); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - assertTrue(databaseServiceProvider.isNsInstExists(createNsRequest.getNsName())); - - final Optional<InlineResponse400> problemDetailsOptional = - workflowQueryService.getProblemDetails(nfvoJob.getProcessInstanceId()); - - final InlineResponse400 problemDetails = problemDetailsOptional.get(); - assertNotNull(problemDetails); - assertEquals("Unable to Create Service Instance in AAI", problemDetails.getDetail()); - - } - - private void mockAAIEndpoints(final CreateNsRequest createNsRequest) { - final String modelEndpoint = getAaiServiceInstanceEndPoint(); - - wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(ok())); - wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(notFound())); - } - - private void mockEtsiCatalogEndpoints(final String nsdId) { - mockRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getNSPackageModel(NSD_ID)), MediaType.APPLICATION_JSON)); - } - - private void mockEtsiCatalogEndpoints() { - mockEtsiCatalogEndpoints(NSD_ID);; - } - - private NsdInfo getNSPackageModel(final String nsdId) { - return new NsdInfo().id(nsdId).nsdId(nsdId).nsdInvariantId(NSD_INVARIANT_ID).nsdName("vcpe").nsdDesigner("ONAP") - .vnfPkgIds(Arrays.asList(GLOBAL_CUSTOMER_ID)); - } - - private CreateNsRequest getCreateNsRequest() { - return getCreateNsRequest(NSD_ID, NS_NAME); - } - - private CreateNsRequest getCreateNsRequest(final String nsdId, final String nsName) { - return new CreateNsRequest().nsdId(nsdId).nsName(nsName); - } - - private Map<String, Object> getVariables(final String jobId, final CreateNsRequest createNsRequest) { - final Map<String, Object> variables = new HashMap<>(); - variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); - variables.put(CamundaVariableNameConstants.CREATE_NS_REQUEST_PARAM_NAME, createNsRequest); - variables.put(CamundaVariableNameConstants.GLOBAL_CUSTOMER_ID_PARAM_NAME, GLOBAL_CUSTOMER_ID); - variables.put(CamundaVariableNameConstants.SERVICE_TYPE_PARAM_NAME, SERVICE_TYPE); - - return variables; - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java deleted file mode 100644 index 017bdf6b70..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.ok; -import static com.github.tomakehurst.wiremock.client.WireMock.okJson; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.time.LocalDateTime; -import java.util.Optional; -import java.util.UUID; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * - */ -public class DeleteNsTaskTest extends BaseTest { - - @Autowired - private JobExecutorService objUnderTest; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void before() { - wireMockServer.resetAll(); - } - - @After - public void after() { - wireMockServer.resetAll(); - } - - @Test - public void testRunDeleteNsJob_nsInstanceIdNotInDatabase_throwsException() { - final String nsInstanceId = UUID.randomUUID().toString(); - assertTrue(databaseServiceProvider.getNfvoNsInst(nsInstanceId).isEmpty()); - - expectedException.expect(NsRequestProcessingException.class); - objUnderTest.runDeleteNsJob(nsInstanceId); - } - - @Test - public void testRunDeleteNsJob_nsInstanceStateInstantiated_throwsException() { - final String nsInstanceId = UUID.randomUUID().toString(); - addDummyNsToDatabase(nsInstanceId, State.INSTANTIATED); - - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInst.isPresent()); - assertEquals(State.INSTANTIATED, optionalNfvoNsInst.get().getStatus()); - - expectedException.expect(NsRequestProcessingException.class); - objUnderTest.runDeleteNsJob(nsInstanceId); - } - - @Test - public void testRunDeleteNsJob_nsInstanceStateInstantiating_throwsException() { - final String nsInstanceId = UUID.randomUUID().toString(); - addDummyNsToDatabase(nsInstanceId, State.INSTANTIATING); - - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInst.isPresent()); - assertEquals(State.INSTANTIATING, optionalNfvoNsInst.get().getStatus()); - - expectedException.expect(NsRequestProcessingException.class); - objUnderTest.runDeleteNsJob(nsInstanceId); - } - - @Test - public void testRunDeleteNsJob_nsInstanceStateTerminating_throwsException() { - final String nsInstanceId = UUID.randomUUID().toString(); - addDummyNsToDatabase(nsInstanceId, State.TERMINATING); - - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInst.isPresent()); - assertEquals(State.TERMINATING, optionalNfvoNsInst.get().getStatus()); - - expectedException.expect(NsRequestProcessingException.class); - objUnderTest.runDeleteNsJob(nsInstanceId); - } - - @Test - public void testRunDeleteNsJob_nsInstanceStateFailed_throwsException() { - final String nsInstanceId = UUID.randomUUID().toString(); - addDummyNsToDatabase(nsInstanceId, State.FAILED); - - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInst.isPresent()); - assertEquals(State.FAILED, optionalNfvoNsInst.get().getStatus()); - - expectedException.expect(NsRequestProcessingException.class); - objUnderTest.runDeleteNsJob(nsInstanceId); - } - - @Test - public void testRunDeleteNsJob_SuccessfulCase() throws InterruptedException { - final String nsInstanceId = UUID.randomUUID().toString(); - addDummyNsToDatabase(nsInstanceId, State.NOT_INSTANTIATED); - mockAaiEndpoints(); - - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInst.isPresent()); - assertEquals(State.NOT_INSTANTIATED, optionalNfvoNsInst.get().getStatus()); - - objUnderTest.runDeleteNsJob(nsInstanceId); - - final Optional<NfvoJob> optional = getJobByResourceId(nsInstanceId); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - - // Confirm Process finishes in STATE_COMPLETED - assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - // Confirm NS Instance no longer in database - final Optional<NfvoNsInst> optionalNfvoNsInstance = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInstance.isEmpty()); - } - - private void addDummyNsToDatabase(final String nsInstanceId, final State state) { - final String nsPackageId = UUID.randomUUID().toString(); - final NfvoNsInst nfvoNsInst = new NfvoNsInst().nsInstId(nsInstanceId).name("nsName").nsPackageId(nsPackageId) - .nsdId("nsdId").nsdInvariantId("nsdId").status(state).statusUpdatedTime(LocalDateTime.now()) - .globalCustomerId(GLOBAL_CUSTOMER_ID).serviceType(SERVICE_TYPE); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); - } - - private void mockAaiEndpoints() { - final String modelEndpoint = getAaiServiceInstanceEndPoint(); - final String resourceVersion = "12345"; - - final String body = - "{\"resource-version\": \"" + resourceVersion + "\",\n\"orchestration-status\": \"Assigned\"}"; - wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()).willReturn(okJson(body))); - - wireMockServer.stubFor( - delete(urlMatching(modelEndpoint + "\\?resource-version=" + resourceVersion)).willReturn(ok())); - } -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java deleted file mode 100644 index f1373bd4ea..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java +++ /dev/null @@ -1,327 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.notFound; -import static com.github.tomakehurst.wiremock.client.WireMock.ok; -import static com.github.tomakehurst.wiremock.client.WireMock.okJson; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaiclient.client.aai.AAIVersion.V19; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_REST_TEMPLATE_BEAN; -import static org.springframework.test.web.client.ExpectedCount.times; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.camunda.bpm.engine.history.HistoricVariableInstance; -import org.hamcrest.text.MatchesPattern; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.aaiclient.client.aai.entities.Results; -import org.onap.aaiclient.client.graphinventory.entities.Resource; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; -import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; -import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest; -import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.Gson; - -/** - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class InstantiateNsTaskTest extends BaseTest { - - private static final String TENANT_ID = "6ca8680feba04dad9254f423c6e28e1c"; - private static final String CLOUD_REGION = "regionOne"; - private static final String CLOUD_OWNER = "CloudOwner"; - private static final String UUID_REGEX = - "[0-9a-zA-Z]{8}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{12}"; - private static final String VCPE_VBRGEMU_VNFD_ID = "b1bb0ce7-2222-4fa7-95ed-4840d70a1102"; - private static final String VCPE_VBNG = "b1bb0ce7-2222-4fa7-95ed-4840d70a1101"; - private static final String VCPE_INFRA_VNFD_ID = "b1bb0ce7-2222-4fa7-95ed-4840d70a1100"; - private static final String VGMUX_VNFD_ID = "0408f076-e6c0-4c82-9940-272fddbb82de"; - private static final String VGW_VNFD_ID = "3fca3543-07f5-492f-812c-ed462e4f94f4"; - private static final String[] VCPE_VNFDS = - new String[] {VGW_VNFD_ID, VGMUX_VNFD_ID, VCPE_INFRA_VNFD_ID, VCPE_VBNG, VCPE_VBRGEMU_VNFD_ID}; - private static final String SAMPLE_NSD_FILE = "src/test/resources/ns.csar"; - private static final String NS_NAME = "InstantiateNetworkService"; - - @Autowired - private DatabaseServiceProvider databaseServiceProvider; - - @Autowired - @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) - private RestTemplate etsiCatalogRestTemplate; - - @Autowired - @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) - private RestTemplate sol003AdapterRestTemplate; - - private MockRestServiceServer mockEtsiCatalogRestServiceServer; - - private MockRestServiceServer mockSol003AdapterRestServiceServer; - - @Autowired - private JobExecutorService objUnderTest; - - @Autowired - private GsonProvider gsonProvider; - - private Gson gson; - - private static final Map<String, String> VNFD_ID_TO_VNFPKG_ID_MAPPING = new HashMap<>(); - static { - for (final String vnfd : VCPE_VNFDS) { - VNFD_ID_TO_VNFPKG_ID_MAPPING.put(vnfd, UUID.randomUUID().toString()); - } - } - - @Before - public void before() { - wireMockServer.resetAll(); - gson = gsonProvider.getGson(); - - mockEtsiCatalogRestServiceServer = - MockRestServiceServer.bindTo(etsiCatalogRestTemplate).ignoreExpectOrder(true).build(); - mockSol003AdapterRestServiceServer = - MockRestServiceServer.bindTo(sol003AdapterRestTemplate).ignoreExpectOrder(true).build(); - - etsiCatalogRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - sol003AdapterRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - - } - - @After - public void after() { - wireMockServer.resetAll(); - mockEtsiCatalogRestServiceServer.reset(); - } - - @Test - public void testInstantiateNsWorkflow_JustUpdateStatus_SuccessfullCase() throws InterruptedException, IOException { - final String nsdId = UUID.randomUUID().toString(); - final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); - - final NfvoNsInst newNfvoNsInst = new NfvoNsInst().nsInstId(nsdId).name(nsdName) - .nsPackageId(UUID.randomUUID().toString()).nsPackageId(nsdId).nsdId(nsdId).nsdInvariantId(nsdId) - .status(State.NOT_INSTANTIATED).statusUpdatedTime(LocalDateTime.now()); - - databaseServiceProvider.saveNfvoNsInst(newNfvoNsInst); - - mockSol003AdapterEndpoints(); - mockAAIEndpoints(nsdId); - mockEtsiCatalogEndpoints(nsdId); - - final String nsLcmOpOccId = - objUnderTest.runInstantiateNsJob(newNfvoNsInst.getNsInstId(), getInstantiateNsRequest()); - - final Optional<NfvoJob> optional = getJobByResourceId(newNfvoNsInst.getNsInstId()); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - - assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); - - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - // check if value in database has updated - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsdId); - final NfvoNsInst nfvoNsInst = optionalNfvoNsInst.get(); - assertEquals(State.INSTANTIATED, nfvoNsInst.getStatus()); - - final HistoricVariableInstance historicVariableInstance = - getVariable(nfvoJob.getProcessInstanceId(), NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME); - assertNotNull(historicVariableInstance); - final NetworkServiceDescriptor nsd = (NetworkServiceDescriptor) historicVariableInstance.getValue(); - assertNotNull(nsd); - - assertEquals(VNFD_ID_TO_VNFPKG_ID_MAPPING.size(), nsd.getVnfs().size()); - - final List<NfvoNfInst> nfvoNfInsts = databaseServiceProvider.getNfvoNfInstByNsInstId(nsdId); - assertNotNull(nsd); - assertEquals(VNFD_ID_TO_VNFPKG_ID_MAPPING.size(), nfvoNfInsts.size()); - - final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); - assertTrue(optionalNsLcmOpOcc.isPresent()); - - assertEquals(OperationStateEnum.COMPLETED, optionalNsLcmOpOcc.get().getOperationState()); - - final Map<String, NfvoNfInst> nfvoNfInstsMap = - nfvoNfInsts.stream().collect(Collectors.toMap(NfvoNfInst::getVnfdId, nfvoNfInst -> nfvoNfInst)); - - for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { - assertTrue(nfvoNfInstsMap.containsKey(entry.getKey())); - assertEquals(State.INSTANTIATED, nfvoNfInstsMap.get(entry.getKey()).getStatus()); - - } - - } - - private void mockSol003AdapterEndpoints() { - mockSol003AdapterRestServiceServer - .expect(times(VNFD_ID_TO_VNFPKG_ID_MAPPING.size()), - requestTo(MatchesPattern.matchesPattern(SOL003_ADAPTER_ENDPOINT_URL + "/vnfs/.*"))) - .andExpect(method(HttpMethod.POST)) - .andRespond(withSuccess(gson.toJson(new CreateVnfResponse().jobId(UUID.randomUUID().toString())), - MediaType.APPLICATION_JSON)); - - mockSol003AdapterRestServiceServer - .expect(times(VNFD_ID_TO_VNFPKG_ID_MAPPING.size()), - requestTo(MatchesPattern.matchesPattern(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/.*"))) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson( - new org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse().operationState( - org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.COMPLETED) - .operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND)), - MediaType.APPLICATION_JSON)); - } - - private void mockEtsiCatalogEndpoints(final String nsdId) throws IOException { - mockEtsiCatalogRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getNSPackageModel(nsdId)), MediaType.APPLICATION_JSON)); - mockEtsiCatalogRestServiceServer - .expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId + "/nsd_content")) - .andExpect(method(HttpMethod.GET)).andRespond(withSuccess( - getFileContent(getAbsolutePath(SAMPLE_NSD_FILE)), MediaType.APPLICATION_OCTET_STREAM)); - - for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { - mockEtsiCatalogRestServiceServer - .expect(requestTo(ETSI_CATALOG_URL + "/vnfpkgm/v1/vnf_packages/" + entry.getValue())) - .andExpect(method(HttpMethod.GET)).andRespond(withSuccess( - gson.toJson(getVnfPkgInfo(entry.getKey(), entry.getValue())), MediaType.APPLICATION_JSON)); - } - - } - - private VnfPkgInfo getVnfPkgInfo(final String vnfdId, final String vnfPkgId) { - return new VnfPkgInfo().id(vnfPkgId).vnfdId(vnfdId); - } - - private InstantiateNsRequest getInstantiateNsRequest() { - final Map<String, Object> additionalParams = new HashMap<>(); - additionalParams.put("vim_id", CLOUD_OWNER + "_" + CLOUD_REGION + "_" + TENANT_ID); - - final InstantiateNsRequest instantiateNsRequest = new InstantiateNsRequest().nsFlavourId("default"); - - for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { - instantiateNsRequest - .addAdditionalParamsForVnfItem(new NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf() - .vnfProfileId(entry.getKey()).additionalParams(additionalParams)); - } - - return instantiateNsRequest; - } - - private NsdInfo getNSPackageModel(final String nsdId) { - return new NsdInfo().id(nsdId).nsdId(nsdId).nsdInvariantId(NSD_INVARIANT_ID).nsdName("vcpe").nsdDesigner("ONAP") - .vnfPkgIds(new ArrayList<>(VNFD_ID_TO_VNFPKG_ID_MAPPING.values())); - } - - private byte[] getFileContent(final String path) throws IOException { - return Files.readAllBytes(Paths.get(path)); - } - - - private String getAbsolutePath(final String path) { - return new File(path).getAbsolutePath(); - } - - private void mockAAIEndpoints(final String nsdId) throws JsonProcessingException { - final String modelEndpoint = "/aai/" + V19 + "/network/generic-vnfs/generic-vnf/" + UUID_REGEX; - - wireMockServer.stubFor( - get(urlMatching(modelEndpoint + "\\?resultIndex=0&resultSize=1&format=count")).willReturn(notFound())); - - wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(ok())); - wireMockServer.stubFor(put(urlMatching(modelEndpoint + "/relationship-list/relationship")).willReturn(ok())); - - wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()) - .willReturn(okJson("{\"orchestration-status\": \"Created\"}"))); - - wireMockServer.stubFor(get(urlMatching("/aai/" + V19 + "/nodes/service-instances/service-instance/.*")) - .willReturn(okJson(getResourceResultsResponseAsJson(nsdId)))); - - wireMockServer.stubFor( - put(urlMatching("/aai/" + V19 + "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" - + CLOUD_REGION + "/tenants/tenant/" + TENANT_ID + "/relationship-list/relationship")) - .willReturn(ok())); - - } - - private String getResourceResultsResponseAsJson(final String nsdId) throws JsonProcessingException { - final Resource resource = new Resource(); - resource.setResourceType("service-instance"); - resource.setResourceLink("/aai/" + V19 + "/business/customers/customer/" + GLOBAL_CUSTOMER_ID - + "/service-subscriptions/service-subscription/NetworkService/service-instances/service-instance/" - + nsdId); - final Results<Resource> results = new Results<>(); - results.getResult().add(resource); - return new ObjectMapper().writeValueAsString(results); - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorInstantiateSol003AdapterNodeTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorInstantiateSol003AdapterNodeTaskTest.java deleted file mode 100644 index ea720cd73b..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorInstantiateSol003AdapterNodeTaskTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.ok; -import static com.github.tomakehurst.wiremock.client.WireMock.okJson; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.camunda.bpm.engine.history.HistoricVariableInstance; -import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.junit.Before; -import org.junit.Test; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks.MonitorInstantiateSol003AdapterNodeTask; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class MonitorInstantiateSol003AdapterNodeTaskTest extends BaseTest { - - private static final String RANDOWM_GENERIC_VNF_ID = UUID.randomUUID().toString(); - private static final String MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW = - "MonitorSol003AdapterCreateNodeStatus"; - - @Before - public void before() { - wireMockServer.resetAll(); - } - - @Test - public void testMonitorSol003AdapterCreateNodeStatus_SuccessfullCase() throws InterruptedException { - - final String modelEndpoint = "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + UUID_REGEX; - - wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()) - .willReturn(okJson("{\"orchestration-status\": \"Created\"}"))); - - - final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW, - RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, RANDOWM_GENERIC_VNF_ID)); - - assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); - - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(processInstance.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), - MonitorInstantiateSol003AdapterNodeTask.CREATE_VNF_NODE_STATUS); - - assertNotNull(nsResponseVariable); - assertTrue((boolean) nsResponseVariable.getValue()); - - } - - private Map<String, Object> getVariables(final String jobId, final String vnfId) { - final Map<String, Object> variables = new HashMap<>(); - variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); - variables.put(CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME, vnfId); - - return variables; - } - - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java deleted file mode 100644 index aa8d8cf10e..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.COMPLETED; -import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum.STATUS_FOUND; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_REST_TEMPLATE_BEAN; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; -import java.util.HashMap; -import java.util.Map; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.camunda.bpm.engine.history.HistoricVariableInstance; -import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.junit.Before; -import org.junit.Test; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; -import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.RestTemplate; -import com.google.gson.Gson; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class MonitorSol003AdapterCreateJobTaskTest extends BaseTest { - - private static final String MONITOR_SOL003_ADAPTER_CREATE_JOB_WORKFLOW = "MonitorSol003AdapterCreateJob"; - - @Autowired - @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) - private RestTemplate restTemplate; - - @Autowired - private GsonProvider gsonProvider; - - private MockRestServiceServer mockRestServiceServer; - private Gson gson; - - @Before - public void before() { - wireMockServer.resetAll(); - final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate); - builder.ignoreExpectOrder(true); - mockRestServiceServer = builder.build(); - - gson = gsonProvider.getGson(); - restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } - - - @Test - public void testMonitorSol003AdapterCreateJobTaskWorkflow_SuccessfullCase() throws InterruptedException { - - mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getQueryJobResponse()), MediaType.APPLICATION_JSON)); - - final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_JOB_WORKFLOW, - RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, new CreateVnfResponse().jobId(RANDOM_JOB_ID))); - - assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); - - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(processInstance.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME); - - assertNotNull(nsResponseVariable); - assertEquals(COMPLETED, nsResponseVariable.getValue()); - - } - - @Test - public void testMonitorSol003AdapterCreateJobTaskWorkflow_FailurelCase() throws InterruptedException { - - mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) - .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND)); - - final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_JOB_WORKFLOW, - RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, new CreateVnfResponse().jobId(RANDOM_JOB_ID))); - - assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); - - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(processInstance.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME); - - assertNull(nsResponseVariable); - - final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); - - final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); - assertNotNull(problemDetails); - assertNotNull(problemDetails.getDetail()); - } - - - private QueryJobResponse getQueryJobResponse() { - return new QueryJobResponse().id(RANDOM_JOB_ID).operationState(COMPLETED) - .operationStatusRetrievalStatus(STATUS_FOUND); - } - - private Map<String, Object> getVariables(final String jobId, final CreateVnfResponse createVnfResponse) { - final Map<String, Object> variables = new HashMap<>(); - variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); - variables.put(CamundaVariableNameConstants.CREATE_VNF_RESPONSE_PARAM_NAME, createVnfResponse); - - return variables; - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterTerminateJobTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterTerminateJobTaskTest.java deleted file mode 100644 index 13fff6d32b..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterTerminateJobTaskTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import com.google.gson.Gson; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.camunda.bpm.engine.history.HistoricVariableInstance; -import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.junit.Before; -import org.junit.Test; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.RestTemplate; -import java.util.HashMap; -import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.COMPLETED; -import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.PROCESSING; -import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum.STATUS_FOUND; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_REST_TEMPLATE_BEAN; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * - */ -public class MonitorSol003AdapterTerminateJobTaskTest extends BaseTest { - - private static final String MONITOR_SOL003_ADAPTER_TERMINATE_JOB_WORKFLOW = "MonitorSol003AdapterTerminateJob"; - - @Autowired - @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) - private RestTemplate restTemplate; - - @Autowired - private GsonProvider gsonProvider; - - private MockRestServiceServer mockRestServiceServer; - private Gson gson; - - @Before - public void before() { - wireMockServer.resetAll(); - - final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate); - builder.ignoreExpectOrder(true); - mockRestServiceServer = builder.build(); - - gson = gsonProvider.getGson(); - restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } - - - @Test - public void testMonitorSol003AdapterTerminateJobTaskWorkflow_SuccessfulCase() throws InterruptedException { - mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getQueryJobResponse(COMPLETED)), MediaType.APPLICATION_JSON)); - - final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_TERMINATE_JOB_WORKFLOW, - RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, new DeleteVnfResponse().jobId(RANDOM_JOB_ID))); - assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); - - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(processInstance.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME); - assertNotNull(nsResponseVariable); - assertEquals(COMPLETED, nsResponseVariable.getValue()); - } - - @Test - public void testMonitorSol003AdapterTerminateJobTaskWorkflow_SuccessfulCaseFollowingProcessingDelay() - throws InterruptedException { - mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getQueryJobResponse(PROCESSING)), MediaType.APPLICATION_JSON)); - mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getQueryJobResponse(PROCESSING)), MediaType.APPLICATION_JSON)); - mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(getQueryJobResponse(COMPLETED)), MediaType.APPLICATION_JSON)); - - final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_TERMINATE_JOB_WORKFLOW, - RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, new DeleteVnfResponse().jobId(RANDOM_JOB_ID))); - assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); - - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(processInstance.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME); - assertNotNull(nsResponseVariable); - assertEquals(COMPLETED, nsResponseVariable.getValue()); - } - - private QueryJobResponse getQueryJobResponse(final OperationStateEnum operationState) { - return new QueryJobResponse().id(RANDOM_JOB_ID).operationState(operationState) - .operationStatusRetrievalStatus(STATUS_FOUND); - } - - private Map<String, Object> getVariables(final String jobId, final DeleteVnfResponse deleteVnfResponse) { - final Map<String, Object> variables = new HashMap<>(); - variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); - variables.put(CamundaVariableNameConstants.DELETE_VNF_RESPONSE_PARAM_NAME, deleteVnfResponse); - - return variables; - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java deleted file mode 100644 index 51460ec4c8..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks; - -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.ok; -import static com.github.tomakehurst.wiremock.client.WireMock.okJson; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_REST_TEMPLATE_BEAN; -import static org.springframework.test.web.client.ExpectedCount.times; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import org.camunda.bpm.engine.history.HistoricProcessInstance; -import org.hamcrest.text.MatchesPattern; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; -import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.RestTemplate; -import com.google.gson.Gson; - -/** - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * - */ -public class TerminateNsTaskTest extends BaseTest { - - @Autowired - @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) - private RestTemplate sol003AdapterRestTemplate; - - private MockRestServiceServer mockSol003AdapterRestServiceServer; - - @Autowired - private JobExecutorService objUnderTest; - - @Autowired - private GsonProvider gsonProvider; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private Gson gson; - - @Before - public void before() { - wireMockServer.resetAll(); - gson = gsonProvider.getGson(); - mockSol003AdapterRestServiceServer = - MockRestServiceServer.bindTo(sol003AdapterRestTemplate).ignoreExpectOrder(true).build(); - sol003AdapterRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } - - @After - public void after() { - wireMockServer.resetAll(); - } - - @Test - public void testRunTerminateNsJob_timeSetInTerminateRequest_throwsNsRequestProcessingException() { - final String nsInstanceId = UUID.randomUUID().toString(); - final TerminateNsRequest terminateNsRequest = new TerminateNsRequest().terminationTime(LocalDateTime.now()); - final String message = "TerminateNsRequest received with terminateTime: " - + terminateNsRequest.getTerminationTime() - + "\nOnly immediate Terminate requests are currently supported \n(i.e., terminateTime field must not be set)."; - expectedException.expect(NsRequestProcessingException.class); - expectedException.expectMessage(message); - objUnderTest.runTerminateNsJob(nsInstanceId, terminateNsRequest); - } - - @Test - public void testRunTerminateNsJob_NsInstNotInDb_throwsNsRequestProcessingException() { - final String nsInstanceId = UUID.randomUUID().toString(); - final TerminateNsRequest terminateNsRequest = new TerminateNsRequest(); - final String message = "No matching NS Instance for id: " + nsInstanceId + " found in database."; - assertThat(databaseServiceProvider.getNfvoNsInst(nsInstanceId)).isEmpty(); - expectedException.expect(NsRequestProcessingException.class); - expectedException.expectMessage(message); - objUnderTest.runTerminateNsJob(nsInstanceId, terminateNsRequest); - } - - @Test - public void testTerminateNsTask_SuccessfulCase() throws InterruptedException, IOException { - final String nsInstanceId = UUID.randomUUID().toString(); - addDummyNsToDatabase(nsInstanceId); - mockSol003AdapterEndpoints(); - mockAAIEndpoints(); - - final String nsLcmOpOccId = objUnderTest.runTerminateNsJob(nsInstanceId, new TerminateNsRequest()); - - final Optional<NfvoJob> optional = getJobByResourceId(nsInstanceId); - assertTrue(optional.isPresent()); - final NfvoJob nfvoJob = optional.get(); - - // Confirm Process finishes in STATE_COMPLETED - assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); - final HistoricProcessInstance historicProcessInstance = - getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); - assertNotNull(historicProcessInstance); - assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); - - // Confirm NS Instance set to NOT_INSTANTIATED and related NF Instances Deleted - final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); - assertTrue(optionalNfvoNsInst.isPresent()); - final NfvoNsInst nfvoNsInst = optionalNfvoNsInst.get(); - assertEquals(State.NOT_INSTANTIATED, nfvoNsInst.getStatus()); - final List<NfvoNfInst> nfvoNfInsts = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstanceId); - assertTrue(nfvoNfInsts.isEmpty()); - - // Confirm NS LCM OP OCC Job set to Completed - final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); - assertTrue(optionalNsLcmOpOcc.isPresent()); - final NsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOcc.get(); - assertEquals(OperationStateEnum.COMPLETED, nsLcmOpOcc.getOperationState()); - } - - private void addDummyNsToDatabase(final String nsInstanceId) { - final String nsPackageId = UUID.randomUUID().toString(); - final NfvoNsInst nfvoNsInst = - new NfvoNsInst().nsInstId(nsInstanceId).name("nsName").nsPackageId(nsPackageId).nsdId("nsdId") - .nsdInvariantId("nsdId").status(State.INSTANTIATED).statusUpdatedTime(LocalDateTime.now()); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); - addDummyNfToDatabase(nfvoNsInst); - addDummyNfToDatabase(nfvoNsInst); - addDummyNfToDatabase(nfvoNsInst); - } - - private void addDummyNfToDatabase(final NfvoNsInst nfvoNsInst) { - final LocalDateTime localDateTime = LocalDateTime.now(); - final String nfPackageId = UUID.randomUUID().toString(); - final NfvoNfInst nfvoNfInst = - new NfvoNfInst().status(State.INSTANTIATED).createTime(localDateTime).lastUpdateTime(localDateTime) - .name("nfName").vnfdId("vnfdId").packageId(nfPackageId).nfvoNsInst(nfvoNsInst); - databaseServiceProvider.saveNfvoNfInst(nfvoNfInst); - } - - private void mockSol003AdapterEndpoints() { - final int numTimes = 3; - - mockSol003AdapterRestServiceServer - .expect(times(numTimes), - requestTo(MatchesPattern.matchesPattern(SOL003_ADAPTER_ENDPOINT_URL + "/vnfs/.*"))) - .andExpect(method(HttpMethod.DELETE)) - .andRespond(withSuccess(gson.toJson(new DeleteVnfResponse().jobId(UUID.randomUUID().toString())), - MediaType.APPLICATION_JSON)); - - mockSol003AdapterRestServiceServer - .expect(times(numTimes), - requestTo(MatchesPattern.matchesPattern(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/.*"))) - .andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson( - new org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse().operationState( - org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.COMPLETED) - .operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND)), - MediaType.APPLICATION_JSON)); - } - - private void mockAAIEndpoints() { - final String modelEndpoint = "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + UUID_REGEX; - final String resourceVersion = "12345"; - - final String body = - "{\"resource-version\": \"" + resourceVersion + "\",\n\"orchestration-status\": \"Assigned\"}"; - wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()).willReturn(okJson(body))); - - wireMockServer.stubFor( - delete(urlMatching(modelEndpoint + "\\?resource-version=" + resourceVersion)).willReturn(ok())); - } - -} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/application.yaml deleted file mode 100644 index 5a8e250157..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/application.yaml +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright © 2020 Nordix Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -spring: - main: - allow-bean-definition-overriding: true - datasource: - hikari: - camunda: - jdbcUrl: jdbc:h2:mem:example-simple;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - driver-class-name: org.h2.Driver - pool-name: ns-lcm-bpmn-pool - registerMbeans: true - nfvo: - jdbcUrl: jdbc:h2:mem:nfvo;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS nfvo;MODE=MYSQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE - driver-class-name: org.h2.Driver - pool-name: ns-lcm-bpmn-pool - registerMbeans: true - test: - database: - replace: NONE - jpa: - generate-ddl: true - dialect: org.hibernate.dialect.MySQL5Dialect - hibernate: - ddl-auto: create - database-platform: org.hibernate.dialect.MariaDBDialect -hibernate: - dialect: org.hibernate.dialect.H2Dialect - hbm2ddl: - auto: create -aai: - version: v19 - endpoint: http://localhost:${wiremock.server.port} -etsi-catalog-manager: - base: - endpoint: http://modeling-etsicatalog.onap:8806/api -so-etsi-ns-lcm-workflow-engine: - requesttimeout: - timeoutInSeconds: 120 - -logging: - level: - org.reflections.Reflections: ERROR
\ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/invalid_ns.csar b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/invalid_ns.csar Binary files differdeleted file mode 100644 index 63bad965b7..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/invalid_ns.csar +++ /dev/null diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/ns.csar b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/ns.csar Binary files differdeleted file mode 100644 index eb19c762ae..0000000000 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/ns.csar +++ /dev/null |