Skip to content

Commit 6c54f57

Browse files
committed
Fixes based on Sonar scanning
1 parent f27e321 commit 6c54f57

File tree

289 files changed

+1270
-2624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+1270
-2624
lines changed

common/src/test/java/oracle/kubernetes/common/logging/CommonLoggingFacadeTest.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
@@ -19,7 +19,7 @@ class CommonLoggingFacadeTest {
1919
CommonLoggingFacade loggingFacade;
2020

2121
@BeforeEach
22-
public void setup() {
22+
void setup() {
2323
mockLogger = new MockLogger();
2424
loggingFacade = new CommonLoggingFacade(mockLogger);
2525
}
@@ -415,10 +415,12 @@ public MockLogger() {
415415
super("MockLogger", "Operator");
416416
}
417417

418+
@Override
418419
public void setLevel(Level level) {
419420
this.level = level;
420421
}
421422

423+
@Override
422424
public boolean isLoggable(Level level) {
423425
int levelValue = this.level.intValue();
424426
return level.intValue() >= levelValue && levelValue != Level.OFF.intValue();
@@ -433,6 +435,7 @@ public void logp(
433435
messageParams = params;
434436
}
435437

438+
@Override
436439
public void logp(
437440
Level level, String sourceClass, String sourceMethod, String msg, Throwable thrown) {
438441
logpCalled = true;
@@ -441,12 +444,14 @@ public void logp(
441444
messageLevel = level;
442445
}
443446

447+
@Override
444448
public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
445449
logpCalled = true;
446450
message = msg;
447451
messageLevel = level;
448452
}
449453

454+
@Override
450455
public void logp(Level level, String sourceClass, String sourceMethod,
451456
String msg, Object param1) {
452457
logpCalled = true;

common/src/test/java/oracle/kubernetes/common/utils/BaseTestUtils.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.utils;
@@ -52,17 +52,17 @@ protected abstract static class TestLogHandler extends Handler {
5252
private List<String> messagesToTrack = new ArrayList<>();
5353

5454
@Override
55-
public void publish(LogRecord record) {
56-
if (record.getThrown() != null && !shouldIgnore(record.getThrown())) {
57-
throwable = record.getThrown();
55+
public void publish(LogRecord rec) {
56+
if (rec.getThrown() != null && !shouldIgnore(rec.getThrown())) {
57+
throwable = rec.getThrown();
5858
}
59-
if (shouldTrack(record)) {
60-
logRecords.add(record);
59+
if (shouldTrack(rec)) {
60+
logRecords.add(rec);
6161
}
6262
}
6363

64-
private boolean shouldTrack(LogRecord record) {
65-
return messagesToTrack == ALL_MESSAGES || messagesToTrack.contains(record.getMessage());
64+
private boolean shouldTrack(LogRecord rec) {
65+
return messagesToTrack == ALL_MESSAGES || messagesToTrack.contains(rec.getMessage());
6666
}
6767

6868
boolean shouldIgnore(Throwable thrown) {
@@ -110,8 +110,8 @@ void throwUncheckedLogMessages() {
110110

111111
SimpleFormatter formatter = new SimpleFormatter();
112112
List<String> messageKeys = new ArrayList<>();
113-
for (LogRecord record : logRecords) {
114-
messageKeys.add(formatter.format(record));
113+
for (LogRecord rec : logRecords) {
114+
messageKeys.add(formatter.format(rec));
115115
}
116116

117117
throw new AssertionError("Unexpected log messages " + messageKeys);

common/src/test/java/oracle/kubernetes/common/utils/SchemaConversionUtilsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static String getMD5Hash(String s) throws NoSuchAlgorithmException {
5757
}
5858

5959
@BeforeEach
60-
public void setUp() throws Exception {
60+
void setUp() throws Exception {
6161
mementos.add(CommonTestUtils.silenceLogger());
6262
mementos.add(BaseTestUtils.silenceJsonPathLogger());
6363
v8Domain = readAsYaml(DOMAIN_V8_AUX_IMAGE30_YAML);
@@ -78,7 +78,7 @@ private static InputStream inputStreamFromClasspath(String path) {
7878
}
7979

8080
@AfterEach
81-
public void tearDown() throws Exception {
81+
void tearDown() throws Exception {
8282
mementos.forEach(Memento::revert);
8383
}
8484

domain-upgrader/src/test/java/oracle/kubernetes/operator/DomainUpgraderTest.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DomainUpgraderTest {
3535
private ByteArrayOutputStream bytes;
3636

3737
@BeforeEach
38-
public void setUp() throws NoSuchFieldException {
38+
void setUp() throws NoSuchFieldException {
3939
mementos.add(CommonTestUtils.silenceLogger().collectLogMessages(logRecords, DOMAIN_UPGRADE_SUCCESS));
4040
mementos.add(StaticStubSupport.install(DomainUpgrader.class, "exitCall", new ExitIntConsumer()));
4141
bytes = new ByteArrayOutputStream();
@@ -44,16 +44,14 @@ public void setUp() throws NoSuchFieldException {
4444
}
4545

4646
@AfterEach
47-
public void tearDown() {
47+
void tearDown() {
4848
mementos.forEach(Memento::revert);
4949
System.setOut(console);
5050
}
5151

5252
@Test
5353
void whenNoInputFileProvided_domainUpgraderExitsWithErrorStatus() {
54-
ExitException thrown = Assertions.assertThrows(ExitException.class, () -> {
55-
DomainUpgrader.main();
56-
});
54+
ExitException thrown = Assertions.assertThrows(ExitException.class, DomainUpgrader::main);
5755
assertThat(thrown.status, is(1));
5856
}
5957

integration-tests/src/test/java/oracle/weblogic/domain/AuxiliaryImage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2021, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.domain;
@@ -80,7 +80,7 @@ public String getSourceWDTInstallHome() {
8080
.orElse(AUXILIARY_IMAGE_DEFAULT_SOURCE_WDT_INSTALL_HOME);
8181
}
8282

83-
public void setSourceWDTInstallHome() {
83+
public void setSourceWDTInstallHome(String sourceWDTInstallHome) {
8484
this.sourceWDTInstallHome = sourceWDTInstallHome;
8585
}
8686

integration-tests/src/test/java/oracle/weblogic/domain/Istio.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Istio {
2121
+ "pod is ready for application traffic. Defaults to 8888.")
2222
private Integer readinessPort = 8888;
2323

24-
public static Integer DEFAULT_REPLICATION_PORT = 4564;
24+
public static final Integer DEFAULT_REPLICATION_PORT = 4564;
2525

2626
@ApiModelProperty(
2727
"The operator will create a `T3` protocol WebLogic network access point on each WebLogic server "

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItAddNewDynamicClusterUsingWlst.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ItAddNewDynamicClusterUsingWlst {
8484
* JUnit engine parameter resolution mechanism
8585
*/
8686
@BeforeAll
87-
public static void initAll(@Namespaces(2) List<String> namespaces) {
87+
static void initAll(@Namespaces(2) List<String> namespaces) {
8888
logger = getLogger();
8989

9090
// get a unique operator namespace

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItAuxV8DomainImplicitUpgrade.java

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes;
@@ -99,7 +99,7 @@ class ItAuxV8DomainImplicitUpgrade {
9999
* JUnit engine parameter resolution mechanism
100100
*/
101101
@BeforeAll
102-
public static void initAll(@Namespaces(2) List<String> namespaces) {
102+
static void initAll(@Namespaces(2) List<String> namespaces) {
103103
logger = getLogger();
104104

105105
// get a new unique opNamespace
@@ -226,7 +226,7 @@ void testMultipleAuxImagesV8Domain() {
226226
logger.info("Run " + KUBERNETES_CLI + " to create the domain");
227227
CommandParams params = new CommandParams().defaults();
228228
params.command(KUBERNETES_CLI + " apply -f "
229-
+ Paths.get(WORK_DIR + "/domain.yaml").toString());
229+
+ Paths.get(WORK_DIR + "/domain.yaml"));
230230
boolean result = Command.withParams(params).execute();
231231
assertTrue(result, "Failed to create domain custom resource");
232232

@@ -300,9 +300,6 @@ void testErrorPathV8DomainMissingWDTBinary() {
300300
deleteDomainResource(domainNamespace, domainUid);
301301
}
302302

303-
final String adminServerPodName = domainUid + "-admin-server";
304-
final String managedServerPrefix = domainUid + "-managed-server";
305-
306303
String missingWdtTag = "missing-wdtbinary-image";
307304
String missingWdtImage = MII_AUXILIARY_IMAGE_NAME + ":" + missingWdtTag;
308305

@@ -336,7 +333,7 @@ void testErrorPathV8DomainMissingWDTBinary() {
336333
logger.info("Run " + KUBERNETES_CLI + " to create the domain");
337334
CommandParams params = new CommandParams().defaults();
338335
params.command(KUBERNETES_CLI + " apply -f "
339-
+ Paths.get(WORK_DIR + "/domain.yaml").toString());
336+
+ Paths.get(WORK_DIR + "/domain.yaml"));
340337
boolean result = Command.withParams(params).execute();
341338
assertTrue(result, "Failed to create domain custom resource");
342339

@@ -367,9 +364,6 @@ void testErrorPathV8DomainMissingDomainConfig() {
367364
deleteDomainResource(domainNamespace, domainUid);
368365
}
369366

370-
final String adminServerPodName = domainUid + "-admin-server";
371-
final String managedServerPrefix = domainUid + "-managed-server";
372-
373367
String missingModelTag = "missing-model-image";
374368
String missingModelImage = MII_AUXILIARY_IMAGE_NAME + ":" + missingModelTag;
375369

@@ -402,7 +396,7 @@ void testErrorPathV8DomainMissingDomainConfig() {
402396
logger.info("Run " + KUBERNETES_CLI + " to create the domain");
403397
CommandParams params = new CommandParams().defaults();
404398
params.command(KUBERNETES_CLI + " apply -f "
405-
+ Paths.get(WORK_DIR + "/domain.yaml").toString());
399+
+ Paths.get(WORK_DIR + "/domain.yaml"));
406400
boolean result = Command.withParams(params).execute();
407401
assertTrue(result, "Failed to create domain custom resource");
408402

@@ -430,9 +424,6 @@ void testErrorPathV8DomainFilePermission() {
430424
deleteDomainResource(domainNamespace, domainUid);
431425
}
432426

433-
final String adminServerPodName = domainUid + "-admin-server";
434-
final String managedServerPrefix = domainUid + "-managed-server";
435-
436427
String permModelTag = "perm-model-image";
437428
String permModelImage = MII_AUXILIARY_IMAGE_NAME + ":" + permModelTag;
438429

@@ -472,7 +463,7 @@ void testErrorPathV8DomainFilePermission() {
472463
logger.info("Run " + KUBERNETES_CLI + " to create the domain");
473464
CommandParams params = new CommandParams().defaults();
474465
params.command(KUBERNETES_CLI + " apply -f "
475-
+ Paths.get(WORK_DIR + "/domain.yaml").toString());
466+
+ Paths.get(WORK_DIR + "/domain.yaml"));
476467
boolean result = Command.withParams(params).execute();
477468
assertTrue(result, "Failed to create domain custom resource");
478469

@@ -545,12 +536,11 @@ void testUpdateBaseImageV8AuxDomain() {
545536
logger.info("Run " + KUBERNETES_CLI + " to create the domain");
546537
CommandParams params = new CommandParams().defaults();
547538
params.command(KUBERNETES_CLI + " apply -f "
548-
+ Paths.get(WORK_DIR + "/domain.yaml").toString());
539+
+ Paths.get(WORK_DIR + "/domain.yaml"));
549540
boolean result = Command.withParams(params).execute();
550541
assertTrue(result, "Failed to create domain custom resource");
551542

552-
String operatorPodName =
553-
assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace));
543+
assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, opNamespace));
554544
logger.info("Wait for admin server pod {0} to be ready in namespace {1}",
555545
adminServerPodName, domainNamespace);
556546
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace);

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItCoherenceTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes;
@@ -9,7 +9,6 @@
99
import java.util.ArrayList;
1010
import java.util.LinkedHashMap;
1111
import java.util.List;
12-
import java.util.Map;
1312

1413
import io.kubernetes.client.openapi.ApiException;
1514
import io.kubernetes.client.openapi.models.V1EnvVar;
@@ -91,15 +90,13 @@ class ItCoherenceTests {
9190
private static final String COHERENCE_IMAGE_NAME = "coherence-image";
9291

9392
private static String domainUid = "coherence-domain";
94-
private static String clusterName = "cluster-1";
9593
private static String adminServerPodName = domainUid + "-admin-server";
9694
private static String managedServerPrefix = domainUid + "-managed-server";
9795
private static String containerName = "weblogic-server";
9896
private static int replicaCount = 2;
9997

10098
private static String opNamespace = null;
10199
private static String domainNamespace = null;
102-
private static Map<String, Object> secretNameMap;
103100
private static LoggingFacade logger = null;
104101

105102
/**
@@ -109,7 +106,7 @@ class ItCoherenceTests {
109106
* JUnit engine parameter resolution mechanism
110107
*/
111108
@BeforeAll
112-
public static void init(@Namespaces(2) List<String> namespaces) {
109+
static void init(@Namespaces(2) List<String> namespaces) {
113110
logger = getLogger();
114111

115112
// get a new unique opNamespace
@@ -197,15 +194,15 @@ private void copyCohProxyClientAppToPods() {
197194
() -> deleteDirectories(domainNamespace, serverName,
198195
null, true, dirsToMake),
199196
String.format("Failed to delete dir %s in pod %s in namespace %s ",
200-
dirsToMake.toString(), serverName, domainNamespace));
197+
dirsToMake, serverName, domainNamespace));
201198
logger.info("Deleted dir {0} in Pod {1} in namespace {2} ",
202199
dirsToMake.toString(), serverName, domainNamespace);
203200

204201
assertDoesNotThrow(
205202
() -> makeDirectories(domainNamespace, serverName,
206203
null, true, dirsToMake),
207204
String.format("Failed to create dir %s in pod %s in namespace %s ",
208-
dirsToMake.toString(), serverName, domainNamespace));
205+
dirsToMake, serverName, domainNamespace));
209206
logger.info("Created dir {0} in Pod {1} in namespace {2} ",
210207
dirsToMake.toString(), serverName, domainNamespace);
211208

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItConfigDistributionStrategy.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2025, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes;
@@ -7,7 +7,6 @@
77
import java.io.FileOutputStream;
88
import java.io.IOException;
99
import java.net.InetAddress;
10-
import java.net.UnknownHostException;
1110
import java.net.http.HttpResponse;
1211
import java.nio.file.Files;
1312
import java.nio.file.Path;
@@ -186,7 +185,7 @@ class ItConfigDistributionStrategy {
186185
* @param namespaces injected by JUnit
187186
*/
188187
@BeforeAll
189-
public void initAll(@Namespaces(3) List<String> namespaces) throws ApiException, IOException {
188+
void initAll(@Namespaces(3) List<String> namespaces) throws ApiException, IOException {
190189
logger = getLogger();
191190

192191
logger.info("Assign a unique namespace for operator");
@@ -264,7 +263,7 @@ public void initAll(@Namespaces(3) List<String> namespaces) throws ApiException,
264263
* Verify the default config before starting any test.
265264
*/
266265
@BeforeEach
267-
public void beforeEach() throws UnknownHostException, IOException, InterruptedException {
266+
void beforeEach() {
268267
getDomainHealth();
269268
//check configuration values before override
270269
verifyConfigXMLOverride(false);
@@ -275,7 +274,7 @@ public void beforeEach() throws UnknownHostException, IOException, InterruptedEx
275274
* Delete the overrides and restart domain to get clean state.
276275
*/
277276
@AfterEach
278-
public void afterEach() throws IOException, InterruptedException {
277+
void afterEach() {
279278
getDomainHealth();
280279
deleteConfigMap(overridecm, domainNamespace);
281280
String patchStr
@@ -933,7 +932,6 @@ private void verifyResourceJDBC1Override(boolean configUpdated) {
933932
}
934933
String baseUri = "http://" + hostAndPort + "/clusterview/ConfigServlet?";
935934
String appURI = "dsTest=true&dsName=" + dsName1 + "&" + "serverName=" + managedServerNameBase + i;
936-
String dsConnectionPoolTestUrl = baseUri + appURI;
937935
testDatasource(appURI);
938936
}
939937
}
@@ -1189,21 +1187,19 @@ private void createFileInPod(String podName, String namespace, String password)
11891187
+ "CREATE USER 'root'@'" + ip + "' IDENTIFIED BY '" + password + "';\n"
11901188
+ "GRANT ALL PRIVILEGES ON *.* TO 'root'@'" + ip + "' WITH GRANT OPTION;\n"
11911189
+ "SELECT host, user FROM mysql.user;");
1192-
StringBuffer mysqlCmd = new StringBuffer("cat " + sourceFile.toString() + " | ");
1190+
StringBuffer mysqlCmd = new StringBuffer("cat " + sourceFile + " | ");
11931191
mysqlCmd.append(KUBERNETES_CLI + " exec -i -n ");
11941192
mysqlCmd.append(namespace);
11951193
mysqlCmd.append(" ");
11961194
mysqlCmd.append(podName);
11971195
mysqlCmd.append(" -- /bin/bash -c \"");
11981196
mysqlCmd.append("cat > /tmp/grant.sql\"");
1199-
//logger.info("mysql command {0}", mysqlCmd.toString());
12001197
result = assertDoesNotThrow(() -> exec(new String(mysqlCmd), false));
1201-
//logger.info("mysql returned {0}", result.toString());
12021198
logger.info("mysql returned EXIT value {0}", result.exitValue());
12031199
assertEquals(0, result.exitValue(), "mysql execution fails");
12041200
}
12051201

1206-
private void getDomainHealth() throws IOException, InterruptedException {
1202+
private void getDomainHealth() {
12071203
testUntil(
12081204
withStandardRetryPolicy,
12091205
() -> {

0 commit comments

Comments
 (0)