diff options
Diffstat (limited to 'adapters')
10 files changed, 590 insertions, 3 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java index b1911654c4..6c1c81c6ef 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java @@ -65,6 +65,9 @@ public class QueryServiceInfo extends CatalogQuery { @Override public String JSON2(boolean isArray, boolean isEmbed) { + if (serviceInfo == null) { + return "\"serviceInfo\": null"; + } StringBuilder sb = new StringBuilder(); sb.append("\"serviceInfo\": "); sb.append("\n"); @@ -73,8 +76,8 @@ public class QueryServiceInfo extends CatalogQuery { put(valueMap, "ID", null == serviceInfo ? null : serviceInfo.getId()); put(valueMap, "SERVICE_INPUT", null == serviceInfo ? null : serviceInfo.getServiceInput()); put(valueMap, "SERVICE_PROPERTIES", null == serviceInfo ? null : serviceInfo.getServiceProperties()); - // String subitem = new QueryServiceArtifact(service.getServiceArtifactList()).JSON2(true, true); - // valueMap.put("_SERVICEARTIFACT_", subitem.replaceAll("(?m)^", "\t\t"));m + String subitem = new QueryServiceArtifact(service.getServiceArtifactList()).JSON2(true, true); + valueMap.put("_SERVICEARTIFACT_", subitem.replaceAll("(?m)^", "\t\t")); sb.append(this.setTemplate(TEMPLATE, valueMap)); sb.append("}"); return sb.toString(); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java index 0eb7d0418e..d5aa472c8d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java @@ -40,7 +40,7 @@ public class QueryServiceMacroHolder extends CatalogQuery { + "\t\"serviceType\" : <SERVICE_TYPE>,\n" + "\t\"serviceRole\" : <SERVICE_ROLE>,\n" + "\t\"environmentContext\" : <ENVIRONMENT_CONTEXT>,\n" + "\t\"resourceOrder\" : <RESOURCE_ORDER>,\n" + "\t\"workloadContext\" : <WORKLOAD_CONTEXT>,\n" + "<_SERVICEVNFS_>,\n" + "<_SERVICENETWORKS_>,\n" - + "<_SERVICEALLOTTEDRESOURCES_>\n" + "\t}}"; + + "<_SERVICEINFO_>,\n" + "<_SERVICEPROXY_>,\n" + "<_SERVICEALLOTTEDRESOURCES_>\n" + "\t}}"; public QueryServiceMacroHolder() { super(); @@ -94,6 +94,12 @@ public class QueryServiceMacroHolder extends CatalogQuery { subitem = new QueryAllottedResourceCustomization(service.getAllottedCustomizations()).JSON2(true, true); valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t")); + subitem = new QueryServiceInfo(serviceMacroHolder.getServiceInfo()).JSON2(true, true); + valueMap.put("_SERVICEINFO_", subitem.replaceAll(LINE_BEGINNING, "\t")); + + subitem = new QueryServiceProxyCustomization(service.getServiceProxyCustomizations()).JSON2(true, true); + valueMap.put("_SERVICEPROXY_", subitem.replaceAll(LINE_BEGINNING, "\t")); + buf.append(this.setTemplate(TEMPLATE, valueMap)); return buf.toString(); } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java new file mode 100644 index 0000000000..94cf304120 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceProxyCustomization.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (c) 2019, CMCC Technologies Co., Ltd. + * ================================================================================ + * 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.catalogdb.catalogrest; + +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@XmlRootElement(name = "serviceProxyCustomizations") +public class QueryServiceProxyCustomization extends CatalogQuery { + + protected static Logger logger = LoggerFactory.getLogger(QueryServiceProxyCustomization.class); + + private List<ServiceProxyResourceCustomization> serviceProxyResourceCustomizationList; + + private static final String TEMPLATE = + "\t{\n" + "\t\t\"modelInfo\" : {\n" + "\t\t\t\"modelName\" : <MODEL_NAME>,\n" + + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_UUID>,\n" + + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n" + + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n" + + "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n" + "\t},\n" + + "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n" + + "\t\t\"description\" : <DESCRIPTION>,\n" + + "\t\t\"sourceModelUuid\" : <SOURCE_SERVICE_MODEL_UUID>\n" + "\t}"; + + public QueryServiceProxyCustomization() { + super(); + this.serviceProxyResourceCustomizationList = new ArrayList<>(); + } + + public QueryServiceProxyCustomization( + List<ServiceProxyResourceCustomization> serviceProxyResourceCustomizationList) { + this.serviceProxyResourceCustomizationList = serviceProxyResourceCustomizationList; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (ServiceProxyResourceCustomization o : serviceProxyResourceCustomizationList) { + sb.append(i).append("\t"); + if (!first) + sb.append("\n"); + + first = false; + sb.append(o); + } + return sb.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"serviceProxy\": ["); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + if (this.serviceProxyResourceCustomizationList != null) { + for (ServiceProxyResourceCustomization o : serviceProxyResourceCustomizationList) { + if (first) + sb.append("\n"); + + first = false; + + boolean arNull = o == null; + + put(valueMap, "MODEL_CUSTOMIZATION_UUID", arNull ? null : o.getModelCustomizationUUID()); + put(valueMap, "MODEL_INSTANCE_NAME", arNull ? null : o.getModelInstanceName()); + put(valueMap, "MODEL_UUID", arNull ? null : o.getModelUUID()); + put(valueMap, "MODEL_INVARIANT_UUID", arNull ? null : o.getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", arNull ? null : o.getModelVersion()); + put(valueMap, "MODEL_NAME", arNull ? null : o.getModelName()); + put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getToscaNodeType()); + put(valueMap, "DESCRIPTION", arNull ? null : o.getDescription()); + put(valueMap, "SOURCE_SERVICE_MODEL_UUID", (String) (arNull ? null + : o.getSourceService() == null ? null : o.getSourceService().getModelUUID())); + + sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); + sep = ",\n"; + } + } + if (!first) + sb.append("\n"); + + if (isArray) + sb.append("]"); + + if (!isEmbed && isArray) + sb.append("}"); + + return sb.toString(); + } + +} diff --git a/adapters/mso-nssmf-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties b/adapters/mso-nssmf-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties new file mode 100644 index 0000000000..f93ec63f37 --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties @@ -0,0 +1 @@ +org.onap.so.adapters.nssmf.extclients.aai.AaiClientPropertiesImpl
\ No newline at end of file diff --git a/adapters/mso-nssmf-adapter/src/main/resources/application.yaml b/adapters/mso-nssmf-adapter/src/main/resources/application.yaml new file mode 100644 index 0000000000..cb2f04d7ec --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/main/resources/application.yaml @@ -0,0 +1,61 @@ +# +# ============LICENSE_START======================================================= +# ONAP - SO +# ================================================================================ +# Copyright (C) 2020 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========================================================= +#/ +aai: + auth: 2A11B07DB6214A839394AA1EC5844695F5114FC407FF5422625FB00175A3DCB8A1FF745F22867EFA72D5369D599BBD88DA8BED4233CF5586 + endpoint: https://aai.onap:30233 +logging: + path: logs + +spring: + datasource: + driver-class-name: org.mariadb.jdbc.Driver + jdbcUrl: jdbc:mariadb://192.168.235.44:30444/requestdb + username: root + password: secretpassword + + jpa: + show-sql: false + hibernate: + dialect: org.hibernate.dialect.MySQL5Dialect + ddl-auto: validate + naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy + enable-lazy-load-no-trans: true +server: + port: 8080 + tomcat: + max-threads: 50 + +mso: + key: 07a7159d3bf51a0e53be7a8f89699be7 + site-name: localSite + logPath: ./logs/nssmf + msb-ip: msb-iag.{{ include "common.namespace" . }} + msb-port: 80 + adapters: + requestDb: + endpoint: https://so-request-db-adapter.{{ include "common.namespace" . }}:8083 + auth: Basic YnBlbDpwYXNzd29yZDEk + +#Actuator +management: + security: + enabled: false + basic: + enabled: false
\ No newline at end of file diff --git a/adapters/mso-nssmf-adapter/src/main/resources/nssmf.jks b/adapters/mso-nssmf-adapter/src/main/resources/nssmf.jks Binary files differnew file mode 100644 index 0000000000..2ecce5bd3d --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/main/resources/nssmf.jks diff --git a/adapters/mso-nssmf-adapter/src/main/resources/nssmf.p12 b/adapters/mso-nssmf-adapter/src/main/resources/nssmf.p12 Binary files differnew file mode 100644 index 0000000000..25e7fbfca9 --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/main/resources/nssmf.p12 diff --git a/adapters/mso-nssmf-adapter/src/main/resources/org.onap.so.jks b/adapters/mso-nssmf-adapter/src/main/resources/org.onap.so.jks Binary files differnew file mode 100644 index 0000000000..f7cd9e8f86 --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/main/resources/org.onap.so.jks diff --git a/adapters/mso-nssmf-adapter/src/main/resources/org.onap.so.p12 b/adapters/mso-nssmf-adapter/src/main/resources/org.onap.so.p12 Binary files differnew file mode 100644 index 0000000000..1927b1f13f --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/main/resources/org.onap.so.p12 diff --git a/adapters/mso-nssmf-adapter/src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java b/adapters/mso-nssmf-adapter/src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java new file mode 100644 index 0000000000..5bfd39096c --- /dev/null +++ b/adapters/mso-nssmf-adapter/src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java @@ -0,0 +1,392 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 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.nssmf; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.LinkedList; +import java.util.List; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpRequestBase; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.onap.so.adapters.nssmf.model.TokenResponse; +import org.onap.so.adapters.nssmf.rest.HttpMethod; +import org.onap.so.adapters.nssmf.rest.NssmfAdapterRest; +import org.onap.so.adapters.nssmf.rest.NssmfInfo; +import org.onap.so.adapters.nssmf.rest.NssmfManager; +import org.onap.so.adapters.nssmf.rest.RestUtil; +import org.onap.so.beans.nsmf.ActDeActNssi; +import org.onap.so.beans.nsmf.AllocateCnNssi; +import org.onap.so.beans.nsmf.CnSliceProfile; +import org.onap.so.beans.nsmf.DeAllocateNssi; +import org.onap.so.beans.nsmf.EsrInfo; +import org.onap.so.beans.nsmf.JobStatusRequest; +import org.onap.so.beans.nsmf.NsiInfo; +import org.onap.so.beans.nsmf.NssiActDeActRequest; +import org.onap.so.beans.nsmf.NssiAllocateRequest; +import org.onap.so.beans.nsmf.NssiDeAllocateRequest; +import org.onap.so.beans.nsmf.NssiResponse; +import org.onap.so.beans.nsmf.PerfReq; +import org.onap.so.beans.nsmf.PerfReqEmbbList; +import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; +import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal; +import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal; +import static org.onap.so.beans.nsmf.NetworkType.CORE; +import static org.onap.so.beans.nsmf.ResourceSharingLevel.NON_SHARED; + +@RunWith(SpringRunner.class) +public class NssmfAdapterRestTest { + + private final static String ALLOCATE = "{\n" + " \"esrInfo\" : {\n" + " \"vendor\" : \"huawei\",\n" + + " \"networkType\" : \"cn\"\n" + " },\n" + " \"allocateCnNssi\" : {\n" + + " \"nssiId\" : \"NSST-C-001-HDBNJ-NSSMF-01-A-ZX\",\n" + " \"nssiName\" : \"eMBB-001\",\n" + + " \"sliceProfile\" : {\n" + " \"snssaiList\" : [ \"001-100001\" ],\n" + + " \"sliceProfileId\" : \"ab9af40f13f721b5f13539d87484098\",\n" + + " \"plmnIdList\" : [ \"460-00\", \"460-01\" ],\n" + " \"perfReq\" : {\n" + + " \"perfReqEmbbList\" : [ {\n" + " \"activityFactor\" : 50\n" + " } ]\n" + + " },\n" + " \"maxNumberofUEs\" : 200,\n" + + " \"coverageAreaTAList\" : [ \"1\", \"2\", \"3\" ],\n" + " \"latency\" : 6,\n" + + " \"resourceSharingLevel\" : \"non-shared\"\n" + " },\n" + " \"scriptName\" : \"CN1\",\n" + + " \"nsiInfo\" : {\n" + " \"nsiName\" : \"eMBB-001\",\n" + + " \"nsiId\" : \"NSI-M-001-HDBNJ-NSMF-01-A-ZX\"\n" + " }\n" + " }\n" + "}"; + + private NssmfManager nssmfMgr; + + @Mock + private ResourceOperationStatusRepository rscOperStatusRepo; + + @Mock + private RestUtil restUtil; + + @Mock + private NssmfAdapterRest nssmfRest; + + @Mock + private HttpResponse tokenResponse; + + @Mock + private HttpEntity tokenEntity; + + @Mock + private HttpResponse commonResponse; + + @Mock + private HttpEntity commonEntity; + + @Mock + private StatusLine statusLine; + + @Mock + private HttpClient httpClient; + + private InputStream postStream; + + private InputStream tokenStream; + + @Before + public void setUp() { + initMocks(this); + nssmfMgr = new NssmfManager(); + nssmfMgr.setRestUtil(restUtil); + nssmfMgr.setRscOperStatusRepo(rscOperStatusRepo); + } + + private void createCommonMock(int statusCode, NssmfInfo nssmf) throws Exception { + when(nssmfRest.getNssmfMgr()).thenReturn(nssmfMgr); + when(nssmfRest.allocateNssi(any(NssiAllocateRequest.class))).thenCallRealMethod(); + when(nssmfRest.deAllocateNssi(any(NssiDeAllocateRequest.class), any(String.class))).thenCallRealMethod(); + when(nssmfRest.activateNssi(any(NssiActDeActRequest.class), any(String.class))).thenCallRealMethod(); + when(nssmfRest.deactivateNssi(any(NssiActDeActRequest.class), any(String.class))).thenCallRealMethod(); + + when(nssmfRest.queryJobStatus(any(JobStatusRequest.class), any(String.class))).thenCallRealMethod(); + when(restUtil.sendRequest(any(String.class), any(HttpMethod.class), any(String.class), any(EsrInfo.class))) + .thenCallRealMethod(); + when(restUtil.getHttpsClient()).thenReturn(httpClient); + + when(statusLine.getStatusCode()).thenReturn(200); + when(restUtil.getNssmfHost(any(EsrInfo.class))).thenReturn(nssmf); + + when(tokenResponse.getEntity()).thenReturn(tokenEntity); + when(tokenResponse.getStatusLine()).thenReturn(statusLine); + when(tokenEntity.getContent()).thenReturn(tokenStream); + + when(commonResponse.getEntity()).thenReturn(commonEntity); + when(commonResponse.getStatusLine()).thenReturn(statusLine); + when(commonEntity.getContent()).thenReturn(postStream); + + Answer<HttpResponse> answer = new Answer<HttpResponse>() { + + public HttpResponse answer(InvocationOnMock invocation) throws Throwable { + Object[] arguments = invocation.getArguments(); + if (arguments != null && arguments.length == 1 && arguments[0] != null) { + + HttpRequestBase base = (HttpRequestBase) arguments[0]; + if (base.getURI().toString().endsWith("/oauth/token")) { + return tokenResponse; + } else { + return commonResponse; + } + } + return commonResponse; + } + }; + doAnswer(answer).when(httpClient).execute(any(HttpRequestBase.class)); + } + + @Test + public void testNssiAllocate() throws Exception { + NssmfInfo nssmf = new NssmfInfo(); + nssmf.setUserName("nssmf-user"); + nssmf.setPassword("nssmf-pass"); + nssmf.setPort("8080"); + nssmf.setIpAddress("127.0.0.1"); + + NssiResponse nssiRes = new NssiResponse(); + nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067"); + nssiRes.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + + TokenResponse token = new TokenResponse(); + token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39"); + token.setExpires(1800); + + postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8)); + tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8)); + + createCommonMock(200, nssmf); + // assertEquals(prettyPrint(allocateNssi()), ALLOCATE); + ResponseEntity res = nssmfRest.allocateNssi(allocateNssi()); + assertNotNull(res); + assertNotNull(res.getBody()); + NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class); + assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067"); + assertEquals(allRes.getNssiId(), "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + } + + @Test + public void testNssiDeAllocate() throws Exception { + NssmfInfo nssmf = new NssmfInfo(); + nssmf.setUserName("nssmf-user"); + nssmf.setPassword("nssmf-pass"); + nssmf.setPort("8080"); + nssmf.setIpAddress("127.0.0.1"); + + NssiResponse nssiRes = new NssiResponse(); + nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067"); + + TokenResponse token = new TokenResponse(); + token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39"); + token.setExpires(1800); + + postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8)); + tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8)); + + createCommonMock(200, nssmf); + ResponseEntity res = nssmfRest.deAllocateNssi(deAllocateNssi(), "ab9af40f13f721b5f13539d87484098"); + assertNotNull(res); + assertNotNull(res.getBody()); + NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class); + assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067"); + } + + @Test + public void testNssiActivate() throws Exception { + NssmfInfo nssmf = new NssmfInfo(); + nssmf.setUserName("nssmf-user"); + nssmf.setPassword("nssmf-pass"); + nssmf.setPort("8080"); + nssmf.setIpAddress("127.0.0.1"); + + NssiResponse nssiRes = new NssiResponse(); + nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067"); + + TokenResponse token = new TokenResponse(); + token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39"); + token.setExpires(1800); + + postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8)); + tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8)); + + createCommonMock(200, nssmf); + ResponseEntity res = nssmfRest.activateNssi(activateNssi(), "001-100001"); + assertNotNull(res); + assertNotNull(res.getBody()); + NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class); + assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067"); + } + + @Test + public void testNssiDeActivate() throws Exception { + NssmfInfo nssmf = new NssmfInfo(); + nssmf.setUserName("nssmf-user"); + nssmf.setPassword("nssmf-pass"); + nssmf.setPort("8080"); + nssmf.setIpAddress("127.0.0.1"); + + NssiResponse nssiRes = new NssiResponse(); + nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067"); + + TokenResponse token = new TokenResponse(); + token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39"); + token.setExpires(1800); + + postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8)); + tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8)); + + createCommonMock(200, nssmf); + ResponseEntity res = nssmfRest.deactivateNssi(deActivateNssi(), "001-100001"); + assertNotNull(res); + assertNotNull(res.getBody()); + NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class); + assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067"); + } + + @Test + public void testAllocateJsonSerDeSer() throws Exception { + assertEquals(marshal(allocateNssi()), ALLOCATE); + NssiAllocateRequest all = unMarshal(ALLOCATE, NssiAllocateRequest.class); + assertNotNull(all); + assertNotNull(all.getAllocateCnNssi()); + assertNotNull(all.getAllocateCnNssi().getSliceProfile()); + assertEquals(all.getAllocateCnNssi().getSliceProfile().getResourceSharingLevel(), NON_SHARED); + assertNotNull(all.getAllocateCnNssi().getSliceProfile().getPerfReq()); + assertNotNull(all.getAllocateCnNssi().getSliceProfile().getPerfReq().getPerfReqEmbbList()); + PerfReqEmbbList embb = + all.getAllocateCnNssi().getSliceProfile().getPerfReq().getPerfReqEmbbList().iterator().next(); + assertNotNull(embb); + assertEquals(embb.getActivityFactor(), 50); + } + + public NssiAllocateRequest allocateNssi() throws Exception { + CnSliceProfile sP = new CnSliceProfile(); + List<String> sns = new LinkedList<>(); + sns.add("001-100001"); + List<String> plmn = new LinkedList<>(); + plmn.add("460-00"); + plmn.add("460-01"); + PerfReqEmbbList embb = new PerfReqEmbbList(); + embb.setActivityFactor(50); + List<PerfReqEmbbList> embbList = new LinkedList<>(); + embbList.add(embb); + PerfReq perfReq = new PerfReq(); + perfReq.setPerfReqEmbbList(embbList); + List<String> taList = new LinkedList<>(); + taList.add("1"); + taList.add("2"); + taList.add("3"); + sP.setSnssaiList(sns); + sP.setSliceProfileId("ab9af40f13f721b5f13539d87484098"); + sP.setPlmnIdList(plmn); + sP.setPerfReq(perfReq); + sP.setMaxNumberofUEs(200); + sP.setCoverageAreaTAList(taList); + sP.setLatency(6); + sP.setResourceSharingLevel(NON_SHARED); + NsiInfo nsiInfo = new NsiInfo(); + nsiInfo.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX"); + nsiInfo.setNsiName("eMBB-001"); + AllocateCnNssi cnNssi = new AllocateCnNssi(); + cnNssi.setNssiId("NSST-C-001-HDBNJ-NSSMF-01-A-ZX"); + cnNssi.setNssiName("eMBB-001"); + cnNssi.setScriptName("CN1"); + cnNssi.setSliceProfile(sP); + cnNssi.setNsiInfo(nsiInfo); + EsrInfo esrInfo = new EsrInfo(); + esrInfo.setVendor("huawei"); + esrInfo.setNetworkType(CORE); + NssiAllocateRequest allocate = new NssiAllocateRequest(); + allocate.setAllocateCnNssi(cnNssi); + allocate.setEsrInfo(esrInfo); + return allocate; + } + + public NssiDeAllocateRequest deAllocateNssi() throws Exception { + DeAllocateNssi deAllocateNssi = new DeAllocateNssi(); + deAllocateNssi.setTerminateNssiOption(0); + List<String> snssai = new LinkedList<>(); + snssai.add("001-100001"); + deAllocateNssi.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX"); + deAllocateNssi.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + deAllocateNssi.setScriptName("CN1"); + deAllocateNssi.setSnssaiList(snssai); + EsrInfo esrInfo = new EsrInfo(); + esrInfo.setVendor("huawei"); + esrInfo.setNetworkType(CORE); + NssiDeAllocateRequest deAllocate = new NssiDeAllocateRequest(); + deAllocate.setDeAllocateNssi(deAllocateNssi); + deAllocate.setEsrInfo(esrInfo); + return deAllocate; + } + + public NssiActDeActRequest activateNssi() throws Exception { + EsrInfo esrInfo = new EsrInfo(); + esrInfo.setVendor("huawei"); + esrInfo.setNetworkType(CORE); + ActDeActNssi act = new ActDeActNssi(); + act.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX"); + act.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + NssiActDeActRequest actReq = new NssiActDeActRequest(); + actReq.setActDeActNssi(act); + actReq.setEsrInfo(esrInfo); + return actReq; + } + + public NssiActDeActRequest deActivateNssi() throws Exception { + EsrInfo esrInfo = new EsrInfo(); + esrInfo.setVendor("huawei"); + esrInfo.setNetworkType(CORE); + ActDeActNssi deAct = new ActDeActNssi(); + deAct.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX"); + deAct.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + NssiActDeActRequest deActReq = new NssiActDeActRequest(); + deActReq.setActDeActNssi(deAct); + deActReq.setEsrInfo(esrInfo); + return deActReq; + } + + public String queryJobStatusNssi() throws Exception { + EsrInfo esrInfo = new EsrInfo(); + esrInfo.setVendor("huawei"); + esrInfo.setNetworkType(CORE); + + JobStatusRequest jobStatus = new JobStatusRequest(); + jobStatus.setEsrInfo(esrInfo); + jobStatus.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX"); + jobStatus.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + return marshal(jobStatus); + } +} |