summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-07-06 12:14:00 -0400
committerDan Timoney <dtimoney@att.com>2020-07-06 14:26:24 -0400
commit7c53d0d44b7f58bcfc5a567878887dcfefd95b01 (patch)
tree75c9a69a437c66daa48c66159cf2a88cc4744ae5
parentfc24231f90399ee7c6395dd5b6d6da7b703a695a (diff)
Add junit testing for preload rpcs
Add jUnit test cases for preload RPCs Change-Id: I8e6519e57c2eb468b1ee6ad781555951d21203a9 Issue-ID: SDNC-1209 Issue-ID: SDNC-1210 Signed-off-by: Dan Timoney <dtimoney@att.com>
-rw-r--r--.gitignore4
-rw-r--r--ms/generic-resource-api/pom.xml84
-rw-r--r--ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java95
-rw-r--r--ms/generic-resource-api/src/test/resources/application.properties3
-rw-r--r--ms/generic-resource-api/src/test/resources/svclogic.properties2
5 files changed, 168 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index 478a06e..3359eb7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,7 @@ output.log
debug-logs/
logs/
**/derby.log
+ms/generic-resource-api/src/main/resources/GENERIC-RESOURCE-API*xml
+ms/generic-resource-api/src/main/resources/SUBNET-API*xml
+ms/generic-resource-api/src/main/resources/graph.versions
+.vscode
diff --git a/ms/generic-resource-api/pom.xml b/ms/generic-resource-api/pom.xml
index dbbfad0..2fb6fa5 100644
--- a/ms/generic-resource-api/pom.xml
+++ b/ms/generic-resource-api/pom.xml
@@ -179,6 +179,53 @@
</artifactItems>
</configuration>
</execution>
+ <!-- DGs are needed for unit tests as well -->
+ <execution>
+ <id>unpack dgs</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/docker-stage/opt/onap/sdnc</outputDirectory>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.onap.sdnc.oam</groupId>
+ <artifactId>platform-logic-installer</artifactId>
+ <version>${sdnc.oam.version}</version>
+ <type>zip</type>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Workaround : for some reason, BeforeClass is not triggered in junit on Jenkins -->
+ <!-- So cannot override default value of serviceLogicDirectory property -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>copy-dockerfile</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>generate-sources</phase>
+ <configuration>
+ <outputDirectory>${basedir}/src/main/resources</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${basedir}/target/docker-stage/opt/onap/sdnc/svclogic/graphs/generic-resource-api</directory>
+ <includes>
+ <include>*.xml</include>
+ <include>graph.versions</include>
+ </includes>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
@@ -221,6 +268,25 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <execution>
+ <id>addSource</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${project.basedir}/target/generated-sources/src/main/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
@@ -252,24 +318,6 @@
<copyPom>false</copyPom>
</configuration>
</execution>
- <execution>
- <id>unpack dgs</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <outputDirectory>${basedir}/target/docker-stage/opt/onap/sdnc</outputDirectory>
- <artifactItems>
- <artifactItem>
- <groupId>org.onap.sdnc.oam</groupId>
- <artifactId>platform-logic-installer</artifactId>
- <version>${sdnc.oam.version}</version>
- <type>zip</type>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
</executions>
</plugin>
<plugin>
diff --git a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java
new file mode 100644
index 0000000..a869249
--- /dev/null
+++ b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java
@@ -0,0 +1,95 @@
+package org.onap.sdnc.apps.ms.gra.controllers;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.sdnc.apps.ms.gra.core.GenericResourceMsApp;
+import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
+import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes={GenericResourceMsApp.class})
+@AutoConfigureMockMvc
+@Transactional
+public class OperationsApiControllerTest {
+
+ private final static String PRELOAD_NETWORK_URL = "/operations/GENERIC-RESOURCE-API:preload-network-topology-operation/";
+ private final static String PRELOAD_VFMODULE_URL = "/operations/GENERIC-RESOURCE-API:preload-vf-module-topology-operation/";
+
+
+ @Autowired
+ private MockMvc mvc;
+
+ @Autowired
+ ConfigPreloadDataRepository configPreloadDataRepository;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ System.out.println("OperationsApiControllerTest: Setting serviceLogicProperties and serviceLogicDirectory");
+ System.setProperty("serviceLogicProperties", "src/test/resources/svclogic.properties");
+ System.setProperty("serviceLogicDirectory", "target/docker-stage/opt/onap/sdnc/svclogic/graphs/generic-resource-api");
+ }
+
+
+ @Test
+ public void operationsGENERICRESOURCEAPIpreloadNetworkTopologyOperationPost() throws Exception {
+
+ // Remove any existing preload data
+ configPreloadDataRepository.deleteAll();
+
+ // Add invalid content
+ String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(403, mvcResult.getResponse().getStatus());
+ assertEquals(0, configPreloadDataRepository.count());
+
+ // Add valid content
+ content = readFileContent("src/test/resources/preload1-rpc-network.json");
+ mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_NETWORK_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+ assertEquals(1, configPreloadDataRepository.count());
+
+ }
+
+ @Test
+ public void operationsGENERICRESOURCEAPIpreloadVfModuleTopologyOperationPost() throws Exception {
+ // Remove any existing preload data
+ configPreloadDataRepository.deleteAll();
+
+ // Add invalid content
+ String content = readFileContent("src/test/resources/preload1-rpc-network.json");
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(403, mvcResult.getResponse().getStatus());
+ assertEquals(0, configPreloadDataRepository.count());
+
+ // Add valid content
+ content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
+ mvcResult = mvc.perform(MockMvcRequestBuilders.post(PRELOAD_VFMODULE_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+ assertEquals(1, configPreloadDataRepository.count());
+ }
+
+ private String readFileContent(String path) throws IOException {
+ String content = new String(Files.readAllBytes(Paths.get(path)));
+ return content;
+ }
+} \ No newline at end of file
diff --git a/ms/generic-resource-api/src/test/resources/application.properties b/ms/generic-resource-api/src/test/resources/application.properties
index 04538f1..9f7990c 100644
--- a/ms/generic-resource-api/src/test/resources/application.properties
+++ b/ms/generic-resource-api/src/test/resources/application.properties
@@ -17,4 +17,5 @@ spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.Im
# spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.database=derby
-serviceLogicProperties=src/test/resources/svclogic.properties \ No newline at end of file
+serviceLogicProperties=src/test/resources/svclogic.properties
+serviceLogicDirectory=target/docker-stage/opt/onap/sdnc/svclogic/graphs/generic-resource-api \ No newline at end of file
diff --git a/ms/generic-resource-api/src/test/resources/svclogic.properties b/ms/generic-resource-api/src/test/resources/svclogic.properties
index b57c43d..95f4c8a 100644
--- a/ms/generic-resource-api/src/test/resources/svclogic.properties
+++ b/ms/generic-resource-api/src/test/resources/svclogic.properties
@@ -26,4 +26,4 @@ org.onap.ccsdk.sli.jdbc.database = sdnctl
org.onap.ccsdk.sli.jdbc.user = sdnc
org.onap.ccsdk.sli.jdbc.password = abc123
-serviceLogicDirectory=src/test/resources
+serviceLogicDirectory=target/docker-stage/opt/onap/sdnc/svclogic/graphs/generic-resource-api