diff options
Diffstat (limited to 'tapisimulator/src/test')
6 files changed, 435 insertions, 0 deletions
diff --git a/tapisimulator/src/test/java/org/onap/tapisimulator/Config.java b/tapisimulator/src/test/java/org/onap/tapisimulator/Config.java new file mode 100644 index 0000000..3ea4d5e --- /dev/null +++ b/tapisimulator/src/test/java/org/onap/tapisimulator/Config.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * TAPI-SIMULATOR + * ================================================================================ + * Copyright (C) 2020 Fujitsu Limited. 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.tapisimulator; + +import static org.mockito.Mockito.when; + +import org.mockito.Mockito; +import org.onap.tapisimulator.utils.Utils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class Config { + + @Bean + public Utils utils() { + Utils utils = Mockito.mock(Utils.class); + String topology = TestUtils.readFileclasspath("tapi-topology.json"); + String sipList = TestUtils.readFileclasspath("siplist.json"); + when(utils.readFromFile("/opt/onap/tapisimulator/templates/tapi1-topology.json")).thenReturn(topology); + when(utils.readFromFile("/opt/onap/tapisimulator/templates/tapi1-siplist.json")).thenReturn(sipList); + + return utils; + } + +} diff --git a/tapisimulator/src/test/java/org/onap/tapisimulator/TestUtils.java b/tapisimulator/src/test/java/org/onap/tapisimulator/TestUtils.java new file mode 100644 index 0000000..102d2b3 --- /dev/null +++ b/tapisimulator/src/test/java/org/onap/tapisimulator/TestUtils.java @@ -0,0 +1,47 @@ +/*
+ * ============LICENSE_START=======================================================
+ * TAPI-SIMULATOR
+ * ================================================================================
+ * Copyright (C) 2020 Fujitsu Limited. 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.tapisimulator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.util.FileCopyUtils;
+
+public class TestUtils {
+
+ public static String readFileclasspath(String filename) {
+ String data = "";
+ Resource resource = new ClassPathResource(filename);
+ InputStream inputStream;
+ try {
+ inputStream = resource.getInputStream();
+ byte[] bdata = FileCopyUtils.copyToByteArray(inputStream);
+ data = new String(bdata, StandardCharsets.UTF_8);
+ return data;
+ } catch (IOException e) {
+ return data;
+ }
+ }
+
+}
diff --git a/tapisimulator/src/test/java/org/onap/tapisimulator/controller/TestTapiController.java b/tapisimulator/src/test/java/org/onap/tapisimulator/controller/TestTapiController.java new file mode 100644 index 0000000..9b4c2f3 --- /dev/null +++ b/tapisimulator/src/test/java/org/onap/tapisimulator/controller/TestTapiController.java @@ -0,0 +1,103 @@ +/* + * ============LICENSE_START======================================================= + * TAPI-SIMULATOR + * ================================================================================ + * Copyright (C) 2020 Fujitsu Limited. 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.tapisimulator.controller; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.onap.tapisimulator.Application; +import org.onap.tapisimulator.Config; +import org.onap.tapisimulator.TestUtils; +import org.onap.tapisimulator.service.TapiService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest( + properties = "spring.main.allow-bean-definition-overriding=true", + classes = {Application.class, Config.class}, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class TestTapiController { + @LocalServerPort + private int port; + + @Autowired + TapiService tapiService; + + @Autowired + TestRestTemplate restTemplate; + + @Before + public void beforeEach() { + + MockitoAnnotations.initMocks(this); + } + + @Test + public void testTopology() throws Exception { + String topology = TestUtils.readFileclasspath("tapi-topology.json"); + String uri = "http://localhost:" + port + "/cxf/tapi/v2/connectivities/topology"; + ResponseEntity<String> response = this.restTemplate.getForEntity(uri, String.class); + + HttpStatus status = response.getStatusCode(); + assertEquals(status, HttpStatus.OK); + String content = response.getBody(); + assertEquals(content, topology); + } + + @Test + public void testServiceCreateTapi() throws Exception { + String serviceCreaterequest = TestUtils.readFileclasspath("service-create-tapi.json"); + String expectedResponse = "Service created Successfully"; + String name = "test"; + String uri = "http://localhost:" + port + "/cxf/tapi/v2/connectivities/create-service/" + name; + ResponseEntity<String> response = this.restTemplate.postForEntity(uri, serviceCreaterequest, String.class); + HttpStatus status = response.getStatusCode(); + assertEquals(HttpStatus.OK, status); + String content = response.getBody(); + assertEquals(content, expectedResponse); + } + + @Test + public void deleteTapiServiceTest() { + String expectedResponse = "Service deleted successfully"; + String name = "test"; + String uri = "http://localhost:" + port + "/cxf/tapi/v2/connectivities/delete-service/" + name; + HttpEntity<String> entity = new HttpEntity<>(""); + ResponseEntity<String> response = this.restTemplate.exchange(uri, HttpMethod.DELETE, entity, String.class); + HttpStatus status = response.getStatusCode(); + assertEquals(HttpStatus.OK, status); + String content = response.getBody(); + assertEquals(content, expectedResponse); + + } + +} diff --git a/tapisimulator/src/test/resources/service-create-tapi.json b/tapisimulator/src/test/resources/service-create-tapi.json new file mode 100644 index 0000000..ec03cef --- /dev/null +++ b/tapisimulator/src/test/resources/service-create-tapi.json @@ -0,0 +1,54 @@ +{ + "create-connectivity-service-input-list": [ + { + "end-point": [ + { + "local-id": "/OTN/Node2-456/ODU2:1-1-1", + "layer-protocol-name": "ODU", + "connection-end-point": [ + { + "topology-uuid": "754a91dc-dcd1-3530-8e95-a4880c298a1f", + "node-edge-point-uuid": "456789", + "node-uuid": "Node2-456", + "connection-end-point-uuid": "efghi" + } + ], + "service-interface-point": { + "service-interface-point-uuid": "efghi" + }, + "protection-role": "WORK" + }, + { + "local-id": "/OTN/Node1-123/ODU2:1-1-1", + "layer-protocol-name": "ODU", + "connection-end-point": [ + { + "topology-uuid": "754a91dc-dcd1-3530-8e95-a4880c298a1f", + "node-edge-point-uuid": "123456", + "node-uuid": "Node1-123", + "connection-end-point-uuid": "abcde" + } + ], + "service-interface-point": { + "service-interface-point-uuid": "abcde" + }, + "protection-role": "WORK" + } + ], + "layer-protocol-name": "ODU", + "connectivity-constraint": { + "service-type": "POINT_TO_POINT_CONNECTIVITY" + }, + "routing-constraint": { + "route-objective-function": "MIN_WORK_ROUTE_COST" + }, + "topology-constraint": [], + "name": [ + { + "value-name": "service-name", + "value": "test" + } + ] + } + ] +} diff --git a/tapisimulator/src/test/resources/siplist.json b/tapisimulator/src/test/resources/siplist.json new file mode 100644 index 0000000..dc5d673 --- /dev/null +++ b/tapisimulator/src/test/resources/siplist.json @@ -0,0 +1,52 @@ +{ + "sip": [ + { + "layer-protocol-name": "ODU", + "uuid": "abcde", + "administrative-state": "UNLOCKED", + "lifecycle-state": "INSTALLED", + "name": [ + { + "value-name": "tid", + "value": "Node1" + }, + { + "value-name": "name", + "value": "1-1-1" + }, + { + "value-name": "rate", + "value": "ODU2" + }, + { + "value-name": "direction", + "value": "BI" + } + ] + }, + { + "layer-protocol-name": "ODU", + "uuid": "efghi", + "administrative-state": "UNLOCKED", + "lifecycle-state": "INSTALLED", + "name": [ + { + "value-name": "tid", + "value": "Node2" + }, + { + "value-name": "name", + "value": "1-1-1" + }, + { + "value-name": "rate", + "value": "ODU2" + }, + { + "value-name": "direction", + "value": "BI" + } + ] + } + ] +} diff --git a/tapisimulator/src/test/resources/tapi-topology.json b/tapisimulator/src/test/resources/tapi-topology.json new file mode 100644 index 0000000..f4278dc --- /dev/null +++ b/tapisimulator/src/test/resources/tapi-topology.json @@ -0,0 +1,135 @@ +{ + "topology": [ + { + "uuid": "754a91dc-dcd1-3530-8e95-a4880c298a1f", + "link": [], + "layer-protocol-name": [], + "node": [ + { + "encap-topology": { + "topology-uuid": "754a91dc-dcd1-3530-8e95-a4880c298a1f" + }, + "uuid": "Node1-123", + "node-edge-point": [ + { + "tapi-connectivity:cep-list": { + "connection-end-point": [ + { + "uuid": "abcde", + "name": [ + { + "value-name": "name", + "value": "1-1-1" + }, + { + "value-name": "direction", + "value": "BI" + } + ] + } + ] + }, + "link-port-direction": "BIDIRECTIONAL", + "layer-protocol-name": "ODU", + "uuid": "123456", + "administrative-state": "UNLOCKED", + "lifecycle-state": "INSTALLED", + "name": [ + { + "value-name": "tid", + "value": "Node1" + }, + { + "value-name": "name", + "value": "1-1-1" + }, + { + "value-name": "rate", + "value": "10GE" + }, + { + "value-name": "direction", + "value": "BI" + } + ] + } + ], + "layer-protocol-name": [ + "ODU" + ], + "name": [ + { + "value-name": "name", + "value": "Node1" + } + ] + }, + { + "encap-topology": { + "topology-uuid": "754a91dc-dcd1-3530-8e95-a4880c298a1f" + }, + "uuid": "Node2-456", + "node-edge-point": [ + { + "tapi-connectivity:cep-list": { + "connection-end-point": [ + { + "uuid": "efghi", + "name": [ + { + "value-name": "name", + "value": "1-1-1" + }, + { + "value-name": "direction", + "value": "BI" + } + ] + } + ] + }, + "link-port-direction": "BIDIRECTIONAL", + "layer-protocol-name": "ODU", + "uuid": "456789", + "administrative-state": "UNLOCKED", + "lifecycle-state": "INSTALLED", + "name": [ + { + "value-name": "tid", + "value": "Node2" + }, + { + "value-name": "name", + "value": "1-1-1" + }, + { + "value-name": "rate", + "value": "10GE" + }, + { + "value-name": "direction", + "value": "BI" + } + ] + } + ], + "layer-protocol-name": [ + "ODU" + ], + "name": [ + { + "value-name": "name", + "value": "Node2" + } + ] + } + ], + "name": [ + { + "value-name": "name", + "value": "OTN" + } + ] + } + ] +} |