Skip to content

Commit 1be2b57

Browse files
authored
Merge pull request #300 from oracle/feature/java-integration-tests
Feature/java integration tests
2 parents 82e9322 + 55a3355 commit 1be2b57

19 files changed

+2847
-247
lines changed

integration-tests/pom.xml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<!-- Copyright 2018, Oracle Corporation and/or its affiliates. All rights
2+
reserved. -->
3+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. -->
4+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>oracle.kubernetes</groupId>
10+
<artifactId>operator-parent</artifactId>
11+
<version>1.0</version>
12+
</parent>
13+
14+
<groupId>oracle.kubernetes</groupId>
15+
<artifactId>operator-integration-tests</artifactId>
16+
<version>1.0</version>
17+
18+
<description>Oracle Weblogic Server Kubernetes Operator</description>
19+
<name>operator-integration-tests</name>
20+
<packaging>jar</packaging>
21+
22+
<url>https://oracle.github.io/weblogic-kubernetes-operator</url>
23+
<inceptionYear>2017</inceptionYear>
24+
<licenses>
25+
<license>
26+
<name>The Universal Permissive License (UPL), Version 1.0</name>
27+
<url>https://github.com/oracle/weblogic-kubernetes-operator/blob/master/LICENSE</url>
28+
</license>
29+
</licenses>
30+
<dependencies>
31+
<!-- test dependencies -->
32+
<dependency>
33+
<!-- note: need to include this before junit since junit includes an obsolete
34+
version of hamcrest -->
35+
<groupId>org.hamcrest</groupId>
36+
<artifactId>hamcrest-junit</artifactId>
37+
<version>2.0.0.0</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>junit</groupId>
42+
<artifactId>junit</artifactId>
43+
<version>${junit-version}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.glassfish.jersey.core</groupId>
48+
<artifactId>jersey-client</artifactId>
49+
<version>${jersey-version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.glassfish.jersey.media</groupId>
53+
<artifactId>jersey-media-json-processing</artifactId>
54+
<version>${jersey-version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.glassfish.jersey.inject</groupId>
58+
<artifactId>jersey-hk2</artifactId>
59+
<version>${jersey-version}</version>
60+
</dependency>
61+
</dependencies>
62+
63+
64+
<profiles>
65+
66+
<profile>
67+
<id>java-integration-tests</id>
68+
<properties>
69+
<src-integration-test>${project.basedir}/src/test/java</src-integration-test>
70+
<resource-integration-test>${project.basedir}/src/test/resources</resource-integration-test>
71+
</properties>
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.codehaus.mojo</groupId>
76+
<artifactId>exec-maven-plugin</artifactId>
77+
<version>1.6.0</version>
78+
<executions>
79+
<execution>
80+
<goals>
81+
<goal>java</goal>
82+
</goals>
83+
</execution>
84+
<execution><!-- pull or build images, create secrets, etc -->
85+
<id>setupenv</id>
86+
<phase>pre-integration-test</phase>
87+
<goals>
88+
<goal>exec</goal>
89+
</goals>
90+
<configuration>
91+
<executable>${resource-integration-test}/setupenv.sh</executable>
92+
</configuration>
93+
</execution>
94+
</executions>
95+
</plugin>
96+
<plugin>
97+
<groupId>org.codehaus.mojo</groupId>
98+
<artifactId>build-helper-maven-plugin</artifactId>
99+
<version>3.0.0</version>
100+
<executions>
101+
<execution>
102+
<id>add-test-source</id>
103+
<phase>generate-test-resources</phase>
104+
<goals>
105+
<goal>add-test-source</goal>
106+
</goals>
107+
<configuration>
108+
<sources>
109+
<source>${src-integration-test}</source>
110+
</sources>
111+
</configuration>
112+
</execution>
113+
<execution>
114+
<id>add-test-resource</id>
115+
<phase>generate-test-resources</phase>
116+
<goals>
117+
<goal>add-test-resource</goal>
118+
</goals>
119+
<configuration>
120+
<resources>
121+
<resource>
122+
<directory>${resource-integration-test}</directory>
123+
</resource>
124+
</resources>
125+
</configuration>
126+
</execution>
127+
</executions>
128+
</plugin>
129+
130+
<plugin>
131+
<groupId>org.apache.maven.plugins</groupId>
132+
<artifactId>maven-failsafe-plugin</artifactId>
133+
<version>2.20.1</version>
134+
<configuration> <!-- run tests in parallel -->
135+
<encoding>UTF-8</encoding>
136+
<argLine>${failsafeArgLine}</argLine>
137+
<failIfNoTests>false</failIfNoTests>
138+
<systemPropertyVariables>
139+
<!-- Add any system properties here -->
140+
<!--<project.build.directory>${project.build.directory}</project.build.directory> -->
141+
<!--<weblogic.operator.root.directory>${basedir}/..</weblogic.operator.root.directory> -->
142+
<!--<TAGS>${env.TAGS}</TAGS> -->
143+
<maxThreads>3</maxThreads>
144+
</systemPropertyVariables>
145+
</configuration>
146+
147+
<executions>
148+
<execution>
149+
<id>integration-tests</id>
150+
<goals>
151+
<goal>integration-test</goal>
152+
<goal>verify</goal>
153+
</goals>
154+
<phase>integration-test</phase>
155+
<configuration>
156+
<skipTests>false</skipTests>
157+
</configuration>
158+
</execution>
159+
<execution>
160+
<id>acceptance-test</id>
161+
<goals>
162+
<goal>integration-test</goal>
163+
<goal>verify</goal>
164+
</goals>
165+
<phase>integration-test</phase>
166+
<configuration>
167+
<!-- do not run unit or integration tests -->
168+
<excludes>
169+
<exclude>**/*Test.java</exclude>
170+
<exclude>**/IT*.java</exclude>
171+
</excludes>
172+
<!-- just run acceptance tests -->
173+
<!-- includes> <include>**/*AT.java</include> </includes -->
174+
</configuration>
175+
</execution>
176+
</executions>
177+
</plugin>
178+
</plugins>
179+
</build>
180+
</profile>
181+
182+
<profile>
183+
<id>default</id>
184+
<activation>
185+
<activeByDefault>true</activeByDefault>
186+
</activation>
187+
<properties>
188+
<surefireArgLine></surefireArgLine>
189+
<failsafeArgLine></failsafeArgLine>
190+
</properties>
191+
</profile>
192+
</profiles>
193+
194+
</project>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator;
6+
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
import java.util.Properties;
10+
import java.util.logging.Logger;
11+
import oracle.kubernetes.operator.utils.ExecCommand;
12+
import oracle.kubernetes.operator.utils.ExecResult;
13+
import oracle.kubernetes.operator.utils.TestUtils;
14+
15+
/**
16+
* Base class which contains common methods to create/shutdown operator and domain. IT tests can
17+
* extend this class.
18+
*/
19+
public class BaseTest {
20+
public static final Logger logger = Logger.getLogger("OperatorIT", "OperatorIT");
21+
22+
private static String resultRoot = "";
23+
private static String pvRoot = "";
24+
// private static String resultDir = "";
25+
private static String userProjectsDir = "";
26+
private static String projectRoot = "";
27+
private static String username = "weblogic";
28+
private static String password = "welcome1";
29+
private static int maxIterationsPod = 50;
30+
private static int waitTimePod = 5;
31+
private static String leaseId = "";
32+
33+
private static Properties appProps;
34+
35+
public static void initialize(String appPropsFile) throws Exception {
36+
37+
// load app props defined
38+
appProps = TestUtils.loadProps(appPropsFile);
39+
40+
// check app props
41+
String baseDir = appProps.getProperty("baseDir");
42+
if (baseDir == null) {
43+
throw new IllegalArgumentException("FAILURE: baseDir is not set");
44+
}
45+
username = appProps.getProperty("username", username);
46+
password = appProps.getProperty("password", password);
47+
maxIterationsPod =
48+
new Integer(appProps.getProperty("maxIterationsPod", "" + maxIterationsPod)).intValue();
49+
waitTimePod = new Integer(appProps.getProperty("waitTimePod", "" + waitTimePod)).intValue();
50+
if (System.getenv("RESULT_ROOT") != null) {
51+
resultRoot = System.getenv("RESULT_ROOT");
52+
} else {
53+
resultRoot = baseDir + "/" + System.getProperty("user.name") + "/wl_k8s_test_results";
54+
}
55+
if (System.getenv("PV_ROOT") != null) {
56+
pvRoot = System.getenv("PV_ROOT");
57+
} else {
58+
pvRoot = resultRoot;
59+
}
60+
if (System.getenv("LEASE_ID") != null) {
61+
leaseId = System.getenv("LEASE_ID");
62+
}
63+
// resultDir = resultRoot + "/acceptance_test_tmp";
64+
userProjectsDir = resultRoot + "/acceptance_test_tmp/user-projects";
65+
projectRoot = System.getProperty("user.dir") + "/..";
66+
logger.info("RESULT_ROOT =" + resultRoot);
67+
logger.info("PV_ROOT =" + pvRoot);
68+
logger.info("userProjectsDir =" + userProjectsDir);
69+
logger.info("projectRoot =" + projectRoot);
70+
71+
logger.info("Env var RESULT_ROOT " + System.getenv("RESULT_ROOT"));
72+
logger.info("Env var PV_ROOT " + System.getenv("PV_ROOT"));
73+
logger.info("Env var K8S_NODEPORT_HOST " + System.getenv("K8S_NODEPORT_HOST"));
74+
logger.info("Env var IMAGE_NAME_OPERATOR= " + System.getenv("IMAGE_NAME_OPERATOR"));
75+
logger.info("Env var IMAGE_TAG_OPERATOR " + System.getenv("IMAGE_TAG_OPERATOR"));
76+
logger.info(
77+
"Env var IMAGE_PULL_POLICY_OPERATOR " + System.getenv("IMAGE_PULL_POLICY_OPERATOR"));
78+
logger.info(
79+
"Env var IMAGE_PULL_SECRET_OPERATOR " + System.getenv("IMAGE_PULL_SECRET_OPERATOR"));
80+
logger.info(
81+
"Env var IMAGE_PULL_SECRET_WEBLOGIC " + System.getenv("IMAGE_PULL_SECRET_WEBLOGIC"));
82+
83+
// create resultRoot, PVRoot, etc
84+
Files.createDirectories(Paths.get(resultRoot));
85+
86+
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
87+
logger.info("Creating PVROOT " + pvRoot);
88+
Files.createDirectories(Paths.get(pvRoot));
89+
ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot);
90+
if (result.exitValue() != 0) {
91+
throw new RuntimeException(
92+
"FAILURE: Couldn't change permissions for PVROOT " + result.stderr());
93+
}
94+
}
95+
96+
// Files.createDirectories(Paths.get(resultDir));
97+
98+
Files.createDirectories(Paths.get(userProjectsDir));
99+
}
100+
101+
public static String getResultRoot() {
102+
return resultRoot;
103+
}
104+
105+
public static String getPvRoot() {
106+
return pvRoot;
107+
}
108+
109+
public static String getUserProjectsDir() {
110+
return userProjectsDir;
111+
}
112+
113+
public static String getProjectRoot() {
114+
return projectRoot;
115+
}
116+
117+
public static String getUsername() {
118+
return username;
119+
}
120+
121+
public static String getPassword() {
122+
return password;
123+
}
124+
125+
public static int getMaxIterationsPod() {
126+
return maxIterationsPod;
127+
}
128+
129+
public static int getWaitTimePod() {
130+
return waitTimePod;
131+
}
132+
133+
public static Properties getAppProps() {
134+
return appProps;
135+
}
136+
137+
public static String getLeaseId() {
138+
return leaseId;
139+
}
140+
141+
protected void logTestBegin(String testName) throws Exception {
142+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
143+
logger.info("BEGIN " + testName);
144+
// renew lease at the beginning for every test method, leaseId is set only for Wercker
145+
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());
146+
}
147+
}

0 commit comments

Comments
 (0)