Add integration test for GR-API docker container 55/115055/1
authorDan Timoney <dtimoney@att.com>
Wed, 18 Nov 2020 20:01:50 +0000 (15:01 -0500)
committerDan Timoney <dtimoney@att.com>
Wed, 18 Nov 2020 20:01:50 +0000 (15:01 -0500)
Add integration test for GR-API docker container

Change-Id: Iebd60f56668c9b50a2aab62b5309c609bc2369ce
Issue-ID: SDNC-1417
Signed-off-by: Dan Timoney <dtimoney@att.com>
ms/generic-resource-api/pom.xml
ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/GenericResourceMsIT.java [new file with mode: 0644]

index 88a6305..cc6471d 100644 (file)
@@ -34,6 +34,7 @@
         <sdnc.gra.jar>${project.artifactId}-${project.version}.jar</sdnc.gra.jar>
         <docker.push.phase>deploy</docker.push.phase>
         <docker.verbose>true</docker.verbose>
+        <docker.autoCreateCustomNetworks>true</docker.autoCreateCustomNetworks>
     </properties>
 
     <dependencies>
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.19.1</version>
+                <configuration>
+                    <forkMode>always</forkMode>
+                    <environmentVariables>
+                        <SDNC_CONFIG_DIR>${basedir}/src/test/resources</SDNC_CONFIG_DIR>
+                        <SVCLOGIC_PROPERTIES>${basedir}/src/test/resources/svclogic.properties</SVCLOGIC_PROPERTIES>
+                    </environmentVariables>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <executions>
+                  <execution>
+                    <goals>
+                      <goal>integration-test</goal>
+                      <goal>verify</goal>
+                    </goals>
+                  </execution>
+                </executions>
+                <configuration>
+                  <skipITs>true</skipITs>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
                             </execution>
                         </executions>
                     </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <executions>
+                          <execution>
+                            <goals>
+                              <goal>integration-test</goal>
+                              <goal>verify</goal>
+                            </goals>
+                          </execution>
+                        </executions>
+                        <configuration>
+                          <skipITs>false</skipITs>
+                          <environmentVariables>
+                            <GRA_PORT>${gra.port}</GRA_PORT>
+                          </environmentVariables>
+                        </configuration>
+                      </plugin>
                     <plugin>
                         <groupId>io.fabric8</groupId>
                         <artifactId>docker-maven-plugin</artifactId>
                                     <goal>build</goal>
                                 </goals>
                             </execution>
-
+                            <execution>
+                                <id>start-it-instance</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>start</goal>
+                                </goals>
+                                <configuration>
+                                    <images>
+                                        <image>
+                                            <name>mariadb:10.5</name>
+                                            <alias>gradb</alias>
+                                            <run>
+                                                <env>
+                                                    <MYSQL_ROOT_PASSWORD>itsASecret</MYSQL_ROOT_PASSWORD>
+                                                    <MYSQL_USER>sdnc</MYSQL_USER>
+                                                    <MYSQL_PASSWORD>abc123</MYSQL_PASSWORD>
+                                                    <MYSQL_DATABASE>sdnctl</MYSQL_DATABASE>
+                                                </env>
+                                                <network>
+                                                    <mode>custom</mode>
+                                                    <name>gra</name>
+                                                    <alias>dbhost</alias>
+                                                </network>
+                                                <ports>
+                                                    <port>gradb.port:3306</port>
+                                                </ports>
+                                                <log>
+                                                    <enabled>true</enabled>
+                                                </log>
+                                            </run>
+                                        </image>
+                                        <image>
+                                            <name>${image.name}:${project.docker.latesttagtimestamp.version}</name>
+                                            <alias>gra-container</alias>
+                                            <run>
+                                                <env>
+                                                    <MYSQL_USER>sdnc</MYSQL_USER>
+                                                    <MYSQL_PASSWORD>abc123</MYSQL_PASSWORD>
+                                                    <MYSQL_DATABASE>sdnctl</MYSQL_DATABASE>
+                                                    <SDNC_CONFIG_DIR>/opt/onap/sdnc/config</SDNC_CONFIG_DIR>
+                                                </env>
+                                                <dependsOn>
+                                                    <container>gradb</container>
+                                                </dependsOn>
+                                                <network>
+                                                    <mode>custom</mode>
+                                                    <name>gra</name>
+                                                    <alias>gra</alias>
+                                                </network>
+                                                <ports>
+                                                    <port>gra.port:8080</port>
+                                                </ports>
+                                                <wait>
+                                                    <log>Started GenericResourceMsApp</log>
+                                                    <time>120000</time>
+                                                </wait>
+                                                <log>
+                                                    <enabled>true</enabled>
+                                                </log>
+                                            </run>
+                                        </image>
+                                    </images>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>stop-it-instance</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
                             <execution>
                                 <id>push-images</id>
                                 <phase>${docker.push.phase}</phase>
diff --git a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/GenericResourceMsIT.java b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/GenericResourceMsIT.java
new file mode 100644 (file)
index 0000000..7f00c6b
--- /dev/null
@@ -0,0 +1,31 @@
+package org.onap.sdnc.apps.ms.gra;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.junit.Test;
+
+public class GenericResourceMsIT {
+    @Test
+    public void healthcheckTest() throws ClientProtocolException, IOException {
+        String graPort = System.getenv("GRA_PORT");
+        if ((graPort == null) || (graPort.length() == 0)) {
+            graPort = "8080";
+        }
+
+        String testUrl = "http://localhost:" + graPort + "/restconf/operations/SLI-API:healthcheck/";
+
+        CloseableHttpClient client = HttpClients.createDefault();
+        HttpPost postCmd = new HttpPost(testUrl);
+        postCmd.addHeader("Content-Type", "application/json");
+        
+        CloseableHttpResponse resp = client.execute(postCmd);
+        assertEquals(200, resp.getStatusLine().getStatusCode());
+    }
+}