aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/test/java/org
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-07-30 15:56:09 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-07-31 11:09:25 -0400
commit5a6a6de6f1a26a1897e4917a0df613e25a24eb70 (patch)
tree59a968f27b4b603aacc9d5e7b51fb598aeec5321 /adapters/mso-openstack-adapters/src/test/java/org
parentb6dc38501f3b746426b42d9de4cc883d894149e8 (diff)
Containerization feature of SO
Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18 Issue-ID: SO-670 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test/java/org')
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java90
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java60
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java47
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java50
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/BpelRestClientTest.java55
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java36
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java39
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java41
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java40
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java533
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java265
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java282
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java41
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java50
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java73
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java254
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java32
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java47
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java49
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java116
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java101
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java54
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java158
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java562
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java319
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java167
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java108
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java70
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java560
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java189
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java184
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java134
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java485
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java77
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java89
35 files changed, 5457 insertions, 0 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java
new file mode 100644
index 0000000000..7aa86da237
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.PojoClassFilter;
+import com.openpojo.reflection.filters.FilterEnum;
+import com.openpojo.reflection.filters.FilterNonConcrete;
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.*;
+import com.openpojo.validation.test.impl.*;
+import org.junit.Test;
+import org.onap.so.openpojo.rules.ToStringTester;
+import org.springframework.stereotype.Component;
+
+
+public class BeansTest {
+
+ private final PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ private final PojoClassFilter enumFilter = new FilterEnum();
+
+ private final PojoClassFilter noNestedClasses = new FilterTestNestedClasses();
+
+
+
+ @Test
+ public void pojoStructure() {
+ test("org.onap.so.adapters.network.async.client");
+ test("org.onap.so.adapters.vnf.async.client");
+ test("org.onap.so.adapters.network");
+ test("org.onap.so.adapters.vnf");
+ test("org.onap.so.adapters.valet");
+ test("org.onap.so.adapters.valet.beans");
+ test("org.onap.so.vdu.utils");
+ }
+
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create()
+ .with(new NoStaticExceptFinalRule())
+ .with(new SerializableMustHaveSerialVersionUIDRule())
+ .with(new NoPublicFieldsExceptStaticFinalRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .with(new ToStringTester())
+
+ .build();
+
+
+ validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete(), noNestedClasses, new FilterBeans());
+ }
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
+
+ private static class FilterTestNestedClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.isNestedClass();
+ }
+ }
+
+ private static class FilterBeans implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return pojoClass.getAnnotations().stream().filter(o -> o instanceof Component).count() <= 0;
+ }
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java
new file mode 100644
index 0000000000..f1ee0eae78
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.msoopenstackadapters;
+import ch.vorburger.exec.ManagedProcessException;
+import ch.vorburger.mariadb4j.DBConfigurationBuilder;
+import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import javax.sql.DataSource;
+
+@Configuration
+@Profile({"test"})
+public class EmbeddedMariaDbConfig {
+
+ @Bean
+ MariaDB4jSpringService mariaDB4jSpringService() {
+ return new MariaDB4jSpringService();
+ }
+
+ @Bean
+ DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService,
+ @Value("${mariaDB4j.databaseName}") String databaseName,
+ @Value("${spring.datasource.username}") String datasourceUsername,
+ @Value("${spring.datasource.password}") String datasourcePassword,
+ @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException {
+ //Create our database with default root user and no password
+ mariaDB4jSpringService.getDB().createDB(databaseName);
+
+ DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration();
+
+ return DataSourceBuilder
+ .create()
+ .username(datasourceUsername)
+ .password(datasourcePassword)
+ .url(config.getURL(databaseName))
+ .driverClassName(datasourceDriver)
+ .build();
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java
new file mode 100644
index 0000000000..4df9a7af6d
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.msoopenstackadapters;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.core.Response;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+
+public class HealthCheckHandlerTest extends BaseRestTestUtils {
+
+ @Test
+ public void testHealthcheckVnf() throws JSONException {
+
+ HttpEntity<String> entity = new HttpEntity<String>(null, headers);
+
+ ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("/manage/health"),
+ HttpMethod.GET, entity, String.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java
new file mode 100644
index 0000000000..be76a9e365
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.msoopenstackadapters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.so.client.policy.JettisonStyleMapperProvider;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+
+@Configuration
+public class TestRestTemplateFactory {
+
+ @Autowired
+ private JettisonStyleMapperProvider objectMapper;
+
+ @Bean("JettisonStyle")
+ public TestRestTemplate createRestTemplate() {
+ TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+ List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
+ MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter();
+ jsonMessageConverter.setObjectMapper(objectMapper.getMapper());
+ restTemplate.getRestTemplate().getMessageConverters().removeIf(m -> m.getClass().getName().equals(MappingJackson2HttpMessageConverter.class.getName()));
+ restTemplate.getRestTemplate().getMessageConverters().add(jsonMessageConverter);
+ return restTemplate;
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/BpelRestClientTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/BpelRestClientTest.java
new file mode 100644
index 0000000000..845155f7f0
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/BpelRestClientTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.network;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.inject.Provider;
+
+import org.junit.Test;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.embedded.LocalServerPort;
+
+public class BpelRestClientTest extends BaseRestTestUtils {
+
+
+ @LocalServerPort
+ private int port;
+ @Autowired
+ @Qualifier("NetworkBpel")
+ private Provider<BpelRestClient> clientProvider;
+
+ @Test
+ public void verifyPropertiesRead() {
+ BpelRestClient client = clientProvider.get();
+
+ assertEquals(5, client.getRetryCount());
+ assertEquals(5, client.getConnectTimeout());
+ assertEquals("test:test", client.getCredentials());
+ assertEquals(5, client.getSocketTimeout());
+ assertEquals("408, 429, 500, 502, 503, 504, 900", client.getRetryList());
+ assertEquals(-15, client.getRetryInterval());
+
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java
new file mode 100644
index 0000000000..46bf21722c
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.network;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ContrailPolicyRefSeqTest {
+ @Test
+ public void ContrailPolicyRefSeqJson_Test()
+ {
+ ContrailPolicyRefSeq cprs = new ContrailPolicyRefSeq("majorVersion 1","minorVersion 0.02");
+ assertTrue(cprs.toString().contains("majorVersion 1"));
+ assertTrue(cprs.toString().contains("minorVersion 0.02"));
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java
new file mode 100644
index 0000000000..7a0f3d0551
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.network;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ContrailPolicyRefTest {
+
+ @Test
+ public void ContrailPolicyRef_Test()
+ {
+ ContrailPolicyRef ref = new ContrailPolicyRef();
+ ref.populate("majorVersion 1", "minorVersion 0.02");
+ String strJson = ref.toJsonString();
+ assertTrue(strJson.contains("majorVersion 1"));
+ assertTrue(strJson.contains("minorVersion 0.02"));
+ }
+
+} \ No newline at end of file
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java
new file mode 100644
index 0000000000..ca8a45e8dc
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java
@@ -0,0 +1,41 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+package org.onap.so.adapters.network;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.so.openstack.beans.HostRoute;
+
+public class ContrailSubnetHostRouteTest {
+
+ private ContrailSubnetHostRoute cshr = new ContrailSubnetHostRoute();
+ HostRoute hr = new HostRoute();
+ @Test
+ public void testContrailSubnetHostRoute() {
+
+ cshr.setPrefix("prefix");
+ cshr.setNextHop("nextHop");
+ assertEquals("prefix", cshr.getPrefix());
+ assertEquals("nextHop", cshr.getNextHop());
+ assert (cshr.toString() != null);
+ cshr.populateWith(hr);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java
new file mode 100644
index 0000000000..fd17c37e6d
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java
@@ -0,0 +1,40 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+
+package org.onap.so.adapters.network;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class ContrailSubnetHostRoutesTest {
+
+ ContrailSubnetHostRoutes cshr = new ContrailSubnetHostRoutes();
+ List<ContrailSubnetHostRoute> host_routes;
+ StringBuilder buf = new StringBuilder();
+ @Test
+ public void testContrailSubnetHostRoutes() {
+ cshr.setHost_routes(host_routes);
+ assertEquals(cshr.getHost_routes(), host_routes);
+ assert (cshr.toString() != null);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java
new file mode 100644
index 0000000000..e473c4c76a
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java
@@ -0,0 +1,533 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.network;
+
+import org.apache.http.HttpStatus;
+import org.junit.Test;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.onap.so.cloud.CloudConfig;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.util.UriComponentsBuilder;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteNeutronNetwork;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteStack_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteStack_500;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetAllNeutronNetworks_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetAllNeutronNetworks_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetNeutronNetwork;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetNeutronNetwork_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreated_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackDeleteOrUpdateComplete_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStack_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStack_500;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostNeutronNetwork_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStack_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutNeutronNetwork;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutNeutronNetwork_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStack;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackGet;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackPost;
+
+public class MSONetworkAdapterImplTest extends BaseRestTestUtils {
+
+ public static final String NETWORK_ID = "43173f6a-d699-414b-888f-ab243dda6dfe";
+ public static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0";
+
+ @Autowired
+ private CloudConfig cloudConfig;
+
+ @Test
+ public void createNetworkByModelNameNeutronModeGetNetworkException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenstackGet("/mockPublicUrl/v2.0/networks",HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameNeutronModeCreateNetworkException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork_404("dvspg-VCE_VPE-mtjnj40avbc");
+
+ mockOpenStackGetAllNeutronNetworks_404();
+
+ mockOpenstackPost("/mockPublicUrl/v2.0/networks", HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameNeutronMode() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork_404("dvspg-VCE_VPE-mtjnj40avbc");
+
+ mockOpenStackGetAllNeutronNetworks_404();
+
+ mockOpenStackPostNeutronNetwork_200("OpenstackCreateNeutronNetworkResponse.json");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameAlreadyExistNeutronMode() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetAllNeutronNetworks_200("OpenstackGetNeutronNetworks.json");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameAlreadyExistNeutronModeFailIfExistTrue() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetAllNeutronNetworks_200("OpenstackGetNeutronNetworks.json");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode_Fail_If_Exist_True.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameHeatMode() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStack_404("dvspg-VCE_VPE-mtjnj40avbc");
+
+ mockOpenStackPostStack_200("OpenstackResponse_Stack.json");
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc/stackId");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameAlreadyExistHeatMode() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPostStack_200("OpenstackResponse_Stack.json");
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameAlreadyExistHeatModeFailIfExistTrue() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_Fail_If_Exist_True.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+
+ @Test
+ public void createNetworkByModelNameHeatModeQueryNetworkException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenstackGet("/mockPublicUrl/stacks/dvspg-VCE_VPE-mtjnj40avbc",HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameHeatModeCreateNetworkException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStack_404("dvspg-VCE_VPE-mtjnj40avbc");
+
+ mockOpenstackPost("/mockPublicUrl/stacks",HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void createNetworkByModelNameCloudSiteNotPresentError() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPostStack_200("OpenstackResponse_Stack.json");
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_InvalidCloudSiteId.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void deleteNetworkHeatModeSuccess() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackDeleteOrUpdateComplete_200("OpenstackResponse_Stack_DeleteComplete.json");
+
+ mockOpenStackDeleteStack_200();
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void deleteNetworkDeleteStackException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackDeleteOrUpdateComplete_200("OpenstackResponse_Stack_DeleteComplete.json");
+
+ mockOpenStackDeleteStack_500();
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void deleteNetworkError() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackDeleteOrUpdateComplete_200("OpenstackResponse_Stack_DeleteComplete.json");
+
+ mockOpenStackDeleteStack_200();
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "43173f6a-d699-414b-888f-ab243dda6dfe");
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("mtn13",""), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+
+ @Test
+ public void deleteNetworkNeureonMode() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK);
+
+ mockOpenStackDeleteNeutronNetwork(NETWORK_ID,HttpStatus.SC_OK);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void deleteNetworkNeutronModeDeleteStackException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK);
+
+ mockOpenStackDeleteNeutronNetwork(NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ //mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", NETWORK_ID);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkNeutronModeSuccess() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK);
+ mockOpenStackPutNeutronNetwork_200("OpenstackCreateNeutronNetworkResponse.json",NETWORK_ID);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkNeutronUpdateException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK);
+ mockOpenStackPutNeutronNetwork(NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkHeatUpdateException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", NETWORK_NAME);
+
+ mockOpenStackPutStack(NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkHeatQueryException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStack_500(NETWORK_NAME);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkHeatStackNotFound() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStack_404(NETWORK_NAME);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkNeutronQueryException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork(NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateNetworkNeutronStackNotFound() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork(NETWORK_ID,HttpStatus.SC_NOT_FOUND);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void queryNetworkHeatModesuccess() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", NETWORK_ID);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void queryNetworkHeatModeQueryException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStack_500(NETWORK_ID);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void queryNetworkNeutronModeSuccess() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork("GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void queryNetworkNeutronModeException() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetNeutronNetwork(NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ String uri = "/services/NetworkAdapter";
+ headers.set("X-ECOMP-RequestID", "123456789456127");
+ ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ public ResponseEntity<String> sendXMLRequest(String requestJson, String uriPath, HttpMethod reqMethod){
+ headers.set("Accept", MediaType.APPLICATION_XML);
+ headers.set("Content-Type", MediaType.APPLICATION_XML);
+
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath));
+
+ HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
+ ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
+ reqMethod, request, String.class);
+
+ return response;
+ }
+
+ public String inputStream(String JsonInput)throws IOException{
+ JsonInput = "src/test/resources/" + JsonInput;
+ String input = new String(Files.readAllBytes(Paths.get(JsonInput)));
+ return input;
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java
new file mode 100644
index 0000000000..094d308221
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java
@@ -0,0 +1,265 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.network;
+
+import org.apache.http.HttpStatus;
+import org.junit.Test;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.onap.so.entity.MsoRequest;
+import org.onap.so.openstack.beans.NetworkRollback;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.containing;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static org.onap.so.bpmn.mock.StubOpenStack.getBodyFromFile;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreatedVUSP_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreated_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackDeleteOrUpdateComplete_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStacks_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccessQueryNetwork;
+
+public class MsoNetworkAdapterAsyncImplTest extends BaseRestTestUtils {
+ @Autowired
+ MsoNetworkAdapterAsyncImpl impl;
+
+ @Test
+ public void healthCheckATest() {
+ MsoNetworkAdapterAsyncImpl mNAAimpl = new MsoNetworkAdapterAsyncImpl();
+ mNAAimpl.healthCheckA();
+ }
+
+ @Test
+ public void rollbackNetworkATest() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/notificationUrl"))
+ .withRequestBody(containing("<completed>true</completed>"))
+ .willReturn(aResponse()
+ .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" +
+ " <soapenv:Header/>\n" +
+ " <soapenv:Body>\n" +
+ " <net:rollbackNetworkNotificationResponse>\n" +
+ " </net:rollbackNetworkNotificationResponse>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>")
+ .withStatus(HttpStatus.SC_OK)));
+ NetworkRollback nrb = getNetworkRollback("mtn13");
+ impl.rollbackNetworkA(nrb, "messageId", "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void rollbackNetworkATest_NotifyException() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/notificationUrl"))
+ .withRequestBody(containing("<completed>true</completed>"))
+ .willReturn(aResponse()
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ NetworkRollback nrb = getNetworkRollback("mtn13");
+ impl.rollbackNetworkA(nrb, "messageId", "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ private NetworkRollback getNetworkRollback(String cloudId) {
+ NetworkRollback nrb = new NetworkRollback();
+ nrb.setCloudId(cloudId);
+ nrb.setMsoRequest(new MsoRequest());
+ nrb.setModelCustomizationUuid("3bdbb104-476c-483e-9f8b-c095b3d3068c");
+ nrb.setNetworkCreated(true);
+ nrb.setNetworkId("networkId");
+ nrb.setNetworkName("networkName");
+ nrb.setNetworkStackId("networkStackId");
+ nrb.setNetworkType("networkType");
+ nrb.setNeutronNetworkId("neutronNetworkId");
+ nrb.setPhysicalNetwork("physicalNetwork");
+ nrb.setTenantId("tenantId");
+ nrb.setVlans(new ArrayList<>());
+ return nrb;
+ }
+
+ @Test
+ public void rollbackNetworkATestNetworkException() {
+ NetworkRollback nrb = getNetworkRollback("cloudId");
+
+ impl.rollbackNetworkA(nrb, "messageId", "http://localhost");
+ }
+
+ @Test
+ public void noRollbackNetworkATest() {
+ impl.rollbackNetworkA(null, "messageId", "http://localhost");
+ }
+
+
+ @Test
+ public void deleteNetworkATest() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/notificationUrl"))
+ .withRequestBody(containing("<completed>true</completed>"))
+ .willReturn(aResponse()
+ .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" +
+ " <soapenv:Header/>\n" +
+ " <soapenv:Body>\n" +
+ " <net:deleteNetworkNotificationResponse>\n" +
+ " </net:deleteNetworkNotificationResponse>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>")
+ .withStatus(HttpStatus.SC_OK)));
+ impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "messageId", new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void deleteNetworkATest_NotifyException() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/notificationUrl"))
+ .withRequestBody(containing("<completed>true</completed>"))
+ .willReturn(aResponse()
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "messageId", new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void deleteNetworkATest_NetworkException() {
+ impl.deleteNetworkA("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "messageId", new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void updateNetworkATest() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc");
+ mockOpenStackGetStackDeleteOrUpdateComplete_200("OpenstackResponse_Stack_UpdateComplete.json");
+ mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200();
+ stubFor(post(urlPathEqualTo("/notificationUrl"))
+ .withRequestBody(containing("updateNetworkNotification"))
+ .willReturn(aResponse()
+ .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" +
+ " <soapenv:Header/>\n" +
+ " <soapenv:Body>\n" +
+ " <net:updateNetworkNotificationResponse>\n" +
+ " </net:updateNetworkNotificationResponse>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>")
+ .withStatus(HttpStatus.SC_OK)));
+ impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "dvspg-VCE_VPE-mtjnj40avbc",
+ "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(), "messageId",
+ new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void updateNetworkATest_NotifyExcpetion() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc");
+ mockOpenStackGetStackDeleteOrUpdateComplete_200("OpenstackResponse_Stack_UpdateComplete.json");
+ mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200();
+ impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "dvspg-VCE_VPE-mtjnj40avbc",
+ "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(), "messageId",
+ new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); }
+
+ @Test
+ public void updateNetworkATest_NetworkException() {
+ impl.updateNetworkA("cloudSiteId", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "networkId",
+ "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(), "messageId",
+ new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void queryNetworkATest() throws IOException {
+ mockOpenStackResponseAccessQueryNetwork(wireMockPort);
+ impl.queryNetworkA("mtn13", "tenantId", "networkId", "messageId", new MsoRequest(),
+ "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void createNetworkATest() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/notificationUrl"))
+ .withRequestBody(containing("createNetworkNotification"))
+ .willReturn(aResponse()
+ .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" +
+ " <soapenv:Header/>\n" +
+ " <soapenv:Body>\n" +
+ " <net:createNetworkNotificationResponse>\n" +
+ " </net:createNetworkNotificationResponse>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>")
+ .withStatus(HttpStatus.SC_OK)));
+ mockOpenStackGetStackCreatedVUSP_200();
+ mockOpenStackPostStacks_200();
+ impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0",
+ "physicalNetworkName", new ArrayList<>(), false, false, new ArrayList<>(), "messageId",
+ new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void createNetworkATest_NotifyException() throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ mockOpenStackGetStackCreatedVUSP_200();
+ mockOpenStackPostStacks_200();
+ impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0",
+ "physicalNetworkName", new ArrayList<>(), false, false, new ArrayList<>(), "messageId",
+ new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+
+ @Test
+ public void createNetworkATest_NetworkException() {
+ impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0",
+ "physicalNetworkName", new ArrayList<>(), false, false, new ArrayList<>(), "messageId",
+ new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl");
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java
new file mode 100644
index 0000000000..a29f2df96a
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java
@@ -0,0 +1,282 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.network;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeletePublicUrlStackByNameAndID_204;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetPublicUrlStackByNameAndID_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetPublicUrlStackByNameAndID_204;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackAppC_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreatedAppC_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackCreatedVUSP_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVUSP_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostPublicUrlWithBodyFile_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPublicUrlStackByID_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPublicUrlStackByName_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutPublicUrlStackByNameAndID_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.onap.so.adapters.nwrest.CreateNetworkRequest;
+import org.onap.so.adapters.nwrest.CreateNetworkResponse;
+import org.onap.so.adapters.nwrest.DeleteNetworkRequest;
+import org.onap.so.adapters.nwrest.DeleteNetworkResponse;
+import org.onap.so.adapters.nwrest.NetworkTechnology;
+import org.onap.so.adapters.nwrest.QueryNetworkError;
+import org.onap.so.adapters.nwrest.QueryNetworkResponse;
+import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
+import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.onap.so.client.policy.JettisonStyleMapperProvider;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.entity.MsoRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+public class NetworkAdapterRestTest extends BaseRestTestUtils {
+
+ @Autowired
+ private CloudConfig cloudConfig;
+ @Autowired
+ private JettisonStyleMapperProvider jettisonTypeObjectMapper;
+ private static final String CLOUDSITE_ID = "mtn13";
+ private static final String TENANT_ID = "ba38bc24a2ef4fb2ad2810c894f1938f";
+ private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b";
+ private static final String NETWORK_TYPE = "CONTRAIL30_BASIC";
+ private static final String MODEL_CUSTOMIZATION_UUID = "3bdbb104-476c-483e-9f8b-c095b3d308ac";
+ private static final String MSO_SERVICE_INSTANCE_ID = "05869d5f-47df-4b45-bbfc-4f03ce0a50bf";
+ private static final String MSO_REQUEST_ID = "requestId";
+ private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0";
+
+ @Test
+ public void testCreateNetwork() throws JSONException, JsonParseException, JsonMappingException, IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateNetworkRequest request = new CreateNetworkRequest();
+ request.setBackout(true);
+ request.setSkipAAI(true);
+ request.setFailIfExists(false);
+ MsoRequest msoReq = new MsoRequest();
+ NetworkTechnology networkTechnology = NetworkTechnology.CONTRAIL;
+
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setMsoRequest(msoReq);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setNetworkId(NETWORK_ID);
+ request.setNetworkName(NETWORK_NAME);
+ request.setNetworkType(NETWORK_TYPE);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setNetworkTechnology(networkTechnology);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPostPublicUrlWithBodyFile_200();
+
+ mockOpenStackGetStackCreatedVUSP_200();
+
+ mockOpenStackGetStackVUSP_404();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateNetworkRequest> entity = new HttpEntity<CreateNetworkRequest>(request, headers);
+ ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class);
+
+ CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateNetworkResponse.json"), CreateNetworkResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testCreateNetwork_JSON() throws JSONException, JsonParseException, JsonMappingException, IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPostPublicUrlWithBodyFile_200();
+
+ mockOpenStackGetStackCreatedAppC_200();
+
+ mockOpenStackGetStackAppC_404();
+
+ headers.add("Content-Type", MediaType.APPLICATION_JSON);
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+
+ String request = readJsonFileAsString("src/test/resources/CreateNetwork.json");
+ HttpEntity<String> entity = new HttpEntity<String>(request, headers);
+
+ ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class);
+
+ CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateNetworkResponse2.json"), CreateNetworkResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testDeleteNetwork() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ DeleteNetworkRequest request = new DeleteNetworkRequest();
+
+ MsoRequest msoReq = new MsoRequest();
+
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setMsoRequest(msoReq);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setNetworkId(NETWORK_ID);
+ request.setNetworkType(NETWORK_TYPE);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setNetworkStackId(NETWORK_ID);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPublicUrlStackByID_200(wireMockPort);
+
+ mockOpenStackGetPublicUrlStackByNameAndID_204(wireMockPort);
+
+ mockOpenStackDeletePublicUrlStackByNameAndID_204();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+
+ HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(request, headers);
+
+ ResponseEntity<DeleteNetworkResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.DELETE, entity, DeleteNetworkResponse.class);
+
+ DeleteNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/DeleteNetworkResponse.json"), DeleteNetworkResponse.class);
+
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+
+ }
+
+ @Test
+ public void testQueryNetwork_Exception() throws IOException{
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ MsoRequest msoReq = new MsoRequest();
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+
+ HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(headers);
+
+ ResponseEntity<QueryNetworkError> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.GET,
+ entity, QueryNetworkError.class);
+
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+
+ }
+
+ @Test
+ public void testQueryNetwork() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(headers);
+
+ ResponseEntity<QueryNetworkResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"+"?cloudSiteId=" + CLOUDSITE_ID + "&tenantId=" + TENANT_ID
+ + "&aaiNetworkId=aaiNetworkId"), HttpMethod.GET,
+ entity, QueryNetworkResponse.class);
+
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
+
+ }
+
+ @Test
+ public void testUpdateNetwork() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ UpdateNetworkRequest request = new UpdateNetworkRequest();
+
+ MsoRequest msoReq = new MsoRequest();
+
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setMsoRequest(msoReq);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setNetworkId(NETWORK_ID);
+ request.setNetworkName(NETWORK_NAME);
+ request.setNetworkType(NETWORK_TYPE);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setNetworkStackId(NETWORK_ID);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPublicUrlStackByName_200(wireMockPort);
+
+ mockOpenStackPublicUrlStackByID_200(wireMockPort);
+
+ mockOpenStackGetPublicUrlStackByNameAndID_200(wireMockPort);
+
+ mockOpenStackPutPublicUrlStackByNameAndID_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+
+ HttpEntity<UpdateNetworkRequest> entity = new HttpEntity<UpdateNetworkRequest>(request, headers);
+
+ ResponseEntity<UpdateNetworkResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.PUT, entity, UpdateNetworkResponse.class);
+
+ UpdateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/UpdateNetworkResponse.json"), UpdateNetworkResponse.class);
+
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Override
+ protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{
+ return new String(Files.readAllBytes(Paths.get(fileLocation)));
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java
new file mode 100644
index 0000000000..a1e0a16819
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java
@@ -0,0 +1,41 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+package org.onap.so.adapters.network.exceptions;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.so.openstack.exceptions.MsoExceptionCategory;
+
+public class NetworkExceptionBeanTest {
+
+ NetworkExceptionBean neb=new NetworkExceptionBean();
+ MsoExceptionCategory msc=MsoExceptionCategory.INTERNAL;
+
+ @Test
+ public void test() {
+ neb.setRolledBack(true);
+ neb.setMessage("message");
+ neb.setCategory(msc);
+ assertEquals("message", neb.getMessage());
+ assertEquals(msc, neb.getCategory());
+ assertEquals(true, neb.isRolledBack());
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java
new file mode 100644
index 0000000000..bd5b07de1f
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java
@@ -0,0 +1,50 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+
+package org.onap.so.adapters.network.exceptions;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.onap.so.openstack.exceptions.MsoExceptionCategory;
+
+public class NetworkExceptionTest{
+
+ NetworkException ne=new NetworkException("msg");
+ NetworkExceptionBean neb =new NetworkExceptionBean();
+ MsoException msoException= new MsoException("msoException") {
+ private static final long serialVersionUID = 1L;
+ };
+ MsoExceptionCategory msc=MsoExceptionCategory.INTERNAL;
+ NetworkException ne1=new NetworkException(msoException);
+ NetworkException ne2=new NetworkException(ne);
+ NetworkException ne3=new NetworkException("msg", ne);
+ NetworkException ne4=new NetworkException("msg", msoException);
+ NetworkException ne5=new NetworkException("msg", msc);
+ NetworkException ne6=new NetworkException("msg", msc, ne);
+
+ @Test
+ public void test() {
+ ne.setFaultInfo(neb);
+ assertEquals(ne.getFaultInfo(), neb);
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java
new file mode 100644
index 0000000000..8a55177f1e
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.tenant;
+
+import java.util.HashMap;
+
+import javax.xml.ws.Holder;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.so.adapters.tenantrest.TenantRollback;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.entity.MsoRequest;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MsoTenantAdapterImplTest {
+
+ @Mock
+ private CloudConfig cloudConfig;
+
+ @Spy
+ @InjectMocks
+ private MsoTenantAdapterImpl msoTenantAdapter;
+
+ @Test
+ public void healthCheck() throws Exception {
+ msoTenantAdapter.healthCheck();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void createTenant() throws Exception {
+ msoTenantAdapter.createTenant("site", "tenant", new HashMap<>(),
+ true, true, new MsoRequest(), new Holder<String>(), new Holder<TenantRollback>());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void queryTenant() throws Exception {
+ msoTenantAdapter.queryTenant("site", "tenant", new MsoRequest(),
+ new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void deleteTenant() throws Exception {
+ msoTenantAdapter.deleteTenant("cloud", "tenant", new MsoRequest(), new Holder<Boolean>());
+ }
+
+ @Test
+ public void rollbackTenant() throws Exception {
+ msoTenantAdapter.rollbackTenant(new TenantRollback());
+ }
+
+} \ No newline at end of file
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java
new file mode 100644
index 0000000000..acfe6568af
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java
@@ -0,0 +1,254 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.tenant;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteTenantById_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetMetadata_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetRoles_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetTenantById_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetTenantById_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetTenantByName_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetTenantByName_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetUser_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostMetadata_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostTenantWithBodyFile_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostTenant_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutRolesAdmin_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccessAdmin;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.so.adapters.tenantrest.CreateTenantRequest;
+import org.onap.so.adapters.tenantrest.CreateTenantResponse;
+import org.onap.so.adapters.tenantrest.DeleteTenantRequest;
+import org.onap.so.adapters.tenantrest.DeleteTenantResponse;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.onap.so.client.policy.JettisonStyleMapperProvider;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.entity.MsoRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+public class TenantAdapterRestTest extends BaseRestTestUtils {
+
+ @Autowired
+ private CloudConfig cloudConfig;
+ @Autowired
+ private JettisonStyleMapperProvider jettisonTypeObjectMapper;
+
+ @Test
+ public void testCreateTenantCreated() throws JsonParseException, JsonMappingException, IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateTenantRequest request = new CreateTenantRequest();
+ String cloudSiteId = "mtn13";
+ String requestId = "62265093-277d-4388-9ba6-449838ade586";
+ String serviceInstanceId = "4147e06f-1b89-49c5-b21f-4faf8dc9805a";
+ String tenantName = "testingTenantName";
+ boolean failIfExists = true;
+ boolean backout = true;
+ Map<String, String> metaData = new HashMap<>();
+ metaData.put("key1", "value2");
+ MsoRequest msoReq = new MsoRequest();
+ msoReq.setRequestId(requestId);
+ msoReq.setServiceInstanceId(serviceInstanceId);
+
+ request.setCloudSiteId(cloudSiteId);
+ request.setMsoRequest(msoReq);
+ request.setTenantName(tenantName);
+ request.setMetadata(metaData);
+ request.setBackout(backout);
+ request.setFailIfExists(failIfExists);
+
+ mockOpenStackResponseAccessAdmin(wireMockPort);
+
+ mockOpenStackGetTenantByName_404(tenantName);
+
+ mockOpenStackPostTenantWithBodyFile_200();
+
+ mockOpenStackGetUser_200("m93945");
+
+ mockOpenStackGetRoles_200("OS-KSADM");
+
+ mockOpenStackPutRolesAdmin_200("OS-KSADM");
+
+ mockOpenStackPostMetadata_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateTenantRequest> entity = new HttpEntity<CreateTenantRequest>(request, headers);
+
+ ResponseEntity<CreateTenantResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/tenants"), HttpMethod.POST,
+ entity, CreateTenantResponse.class);
+
+ CreateTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateTenantResponse_Created.json"), CreateTenantResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testCreateTenantExists() throws JsonParseException, JsonMappingException, IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateTenantRequest request = new CreateTenantRequest();
+ String cloudSiteId = "mtn13";
+ String requestId = "62265093-277d-4388-9ba6-449838ade586";
+ String serviceInstanceId = "4147e06f-1b89-49c5-b21f-4faf8dc9805a";
+ String tenantName = "testingTenantName";
+ boolean failIfExists = false;
+ boolean backout = true;
+ Map<String, String> metadata = new HashMap<>();
+
+ MsoRequest msoReq = new MsoRequest();
+ msoReq.setRequestId(requestId);
+ msoReq.setServiceInstanceId(serviceInstanceId);
+
+ request.setCloudSiteId(cloudSiteId);
+ request.setMsoRequest(msoReq);
+ request.setTenantName(tenantName);
+ request.setMetadata(metadata);
+ request.setBackout(backout);
+ request.setFailIfExists(failIfExists);
+
+ mockOpenStackResponseAccessAdmin(wireMockPort);
+
+ mockOpenStackGetTenantByName_200(tenantName);
+
+ mockOpenStackPostTenant_200();
+
+ mockOpenStackGetMetadata_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateTenantRequest> entity = new HttpEntity<CreateTenantRequest>(request, headers);
+
+ ResponseEntity<CreateTenantResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/tenants"), HttpMethod.POST,
+ entity, CreateTenantResponse.class);
+
+ CreateTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateTenantResponse_Exists.json"), CreateTenantResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testDeleteTenant() throws IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ DeleteTenantRequest request = new DeleteTenantRequest();
+ String cloudSiteId = "mtn13";
+ String tenantId = "tenantId";
+ String requestId = "ra1";
+ String serviceInstanceId = "sa1";
+
+ MsoRequest msoReq = new MsoRequest();
+ msoReq.setRequestId(requestId);
+ msoReq.setServiceInstanceId(serviceInstanceId);
+
+ request.setCloudSiteId(cloudSiteId);
+ request.setTenantId(tenantId);
+ request.setMsoRequest(msoReq);
+
+ mockOpenStackResponseAccessAdmin(wireMockPort);
+
+ mockOpenStackGetTenantById_200(tenantId);
+
+ mockOpenStackDeleteTenantById_200(tenantId);
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<DeleteTenantRequest> entity = new HttpEntity<DeleteTenantRequest>(request, headers);
+
+ ResponseEntity<DeleteTenantResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/tenants/tenantId"), HttpMethod.DELETE,
+ entity, DeleteTenantResponse.class);
+
+ DeleteTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/DeleteTenantResponse_Success.json"), DeleteTenantResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ //@Ignore
+ @Test
+ public void testDeleteTenantFails() throws IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ DeleteTenantRequest request = new DeleteTenantRequest();
+ String cloudSiteId = "mtn13";
+ String tenantId = "tenantId";
+ String requestId = "ra1";
+ String serviceInstanceId = "sa1";
+
+ MsoRequest msoReq = new MsoRequest();
+ msoReq.setRequestId(requestId);
+ msoReq.setServiceInstanceId(serviceInstanceId);
+
+ request.setCloudSiteId(cloudSiteId);
+ request.setTenantId(tenantId);
+ request.setMsoRequest(msoReq);
+
+ mockOpenStackResponseAccessAdmin(wireMockPort);
+
+ mockOpenStackGetTenantById_404(tenantId);
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<DeleteTenantRequest> entity = new HttpEntity<DeleteTenantRequest>(request, headers);
+
+ ResponseEntity<DeleteTenantResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/tenants/tenantId"), HttpMethod.DELETE,
+ entity, DeleteTenantResponse.class);
+
+ DeleteTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/DeleteTenantResponse_Failed.json"), DeleteTenantResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Ignore
+ @Test
+ public void testQuaryTenant() {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java
new file mode 100644
index 0000000000..6288dc9573
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java
@@ -0,0 +1,32 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+
+package org.onap.so.adapters.tenant.exceptions;
+
+import org.junit.Test;
+
+public class TenantAlreadyExistsTest {
+
+ @Test
+ public void test() {
+ TenantAlreadyExists tar= new TenantAlreadyExists("name", "cloudId", "tenantId");
+ assert(tar!=null);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java
new file mode 100644
index 0000000000..178495105b
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java
@@ -0,0 +1,47 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+
+package org.onap.so.adapters.tenant.exceptions;
+
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.openstack.exceptions.MsoExceptionCategory;
+
+public class TenantExceptionBeanTest {
+
+@Mock
+private MsoExceptionCategory mec;
+
+@InjectMocks
+private TenantExceptionBean teb;
+
+@Test
+ public void test() {
+ teb =new TenantExceptionBean("message",mec);
+ teb.setMessage("message");
+ teb.setCategory(MsoExceptionCategory.INTERNAL);
+ teb.setCategory(MsoExceptionCategory.IO);
+ teb.setCategory(MsoExceptionCategory.OPENSTACK);
+ teb.setCategory(MsoExceptionCategory.USERDATA);
+ assert(teb.getMessage().equals("message"));
+ assert(teb.getCategory()!=null);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java
new file mode 100644
index 0000000000..73614a3628
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java
@@ -0,0 +1,49 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+
+package org.onap.so.adapters.tenant.exceptions;
+
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.openstack.exceptions.MsoExceptionCategory;
+
+public class TenantExceptionTest {
+
+ @Mock
+ private TenantExceptionBean teb;
+
+ @Mock
+ private MsoExceptionCategory mec;
+
+ @InjectMocks
+ private TenantException te;
+
+ @Test
+ public void test() {
+ teb=new TenantExceptionBean("message");
+ teb.setMessage("message");
+ teb.setCategory(MsoExceptionCategory.INTERNAL);
+ te = new TenantException("message", mec);
+ te.setFaultInfo(teb);
+ assert(te.getFaultInfo()!=null);
+ assert(te.getFaultInfo().equals(teb));
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java
new file mode 100644
index 0000000000..141be6bd7c
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.valet;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockValetConfirmPutRequest_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockValetCreatePostResponse_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockValetCreatePutResponse_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockValetDeleteDeleteResponse_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockValetRollbackPutRequest_200;
+
+import java.io.File;
+
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.adapters.valet.beans.ValetConfirmResponse;
+import org.onap.so.adapters.valet.beans.ValetCreateResponse;
+import org.onap.so.adapters.valet.beans.ValetDeleteResponse;
+import org.onap.so.adapters.valet.beans.ValetRollbackResponse;
+import org.onap.so.adapters.valet.beans.ValetUpdateResponse;
+import org.onap.so.adapters.vnf.BaseRestTestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class ValetClientTest extends BaseRestTestUtils {
+ @Autowired
+ protected ValetClient client;
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Before
+ public void init() {
+ client.baseUrl = "http://localhost:" + wireMockPort;
+ }
+
+ @Test
+ public void testCallValetCreateRequest() throws Exception {
+ ValetCreateResponse vcr = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), ValetCreateResponse.class);
+ GenericValetResponse<ValetCreateResponse> expected = new GenericValetResponse<ValetCreateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr);
+
+ mockValetCreatePostResponse_200("requestId", mapper.writeValueAsString(vcr));
+
+ GenericValetResponse<ValetCreateResponse> actual = client.callValetCreateRequest("requestId", "regionId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void testCallValetUpdateRequest() throws Exception {
+ ValetUpdateResponse vur = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), ValetUpdateResponse.class);
+ GenericValetResponse<ValetUpdateResponse> expected = new GenericValetResponse<ValetUpdateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vur);
+
+ mockValetCreatePutResponse_200("requestId", mapper.writeValueAsString(vur));
+
+ GenericValetResponse<ValetUpdateResponse> actual = client.callValetUpdateRequest("requestId", "regionId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void testCallValetDeleteRequest() throws Exception {
+ ValetDeleteResponse vdr = mapper.readValue(new File("src/test/resources/__files/ValetDeleteRequest.json"), ValetDeleteResponse.class);
+ GenericValetResponse<ValetDeleteResponse> expected = new GenericValetResponse<ValetDeleteResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vdr);
+
+ mockValetDeleteDeleteResponse_200("requestId", mapper.writeValueAsString(vdr));
+
+ GenericValetResponse<ValetDeleteResponse> actual = client.callValetDeleteRequest("requestId", "regionId", "tenantId", "vfModuleId", "vfModuleName");
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void testCallValetConfirmRequest() throws Exception {
+ ValetConfirmResponse vcr = new ValetConfirmResponse();
+ GenericValetResponse<ValetConfirmResponse> expected = new GenericValetResponse<ValetConfirmResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr);
+
+ mockValetConfirmPutRequest_200("requestId", "{}");
+
+ GenericValetResponse<ValetConfirmResponse> actual = client.callValetConfirmRequest("requestId", "stackId");
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void testCallValetRollbackRequest() throws Exception {
+ ValetRollbackResponse vrr = new ValetRollbackResponse();
+ GenericValetResponse<ValetRollbackResponse> expected = new GenericValetResponse<ValetRollbackResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vrr);
+
+ mockValetRollbackPutRequest_200("requestId", "{}");
+
+ GenericValetResponse<ValetRollbackResponse> actual = client.callValetRollbackRequest("requestId", "stackId", true, "error");
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
new file mode 100644
index 0000000000..a2faaaff78
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
@@ -0,0 +1,101 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.openstack.MsoOpenstackAdaptersApplication;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.embedded.LocalServerPort;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
+import org.springframework.http.HttpHeaders;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.reset;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MsoOpenstackAdaptersApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+@AutoConfigureWireMock(port = 0)
+public class BaseRestTestUtils {
+ @Value("${wiremock.server.port}")
+ protected int wireMockPort;
+
+ @Autowired
+ @Qualifier("JettisonStyle")
+ protected TestRestTemplate restTemplate;
+
+ protected HttpHeaders headers = new HttpHeaders();
+
+ @LocalServerPort
+ private int port;
+
+ protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(new File(fileLocation));
+ return jsonNode.asText();
+ }
+
+ protected String createURLWithPort(String uri) {
+ return "http://localhost:" + port + uri;
+ }
+
+ protected String readFile(String fileName) throws IOException {
+ try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ sb.append("\n");
+ line = br.readLine();
+ }
+ return sb.toString();
+ }
+ }
+
+ @Before
+ public void setUp(){
+ reset();
+ }
+
+ @Test
+ public void testNothing(){
+
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java
new file mode 100644
index 0000000000..1038299190
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.inject.Provider;
+
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.embedded.LocalServerPort;
+
+public class BpelRestClientTest extends BaseRestTestUtils{
+
+
+ @LocalServerPort
+ private int port;
+ @Autowired
+ @Qualifier("VnfBpel")
+ private Provider<BpelRestClient> clientProvider;
+
+ @Test
+ public void verifyPropertiesRead() {
+ BpelRestClient client = clientProvider.get();
+
+ assertEquals(5, client.getRetryCount());
+ assertEquals(30, client.getConnectTimeout());
+ assertEquals("test:test", client.getCredentials());
+ assertEquals(30, client.getSocketTimeout());
+ assertEquals("408, 429, 500, 502, 503, 504, 900", client.getRetryList());
+ assertEquals(-15, client.getRetryInterval());
+
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java
new file mode 100644
index 0000000000..d0425371bb
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+
+import org.apache.http.HttpStatus;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.adapters.vnf.exceptions.VnfException;
+import org.onap.so.entity.MsoRequest;
+import org.onap.so.openstack.beans.VnfRollback;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.mock.mockito.SpyBean;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.containing;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.verify;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+
+public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils {
+
+ @Autowired
+ MsoVnfAdapterAsyncImpl instance;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void healthCheckVNFTest() {
+ instance.healthCheckA();
+ }
+
+ @Test
+ public void createVNFTest() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
+ (containing("messageId"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
+
+ String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
+ String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
+ instance.createVnfA("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", new HashMap<String, String>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId",
+ msoRequest, notificationUrl);
+
+ verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
+ }
+
+ @Test
+ public void createVNFTest_Exception() throws Exception {
+ String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
+ instance.createVnfA("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", new HashMap<String, String>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId",
+ null, notificationUrl);
+
+ verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
+
+ }
+
+ @Test
+ public void updateVnfTest() throws Exception{
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
+ (containing("messageId"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
+ String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
+ instance.updateVnfA("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", map, "messageId", msoRequest,
+ notificationUrl);
+ }
+
+ @Test
+ public void updateVnfTest_Exception() throws Exception{
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
+ (containing("messageId"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
+ String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
+ instance.updateVnfA("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", map, "messageId", msoRequest,
+ notificationUrl);
+ verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
+ }
+
+ @Test
+ public void queryVnfTest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ instance.queryVnfA("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
+ "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
+ }
+
+ @Test
+ public void deleteVnfTest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ instance.deleteVnfA("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
+ "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
+ }
+
+ @Test
+ public void rollbackVnfTest() {
+ VnfRollback vnfRollBack = new VnfRollback();
+ vnfRollBack.setCloudSiteId("mdt1");
+ vnfRollBack.setTenantId("88a6ca3ee0394ade9403f075db23167e");
+ vnfRollBack.setVnfId("ff5256d1-5a33-55df-13ab-12abad84e7ff");
+ instance.rollbackVnfA(vnfRollBack, "messageId",
+ "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java
new file mode 100644
index 0000000000..0ce3683a1e
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java
@@ -0,0 +1,562 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+
+import com.github.tomakehurst.wiremock.client.WireMock;
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.MockitoAnnotations;
+import org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists;
+import org.onap.so.adapters.vnf.exceptions.VnfException;
+import org.onap.so.adapters.vnf.exceptions.VnfNotFound;
+import org.onap.so.db.catalog.beans.HeatEnvironment;
+import org.onap.so.db.catalog.beans.HeatTemplate;
+import org.onap.so.db.catalog.beans.HeatTemplateParam;
+import org.onap.so.db.catalog.beans.VfModule;
+import org.onap.so.db.catalog.beans.VfModuleCustomization;
+import org.onap.so.db.catalog.beans.VnfResource;
+import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
+import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
+import org.onap.so.entity.MsoRequest;
+import org.onap.so.openstack.beans.HeatStatus;
+import org.onap.so.openstack.beans.StackInfo;
+import org.onap.so.openstack.beans.VnfRollback;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.onap.so.openstack.utils.MsoHeatUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.mock.mockito.MockBean;
+
+import javax.xml.ws.Holder;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStack;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackGetWithResponse;
+
+
+public class MsoVnfAdapterImplTest extends BaseRestTestUtils {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Autowired
+ private MsoHeatUtils heatUtils;
+
+ @Autowired
+ MsoVnfAdapterImpl instance;
+
+ String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
+
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+ WireMock.reset();
+ }
+
+ @Test
+ @Ignore
+ public void healthCheckVNFTest() {
+ MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
+ instance.healthCheck();
+ }
+
+ @Test
+ public void createVnfTest() throws Exception {
+ StackInfo info = new StackInfo();
+ info.setStatus(HeatStatus.CREATED);
+
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_HeatStatusUpdating() throws Exception {
+ expectedException.expect(VnfAlreadyExists.class);
+ mockOpenStackResponseAccess(wireMockPort);
+
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Updating_VfModule.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_HeatStatusUpdated() throws Exception {
+ expectedException.expect(VnfAlreadyExists.class);
+ mockOpenStackResponseAccess(wireMockPort);
+
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_StackId.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_HeatStatusFailed() throws Exception {
+ expectedException.expect(VnfAlreadyExists.class);
+ mockOpenStackResponseAccess(wireMockPort);
+
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Failed_VfModule.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_HeatStatusCreated() throws Exception {
+ expectedException.expect(VnfAlreadyExists.class);
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackVfModule_200();
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+
+ @Test
+ public void createVnfTest_ExceptionInGettingHeat() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_NestedHeatStatusNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_ExceptionInGettingNestedHeat() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_NestedBaseHeatStatus_NotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_ExceptionInGettingBaseNestedHeat() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_ExceptionInCreateStack() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+
+ VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
+ VfModule vfModule = new VfModule();
+ vfModule.setIsBase(false);
+
+ HeatTemplate heatTemplate = new HeatTemplate();
+ heatTemplate.setTemplateBody("");
+ heatTemplate.setTimeoutMinutes(200);
+ vfModule.setModuleHeatTemplate(heatTemplate);
+ vfModuleCustomization.setVfModule(vfModule);
+
+ HeatEnvironment heatEnvironment = new HeatEnvironment();
+ heatEnvironment.setEnvironment("ist");
+ vfModuleCustomization.setHeatEnvironment(heatEnvironment);
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_ModelCustUuidIsNull() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+
+ VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
+ VfModule vfModule = new VfModule();
+ vfModule.setIsBase(false);
+
+ HeatTemplate heatTemplate = new HeatTemplate();
+ heatTemplate.setTemplateBody("");
+ heatTemplate.setTimeoutMinutes(200);
+ vfModule.setModuleHeatTemplate(heatTemplate);
+ vfModuleCustomization.setVfModule(vfModule);
+
+ HeatEnvironment heatEnvironment = new HeatEnvironment();
+ heatEnvironment.setEnvironment("ist");
+ vfModuleCustomization.setHeatEnvironment(heatEnvironment);
+
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setAicVersionMin("1");
+ vnfResource.setAicVersionMin("3");
+
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "XVFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", null, map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVnfTest_HeatEnvironment_ContainsParameters() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK)));
+
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ private MsoRequest getMsoRequest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ return msoRequest;
+ }
+
+ @Test
+ public void updateVnfTest_CloudSiteIdNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_HeatStackNotFound() throws Exception {
+ expectedException.expect(VnfNotFound.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_ExceptionInGettingNestedHeatStack() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_NestedHeatStackNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_ExceptionInGettingNestedBaseHeatStack() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_INTERNAL_SERVER_ERROR,"OpenstackResponse_Stack_Created_VfModule.json");
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_NestedBaseHeatStackNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_NOT_FOUND,"OpenstackResponse_Stack_Created_VfModule.json");
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_MissingParams() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest_UpdateStackException() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+
+ VfModuleCustomization vfModuleCustomization = getVfModuleCustomization();
+ vfModuleCustomization.getVfModule().getModuleHeatTemplate().setParameters(new HashSet<>());
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void updateVnfTest() throws Exception {
+ MsoRequest msoRequest = getMsoRequest();
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/"+vnfName,HttpStatus.SC_OK,"OpenstackResponse_Stack_UpdateComplete.json");
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json");
+ mockOpenStackPutStack("null/stackId", HttpStatus.SC_OK);
+ mockOpenstackGetWithResponse("/mockPublicUrl/stacks/null/stackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_UpdateComplete.json");
+
+ VfModuleCustomization vfModuleCustomization = getVfModuleCustomization();
+ vfModuleCustomization.getVfModule().getModuleHeatTemplate().setParameters(new HashSet<>());
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ instance.updateVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId",
+ "b4ea86b4-253f-11e7-93ae-92361f002671", map, msoRequest, new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ @Ignore
+ public void deleteVnfTest() throws MsoException {
+
+ Map<String, Object> outputs = new HashMap<>();
+ outputs.put("Key1", "value1");
+ when(heatUtils.queryStackForOutputs("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12")).thenReturn(outputs);
+
+ MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
+ MsoRequest msoRequest = getMsoRequest();
+ try {
+ instance.deleteVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<Map<String, String>>());
+ } catch (Exception e) {
+
+ }
+ }
+
+ private VfModuleCustomization getVfModuleCustomization() {
+ VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
+ VfModule vfModule = new VfModule();
+ vfModule.setIsBase(false);
+
+ HeatTemplate heatTemplate = new HeatTemplate();
+ heatTemplate.setTemplateBody("");
+ heatTemplate.setTimeoutMinutes(200);
+ HeatTemplateParam heatTemplateParam = new HeatTemplateParam();
+ heatTemplateParam.setParamAlias("ParamAlias");
+ heatTemplateParam.setRequired(true);
+ heatTemplateParam.setParamName("test");
+ Set set = new HashSet();
+ set.add(heatTemplateParam);
+ heatTemplate.setParameters(set);
+ vfModule.setModuleHeatTemplate(heatTemplate);
+ vfModuleCustomization.setVfModule(vfModule);
+
+ HeatEnvironment heatEnvironment = new HeatEnvironment();
+ heatEnvironment.setEnvironment("parameters:ist");
+ vfModuleCustomization.setHeatEnvironment(heatEnvironment);
+ return vfModuleCustomization;
+ }
+
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java
new file mode 100644
index 0000000000..6f2c6cf86d
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java
@@ -0,0 +1,319 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import org.apache.http.HttpStatus;
+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.vnf.exceptions.VnfException;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.cloud.CloudifyManager;
+import org.onap.so.entity.MsoRequest;
+import org.onap.so.openstack.beans.VnfRollback;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.xml.ws.Holder;
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+
+public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Autowired
+ private MsoVnfCloudifyAdapterImpl instance;
+
+ @Autowired
+ private CloudConfig cloudConfig;
+
+ @Before
+ public void before(){
+ super.setUp();
+ CloudifyManager cloudifyManager = new CloudifyManager();
+ cloudifyManager.setId("mtn13");
+ cloudifyManager.setCloudifyUrl("http://localhost:"+wireMockPort+"/v2.0");
+ cloudifyManager.setUsername("m93945");
+ cloudifyManager.setPassword("93937EA01B94A10A49279D4572B48369");
+ cloudConfig.getCloudifyManagers().put("mtn13",cloudifyManager);
+ }
+
+ @After
+ public void after(){
+ cloudConfig.getCloudifyManagers().clear();
+ }
+
+ @Test
+ public void queryVnfNullPointerExceptionTest() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.queryVnf("siteid", "1234", "vfname",
+ msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
+ new Holder<>());
+ }
+
+ @Test
+ public void queryVnfTest() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
+ .withBody("{ \"id\": \"123\" }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
+ .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
+ .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
+ .withBodyFile("OpenstackResponse_Access.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ instance.queryVnf("mtn13", "1234", "vfname",
+ msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
+ new Holder<>());
+ }
+
+ @Test
+ public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.deleteVfModule("mtn13", "1234", "vfname", msoRequest, new Holder<>());
+ }
+
+ @Test
+ public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
+ .withBody("{ \"id\": \"123\" }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
+ .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
+ .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
+ .withBodyFile("OpenstackResponse_Access.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ instance.deleteVfModule("mtn13", "1234", "vfname", msoRequest, new Holder<>());
+ }
+
+ @Test
+ public void deleteVnfVnfExceptionTest() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.deleteVnf("12344", "234", "vnfname", msoRequest);
+
+ }
+
+ @Test
+ public void rollbackVnf() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ VnfRollback vnfRollback = new VnfRollback();
+ vnfRollback.setModelCustomizationUuid("1234");
+ vnfRollback.setVfModuleStackId("2134");
+ vnfRollback.setVnfId("123");
+ vnfRollback.setModelCustomizationUuid("1234");
+
+ instance.rollbackVnf(vnfRollback);
+ }
+
+ @Test
+ public void rollbackVnf_Created() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ VnfRollback vnfRollback = new VnfRollback();
+ vnfRollback.setModelCustomizationUuid("1234");
+ vnfRollback.setVfModuleStackId("2134");
+ vnfRollback.setVnfId("123");
+ vnfRollback.setModelCustomizationUuid("1234");
+ vnfRollback.setVnfCreated(true);
+
+ instance.rollbackVnf(vnfRollback);
+ }
+
+ @Test
+ public void createVfModuleVnfException() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", "123", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void createVfModule_ModelCustUuidIsNull() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", null, new
+ HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void createVfModule_CloudSiteIdNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void createVfModule_MsoCloudifyManagerNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.createVfModule("mtn13", "123", "vf", "v1", "module-005", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void createVfModule() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
+ .withBody("{ \"id\": \"123\" }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
+ .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
+ .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
+ .withBodyFile("OpenstackResponse_Access.json")
+ .withStatus(HttpStatus.SC_OK)));
+
+ instance.createVfModule("mtn13", "123", "vf", "v1", "vfname", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void updateVfModuleVnfException() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ instance.updateVfModule("123", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
+ }
+
+ @Test
+ public void healthCheckVNFTest() {
+ instance.healthCheck();
+ }
+
+ @Test
+ public void createVnfTest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ try {
+ instance.createVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),
+ new Holder<>());
+ } catch (Exception e) {
+ }
+ }
+
+ @Test
+ public void updateVnfTest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+
+ map.put("key1", "value1");
+ try {
+ instance.updateVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(),
+ new Holder<>());
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void deleteVnfTest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ try {
+ instance.deleteVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
+ } catch (Exception e) {
+
+ }
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java
new file mode 100644
index 0000000000..b21f1f3db2
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java
@@ -0,0 +1,167 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.adapters.vnf.exceptions.VnfException;
+import org.onap.so.entity.MsoRequest;
+import org.onap.so.openstack.beans.VnfRollback;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.xml.ws.Holder;
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+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.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+
+public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Autowired
+ MsoVnfPluginAdapterImpl msoVnfPluginAdapter;
+
+ String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
+
+ @Test
+ public void createVfModule_ModelCustUuidIsNull() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", null, map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVfModule_ModelCustUuidIsNotFound() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVfModule_VduException() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVfModule_INSTANTIATED() throws Exception {
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ MsoRequest msoRequest = getMsoRequest();
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVfModule_queryVduNotFoundWithVolumeGroupId() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ MsoRequest msoRequest = getMsoRequest();
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void createVfModule_CreateVduException() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
+ .withStatus(HttpStatus.SC_OK)));
+ MsoRequest msoRequest = getMsoRequest();
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
+ "volumeGroupHeatStackId", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
+ Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
+ new Holder<VnfRollback>());
+ }
+
+ @Test
+ public void deleteVfModule_QueryVduException() throws Exception {
+ expectedException.expect(VnfException.class);
+ MsoRequest msoRequest = getMsoRequest();
+ msoVnfPluginAdapter.deleteVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<Map<String, String>>());
+ }
+
+ @Test
+ public void deleteVfModule_DeleteVduException() throws Exception {
+ expectedException.expect(VnfException.class);
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_200();
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vSAMP12"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+ MsoRequest msoRequest = getMsoRequest();
+ msoVnfPluginAdapter.deleteVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<Map<String, String>>());
+ }
+
+ private MsoRequest getMsoRequest() {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+ return msoRequest;
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java
new file mode 100644
index 0000000000..d6cdbdfccd
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.util.Map;
+
+import javax.xml.ws.Holder;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.so.adapters.vnf.exceptions.VnfException;
+import org.onap.so.openstack.beans.HeatStatus;
+import org.onap.so.openstack.beans.StackInfo;
+import org.onap.so.openstack.beans.VnfStatus;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.onap.so.openstack.exceptions.MsoOpenstackException;
+import org.onap.so.openstack.utils.MsoHeatUtils;
+
+@RunWith(MockitoJUnitRunner.class)
+public class QueryTest {
+
+ @Mock
+ private MsoHeatUtils heat;
+ @InjectMocks
+ private MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @Test
+ public void testQueryCreatedVnf() throws VnfException, MsoException {
+ StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
+ when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vnfId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
+
+ assertTrue(vnfExists.value);
+ }
+
+ @Test
+ public void testQueryNotFoundVnf() throws VnfException, MsoException {
+ StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
+ when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vnfId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
+
+ assertFalse(vnfExists.value);
+ }
+
+ @Test()
+ // @Ignore // 1802 merge
+ public void testQueryVnfWithException() throws VnfException, MsoException {
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vnfId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+ thrown.expect(VnfException.class);
+ thrown.expectCause(hasProperty("context", is("QueryVNF")));
+ when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new MsoOpenstackException(1, "test messsage", "test detail"));
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java
new file mode 100644
index 0000000000..a59de7695c
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java
@@ -0,0 +1,70 @@
+/*
+* ============LICENSE_START=======================================================
+ * ONAP : SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+*/
+package org.onap.so.adapters.vnf;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+public class VfRollbackTest {
+ private VfRollback vfRollback = new VfRollback();
+
+ @Test
+ public void test() {
+ vfRollback.setVnfId("vnfId");
+ vfRollback.setTenantId("tenantId");
+ vfRollback.setCloudSiteId("cloudId");
+ vfRollback.setTenantCreated(true);
+ vfRollback.setVnfCreated(true);
+ vfRollback.setMsoRequest(null);
+ vfRollback.setVolumeGroupName("volumeGroupName");
+ vfRollback.setVolumeGroupId("volumeGroupId");
+ vfRollback.setRequestType("requestType");
+ vfRollback.setVolumeGroupHeatStackId("volumeGroupHeatStackId");
+ vfRollback.setBaseGroupHeatStackId("baseGroupHeatStackId");
+ vfRollback.setIsBase(true);
+ vfRollback.setVfModuleStackId("vfModuleStackId");
+ assert(vfRollback.getVnfId() != null);
+ assert(vfRollback.getTenantId() != null);
+ assert(vfRollback.getCloudSiteId() != null);
+ assert(vfRollback.getVolumeGroupName() != null);
+ assert(vfRollback.getVolumeGroupId() != null);
+ assert(vfRollback.getRequestType() != null);
+ assert(vfRollback.getVolumeGroupHeatStackId() != null);
+ assert(vfRollback.getBaseGroupHeatStackId() != null);
+ assert(vfRollback.getVfModuleStackId() != null);
+ assertEquals("vnfId", vfRollback.getVnfId());
+ assertEquals("tenantId", vfRollback.getTenantId());
+ assertEquals("cloudId", vfRollback.getCloudSiteId());
+ assertEquals(true, vfRollback.getTenantCreated());
+ assertEquals(true, vfRollback.getVnfCreated());
+ assertEquals(null, vfRollback.getMsoRequest());
+ assertEquals("volumeGroupName", vfRollback.getVolumeGroupName());
+ assertEquals("volumeGroupId", vfRollback.getVolumeGroupId());
+ assertEquals("requestType", vfRollback.getRequestType());
+ assertEquals("volumeGroupHeatStackId", vfRollback.getVolumeGroupHeatStackId());
+ assertEquals("baseGroupHeatStackId", vfRollback.getBaseGroupHeatStackId());
+ assertEquals(true, vfRollback.isBase());
+ assertEquals("vfModuleStackId", vfRollback.getVfModuleStackId());
+ }
+
+ @Test
+ public void testtoString() {
+ assert(vfRollback.toString() != null);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java
new file mode 100644
index 0000000000..93841a5037
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java
@@ -0,0 +1,560 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import org.json.JSONException;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
+import org.onap.so.adapters.vnfrest.CreateVfModuleResponse;
+import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
+import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse;
+import org.onap.so.adapters.vnfrest.QueryVfModuleResponse;
+import org.onap.so.adapters.vnfrest.RollbackVfModuleRequest;
+import org.onap.so.adapters.vnfrest.RollbackVfModuleResponse;
+import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest;
+import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse;
+import org.onap.so.adapters.vnfrest.VfModuleExceptionResponse;
+import org.onap.so.adapters.vnfrest.VfModuleRollback;
+import org.onap.so.client.policy.JettisonStyleMapperProvider;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.entity.MsoRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeletePublicUrlStackByNameAndID_204;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteStacks;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetPublicUrlStackByNameAndID_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksBaseStack_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksStackId_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksStackId_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksVUSP_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksVfModuleWithLocationHeader_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksWithBody_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksWithBody_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacks_404;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStacks_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStacks_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+
+public class VnfAdapterRestTest extends BaseRestTestUtils {
+
+ @Autowired
+ private CloudConfig cloudConfig;
+ @Autowired
+ private JettisonStyleMapperProvider jettisonTypeObjectMapper;
+ private static final String MESSAGE_ID = "62265093-277d-4388-9ba6-449838ade586-1517252396874";
+ private static final String AAI_VNF_ID = "c93e0d34-5b63-45de-bbae-b0fe49dd3bd9";
+ private static final String MSO_REQUEST_ID = "62265093-277d-4388-9ba6-449838ade586";
+ private static final String MSO_SERVICE_INSTANCE_ID = "4147e06f-1b89-49c5-b21f-4faf8dc9805a";
+ private static final String CLOUDSITE_ID = "mtn13";
+ private static final String TENANT_ID = "0422ffb57ba042c0800a29dc85ca70f8";
+ private static final String VNF_TYPE = "MSOTADevInfra_vSAMP10a_Service/vSAMP10a 1";
+ private static final String VNF_NAME = "MSO-DEV-VNF-1802-it3-pwt3-vSAMP10a-1XXX-Replace";
+ private static final String VNF_VERSION = "1.0";
+ private static final String VF_MODULE_ID = "1d48aaec-b7f3-4c24-ba4a-4e798ed3223c";
+ private static final String VF_MODULE_NAME = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001";
+ private static final String VF_MODULE_TYPE = "vSAMP10aDEV::PCM::module-2";
+ private static final String MODEL_CUSTOMIZATION_UUID = "cb82ffd8-252a-11e7-93ae-92361f002671";
+ private static final String BASE_VF_MODULE_ID = "3d7ff7b4-720b-4604-be0a-1974fc58ed96";
+ // vfModuleParams specific variables
+ private static final String NETWORK_NAME = "Dev-vSAMP10a-ntwk-1802-pwt3-v6-Replace-1001";
+ private static final String SERVER_NAME = "Dev-vSAMP10a-addon2-1802-pwt3-v6-Replace-1001";
+ private static final String IMAGE = "ubuntu_14.04_IPv6";
+ private static final String EXN_DIRECT_NET_FQDN = "direct";
+ private static final String EXN_HSL_NET_FQDN = "hsl";
+ private static final String AVAILABILITY_ZONE_0 = "nova";
+ private static final String VF_MODULE_INDEX = "0";
+ private static final String REQUEST_TYPE = "";
+
+ @Test
+ public void testCreateVfModule() throws JSONException, JsonParseException, JsonMappingException, IOException {
+
+ CreateVfModuleRequest request = populateCreateVfModuleRequest();
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackVfModule_404();
+
+ mockOpenStackPostStacks_200();
+
+ mockOpenStackGetStackVfModule_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers);
+
+ ResponseEntity<CreateVfModuleResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, CreateVfModuleResponse.class);
+
+ ResponseEntity<CreateVfModuleResponse> responseV2 = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, CreateVfModuleResponse.class);
+
+ CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+
+ assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value());
+ assertThat(responseV2.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testCreateVfModuleAsyncCall() throws Exception {
+ CreateVfModuleRequest request = populateCreateVfModuleRequest();
+ request.setNotificationUrl( createURLWithPort("/mso/WorkflowMesssage"));
+
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStackVfModule_404();
+ mockOpenStackPostStacks_200();
+ mockOpenStackGetStackVfModule_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers);
+
+ ResponseEntity<CreateVfModuleResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, CreateVfModuleResponse.class);
+
+ CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testCreateVfModuleWithEnableBridgeNull()
+ throws JSONException, JsonParseException, JsonMappingException, IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateVfModuleRequest request = new CreateVfModuleRequest();
+ request.setBackout(true);
+ request.setSkipAAI(true);
+ request.setFailIfExists(false);
+ MsoRequest msoReq = new MsoRequest();
+ boolean failIfExists = true;
+ Boolean enableBridge = null;
+ Map<String, String> vfModuleParams = new HashMap<String, String>();
+
+
+ vfModuleParams.put("vf_module_id", VF_MODULE_ID);
+ vfModuleParams.put("vnf_id", AAI_VNF_ID);
+ vfModuleParams.put("network_name", NETWORK_NAME);
+ vfModuleParams.put("vnf_name", VNF_NAME);
+ vfModuleParams.put("environment_context", "");
+ vfModuleParams.put("server_name", SERVER_NAME);
+ vfModuleParams.put("image", IMAGE);
+ vfModuleParams.put("workload_context", "");
+ vfModuleParams.put("vf_module_index", VF_MODULE_INDEX);
+ vfModuleParams.put("vf_module_name", VF_MODULE_NAME);
+ vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0);
+ vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN);
+ vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN);
+
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setMsoRequest(msoReq);
+ request.setRequestType(REQUEST_TYPE);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setVnfId(AAI_VNF_ID);
+ request.setVnfVersion(VNF_VERSION);
+ request.setVfModuleId(VF_MODULE_ID);
+ request.setVfModuleName(VF_MODULE_NAME);
+ request.setBaseVfModuleId(BASE_VF_MODULE_ID);
+ request.setFailIfExists(failIfExists);
+ request.setEnableBridge(enableBridge);
+ request.setVfModuleParams(vfModuleParams);
+ request.setMessageId(MESSAGE_ID);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackVfModule_404();
+
+ mockOpenStackPostStacks_200();
+
+ mockOpenStackGetStackVfModule_200();
+
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers);
+
+ ResponseEntity<CreateVfModuleResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, CreateVfModuleResponse.class);
+
+ CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testCreateVfModuleFail() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateVfModuleRequest request = new CreateVfModuleRequest();
+ request.setBackout(true);
+ request.setSkipAAI(true);
+ request.setFailIfExists(false);
+ MsoRequest msoReq = new MsoRequest();
+ boolean failIfExists = true;
+ boolean enableBridge = false;
+ Map<String, String> vfModuleParams = new HashMap<String, String>();
+
+ vfModuleParams.put("vf_module_id", VF_MODULE_ID);
+ vfModuleParams.put("vnf_id", AAI_VNF_ID);
+ vfModuleParams.put("network_name", NETWORK_NAME);
+ vfModuleParams.put("vnf_name", VNF_NAME);
+ vfModuleParams.put("environment_context", "");
+ vfModuleParams.put("server_name", SERVER_NAME);
+ vfModuleParams.put("image", IMAGE);
+ vfModuleParams.put("workload_context", "");
+ vfModuleParams.put("vf_module_index", VF_MODULE_INDEX);
+ vfModuleParams.put("vf_module_name", VF_MODULE_NAME);
+ vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0);
+ vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN);
+ vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN);
+
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setMsoRequest(msoReq);
+ request.setRequestType(REQUEST_TYPE);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setVnfId(AAI_VNF_ID);
+ request.setVnfType(VNF_TYPE);
+ request.setVnfVersion(VNF_VERSION);
+ request.setVfModuleId(VF_MODULE_ID);
+ request.setVfModuleName(VF_MODULE_NAME);
+ request.setVfModuleType(VF_MODULE_TYPE);
+ request.setBaseVfModuleStackId(BASE_VF_MODULE_ID);
+ request.setFailIfExists(failIfExists);
+ request.setEnableBridge(enableBridge);
+ request.setVfModuleParams(vfModuleParams);
+ request.setMessageId(MESSAGE_ID);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStackVfModule_404();
+
+ mockOpenStackGetStacks_404();
+
+ mockOpenStackPostStacks_200();
+
+ mockOpenStackGetStackVfModule_200();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers);
+
+ ResponseEntity<VfModuleExceptionResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, VfModuleExceptionResponse.class);
+
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+
+ mockOpenStackGetStacksWithBody_200("DELETE_IN_PROGRESS");
+
+ response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, VfModuleExceptionResponse.class);
+
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+
+ mockOpenStackGetStacksWithBody_200("DELETE_FAILED");
+
+ response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, VfModuleExceptionResponse.class);
+
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+
+ mockOpenStackGetStacksWithBody_200("UPDATE_COMPLETE");
+
+ response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, VfModuleExceptionResponse.class);
+
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+
+ mockOpenStackGetStacksWithBody_404();
+
+ response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST,
+ entity, VfModuleExceptionResponse.class);
+
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+
+ }
+
+ @Test
+ public void testDeleteVfModule() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ DeleteVfModuleRequest request = new DeleteVfModuleRequest();
+ MsoRequest msoRequest = new MsoRequest();
+ String vfModuleStackId = "stackId";
+
+ msoRequest.setRequestId(MSO_REQUEST_ID);
+ msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setVfModuleId(VF_MODULE_ID);
+ request.setVfModuleStackId(vfModuleStackId);
+ request.setVnfId(AAI_VNF_ID);
+ request.setMsoRequest(msoRequest);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackPostStacks_200();
+
+ mockOpenStackGetStacksStackId_404();
+
+ mockOpenStackGetPublicUrlStackByNameAndID_200(wireMockPort);
+
+ mockOpenStackDeletePublicUrlStackByNameAndID_204();
+
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<DeleteVfModuleRequest> entity = new HttpEntity<DeleteVfModuleRequest>(request, headers);
+
+ ResponseEntity<DeleteVfModuleResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID), HttpMethod.DELETE,
+ entity, DeleteVfModuleResponse.class);
+
+ ResponseEntity<DeleteVfModuleResponse> responseV2 = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID), HttpMethod.DELETE,
+ entity, DeleteVfModuleResponse.class);
+
+
+ DeleteVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/DeleteVfModuleResponse.json"), DeleteVfModuleResponse.class);
+
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+
+ assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value());
+ assertThat(responseV2.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ @Test
+ public void testUpdateVfModule() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ UpdateVfModuleRequest request = new UpdateVfModuleRequest();
+ MsoRequest msoRequest = new MsoRequest();
+ String vfModuleStackId = "vfModuleStackId";
+ Boolean failIfExists = false;
+ Boolean backout = false;
+ msoRequest.setRequestId(MSO_REQUEST_ID);
+ msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+
+ Map<String, String> vfModuleParams = new HashMap<String, String>();
+
+ vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN);
+ vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN);
+
+ Map<String, String> vfModuleOutputs = new HashMap<String, String>();
+
+ vfModuleOutputs.put("output name", "output value");
+
+ request.setBackout(backout);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setFailIfExists(failIfExists);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setMsoRequest(msoRequest);
+ request.setRequestType(REQUEST_TYPE);
+ request.setTenantId(TENANT_ID);
+ request.setVfModuleId(VF_MODULE_ID);
+ request.setVfModuleName(VF_MODULE_NAME);
+ request.setVfModuleStackId(vfModuleStackId);
+ request.setBackout(backout);
+ request.setVfModuleParams(vfModuleParams);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStacksVfModuleWithLocationHeader_200(wireMockPort);
+
+ mockOpenStackGetStacksVfModule_200(wireMockPort);
+
+ mockOpenStackGetStacksBaseStack_200(wireMockPort);
+
+ mockOpenStackPutStacks_200();
+
+ UpdateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/UpdateVfModuleResponse.json"), UpdateVfModuleResponse.class);
+ expectedResponse.setVfModuleOutputs(vfModuleOutputs);
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<UpdateVfModuleRequest> entity = new HttpEntity<UpdateVfModuleRequest>(request, headers);
+
+ ResponseEntity<UpdateVfModuleResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_TYPE), HttpMethod.PUT,
+ entity, UpdateVfModuleResponse.class);
+
+ ResponseEntity<UpdateVfModuleResponse> responseV2 = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_TYPE), HttpMethod.PUT,
+ entity, UpdateVfModuleResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+
+ assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value());
+ assertThat(responseV2.getBody(), sameBeanAs(expectedResponse));
+
+ }
+
+ @Test
+ public void testRollbackVfModule() throws IOException {
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId(MSO_REQUEST_ID);
+ msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+
+ VfModuleRollback vfModuleRollback = new VfModuleRollback(AAI_VNF_ID, VF_MODULE_ID,
+ "StackId", false, TENANT_ID, CLOUDSITE_ID, msoRequest, "messageId");
+
+ RollbackVfModuleRequest request = new RollbackVfModuleRequest();
+ request.setVfModuleRollback(vfModuleRollback);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+ mockOpenStackGetStacksStackId_200(wireMockPort);
+
+ mockOpenStackDeleteStacks();
+
+ mockOpenStackGetStacksVUSP_404();
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ HttpEntity<RollbackVfModuleRequest> entity = new HttpEntity<RollbackVfModuleRequest>(request, headers);
+
+ ResponseEntity<RollbackVfModuleResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID + "/rollback"), HttpMethod.DELETE,
+ entity, RollbackVfModuleResponse.class);
+
+ RollbackVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/RollbackVfModuleResponse.json"),RollbackVfModuleResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+
+ }
+
+ @Ignore
+ @Test
+ public void testQueryVfModule() throws IOException{
+
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ String testUrl = createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID);
+ String testUri = UriBuilder.fromPath("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID )
+ .host("localhost").port(wireMockPort).scheme("http")
+ //.queryParam("cloudSiteId", CLOUDSITE_ID).queryParam("tenantId", TENANT_ID)
+ .build().toString();
+ System.out.println(testUri);
+
+ mockOpenStackResponseAccess(wireMockPort);
+
+
+ headers.add("Accept", MediaType.APPLICATION_JSON);
+ //HttpEntity entity = new HttpEntity(null, headers);
+ ResponseEntity<QueryVfModuleResponse> response = restTemplate.getForEntity(testUri, QueryVfModuleResponse.class);
+ //System.out.println(response);
+
+ QueryVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue(
+ new File("src/test/resources/__files/QueryVfModuleResponse.json"),QueryVfModuleResponse.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(response.getBody(), sameBeanAs(expectedResponse));
+ }
+
+ private CreateVfModuleRequest populateCreateVfModuleRequest(){
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateVfModuleRequest request = new CreateVfModuleRequest();
+ request.setBackout(true);
+ request.setSkipAAI(true);
+ request.setFailIfExists(false);
+ MsoRequest msoReq = new MsoRequest();
+ boolean failIfExists = true;
+ boolean enableBridge = false;
+ Map<String, String> vfModuleParams = new HashMap<String, String>();
+
+ vfModuleParams.put("vf_module_id", VF_MODULE_ID);
+ vfModuleParams.put("vnf_id", AAI_VNF_ID);
+ vfModuleParams.put("network_name", NETWORK_NAME);
+ vfModuleParams.put("vnf_name", VNF_NAME);
+ vfModuleParams.put("environment_context", "");
+ vfModuleParams.put("server_name", SERVER_NAME);
+ vfModuleParams.put("image", IMAGE);
+ vfModuleParams.put("workload_context", "");
+ vfModuleParams.put("vf_module_index", VF_MODULE_INDEX);
+ vfModuleParams.put("vf_module_name", VF_MODULE_NAME);
+ vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0);
+ vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN);
+ vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN);
+
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ request.setMsoRequest(msoReq);
+ request.setRequestType(REQUEST_TYPE);
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setVnfId(AAI_VNF_ID);
+ request.setVnfType(VNF_TYPE);
+ request.setVnfVersion(VNF_VERSION);
+ request.setVfModuleId(VF_MODULE_ID);
+ request.setVfModuleName(VF_MODULE_NAME);
+ request.setVfModuleType(VF_MODULE_TYPE);
+ request.setBaseVfModuleId(BASE_VF_MODULE_ID);
+ request.setFailIfExists(failIfExists);
+ request.setEnableBridge(enableBridge);
+ request.setVfModuleParams(vfModuleParams);
+ request.setMessageId(MESSAGE_ID);
+
+ return request;
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java
new file mode 100644
index 0000000000..f602690a10
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import org.junit.Test;
+import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.QueryVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.VolumeGroupExceptionResponse;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackWithBody_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksWithBody_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStacks_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStack;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+
+public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon {
+
+ @Test
+ public void testCreateVNFVolumes() throws IOException {
+
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackPostStacks_200();
+ mockOpenStackGetStackVfModule_200();
+ CreateVolumeGroupRequest request = buildCreateVfModuleRequest();
+
+ HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups"), HttpMethod.POST,
+ entity, CreateVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testCreateVNFVolumesAsync() throws IOException {
+
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackPostStacks_200();
+ mockOpenStackGetStackVfModule_200();
+ CreateVolumeGroupRequest request = buildCreateVfModuleRequest();
+ request.setNotificationUrl("http://localhost:8080");
+
+ HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups"), HttpMethod.POST,
+ entity, CreateVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testDeleteVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest();
+ HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE,
+ entity, DeleteVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testDeleteVNFVolumesAsync() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE,
+ entity, DeleteVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testRollbackVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest();
+ HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE,
+ entity, RollbackVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testRollbackVNFVolumesAsync() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE,
+ entity, RollbackVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testQueryVNFVolumes() throws IOException{
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("UPDATE_COMPLETE");
+ javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID);
+ builder.queryParam("cloudSiteId", CLOUDSITE_ID).queryParam("tenantId", TENANT_ID)
+ .queryParam("volumeGroupStackId", VOUME_GROUP_NAME).queryParam("skipAAI", true)
+ .queryParam("msoRequest.requestId", MSO_REQUEST_ID)
+ .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID);
+
+ ResponseEntity<QueryVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort(builder.build().toString()), HttpMethod.GET,
+ null,QueryVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testQueryVNFVolumesError() throws IOException{
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("UPDATE_COMPLETE");
+ javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID);
+ builder.queryParam("tenantId", TENANT_ID)
+ .queryParam("volumeGroupStackId", VOUME_GROUP_NAME).queryParam("skipAAI", true)
+ .queryParam("msoRequest.requestId", MSO_REQUEST_ID)
+ .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID);
+
+ ResponseEntity<VolumeGroupExceptionResponse> response = restTemplate.exchange(
+ createURLWithPort(builder.build().toString()), HttpMethod.GET,
+ null,VolumeGroupExceptionResponse.class);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testUpdateVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("CREATE_COMPLETE");
+ mockOpenStackPutStack(VOUME_GROUP_NAME+"/stackId",200);
+ mockOpenStackGetStackWithBody_200("UPDATE_COMPLETE");
+ UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest();
+ HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT,
+ entity,UpdateVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testUpdateVNFVolumesAsync() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("CREATE_COMPLETE");
+ mockOpenStackPutStack(VOUME_GROUP_NAME+"/stackId",200);
+ mockOpenStackGetStackWithBody_200("UPDATE_COMPLETE");
+ UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT,
+ entity,UpdateVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java
new file mode 100644
index 0000000000..dba169c311
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java
@@ -0,0 +1,184 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import org.junit.Test;
+import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.QueryVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse;
+import org.onap.so.adapters.vnfrest.VolumeGroupExceptionResponse;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackWithBody_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStacksWithBody_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStacks_200;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStack;
+import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
+
+public class VolumeAdapterRestV2Test extends VolumeGroupAdapterCommon {
+
+ @Test
+ public void testCreateVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackPostStacks_200();
+ mockOpenStackGetStackVfModule_200();
+ CreateVolumeGroupRequest request = buildCreateVfModuleRequest();
+
+ HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups"), HttpMethod.POST,
+ entity, CreateVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testCreateVNFVolumesAsync() throws IOException {
+
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackPostStacks_200();
+ mockOpenStackGetStackVfModule_200();
+ CreateVolumeGroupRequest request = buildCreateVfModuleRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups"), HttpMethod.POST,
+ entity, CreateVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testDeleteVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest();
+ HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE,
+ entity, DeleteVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testDeleteVNFVolumesAsync() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE,
+ entity, DeleteVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testRollbackVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest();
+ HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE,
+ entity, RollbackVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testRollbackVNFVolumesAsync() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE,
+ entity, RollbackVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testQueryVNFVolumes() throws IOException{
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("UPDATE_COMPLETE");
+ javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID);
+ builder.queryParam("cloudSiteId", CLOUDSITE_ID).queryParam("tenantId", TENANT_ID)
+ .queryParam("volumeGroupStackId", VOUME_GROUP_NAME).queryParam("skipAAI", true)
+ .queryParam("msoRequest.requestId", MSO_REQUEST_ID)
+ .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID);
+
+ ResponseEntity<QueryVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort(builder.build().toString()), HttpMethod.GET,
+ null,QueryVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testQueryVNFVolumesError() throws IOException{
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("UPDATE_COMPLETE");
+ javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID);
+ builder.queryParam("tenantId", TENANT_ID)
+ .queryParam("volumeGroupStackId", VOUME_GROUP_NAME).queryParam("skipAAI", true)
+ .queryParam("msoRequest.requestId", MSO_REQUEST_ID)
+ .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID);
+
+ ResponseEntity<VolumeGroupExceptionResponse> response = restTemplate.exchange(
+ createURLWithPort(builder.build().toString()), HttpMethod.GET,
+ null,VolumeGroupExceptionResponse.class);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ }
+ @Test
+ public void testUpdateVNFVolumes() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("CREATE_COMPLETE");
+ mockOpenStackPutStack(VOUME_GROUP_NAME+"/stackId",200);
+ mockOpenStackGetStackWithBody_200("UPDATE_COMPLETE");
+ UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest();
+ HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT,
+ entity,UpdateVolumeGroupResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void testUpdateVNFVolumesAsync() throws IOException {
+ mockOpenStackResponseAccess(wireMockPort);
+ mockOpenStackGetStacksWithBody_200("CREATE_COMPLETE");
+ mockOpenStackPutStack(VOUME_GROUP_NAME+"/stackId",200);
+ mockOpenStackGetStackWithBody_200("UPDATE_COMPLETE");
+ UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest();
+ request.setNotificationUrl("http://localhost:8080");
+ HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers);
+ ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange(
+ createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT,
+ entity,UpdateVolumeGroupResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java
new file mode 100644
index 0000000000..d8177363f4
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnf;
+
+import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest;
+import org.onap.so.adapters.vnfrest.VolumeGroupRollback;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.entity.MsoRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class VolumeGroupAdapterCommon extends BaseRestTestUtils {
+
+ @Autowired
+ protected CloudConfig cloudConfig;
+
+ protected static final String MSO_REQUEST_ID = "62265093-277d-4388-9ba6-449838ade586";
+ protected static final String MSO_SERVICE_INSTANCE_ID = "4147e06f-1b89-49c5-b21f-4faf8dc9805a";
+ protected static final String CLOUDSITE_ID = "mtn13";
+ protected static final String TENANT_ID = "0422ffb57ba042c0800a29dc85ca70f8";
+ protected static final String VOUME_GROUP_NAME = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001";
+ protected static final String VOLUME_GROUP_ID = "0422ffb57ba042c0800a29dc85ca70v1";
+ protected static final String VNF_TYPE = "TestVnfType";
+ protected static final String VNF_VERSION = "1.0";
+ protected static final String VF_MODULE_TYPE = "TestModule-0";
+ protected static final String MODEL_CUSTOMIZATION_UUID = "9b339a61-69ca-465f-86b8-1c72c582b8e8";
+
+ protected UpdateVolumeGroupRequest buildUpdateVolumeGroupRequest() {
+ UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest();
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setVolumeGroupId(VOLUME_GROUP_ID);
+ request.setVnfType(VNF_TYPE);
+ request.setVnfVersion(VNF_VERSION);
+ request.setVfModuleType(VF_MODULE_TYPE);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setSkipAAI(true);
+ request.setVolumeGroupStackId(VOUME_GROUP_NAME);
+ Map<String, String> volumeGroupParams = getVolumeGroupParamsMap();
+ request.setVolumeGroupParams(volumeGroupParams);
+ MsoRequest msoReq = getMsoRequest();
+ request.setMsoRequest(msoReq);
+ return request;
+ }
+
+ protected RollbackVolumeGroupRequest buildRollbackVolumeGroupRequest() {
+ RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest();
+ VolumeGroupRollback volumeGroupRollback = new VolumeGroupRollback();
+ volumeGroupRollback.setCloudSiteId(CLOUDSITE_ID);
+ volumeGroupRollback.setMessageId(MSO_REQUEST_ID);
+ volumeGroupRollback.setTenantId(TENANT_ID);
+ MsoRequest msoReq = getMsoRequest();
+ volumeGroupRollback.setVolumeGroupCreated(true);
+ volumeGroupRollback.setVolumeGroupId(VOLUME_GROUP_ID);
+ volumeGroupRollback.setVolumeGroupStackId(VOLUME_GROUP_ID);
+ volumeGroupRollback.setMsoRequest(msoReq);
+ request.setVolumeGroupRollback(volumeGroupRollback);
+ return request;
+ }
+
+ protected DeleteVolumeGroupRequest buildDeleteVolumeGroupRequest() {
+ DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest();
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setVolumeGroupStackId("testStackId");
+ request.setVolumeGroupId(VOLUME_GROUP_ID);
+ MsoRequest msoReq = getMsoRequest();
+ request.setMsoRequest(msoReq);
+ return request;
+ }
+
+ protected CreateVolumeGroupRequest buildCreateVfModuleRequest() {
+ cloudConfig.getIdentityService("MTN13").setIdentityUrl("http://localhost:" + wireMockPort + "/v2.0");
+ CreateVolumeGroupRequest request = new CreateVolumeGroupRequest();
+ request.setCloudSiteId(CLOUDSITE_ID);
+ request.setTenantId(TENANT_ID);
+ request.setVolumeGroupName(VOUME_GROUP_NAME);
+ request.setVolumeGroupId(VOLUME_GROUP_ID);
+ request.setVnfType(VNF_TYPE);
+ request.setVnfVersion(VNF_VERSION);
+ request.setVfModuleType(VF_MODULE_TYPE);
+ request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID);
+ request.setSkipAAI(true);
+ request.setFailIfExists(false);
+ request.setFailIfExists(true);
+ request.setEnableBridge(false);
+ request.setSuppressBackout(true);
+ Map<String, String> volumeGroupParams = getVolumeGroupParamsMap();
+ request.setVolumeGroupParams(volumeGroupParams);
+ MsoRequest msoReq = getMsoRequest();
+ request.setMsoRequest(msoReq);
+
+ return request;
+ }
+
+ private Map<String, String> getVolumeGroupParamsMap() {
+ Map<String, String> volumeGroupParams = new HashMap<>();
+ volumeGroupParams.put("fsb_volume_type_0","volume_type");
+ volumeGroupParams.put("fsb_volume_image_name_1","vol_img_1");
+ volumeGroupParams.put("fsb_volume_image_name_0","vol_img_0");
+ volumeGroupParams.put("fsb_volume_size_0","100");
+ return volumeGroupParams;
+ }
+
+ private MsoRequest getMsoRequest() {
+ MsoRequest msoReq = new MsoRequest();
+ msoReq.setRequestId(MSO_REQUEST_ID);
+ msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID);
+ return msoReq;
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java
new file mode 100644
index 0000000000..98d5f7eb5f
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java
@@ -0,0 +1,485 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.mock;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.containing;
+import static com.github.tomakehurst.wiremock.client.WireMock.delete;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.http.HttpStatus;
+
+public class StubOpenStack {
+ private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0";
+ private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b";
+ private static final String NETWORK_NAME_2 = "stackname";
+ private static final String NETWORK_ID_2 = "stackId";
+
+ public static void mockOpenStackResponseAccess(int port) throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackResponseAccessQueryNetwork(int port) throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens"))
+ .withRequestBody(containing("tenantId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access_queryNetwork.json", port, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackResponseAccessAdmin(int port) throws IOException {
+ stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFile("OpenstackResponse_Access_Admin.json", port, "/mockPublicUrl"))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPublicUrlStackByName_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME)).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME)
+ .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPublicUrlStackByID_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_ID)).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME)
+ .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetPublicUrlStackByNameAndID_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME)
+ .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetPublicUrlStackByNameAndID_204(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)
+ .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME))
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackPutPublicUrlStackByNameAndID_200() {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200() {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME_2+"/"+NETWORK_ID_2)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackDeletePublicUrlStackByNameAndID_204() {
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NO_CONTENT)));
+ }
+
+ public static void mockOpenStackPostPublicUrlWithBodyFile_200() {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStackCreatedAppC_200() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStackAppC_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetStackCreatedVUSP_200() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStackVUSP_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackPostStack_200(String filename) {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPostNeutronNetwork_200(String filename) {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPutNeutronNetwork_200(String filename,String networkId) {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPutNeutronNetwork(String networkId, int responseCode) {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withStatus(responseCode)));
+ }
+
+ public static void mockOpenStackGetAllNeutronNetworks_200(String filename){
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetNeutronNetwork_404(String networkName) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkName)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetAllNeutronNetworks_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenstackGetWithResponse(String url,int responseCode, String responseFile) {
+ stubFor(get(urlPathEqualTo(url)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile(responseFile)
+ .withStatus(responseCode)));
+ }
+
+ public static void mockOpenstackPostWithResponse(String url,int responseCode, String responseFile) {
+ stubFor(post(urlPathEqualTo(url)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile(responseFile)
+ .withStatus(responseCode)));
+ }
+
+ public static void mockOpenstackGet(String url,int responseCode) {
+ stubFor(get(urlPathEqualTo(url)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withStatus(responseCode)));
+ }
+
+ public static void mockOpenstackPost(String url,int responseCode) {
+ stubFor(post(urlPathEqualTo(url)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withStatus(responseCode)));
+ }
+
+ public static void mockOpenStackGetStackVfModule_200() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStackVfModule_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackPostStacks_200() {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStacks_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/3d7ff7b4-720b-4604-be0a-1974fc58ed96"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetStacksWithBody_200(String replaceWith) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFileVnfAdapter(replaceWith))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStackWithBody_200(String replaceWith) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFileVnfAdapter(replaceWith))
+ .withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStacksWithBody_404() throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(getBodyFromFileVnfAdapter(null))
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetStacksStackId_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackId"))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetStacksVfModule_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStacksVfModuleWithLocationHeader_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")
+ .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStacksBaseStack_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfModuleStackId")).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/baseVfModuleStackId")
+ .withBody(getBodyFromFile("OpenstackResponse_VnfBaseStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPutStacks_200() {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPutStack(String networkId,int responseCode) {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+networkId))
+ .willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withStatus(responseCode)));
+ }
+
+ public static void mockOpenStackGetStacksStackId_200(int port) throws IOException {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/StackId")).willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/stackId")
+ .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackDeleteStacks() {
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b"))
+ .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest")));
+ }
+
+ public static void mockOpenStackGetStacksVUSP_404() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b"))
+ .willReturn(aResponse()
+ .withHeader("X-Openstack-Request-Id", "openstackRquest")
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetStackCreated_200(String filename, String networkName) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetStack_404(String networkName) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetStack_500(String networkName) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+ }
+
+ public static void mockOpenStackGetStackDeleteOrUpdateComplete_200(String filename) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetNeutronNetwork(String filename,String networkId,int status) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile(filename).withStatus(status)));
+ }
+
+ public static void mockOpenStackGetNeutronNetwork(String networkId,int status) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(status)));
+ }
+
+ public static void mockOpenStackDeleteStack_200() {
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackDeleteStack_500() {
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2))
+ .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+ }
+
+ public static void mockOpenStackDeleteNeutronNetwork(String networkId,int responseCode) {
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId))
+ .willReturn(aResponse().withStatus(responseCode)));
+ }
+
+ public static void mockOpenStackPostMetadata_200() {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetMetadata_200() {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPostTenantWithBodyFile_200() throws IOException {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants"))
+ .withRequestBody(equalToJson(readFile("src/test/resources/__files/OpenstackRequest_Tenant.json"))).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPostTenant_200() throws IOException {
+ stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetTenantByName_200(String tenantName) {
+ stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetTenantByName_404(String tenantName) {
+ stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackGetTenantById_200(String tenantId) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetTenantById_404(String tenantId) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
+ }
+
+ public static void mockOpenStackDeleteTenantById_200(String tenantId) {
+ stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetUser_200(String user) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackGetRoles_200(String roleFor) {
+ stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockOpenStackPutRolesAdmin_200(String roleFor) {
+ stubFor(put(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/users/msoId/roles/" + roleFor + "/admin")).willReturn(aResponse()
+ .withHeader("Content-Type", "application/json")
+ .withBody("").withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockValetCreatePostResponse_200(String requestId, String body) {
+ stubFor(post(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(body).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockValetCreatePutResponse_200(String requestId, String body) {
+ stubFor(put(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(body).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockValetDeleteDeleteResponse_200(String requestId, String body) {
+ stubFor(delete(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(body).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockValetConfirmPutRequest_200(String requestId, String body) {
+ stubFor(put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/confirm/"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(body).withStatus(HttpStatus.SC_OK)));
+ }
+
+ public static void mockValetRollbackPutRequest_200(String requestId, String body) {
+ stubFor(put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/rollback/"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(body).withStatus(HttpStatus.SC_OK)));
+ }
+
+ private static String getBodyFromFileVnfAdapter(String replaceWith) throws IOException {
+ String temp = readFile("src/test/resources/__files/OpenstackResponse_Stack_Created_VfModule.json");
+ if (replaceWith == null) {
+ return temp;
+ }
+ return temp.replaceAll("CREATE_COMPLETE", replaceWith);
+ }
+
+ private static String readFile(String fileName) throws IOException {
+ try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
+ StringBuilder sb = new StringBuilder();
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ sb.append("\n");
+ line = br.readLine();
+ }
+ return sb.toString();
+ }
+ }
+
+ public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException {
+ return readFile("src/test/resources/__files/" + fileName).replaceAll("port", "http://localhost:" + port + urlPath);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java
new file mode 100644
index 0000000000..b382b6bcf8
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.vdu.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class VduBlueprintTest {
+
+ private VduBlueprint vduBlueprint;
+
+ private Map<String, byte[]> templateFiles;
+ private Map<String, byte[]> attachedFiles;
+
+ @Before
+ public void setUp() {
+ vduBlueprint = new VduBlueprint();
+ }
+
+ @Test
+ public void testGetVduModelId() {
+ vduBlueprint.setVduModelId("vduModelId");
+ Assert.assertNotNull(vduBlueprint.getVduModelId());
+ Assert.assertEquals("vduModelId", vduBlueprint.getVduModelId());
+ }
+
+ @Test
+ public void testGetMainTemplateName() {
+ vduBlueprint.setMainTemplateName("MainTemplateName");
+ Assert.assertNotNull(vduBlueprint.getMainTemplateName());
+ Assert.assertEquals("MainTemplateName", vduBlueprint.getMainTemplateName());
+ }
+
+ @Test
+ public void testGetTemplateFiles() {
+ byte[] templateFileData = "some template file data".getBytes();
+ templateFiles = new HashMap<>();
+ templateFiles.put("templateKey1", templateFileData);
+ vduBlueprint.setTemplateFiles(templateFiles);
+ Assert.assertNotNull(vduBlueprint.getTemplateFiles());
+ Assert.assertTrue(vduBlueprint.getTemplateFiles().containsKey("templateKey1"));
+ Assert.assertTrue(vduBlueprint.getTemplateFiles().containsValue(templateFileData));
+ }
+
+ @Test
+ public void testGetAttachedFiles() {
+ byte[] attachedFileData = "some file data".getBytes();
+ attachedFiles = new HashMap<>();
+ attachedFiles.put("attachedKey1", attachedFileData);
+ vduBlueprint.setAttachedFiles(attachedFiles);
+ Assert.assertNotNull(vduBlueprint.getAttachedFiles());
+ Assert.assertTrue(vduBlueprint.getAttachedFiles().containsKey("attachedKey1"));
+ Assert.assertTrue(vduBlueprint.getAttachedFiles().containsValue(attachedFileData));
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java
new file mode 100644
index 0000000000..6331563362
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 TechMahindra
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.vdu.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class VduInfoTest {
+
+ private VduInfo vduInfo;
+ private VduStatus status = VduStatus.NOTFOUND;
+ private Map<String, Object> outputs;
+ private Map<String, Object> inputs;
+
+ @Before
+ public void setUp() {
+ vduInfo = new VduInfo();
+ }
+
+ @Test
+ public void testGetVnfInstanceId() {
+ String vnfInstanceId = "vnfInstanceId";
+ vduInfo.setVnfInstanceId(vnfInstanceId);
+ Assert.assertNotNull(vduInfo.getVnfInstanceId());
+ Assert.assertEquals("vnfInstanceId", vduInfo.getVnfInstanceId());
+ }
+
+ @Test
+ public void testGetVnfInstanceName() {
+ String vnfInstanceName = "vnfInstanceName";
+ vduInfo.setVnfInstanceName(vnfInstanceName);
+ Assert.assertNotNull(vduInfo.getVnfInstanceName());
+ Assert.assertEquals("vnfInstanceName", vduInfo.getVnfInstanceName());
+ }
+
+ @Test
+ public void testGetStatus() {
+ vduInfo.setStatus(status);
+ Assert.assertNotNull(vduInfo.getStatus());
+ Assert.assertEquals(status, vduInfo.getStatus());
+ }
+
+ @Test
+ public void testGetOutputs() {
+ Object obj = new Object();
+ String str = "some text";
+ outputs = new HashMap<>();
+ outputs.put(str, obj);
+ vduInfo.setOutputs(outputs);
+ Assert.assertNotNull(vduInfo.getOutputs());
+ Assert.assertTrue(vduInfo.getOutputs().containsKey(str));
+ Assert.assertTrue(vduInfo.getOutputs().containsValue(obj));
+ }
+
+ @Test
+ public void testGetInputs() {
+ Object obj = new Object();
+ String str = "some text";
+ inputs = new HashMap<>();
+ inputs.put(str, obj);
+ vduInfo.setInputs(inputs);
+ Assert.assertNotNull(vduInfo.getInputs());
+ Assert.assertTrue(vduInfo.getInputs().containsKey(str));
+ Assert.assertTrue(vduInfo.getInputs().containsValue(obj));
+ }
+
+}