Skip to content

Commit 6e0ac92

Browse files
committed
refactor (OracleContainer): withOraclePassword rename to withSystemPassword
refactor (OracleContainer): oraclePassword rename to systemPassword refactor (OracleContainer): oraclePasswordExplicitlySet rename to systemPasswordExplicitlySet
1 parent ec95b8f commit 6e0ac92

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

modules/oracle-free/src/main/java/org/testcontainers/oracle/OracleContainer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
6060

6161
/**
6262
* Password for Oracle system user (e.g. SYSTEM/SYS). Defaults to {@link #APP_USER_PASSWORD}
63-
* for backwards compatibility, but can be customized independently via {@link #withOraclePassword(String)}.
63+
* for backwards compatibility, but can be customized independently via {@link #withSystemPassword(String)}.
6464
*/
6565
private String oraclePassword = APP_USER_PASSWORD;
6666

6767
/**
68-
* Tracks whether {@link #withOraclePassword(String)} was called to avoid overriding
68+
* Tracks whether {@link #withSystemPassword(String)} was called to avoid overriding
6969
* the system password when {@link #withPassword(String)} is used for the application user only.
7070
*/
71-
private boolean oraclePasswordExplicitlySet = false;
71+
private boolean systemPasswordExplicitlySet = false;
7272

7373
private boolean usingSid = false;
7474

