summaryrefslogtreecommitdiffstats
path: root/ms/neng/src/test/java
diff options
context:
space:
mode:
authorBT2983 <BT2983@att.com>2018-07-23 23:51:20 -0600
committerBT2983 <BT2983@att.com>2018-07-23 23:51:20 -0600
commitf5da5198e43addc77989dee8b500cb69e9885f93 (patch)
treed68226f2b418787e012bd044f57dea60b1b2a331 /ms/neng/src/test/java
parent3437d0aa56f7c0630cbd1b9074579f7e0f8a44ae (diff)
Adding naming micro-service code - more tests.
Integration tests and more unit tests. Change-Id: Id3500085a43ff817d04d8f407e5cdbc4271dfb35 Issue-ID: CCSDK-342 Signed-off-by: BT2983 <BT2983@att.com>
Diffstat (limited to 'ms/neng/src/test/java')
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyParametersImplTest.java66
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtilsTest.java38
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReaderTest.java44
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java101
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/RecipeParserTest.java60
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/AaiAuthorizationInterceptorTest.java90
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/PolicyManagerAuthorizationInterceptorTest.java87
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/seq/TestSequenceGenerator.java85
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/HelloTest.java53
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java221
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java108
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/TestApplicationConfig.java58
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java200
13 files changed, 1211 insertions, 0 deletions
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyParametersImplTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyParametersImplTest.java
new file mode 100644
index 00000000..e897e4fe
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyParametersImplTest.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.policy;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+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.ccsdk.apps.ms.neng.persistence.entity.IdentifierMap;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.ServiceParameter;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.IdentifierMapRespository;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PolicyParametersImplTest {
+ @Mock
+ IdentifierMapRespository identifierMapRepository;
+ @Mock
+ ServiceParameterRepository serviceParameterRepository;
+ @Mock
+ IdentifierMap identifierMap;
+ @InjectMocks
+ PolicyParametersImpl policyParametersImpl;
+ @Mock
+ ServiceParameter sp;
+
+ static final String RECIPE_SEPERATOR_PARAM = "recipe_separator";
+ static final String MAX_GEN_ATTEMPT_PARAM = "max_gen_attempt";
+
+ @Test
+ public void policyParameterTest() throws Exception {
+ Mockito.when(serviceParameterRepository.findByName(RECIPE_SEPERATOR_PARAM)).thenReturn(sp);
+ Mockito.when(sp.getValue()).thenReturn("value");
+ assertEquals("value", policyParametersImpl.getRecipeSeparator());
+
+ Mockito.when(identifierMapRepository.findByPolicyFnName("name")).thenReturn(identifierMap);
+ Mockito.when(identifierMap.getJsFnName()).thenReturn("jsFnName");
+ assertEquals("jsFnName", policyParametersImpl.mapFunction("name"));
+
+ Mockito.when(sp.getValue()).thenReturn("1");
+ Mockito.when(serviceParameterRepository.findByName(MAX_GEN_ATTEMPT_PARAM)).thenReturn(sp);
+ assertEquals(1, policyParametersImpl.getMaxGenAttempt());
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtilsTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtilsTest.java
new file mode 100644
index 00000000..f527b38b
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtilsTest.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.policy;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class PolicyPropertyMethodUtilsTest {
+
+ @Test
+ public void testAll() {
+ assertEquals("TRLAK", PolicyPropertyMethodUtils.substring("TRLAKDG", "5"));
+ assertEquals("KDG", PolicyPropertyMethodUtils.substring("TRLAKDG", "-3"));
+ assertEquals("TRLAKDG", PolicyPropertyMethodUtils.substring("TRLAKDG", "8"));
+ assertEquals("TRLAKDG", PolicyPropertyMethodUtils.substring("TRLAKDG", "-11"));
+ assertEquals("XYSZ1NNN", PolicyPropertyMethodUtils.toUpperCase("XySz1NNN"));
+ assertEquals("xysz1nnn", PolicyPropertyMethodUtils.toLowerCase("XySz1NNN"));
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReaderTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReaderTest.java
new file mode 100644
index 00000000..30fc6e45
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReaderTest.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.policy;
+
+import static org.junit.Assert.assertEquals;
+import static org.onap.ccsdk.apps.ms.neng.core.policy.PolicyReader.namingModels;
+
+import java.util.Map;
+import org.junit.Test;
+
+public class PolicyReaderTest {
+ @Test
+ public void getPolicyFromFile() throws Exception {
+ Map<String, Object> policy = new FilePolicyReader("sample_policy.json").getPolicy();
+ assertEquals("VNF", namingModels(policy).get(0).get("naming-type"));
+ assertEquals("COMPLEX|SEQUENCE|NF_NAMING_CODE", namingModels(policy).get(0).get("naming-recipe"));
+ }
+
+ @Test
+ public void relaxedNamingType() throws Exception {
+ assertEquals("VNF", PolicyReader.relaxedNamingType("VNF_NAME"));
+ assertEquals("VNF", PolicyReader.relaxedNamingType("VNF-NAME"));
+ assertEquals("VNF", PolicyReader.relaxedNamingType("vnf-name"));
+ assertEquals("VNF", PolicyReader.relaxedNamingType("vnf_name"));
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java
new file mode 100644
index 00000000..9d6c3f92
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java
@@ -0,0 +1,101 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.policy;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PropertyOperatorTest {
+ @Mock
+ private PolicyParameters params = mock(PolicyParameters.class);
+
+ @Test
+ public void operationFunction() throws Exception {
+ assertEquals(null, PropertyOperator.operationFunction(""));
+ assertEquals(null, PropertyOperator.operationFunction(" "));
+
+ assertEquals(null, PropertyOperator.operationFunction(" (("));
+
+ assertEquals("to_lower_case", PropertyOperator.operationFunction("to_lower_case()"));
+ assertEquals("to_lower_case", PropertyOperator.operationFunction(" to_lower_case() "));
+
+ assertEquals("sub_str", PropertyOperator.operationFunction("sub_str(0,5)"));
+ assertEquals("sub_str", PropertyOperator.operationFunction("\tsub_str(0,5)"));
+ }
+
+ @Test
+ public void camelConverted() throws Exception {
+ assertEquals("", PropertyOperator.camelConverted(""));
+
+ assertEquals("toLowerCase", PropertyOperator.camelConverted("to_lower_case"));
+ }
+
+ @Test
+ public void applyToLowerCase() throws Exception {
+ Map<String, String> props = new HashMap<>();
+ props.put("property-operation", "to_lower_case()");
+ PropertyOperator op = new PropertyOperator();
+ assertEquals("asdf", op.apply("ASDF", props, params));
+ }
+
+ @Test
+ public void applyToUpperCase() throws Exception {
+ Map<String, String> props = new HashMap<>();
+ props.put("property-operation", "to_upper_case()");
+ PropertyOperator op = new PropertyOperator();
+ assertEquals("ASDF", op.apply("asdf", props, params));
+ }
+
+ @Test
+ public void applySubstr() throws Exception {
+ when(params.mapFunction("sub_str")).thenReturn("substring");
+ PropertyOperator op = new PropertyOperator();
+
+ Map<String, String> props = new HashMap<>();
+
+ props.put("property-operation", "sub_str(0,5)");
+ assertEquals("01234", op.apply("0123456789", props, params));
+
+ props.put("property-operation", " sub_str(0,4)");
+ assertEquals("0123", op.apply("0123456789", props, params));
+
+ props.put("property-operation", "sub_str(1,5)");
+ assertEquals("1234", op.apply("0123456789", props, params));
+
+ props.put("property-operation", "sub_str(1)");
+ assertEquals("0", op.apply("0", props, params));
+
+ props.put("property-operation", "sub_str(-2)");
+ assertEquals("89", op.apply("0123456789", props, params));
+
+ props.put("property-operation", "sub_str(-3)");
+ assertEquals("789", op.apply("0123456789", props, params));
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/RecipeParserTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/RecipeParserTest.java
new file mode 100644
index 00000000..744d967d
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/RecipeParserTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.policy;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RecipeParserTest {
+ @Mock
+ private PolicyParameters params = mock(PolicyParameters.class);
+
+ @Test
+ public void parseRecipe() throws Exception {
+ assertEquals(0, RecipeParser.parseRecipe(params, "").size());
+ assertEquals("[]", RecipeParser.parseRecipe(params, "").toString());
+
+ assertEquals(1, RecipeParser.parseRecipe(params, "a").size());
+ assertEquals("[a]", RecipeParser.parseRecipe(params, "a").toString());
+
+ assertEquals(2, RecipeParser.parseRecipe(params, "a,b").size());
+ assertEquals(2, RecipeParser.parseRecipe(params, "a|b").size());
+ assertEquals(2, RecipeParser.parseRecipe(params, "a:b").size());
+
+ assertEquals("[a, b]", RecipeParser.parseRecipe(params, "a,b").toString());
+ assertEquals("[a, b]", RecipeParser.parseRecipe(params, "a|b").toString());
+ assertEquals("[a, b]", RecipeParser.parseRecipe(params, "a:b").toString());
+
+ assertEquals(3, RecipeParser.parseRecipe(params, "a,b,c").size());
+ assertEquals(3, RecipeParser.parseRecipe(params, "a|b|c").size());
+ assertEquals(3, RecipeParser.parseRecipe(params, "a:b:c").size());
+
+ assertEquals("[a, b, c]", RecipeParser.parseRecipe(params, "a,b,c").toString());
+ assertEquals("[a, b, c]", RecipeParser.parseRecipe(params, "a|b|c").toString());
+ assertEquals("[a, b, c]", RecipeParser.parseRecipe(params, "a:b:c").toString());
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/AaiAuthorizationInterceptorTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/AaiAuthorizationInterceptorTest.java
new file mode 100644
index 00000000..40e507ea
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/AaiAuthorizationInterceptorTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.rs.interceptors;
+
+import static org.junit.Assert.assertNotNull;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
+
+import java.net.URI;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.GetConfigRequest;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.GetConfigResponse;
+import org.onap.ccsdk.apps.ms.neng.extinf.props.AaiProps;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.web.client.ExpectedCount;
+import org.springframework.test.web.client.MockRestServiceServer;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiAuthorizationInterceptorTest {
+ MockRestServiceServer mockServer;
+ RestTemplate restTemplate;
+ String aaiHostName = "http://0.0.0.1:8080/";
+ String aaiPath = "services/service/networkInfrastructureResourcesSample/v1";
+
+ @InjectMocks
+ AaiAuthorizationInterceptor aaiAuthorizationInterceptor;
+ @Spy
+ AaiProps props = new AaiProps();
+
+ /**
+ * Does the setup.
+ */
+ @Before
+ public void setUp() {
+ if (restTemplate == null) {
+ restTemplate = new RestTemplate();
+ }
+ props.setAccept("application/json");
+ props.setCert("c:/certs");
+ props.setCertPassword("password");
+ props.setFromAppId("namegen-ms");
+ props.setUriBase("https://localhost:8080/aai/v13/");
+ props.setTransactionId("X12345YV");
+ restTemplate.getInterceptors().add(aaiAuthorizationInterceptor);
+ mockServer = MockRestServiceServer.bindTo(restTemplate).build();
+ }
+
+ @Test
+ public void testAuth() throws Exception {
+
+ mockServer.expect(ExpectedCount.once(), requestTo(aaiHostName + aaiPath)).andExpect(method(HttpMethod.POST))
+ .andExpect(header("x-FromAppId", new String[] {"namegen-ms"}))
+ .andRespond(withSuccess("", MediaType.APPLICATION_JSON));
+ GetConfigRequest req = new GetConfigRequest();
+ RequestEntity<GetConfigRequest> re = RequestEntity.post(new URI(aaiHostName + aaiPath))
+ .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).body(req);
+ ResponseEntity<GetConfigResponse> resp = restTemplate.exchange(re, GetConfigResponse.class);
+ mockServer.verify();
+ assertNotNull(resp);
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/PolicyManagerAuthorizationInterceptorTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/PolicyManagerAuthorizationInterceptorTest.java
new file mode 100644
index 00000000..d814c253
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/rs/interceptors/PolicyManagerAuthorizationInterceptorTest.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.rs.interceptors;
+
+import static org.junit.Assert.assertNotNull;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
+
+import java.net.URI;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.GetConfigRequest;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.GetConfigResponse;
+import org.onap.ccsdk.apps.ms.neng.extinf.props.PolicyManagerProps;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.web.client.ExpectedCount;
+import org.springframework.test.web.client.MockRestServiceServer;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PolicyManagerAuthorizationInterceptorTest {
+ MockRestServiceServer mockServer;
+ RestTemplate restTemplate;
+ String policyManagerHostname = "http://0.0.0.1:8080/";
+ String policyManagerResPath = "services/service/networkInfrastructureResourcesSample/v1";
+ @InjectMocks
+ PolicyManagerAuthorizationInterceptor policyManagerInterceptor;
+ @Spy
+ PolicyManagerProps props = new PolicyManagerProps();
+
+ /**
+ * Does the setup for tests.
+ */
+ @Before
+ public void setUp() {
+ if (restTemplate == null) {
+ restTemplate = new RestTemplate();
+ }
+ props.setBasicAuth("Basic bnVsbDpudWxs");
+ props.setClientAuth("Basic bnVsbDpudWxs");
+ props.setEcompRequestId("xxuv");
+ props.setEnvironment("TEST");
+ restTemplate.getInterceptors().add(policyManagerInterceptor);
+ mockServer = MockRestServiceServer.bindTo(restTemplate).build();
+ }
+
+ @Test
+ public void testAuth() throws Exception {
+ mockServer.expect(ExpectedCount.once(), requestTo(policyManagerHostname + policyManagerResPath))
+ .andExpect(method(HttpMethod.POST))
+ .andExpect(header("Authorization", new String[] {"Basic bnVsbDpudWxs"}))
+ .andRespond(withSuccess("", MediaType.APPLICATION_JSON));
+ GetConfigRequest req = new GetConfigRequest();
+ RequestEntity<GetConfigRequest> re = RequestEntity.post(new URI(policyManagerHostname + policyManagerResPath))
+ .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).body(req);
+ ResponseEntity<GetConfigResponse> resp = restTemplate.exchange(re, GetConfigResponse.class);
+ mockServer.verify();
+ assertNotNull(resp);
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/seq/TestSequenceGenerator.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/seq/TestSequenceGenerator.java
new file mode 100644
index 00000000..fcee4da0
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/seq/TestSequenceGenerator.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.seq;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+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.ccsdk.apps.ms.neng.core.policy.PolicySequence;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.ServiceParameter;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.GeneratedNameRespository;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestSequenceGenerator {
+ @Mock
+ private GeneratedNameRespository genNameRepo = mock(GeneratedNameRespository.class);
+ @Mock
+ private ServiceParameterRepository servParamRepo = mock(ServiceParameterRepository.class);
+ @Mock
+ private PolicySequence params = mock(PolicySequence.class);
+ @Mock
+ private ServiceParameter sp = mock(ServiceParameter.class);
+ @InjectMocks
+ SequenceGenerator sg;
+
+ @Test
+ public void testGenerate() throws Exception {
+ assertEquals(0, sg.generate("zSSRX1234", null, params, null, 1));
+
+ Mockito.when(params.getLastReleaseSeqNumTried()).thenReturn(null);
+ Mockito.when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn("4");
+
+ assertEquals(0, sg.generate("zSSRX1234", null, params, null, 1));
+
+ Mockito.when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn("2");
+ Mockito.when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn(null);
+ Mockito.when(servParamRepo.findByName("initial_increment")).thenReturn(sp);
+ Mockito.when(sp.getValue()).thenReturn("1");
+
+ assertEquals(0, sg.generate("zSSRX1234", null, params, 1L, 2));
+
+ Mockito.when(genNameRepo.findNextReleasedSeq(0L, "zSSRX1234", null)).thenReturn(null);
+ assertEquals(0, sg.generate("zSSRX1234", null, params, null, 1));
+ }
+
+ @Test(expected = Exception.class)
+ public void exceltionTest() throws Exception {
+ Mockito.when(genNameRepo.findNextReleasedSeq(1L, "zSSRX1234", null)).thenReturn(null);
+ Mockito.when(params.getLastReleaseSeqNumTried()).thenReturn(1L);
+ sg.generate("zSSRX1234", null, params, null, 1);
+ }
+
+ @Test
+ public void testAlreadyUsedSequesnce() throws Exception {
+ Mockito.when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn("1");
+ Mockito.when(sp.getValue()).thenReturn("4");
+ Mockito.when(params.getIncrement()).thenReturn(2L);
+ assertEquals(0L, sg.generate("zSSRX1234", null, params, 2L, 0));
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/HelloTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/HelloTest.java
new file mode 100644
index 00000000..1c5fa81f
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/HelloTest.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.service;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.ccsdk.apps.ms.neng.core.service.rs.RestService;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.GeneratedNameRespository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@EnableAutoConfiguration
+@WebAppConfiguration
+@SpringBootTest
+@ActiveProfiles("test")
+public class HelloTest {
+ @Autowired
+ RestService service;
+ @Autowired
+ GeneratedNameRespository repo;
+
+ @Test
+ public void testQuickHello() throws Exception {
+ Response response = service.getQuickHello("test");
+ assertEquals("message = Hello test!", response.getEntity().toString());
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java
new file mode 100644
index 00000000..a1873692
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java
@@ -0,0 +1,221 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.service;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.when;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
+import org.onap.ccsdk.apps.ms.neng.core.persistence.NamePersister;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenRequest;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenResponse;
+import org.onap.ccsdk.apps.ms.neng.core.service.rs.RestServiceImpl;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.GeneratedName;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.PolicyDetails;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.PolicyDetailsRepository;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
+import org.onap.ccsdk.apps.ms.neng.service.extinf.impl.AaiServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.boot.test.mock.mockito.SpyBean;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@DataJpaTest
+@ActiveProfiles("test")
+public class SpringServiceIntTest {
+ @Autowired
+ TestEntityManager entityManager;
+ @SpyBean
+ SpringService springService;
+ @Autowired
+ NamePersister namePersister;
+ @Autowired
+ @Qualifier("policyMgrRestTempBuilder")
+ RestTemplateBuilder policyMgrRestTempBuilder;
+ @Mock
+ RestTemplate restTemplate;
+ @Autowired
+ PolicyDetailsRepository policyDetailsRepo;
+ @Autowired
+ ServiceParameterRepository serviceParamRepo;
+ @Autowired
+ AaiServiceImpl aaiServiceImpl;
+ @Autowired
+ RestServiceImpl restServiceImpl;
+
+ @Before
+ public void setup() {
+ doReturn(restTemplate).when(policyMgrRestTempBuilder).build();
+ }
+
+ @Test
+ public void testObjects() {
+ assertNotNull(entityManager);
+ assertNotNull(namePersister);
+ assertNotNull(springService);
+ }
+
+ @Test
+ public void testNamePersiser() throws Exception {
+ GeneratedName name = new GeneratedName();
+ name.setName("abcd6ytx");
+ name.setPrefix("dlpv");
+ name.setSuffix("ytx");
+ name.setSequenceNumber(006L);
+ name.setElementType("VNF");
+ name.setGeneratedNameId(1000);
+ name.setExternalId("EXT-11");
+
+ namePersister.persist(name);
+ name = namePersister.findBy("VNF", "abcd6ytx", null);
+ assertNotNull(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGenName_1() throws Exception {
+ ResponseEntity<Object> resp = new ResponseEntity<Object>(
+ getConfigResponse("JQINSRIOV.Config_MS_SriovBigJson.1.xml"), HttpStatus.OK);
+ when(restTemplate.exchange(Matchers.any(RequestEntity.class), Matchers.any(Class.class))).thenReturn(resp);
+ when(aaiServiceImpl.validate(Matchers.anyString(), Matchers.anyString())).thenReturn(true);
+ NameGenRequest request = nameGenRequest_1();
+ NameGenResponse genresp = springService.genNetworkElementName(request);
+ assertTrue("vnf-name".equals(genresp.getElements().get(0).get("resource-name")));
+ }
+
+ NameGenRequest nameGenRequest_1() {
+ Map<String, String> vnfMap = new HashMap<>();
+ vnfMap.put("external-key", "VQA-UN8");
+ vnfMap.put("policy-instance-name", "JQINSRIOV.Config_MS_SriovBigJson.1.xml");
+ vnfMap.put("complex", "vnfunfc");
+ vnfMap.put("NF_NAMING_CODE", "xyFg12");
+ vnfMap.put("resource-name", "vnf-name");
+ vnfMap.put("naming-type", "VNF");
+ vnfMap.put("nf-role", "vPE");
+
+ List<Map<String, String>> elements = new ArrayList<>();
+ elements.add(vnfMap);
+ NameGenRequest request = new NameGenRequest();
+ request.setElements(elements);
+
+ return request;
+ }
+
+ NameGenRequest nameGenRequestRelease() {
+ NameGenRequest request = new NameGenRequest();
+ Map<String, String> vnfMap = new HashMap<>();
+ vnfMap.put("external-key", "VQA-UN8");
+ List<Map<String, String>> elements = new ArrayList<>();
+ elements.add(vnfMap);
+ request.setElements(elements);
+
+ return request;
+ }
+
+ Object getConfigResponse(String policyName) throws Exception {
+ ObjectMapper objectmapper = new ObjectMapper();
+ objectmapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
+ PolicyDetails policyDetails = policyDetailsRepo.findPolicyResponseByName(policyName);
+ List<Map<Object, Object>> respObj = objectmapper.readValue(policyDetails.getPolicyResponse(),
+ new TypeReference<List<Map<Object, Object>>>() {});
+ return respObj;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testRestGenerateNetworkElementName() throws Exception {
+ NameGenRequest request = nameGenRequest_1();
+ ResponseEntity<Object> resp = new ResponseEntity<Object>(
+ getConfigResponse("JQINSRIOV.Config_MS_SriovBigJson.1.xml"), HttpStatus.OK);
+ when(restTemplate.exchange(Matchers.any(RequestEntity.class), Matchers.any(Class.class))).thenReturn(resp);
+ when(aaiServiceImpl.validate(Matchers.anyString(), Matchers.anyString())).thenReturn(true);
+ restServiceImpl.generateNetworkElementName(request);
+ }
+
+ @Test
+ public void testRestGenerateNetworkElementName_exp() throws Exception {
+ NameGenRequest request = nameGenRequest_1();
+ doThrow(new NengException("")).when(springService).genNetworkElementName(request);
+ restServiceImpl.generateNetworkElementName(request);
+ }
+
+ @Test
+ public void testRestReleaseNetworkElementName() throws Exception {
+ NameGenRequest request = nameGenRequestRelease();
+ restServiceImpl.releaseNetworkElementName(request);
+ }
+
+ @Test
+ public void testRestReleaseNetworkElementName_exp() throws Exception {
+ NameGenRequest request = nameGenRequestRelease();
+ doThrow(new NengException("")).when(springService).releaseNetworkElementName(request);
+ restServiceImpl.releaseNetworkElementName(request);
+ }
+
+ @Test
+ public void testRestGetPolicyResponse() throws Exception {
+ List<Map<String, Object>> policyResponse =
+ restServiceImpl.getPolicyResponse("JQINSRIOV.Config_MS_SriovBigJson.1.xml");
+ assertNotNull(policyResponse);
+ }
+
+ @Test
+ public void testRestAddPolicyToDb() throws Exception {
+ Map<String, Object> policy = new HashMap<>();
+ policy.put("policyName", "policyname");
+ policy.put("policyValue", "policyname");
+ restServiceImpl.addPolicyToDb(policy);
+ }
+
+ @Test
+ public void testRestAddPolicyToDB_exp() throws Exception {
+ Map<String, Object> policy = new HashMap<>();
+ policy.put("policyName", "policyname");
+ policy.put("policyValue", "policyname");
+
+ doThrow(new NengException("")).when(springService).addPolicy(policy);
+ restServiceImpl.addPolicyToDb(policy);
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java
new file mode 100644
index 00000000..303692c5
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+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.ccsdk.apps.ms.neng.core.resource.model.NameGenRequest;
+import org.onap.ccsdk.apps.ms.neng.core.validator.ExternalKeyValidator;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.GeneratedName;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.PolicyDetails;
+import org.onap.ccsdk.apps.ms.neng.persistence.entity.ServiceParameter;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.GeneratedNameRespository;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.PolicyDetailsRepository;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SpringServiceTest {
+
+ @Mock
+ ExternalKeyValidator externalKeyValidator;
+ @Mock
+ ServiceParameter param;
+ @Mock
+ ServiceParameterRepository serviceParamRepo;
+ @Mock
+ PolicyDetails policyDetails;
+ @Mock
+ PolicyDetailsRepository policyDetailsRepository;
+ @Mock
+ GeneratedNameRespository generatedNameRepository;
+
+ @InjectMocks
+ SpringServiceImpl springserviceImpl;
+
+ Map<String, String> req = new HashMap<>();
+ List<Map<String, String>> rsp = new ArrayList<>();
+ NameGenRequest request = new NameGenRequest();
+
+ {
+ req.put("external-key", "Xyx-zzk");
+ req.put("policy-instance-name", "testDbPolicy66");
+ req.put("COMPLEX", "TRLAKDG");
+ req.put("NFC-NAMING-CODE", "ESP");
+ req.put("CLOUD_REGION_ID", "SSR");
+ req.put("NF_CODE", "X1234");
+ req.put("resource-name", "vm-name");
+ req.put("naming-type", "VM");
+ req.put("nf-role", "vPE");
+ rsp.add(req);
+ request.setElements(rsp);
+ }
+
+ @Test(expected = Exception.class)
+ public void genNetworkElementNameTest() throws Exception {
+ Mockito.when(externalKeyValidator.isPresent(req.get("external-key"))).thenReturn(false);
+ Mockito.when(serviceParamRepo.findByName("use_db_policy")).thenReturn(param);
+ springserviceImpl.genNetworkElementName(request);
+
+ }
+
+ @Test
+ public void getPolicyDetailsTest() {
+ Mockito.when(policyDetailsRepository.findPolicyResponseByName("testDbPolicy66")).thenReturn(policyDetails);
+ org.junit.Assert.assertNotNull(springserviceImpl.getPolicyDetails("testDbPolicy66"));
+ }
+
+ @Test
+ public void addPolicy() throws Exception {
+ springserviceImpl.addPolicy(req);
+ }
+
+ @Test
+ public void releaseNetworkElementNameTest() throws Exception {
+ GeneratedName gn = new GeneratedName();
+ List<GeneratedName> generatedNameList = new ArrayList<>();
+ generatedNameList.add(gn);
+
+ Mockito.when(generatedNameRepository.findByExternalId(req.get("external-key"))).thenReturn(generatedNameList);
+ Assert.assertNotNull(springserviceImpl.releaseNetworkElementName(request));
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/TestApplicationConfig.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/TestApplicationConfig.java
new file mode 100644
index 00000000..5e30bac9
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/TestApplicationConfig.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.core.service;
+
+import static org.mockito.Mockito.spy;
+
+import org.mockito.Mockito;
+import org.onap.ccsdk.apps.ms.neng.core.rs.interceptors.PolicyManagerAuthorizationInterceptor;
+import org.onap.ccsdk.apps.ms.neng.service.extinf.impl.AaiServiceImpl;
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@SpringBootConfiguration
+@ActiveProfiles("test")
+@ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.neng"})
+@EnableJpaRepositories(basePackages = "org.onap.ccsdk.apps.ms.neng.persistence.repository")
+@EntityScan(basePackages = {"org.onap.ccsdk.apps.ms.neng.persistence.entity"})
+@EnableTransactionManagement
+public class TestApplicationConfig {
+
+ @Bean
+ @Primary
+ public RestTemplateBuilder policyMgrRestTempBuilder(PolicyManagerAuthorizationInterceptor auth) {
+ RestTemplateBuilder restTemplateBuiler = new RestTemplateBuilder();
+ return spy(restTemplateBuiler.additionalInterceptors(auth));
+ }
+
+ @Bean
+ @Primary
+ AaiServiceImpl aaiServiceImpl() {
+ return Mockito.mock(AaiServiceImpl.class);
+ }
+}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java
new file mode 100644
index 00000000..17dddd4e
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java
@@ -0,0 +1,200 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * 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.ccsdk.apps.ms.neng.service.extinf.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.GetConfigRequest;
+import org.onap.ccsdk.apps.ms.neng.core.resource.model.GetConfigResponse;
+import org.onap.ccsdk.apps.ms.neng.core.rs.interceptors.PolicyManagerAuthorizationInterceptor;
+import org.onap.ccsdk.apps.ms.neng.extinf.props.PolicyManagerProps;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.RequestEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PolicyFinderServiceImplTest {
+ @InjectMocks
+ @Spy
+ PolicyFinderServiceImpl policyFinder;
+ @Spy
+ PolicyManagerProps policManProps;
+ @Mock
+ RestTemplateBuilder policyMgrRestTempBuilder;
+ @Mock
+ PolicyManagerAuthorizationInterceptor authInt;
+ @Mock
+ RestTemplate restTemplate;
+
+ @Test
+ public void testConfig() throws Exception {
+ doReturn(new GetConfigResponse()).when(policyFinder).makeOutboundCall(Matchers.any(), Matchers.any());
+ assertNotNull(policyFinder.getConfig("policy"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testmakeOutboundCall() throws Exception {
+ Map<String, Object> configMap = buildPolicyResponse();
+ Object resp = Arrays.asList(new Object[] {configMap});
+ ResponseEntity<Object> respEn = new ResponseEntity<>(resp, HttpStatus.OK);
+ when(restTemplate.exchange(Matchers.any(RequestEntity.class), Matchers.any(Class.class))).thenReturn(respEn);
+
+ policManProps.setUrl("http://policyManager.onap.org");
+
+ GetConfigRequest request = new GetConfigRequest();
+ request.setPolicyName("policy");
+ GetConfigResponse configResp = policyFinder.makeOutboundCall(request, GetConfigResponse.class);
+ assertNotNull(configResp);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(expected = NengException.class)
+ public void testmakeOutboundCall_500() throws Exception {
+ Map<String, Object> configMap = buildPolicyResponse();
+ Object resp = Arrays.asList(new Object[] {configMap});
+ ResponseEntity<Object> respEn = new ResponseEntity<>(resp, HttpStatus.INTERNAL_SERVER_ERROR);
+ when(restTemplate.exchange(Matchers.any(RequestEntity.class), Matchers.any(Class.class))).thenReturn(respEn);
+
+ policManProps.setUrl("http://policyManager.onap.org");
+
+ GetConfigRequest request = new GetConfigRequest();
+ request.setPolicyName("policy");
+ policyFinder.makeOutboundCall(request, GetConfigResponse.class);
+ }
+
+ @Test
+ public void testGetRestTemplate() throws Exception {
+ PolicyFinderServiceImpl service = new PolicyFinderServiceImpl();
+ RestTemplateBuilder policyRestTemplateBuilder = new RestTemplateBuilder();
+ service.setPolicyMgrRestTempBuilder(policyRestTemplateBuilder);
+ service.setAuthInt(new PolicyManagerAuthorizationInterceptor());
+
+ assertNotNull(service.getPolicyMgrRestTempBuilder());
+ assertNotNull(service.getAuthInt());
+ assertNotNull(service.getRestTemplate());
+ }
+
+ @Test
+ public void testTransformConfigObject() throws Exception {
+ String config = "{\"riskLevel\":\"4\",\"riskType\":\"test\","
+ + "\"policyName\":\"1806SriovBigJson\",\"service\":\"SDNC-GenerateName\","
+ + "\"guard\":\"False\",\"description\":\"1806SriovBigJson\","
+ + "\"templateVersion\":\"1607\",\"priority\":\"4\",\"version\":\"pannny_nnnn\","
+ + "\"content\":{\"policy-instance-name\":\"1806NameGenerationPolicyForSRIOV\","
+ + "\"naming-models\":[{\"naming-properties\":[{\"property-operation\":\"substr(5)\","
+ + "\"property-name\":\"COMPLEX\"},{\"property-name\":\"SEQUENCE\","
+ + "\"increment-sequence\":{\"max\":\"zzz\",\"scope\":\"ENTIRETY\","
+ + "\"start-value\":\"001\",\"length\":\"3\",\"increment\":\"1\","
+ + "\"sequence-type\":\"alpha-numeric\"}},{\"property-name\":\"NF_NAMING_CODE\"}],"
+ + "\"naming-type\":\"VNF\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"COMPLEX|SEQUENCE|NF_NAMING_CODE\"},"
+ + "{\"naming-properties\":[{\"property-name\":\"VNF_NAME\"},"
+ + "{\"property-name\":\"SEQUENCE\",\"increment-sequence\":"
+ + "{\"max\":\"999\",\"scope\":\"ENTIRETY\",\"start-value\":\"001\",\"length\":\"3\","
+ + "\"increment\":\"1\",\"sequence-type\":\"numeric\"}},"
+ + "{\"property-operation\":\"substr(-3)\",\"property-name\":\"NFC_NAMING_CODE\"}],"
+ + "\"naming-type\":\"VM\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"VNF_NAME|SEQUENCE|NFC_NAMING_CODE\"},"
+ + "{\"naming-properties\":[{\"property-name\":\"VNF_NAME\"},"
+ + "{\"property-value\":\"-\",\"property-name\":\"DELIMITER\"},"
+ + "{\"property-name\":\"VF_MODULE_LABEL\"},{\"property-name\":\"VF_MODULE_TYPE\"},"
+ + "{\"property-name\":\"SEQUENCE\",\"increment-sequence\":"
+ + "{\"max\":\"99\",\"scope\":\"PRECEEDING\",\"start-value\":\"01\",\"length\":\"2\","
+ + "\"increment\":\"1\",\"sequence-type\":\"numeric\"}}],"
+ + "\"naming-type\":\"VF-MODULE\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"VNF_NAME|DELIMITER|VF_MODULE_LABEL|DELIMITER"
+ + "|VF_MODULE_TYPE|DELIMITER|SEQUENCE\"},"
+ + "{\"naming-properties\":[{\"property-name\":\"VF-MODULE_NAME\"},"
+ + "{\"property-value\":\"-\",\"property-name\":\"DELIMITER\"},"
+ + "{\"property-value\":\"volumegroup\",\"property-name\":\"CONSTANT\"}],"
+ + "\"naming-type\":\"VOLUME_GROUP\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"VF-MODULE_NAME|DELIMITER|CONSTANT\"},"
+ + "{\"naming-properties\":[{\"property-name\":\"VOLUME_GROUP_NAME\"},"
+ + "{\"property-value\":\"-\",\"property-name\":\"DELIMITER\"},"
+ + "{\"property-value\":\"volume\",\"property-name\":\"CONSTANT\"},"
+ + "{\"property-name\":\"SEQUENCE\",\"increment-sequence\":"
+ + "{\"max\":\"99\",\"scope\":\"PRECEEDING\",\"start-value\":\"01\","
+ + "\"length\":\"2\",\"increment\":\"1\",\"sequence-type\":\"numeric\"}}],"
+ + "\"naming-type\":\"VOLUME\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"VOLUME_GROUP_NAME|DELIMITER|CONSTANT|DELIMITER|SEQUENCE\"},"
+ + "{\"naming-properties\":[{\"property-name\":\"VNF_NAME\"},"
+ + "{\"property-value\":\"-\",\"property-name\":\"DELIMITER\"},"
+ + "{\"property-value\":\"affinity\",\"property-name\":\"CONSTANT\"}],"
+ + "\"naming-type\":\"AFFINITY\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"VNF_NAME|DELIMITER|CONSTANT\"},"
+ + "{\"naming-properties\":[{\"property-name\":\"VNF_NAME\"},"
+ + "{\"property-value\":\"-\",\"property-name\":\"DELIMITER\"},"
+ + "{\"property-value\":\"INT\",\"property-name\":\"CONSTANT\"},"
+ + "{\"property-name\":\"SEQUENCE\",\"increment-sequence\":"
+ + "{\"max\":\"99\",\"scope\":\"PRECEEDING\",\"start-value\":\"01\","
+ + "\"length\":\"2\",\"increment\":\"1\",\"sequence-type\":\"numeric\"}}],"
+ + "\"naming-type\":\"INTERNAL_NETWORK\",\"nfRole\":\"vPE\","
+ + "\"naming-recipe\":\"VNF_NAME|DELIMITER|CONSTANT|SEQUENCE\"}]}}";
+ Map<Object, Object> configMap = new HashMap<>();
+ configMap.put("config", config);
+ ObjectMapper objectmapper = new ObjectMapper();
+ List<Map<Object, Object>> respList = new ArrayList<>();
+ respList.add(configMap);
+ policyFinder.transformConfigObject(objectmapper, respList);
+ assertNotNull(respList.get(0).get("config"));
+ }
+
+ Map<String, Object> buildPolicyResponse() {
+ Map<String, Object> policyDataMap = new HashMap<>();
+ policyDataMap.put("policy-instance-name", "SDNC_Policy.Config_MS_VNFCNamingPolicy");
+ Map<String, Object> namingModelMap = new HashMap<>();
+ namingModelMap.put("nf-role", "vPE");
+ namingModelMap.put("naming-type", "VNF");
+ namingModelMap.put("naming-recipe", "COMPLEX|NF-NAMING-CODE|Field2|Field3|Field4");
+ Map<String, Object> namingPropertyMap = new HashMap<>();
+ Map<String, Object> propertyMap1 = new HashMap<>();
+ propertyMap1.put("property-name", "COMPLEX");
+ Map<String, Object> propertyMap2 = new HashMap<>();
+ propertyMap2.put("property-name", "NF-NAMING-CODE");
+ namingPropertyMap.put("", Arrays.asList(new Object[] {propertyMap1, propertyMap2}));
+ namingModelMap.put("naming-properties", namingPropertyMap);
+ policyDataMap.put("naming-models", Arrays.asList(new Object[] {namingModelMap}));
+ Map<String, Object> configMap = new HashMap<>();
+ Map<String, Object> contentMap = new HashMap<>();
+ contentMap.put("content", policyDataMap);
+ configMap.put("config", contentMap);
+ return configMap;
+ }
+}