Skip to content

Commit 6e636ca

Browse files
authored
Fixed three messages for internationalization/localization (#357)
* remove duplicate code block from UpdateImage * added SystemStubs test tool for testing methods with Environment variable dependencies * moved order of Sonar analysis
1 parent e690dae commit 6e636ca

File tree

7 files changed

+148
-32
lines changed

7 files changed

+148
-32
lines changed

Jenkinsfile

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pipeline {
3434
sh 'mvn -B -DskipTests -DskipITs clean install'
3535
}
3636
}
37-
stage ('Test') {
37+
stage ('Unit Tests') {
3838
when {
3939
not { changelog '\\[skip-ci\\].*' }
4040
}
@@ -47,6 +47,25 @@ pipeline {
4747
}
4848
}
4949
}
50+
stage ('Sonar Analysis') {
51+
when {
52+
anyOf {
53+
changeRequest()
54+
branch "main"
55+
}
56+
}
57+
tools {
58+
maven 'maven-3.6.0'
59+
jdk 'jdk11'
60+
}
61+
steps {
62+
withSonarQubeEnv('SonarCloud') {
63+
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
64+
runSonarScanner()
65+
}
66+
}
67+
}
68+
}
5069
stage ('SystemTest Gate') {
5170
when {
5271
allOf {
@@ -99,25 +118,6 @@ pipeline {
99118
}
100119
}
101120
}
102-
stage ('Analyze') {
103-
when {
104-
anyOf {
105-
changeRequest()
106-
branch "main"
107-
}
108-
}
109-
tools {
110-
maven 'maven-3.6.0'
111-
jdk 'jdk11'
112-
}
113-
steps {
114-
withSonarQubeEnv('SonarCloud') {
115-
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
116-
runSonarScanner()
117-
}
118-
}
119-
}
120-
}
121121
stage ('Save Nightly Installer'){
122122
when {
123123
allOf {

imagetool/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
<dependency>
3838
<groupId>org.junit.jupiter</groupId>
3939
<artifactId>junit-jupiter-engine</artifactId>
40-
<scope>test</scope>
4140
</dependency>
4241
<dependency>
4342
<groupId>com.github.spullara.mustache.java</groupId>
@@ -48,6 +47,10 @@
4847
<artifactId>annotations</artifactId>
4948
<scope>provided</scope>
5049
</dependency>
50+
<dependency>
51+
<groupId>uk.org.webcompere</groupId>
52+
<artifactId>system-stubs-jupiter</artifactId>
53+
</dependency>
5154
</dependencies>
5255

5356
<build>

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ public CommandResponse call() throws Exception {
161161
} catch (Exception ex) {
162162
return CommandResponse.error(ex.getMessage());
163163
} finally {
164-
if (!skipcleanup) {
165-
Utils.deleteFilesRecursively(buildDir());
166-
Utils.removeIntermediateDockerImages(buildEngine, buildId());
167-
}
164+
cleanup();
168165
}
169166
Instant endTime = Instant.now();
170167
logger.finer("Exiting UpdateImage.call ");

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ public static String findProxyUrl(String proxyUrl, String protocol) {
471471
if (isEmptyString(retVal)) {
472472
retVal = System.getProperty("http.nonProxyHosts", null);
473473
if (!isEmptyString(retVal)) {
474-
retVal = retVal.replaceAll("\\|", ",");
474+
//http.nonProxyHosts property uses | instead of , as a separator
475+
retVal = retVal.replace("|", ",");
475476
}
476477
}
477478
break;
@@ -538,13 +539,13 @@ public static String getBuildWorkingDir() throws IOException {
538539
boolean pathExists = Files.exists(path, LinkOption.NOFOLLOW_LINKS);
539540

540541
if (!pathExists) {
541-
throw new IOException("Working Directory does not exists " + workingDir);
542+
throw new IOException(Utils.getMessage("IMG-0111", workingDir));
542543
} else {
543544
if (!Files.isDirectory(path)) {
544-
throw new IOException("Working Directory specified is not a directory " + workingDir);
545+
throw new IOException(Utils.getMessage("IMG-0112", workingDir));
545546
}
546547
if (!Files.isWritable(path)) {
547-
throw new IOException("Working Directory specified is not writable " + workingDir);
548+
throw new IOException(Utils.getMessage("IMG-0113", workingDir));
548549
}
549550
}
550551

imagetool/src/main/resources/ImageTool.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,6 @@ IMG-0107=Failed to download and save file {0} from {1}: {2}
109109
IMG-0108=Environment variable {0}=`{1}` is not an integer and will be ignored.
110110
IMG-0109=Invalid value found in {0}. {1} < {2}. Using default value: {3}.
111111
IMG-0110=Retries exhausted, unable to obtain patch information from Oracle
112+
IMG-0111=The directory specified with WLSIMG_BLDDIR must exist prior to running this tool: {0}
113+
IMG-0112=The value specified with WLSIMG_BLDDIR must be a directory: {0}
114+
IMG-0113=The directory specified with WLSIMG_BLDDIR must be writable: {0}

imagetool/src/test/java/com/oracle/weblogic/imagetool/util/UtilsTest.java

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,42 @@
44
package com.oracle.weblogic.imagetool.util;
55

66
import java.io.IOException;
7+
import java.nio.file.Files;
78
import java.nio.file.Path;
89
import java.nio.file.Paths;
910
import java.util.ArrayList;
11+
import java.util.Arrays;
1012
import java.util.List;
1113
import java.util.logging.Level;
1214

1315
import com.oracle.weblogic.imagetool.api.model.CachedFile;
1416
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
1517
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
18+
import org.junit.jupiter.api.DisplayName;
1619
import org.junit.jupiter.api.Tag;
1720
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.extension.ExtendWith;
22+
import org.junit.jupiter.api.io.TempDir;
23+
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
24+
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
25+
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
26+
import uk.org.webcompere.systemstubs.properties.SystemProperties;
1827

1928
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertNull;
30+
import static org.junit.jupiter.api.Assertions.assertThrows;
2031
import static org.junit.jupiter.api.Assertions.assertTrue;
2132

2233
@Tag("unit")
34+
@ExtendWith(SystemStubsExtension.class)
2335
class UtilsTest {
2436

37+
@SystemStub
38+
private EnvironmentVariables environment;
39+
40+
@SystemStub
41+
private SystemProperties overrideProperties;
42+
2543
@Test
2644
void compareVersions() {
2745
assertEquals(0, Utils.compareVersions("12.2.1.3.0", "12.2.1.3.0"));
@@ -106,4 +124,96 @@ void oracleHomeFromResponseFile() throws Exception {
106124
logger.setLevel(oldLevel);
107125
}
108126
}
127+
128+
@Test
129+
@DisplayName("Default working directory to User's home dir")
130+
void getBuildWorkingDir1() throws IOException {
131+
String expected = System.getProperty("user.home");
132+
assertEquals(expected, Utils.getBuildWorkingDir());
133+
}
134+
135+
@Test
136+
@DisplayName("Override working directory with system property")
137+
void getBuildWorkingDir2(@TempDir Path tempDir) throws IOException {
138+
// provide existing directory as input to WLSIMG_BLDDIR should succeed
139+
String expected = tempDir.toString();
140+
overrideProperties.set("WLSIMG_BLDDIR", expected);
141+
assertEquals(expected, Utils.getBuildWorkingDir());
142+
143+
// Create a read-only directory as input for WLSIMG_BLDDIR
144+
Path unwritableDir = tempDir.resolve("unwritable");
145+
Files.createDirectory(unwritableDir);
146+
if (!unwritableDir.toFile().setReadOnly()) {
147+
throw new IOException("Unable to mark test directory as read-only");
148+
}
149+
// read-only directory as input for working directory should throw an exception
150+
overrideProperties.set("WLSIMG_BLDDIR", unwritableDir.toString());
151+
assertThrows(IOException.class, Utils::getBuildWorkingDir);
152+
}
153+
154+
@Test
155+
@DisplayName("Override working directory with invalid directory")
156+
void getBuildWorkingDir3() {
157+
String expected = "/this/does/not/exist";
158+
overrideProperties.set("WLSIMG_BLDDIR", expected);
159+
assertThrows(IOException.class, Utils::getBuildWorkingDir);
160+
}
161+
162+
@Test
163+
@DisplayName("Override working directory with invalid file")
164+
void getBuildWorkingDir4(@TempDir Path tempDir) throws IOException {
165+
Path tempFile = tempDir.resolve("getBuildWorkingDir4.txt");
166+
List<String> lines = Arrays.asList("a", "b");
167+
Files.write(tempFile, lines);
168+
169+
String expected = tempFile.toString();
170+
overrideProperties.set("WLSIMG_BLDDIR", expected);
171+
// The override for WLSIMG_BUILDDIR must be a directory, NOT a file
172+
assertThrows(IOException.class, Utils::getBuildWorkingDir);
173+
}
174+
175+
@Test
176+
void findProxyUrlWithCommandLine() {
177+
// Always default to the proxy set by the user on the tool's command line
178+
String expected = "http://some.proxy-host.com";
179+
assertEquals(expected, Utils.findProxyUrl(expected, "http"));
180+
assertEquals(expected, Utils.findProxyUrl(expected, "https"));
181+
}
182+
183+
/**
184+
* If not specified by the user, the environment variable value should be returned
185+
* for http_proxy and https_proxy.
186+
*/
187+
@Test
188+
void findProxyUrlWithEnvironment() {
189+
// No ENV variable set (filed issue on SystemStub)
190+
environment.set("http_proxy", null);
191+
environment.set("HTTP_PROXY", null);
192+
assertNull(Utils.findProxyUrl("", "http"));
193+
194+
String expected = "http://env.proxy-host.com";
195+
// ENV for http_proxy and https_proxy are set
196+
environment.set("http_proxy", expected);
197+
environment.set("https_proxy", expected);
198+
assertEquals(expected, Utils.findProxyUrl("", "http"));
199+
assertEquals(expected, Utils.findProxyUrl("", "https"));
200+
}
201+
202+
@Test
203+
void findProxyUrlForNoProxy() {
204+
// No ENV variable set (filed issue on SystemStub)
205+
environment.set("no_proxy", null);
206+
environment.set("NO_PROXY", null);
207+
assertNull(Utils.findProxyUrl("", "none"));
208+
209+
String expected = ".host.com,.anotherhost.com,.and.another.com";
210+
// | (bar) should be replaced by , (comma) for http.nonProxyHosts system property
211+
String withBars = expected.replace(",", "|");
212+
overrideProperties.set("http.nonProxyHosts", withBars);
213+
assertEquals(expected, Utils.findProxyUrl("", "none"));
214+
215+
// ENV for no_proxy is set
216+
environment.set("no_proxy", expected);
217+
assertEquals(expected, Utils.findProxyUrl("", "none"));
218+
}
109219
}

pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@
7474
<groupId>org.junit.jupiter</groupId>
7575
<artifactId>junit-jupiter-engine</artifactId>
7676
<version>5.8.1</version>
77+
<scope>test</scope>
7778
</dependency>
7879
<dependency>
79-
<groupId>com.google.guava</groupId>
80-
<artifactId>guava</artifactId>
81-
<version>29.0-jre</version>
80+
<groupId>uk.org.webcompere</groupId>
81+
<artifactId>system-stubs-jupiter</artifactId>
82+
<version>1.2.0</version>
83+
<scope>test</scope>
8284
</dependency>
8385
<dependency>
8486
<groupId>com.github.spullara.mustache.java</groupId>

0 commit comments

Comments
 (0)