@@ -155,9 +155,9 @@ public OracleContainer withPassword(String password) {
155155
throw new IllegalArgumentException("Password cannot be null or empty");
156156
}
157157
this.password = password;
158-
// Maintain backwards compatibility: if oracle password wasn't set explicitly,
158+
// Maintain backwards compatibility: if system password wasn't set explicitly,
159159
// align it with the application user's password.
160-
if (!oraclePasswordExplicitlySet) {
160+
if (!systemPasswordExplicitlySet) {
161161
this.oraclePassword = password;
162162
}
163163
return self();
@@ -170,12 +170,12 @@ public OracleContainer withPassword(String password) {
170170
* @param oraclePassword password for SYSTEM/SYS users inside the container
171171
* @return this container instance
172172
*/
173-
public OracleContainer withOraclePassword(String oraclePassword) {
173+
public OracleContainer withSystemPassword(String oraclePassword) {
174174
if (StringUtils.isEmpty(oraclePassword)) {
175175
throw new IllegalArgumentException("Oracle password cannot be null or empty");
176176
}
177177
this.oraclePassword = oraclePassword;
178-
this.oraclePasswordExplicitlySet = true;
178+
this.systemPasswordExplicitlySet = true;
179179
return self();
180180
}
181181

modules/oracle-free/src/test/java/org/testcontainers/junit/oracle/SimpleOracleTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,25 @@ void testSIDAndCustomPassword() throws SQLException {
112112
}
113113

114114
@Test
115-
public void testSeparateSystemAndAppPasswords() throws SQLException {
116-
// SID mode should use system password
115+
public void testWithSystemPassword() throws SQLException {
117116
try (
118-
OracleContainer oracleSid = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
117+
OracleContainer oracle = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
119118
.usingSid()
120-
.withOraclePassword("SysP@ss1!")
119+
.withSystemPassword("SysP@ss1!")
121120
.withPassword("AppP@ss1!")
122121
) {
123-
runTestSystemUser(oracleSid, "freepdb1", "system", "SysP@ss1!");
122+
runTestSystemUser(oracle, "freepdb1", "system", "SysP@ss1!");
124123
}
124+
}
125125

126-
// Non-SID mode should use application user's password
126+
@Test
127+
public void testWithPassword() throws SQLException {
127128
try (
128-
OracleContainer oraclePdb = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
129-
.withOraclePassword("SysP@ss2!")
129+
OracleContainer oracle = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
130+
.withSystemPassword("SysP@ss2!")
130131
.withPassword("AppP@ss2!")
131132
) {
132-
runTest(oraclePdb, "freepdb1", "test", "AppP@ss2!");
133+
runTest(oracle, "freepdb1", "test", "AppP@ss2!");
133134
}
134135
}
135136

modules/oracle-xe/src/main/java/org/testcontainers/containers/OracleContainer.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
6363

6464
/**
6565
* Password for Oracle system user (e.g. SYSTEM/SYS). Defaults to {@link #APP_USER_PASSWORD}
66-
* for backwards compatibility, but can be customized independently via {@link #withOraclePassword(String)}.
66+
* for backwards compatibility, but can be customized independently via {@link #withSystemPassword(String)}.
6767
*/
68-
private String oraclePassword = APP_USER_PASSWORD;
68+
private String systemPassword = APP_USER_PASSWORD;
6969

7070
/**
71-
* Tracks whether {@link #withOraclePassword(String)} was called to avoid overriding
71+
* Tracks whether {@link #withSystemPassword(String)} was called to avoid overriding
7272
* the system password when {@link #withPassword(String)} is used for the application user only.
7373
*/
74-
private boolean oraclePasswordExplicitlySet = false;
74+
private boolean systemPasswordExplicitlySet = false;
7575

7676
private boolean usingSid = false;
7777

@@ -138,7 +138,7 @@ public String getUsername() {
138138
@Override
139139
public String getPassword() {
140140
// When connecting via SID we authenticate as SYSTEM. Use the dedicated system password.
141-
return isUsingSid() ? oraclePassword : password;
141+
return isUsingSid() ? systemPassword : password;
142142
}
143143

144144
@Override
@@ -170,8 +170,8 @@ public OracleContainer withPassword(String password) {
170170
this.password = password;
171171
// Maintain backwards compatibility: if oracle password wasn't set explicitly,
172172
// align it with the application user's password.
173-
if (!oraclePasswordExplicitlySet) {
174-
this.oraclePassword = password;
173+
if (!systemPasswordExplicitlySet) {
174+
this.systemPassword = password;
175175
}
176176
return self();
177177
}
@@ -183,12 +183,12 @@ public OracleContainer withPassword(String password) {
183183
* @param oraclePassword password for SYSTEM/SYS users inside the container
184184
* @return this container instance
185185
*/
186-
public OracleContainer withOraclePassword(String oraclePassword) {
186+
public OracleContainer withSystemPassword(String oraclePassword) {
187187
if (StringUtils.isEmpty(oraclePassword)) {
188188
throw new IllegalArgumentException("Oracle password cannot be null or empty");
189189
}
190-
this.oraclePassword = oraclePassword;
191-
this.oraclePasswordExplicitlySet = true;
190+
this.systemPassword = oraclePassword;
191+
this.systemPasswordExplicitlySet = true;
192192
return self();
193193
}
194194

@@ -238,7 +238,7 @@ public String getTestQueryString() {
238238
@Override
239239
protected void configure() {
240240
// Configure system user password independently from application user's password
241-
withEnv("ORACLE_PASSWORD", oraclePassword);
241+
withEnv("ORACLE_PASSWORD", systemPassword);
242242

243243
// Only set ORACLE_DATABASE if different than the default.
244244
if (databaseName != DEFAULT_DATABASE_NAME) {

modules/oracle-xe/src/test/java/org/testcontainers/junit/oracle/SimpleOracleTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ private void runTest(OracleContainer container, String databaseName, String user
3333

3434
private void runTestSystemUser(OracleContainer container, String databaseName, String username, String password)
3535
throws SQLException {
36-
//Test config was honored
3736
assertThat(container.getDatabaseName()).isEqualTo(databaseName);
3837
assertThat(container.getUsername()).isEqualTo(username);
3938
assertThat(container.getPassword()).isEqualTo(password);
4039

41-
//Test we can get a connection and execute a system-level command
4240
container.start();
4341
ResultSet resultSet = performQuery(container, "GRANT DBA TO " + username);
4442
int resultSetInt = resultSet.getInt(1);
@@ -113,11 +111,10 @@ void testSIDAndCustomPassword() throws SQLException {
113111

114112
@Test
115113
public void testSeparateSystemAndAppPasswords() throws SQLException {
116-
// SID mode should use system password
117114
try (
118115
OracleContainer oracleSid = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
119116
.usingSid()
120-
.withOraclePassword("SysP@ss1!")
117+
.withSystemPassword("SysP@ss1!")
121118
.withPassword("AppP@ss1!")
122119
) {
123120
runTestSystemUser(oracleSid, "xepdb1", "system", "SysP@ss1!");
@@ -126,7 +123,7 @@ public void testSeparateSystemAndAppPasswords() throws SQLException {
126123
// Non-SID mode should use application user's password
127124
try (
128125
OracleContainer oraclePdb = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
129-
.withOraclePassword("SysP@ss2!")
126+
.withSystemPassword("SysP@ss2!")
130127
.withPassword("AppP@ss2!")
131128
) {
132129
runTest(oraclePdb, "xepdb1", "test", "AppP@ss2!");

0 commit comments

Comments
 (0)