aboutsummaryrefslogtreecommitdiffstats
path: root/tapisimulator/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'tapisimulator/src/test/java')
-rw-r--r--tapisimulator/src/test/java/org/onap/tapisimulator/Config.java44
-rw-r--r--tapisimulator/src/test/java/org/onap/tapisimulator/TestUtils.java47
-rw-r--r--tapisimulator/src/test/java/org/onap/tapisimulator/controller/TestTapiController.java103
3 files changed, 194 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);
+
+ }
+
+}