Skip to content

Commit 444c969

Browse files
committed
Added unit tests
1 parent 3852a5f commit 444c969

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommandTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,79 @@ void call_withOnlyDeprecatedThreads_shouldApplyValue() throws Exception {
149149
// Verify the value was applied to maxThreads
150150
assertEquals(12, command.maxThreads);
151151
}
152+
153+
@Test
154+
void call_withBothLogSuccessAndEnableLogSuccess_shouldThrowException() throws Exception {
155+
Path configFile = tempDir.resolve("config.properties");
156+
Files.createFile(configFile);
157+
Path importFile = tempDir.resolve("import.json");
158+
Files.createFile(importFile);
159+
160+
// Simulate command line parsing with both deprecated and new options
161+
String[] args = {
162+
"--config",
163+
configFile.toString(),
164+
"--file",
165+
importFile.toString(),
166+
"--namespace",
167+
"sample",
168+
"--table",
169+
"table",
170+
"--log-success",
171+
"--enable-log-success",
172+
"--max-threads",
173+
"16"
174+
};
175+
ImportCommand command = new ImportCommand();
176+
CommandLine cmd = new CommandLine(command);
177+
// Parse args - this will trigger our validation
178+
cmd.parseArgs(args);
179+
180+
// Now call the command, which should throw the validation error
181+
CommandLine.ParameterException thrown =
182+
assertThrows(
183+
CommandLine.ParameterException.class,
184+
command::call,
185+
"Expected to throw ParameterException when both deprecated and new options are specified");
186+
assertTrue(
187+
thrown
188+
.getMessage()
189+
.contains(
190+
"Cannot specify both deprecated option '--log-success' and new option '--enable-log-success'"));
191+
}
192+
193+
@Test
194+
void call_withOnlyDeprecatedLogSuccess_shouldApplyValue() throws Exception {
195+
Path configFile = tempDir.resolve("config.properties");
196+
Files.createFile(configFile);
197+
Path importFile = tempDir.resolve("import.json");
198+
Files.createFile(importFile);
199+
200+
// Simulate command line parsing with only deprecated option
201+
String[] args = {
202+
"--config",
203+
configFile.toString(),
204+
"--file",
205+
importFile.toString(),
206+
"--namespace",
207+
"sample",
208+
"--table",
209+
"table",
210+
"--max-threads",
211+
"12",
212+
"--log-success"
213+
};
214+
ImportCommand command = new ImportCommand();
215+
CommandLine cmd = new CommandLine(command);
216+
cmd.parseArgs(args);
217+
218+
// Verify the deprecated value was parsed
219+
assertTrue(command.logSuccessRecordsDeprecated);
220+
221+
// Apply deprecated options (this is what the command does after validation)
222+
command.applyDeprecatedOptions();
223+
224+
// Verify the value was applied to enable-log-success
225+
assertTrue(command.enableLogSuccessRecords);
226+
}
152227
}

0 commit comments

Comments
 (0)