Skip to content

Commit c607435

Browse files
committed
Add more unit test cases
1 parent cb6058f commit c607435

File tree

2 files changed

+101
-7
lines changed

2 files changed

+101
-7
lines changed

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandTest.java

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.scalar.db.dataloader.cli.command.dataexport;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46

57
import com.scalar.db.dataloader.core.DataLoaderError;
68
import com.scalar.db.dataloader.core.FileFormat;
79
import java.io.File;
810
import java.nio.file.Paths;
911
import org.junit.jupiter.api.AfterEach;
10-
import org.junit.jupiter.api.Assertions;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Test;
1314
import picocli.CommandLine;
@@ -54,8 +55,7 @@ void call_withBlankScalarDBConfigurationFile_shouldThrowException() {
5455
IllegalArgumentException.class,
5556
exportCommand::call,
5657
"Expected to throw FileNotFound exception as configuration path is invalid");
57-
Assertions.assertEquals(
58-
DataLoaderError.CONFIG_FILE_PATH_BLANK.buildMessage(), thrown.getMessage());
58+
assertEquals(DataLoaderError.CONFIG_FILE_PATH_BLANK.buildMessage(), thrown.getMessage());
5959
}
6060

6161
@Test
@@ -68,7 +68,7 @@ void call_withInvalidScalarDBConfigurationFile_shouldReturnOne() throws Exceptio
6868
exportCommand.outputDirectory = "";
6969
exportCommand.outputFileName = "sample.json";
7070
exportCommand.outputFormat = FileFormat.JSON;
71-
Assertions.assertEquals(1, exportCommand.call());
71+
assertEquals(1, exportCommand.call());
7272
}
7373

7474
@Test
@@ -97,7 +97,7 @@ void call_withBothStartExclusiveAndStartInclusive_shouldThrowException() {
9797
CommandLine.ParameterException.class,
9898
command::call,
9999
"Expected to throw ParameterException when both deprecated and new options are specified");
100-
Assertions.assertTrue(
100+
assertTrue(
101101
thrown
102102
.getMessage()
103103
.contains(
@@ -130,10 +130,68 @@ void call_withBothEndExclusiveAndEndInclusive_shouldThrowException() {
130130
CommandLine.ParameterException.class,
131131
command::call,
132132
"Expected to throw ParameterException when both deprecated and new options are specified");
133-
Assertions.assertTrue(
133+
assertTrue(
134134
thrown
135135
.getMessage()
136136
.contains(
137137
"Cannot specify both deprecated option '--end-exclusive' and new option '--end-inclusive'"));
138138
}
139+
140+
@Test
141+
void call_withOnlyDeprecatedStartExclusive_shouldApplyInvertedValue() {
142+
// Simulate command line parsing with only deprecated option
143+
String[] args = {
144+
"--config",
145+
"scalardb.properties",
146+
"--namespace",
147+
"scalar",
148+
"--table",
149+
"asset",
150+
"--format",
151+
"JSON",
152+
"--start-exclusive=true"
153+
};
154+
ExportCommand command = new ExportCommand();
155+
CommandLine cmd = new CommandLine(command);
156+
cmd.parseArgs(args);
157+
158+
// Verify the deprecated value was parsed
159+
assertEquals(true, command.startExclusiveDeprecated);
160+
161+
// Apply deprecated options (this is what the command does after validation)
162+
command.applyDeprecatedOptions();
163+
164+
// Verify the value was applied with inverted logic
165+
// start-exclusive=true should become start-inclusive=false
166+
assertEquals(false, command.scanStartInclusive);
167+
}
168+
169+
@Test
170+
void call_withOnlyDeprecatedEndExclusive_shouldApplyInvertedValue() {
171+
// Simulate command line parsing with only deprecated option
172+
String[] args = {
173+
"--config",
174+
"scalardb.properties",
175+
"--namespace",
176+
"scalar",
177+
"--table",
178+
"asset",
179+
"--format",
180+
"JSON",
181+
"--end-exclusive=false"
182+
};
183+
ExportCommand command = new ExportCommand();
184+
CommandLine cmd = new CommandLine(command);
185+
cmd.parseArgs(args);
186+
187+
// Verify the deprecated value was parsed
188+
assertEquals(false, command.endExclusiveDeprecated);
189+
190+
// Apply deprecated options (this is what the command does after validation)
191+
command.applyDeprecatedOptions();
192+
193+
// Verify the value was applied with inverted logic
194+
// end-exclusive=false should become end-inclusive=true
195+
assertEquals(true, command.scanEndInclusive);
196+
}
139197
}

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.scalar.db.dataloader.cli.command.dataimport;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
46

57
import com.scalar.db.dataloader.core.FileFormat;
68
import com.scalar.db.dataloader.core.dataimport.ImportMode;
@@ -107,10 +109,44 @@ void call_withBothThreadsAndMaxThreads_shouldThrowException() throws Exception {
107109
CommandLine.ParameterException.class,
108110
command::call,
109111
"Expected to throw ParameterException when both deprecated and new options are specified");
110-
org.junit.jupiter.api.Assertions.assertTrue(
112+
assertTrue(
111113
thrown
112114
.getMessage()
113115
.contains(
114116
"Cannot specify both deprecated option '--threads' and new option '--max-threads'"));
115117
}
118+
119+
@Test
120+
void call_withOnlyDeprecatedThreads_shouldApplyValue() throws Exception {
121+
Path configFile = tempDir.resolve("config.properties");
122+
Files.createFile(configFile);
123+
Path importFile = tempDir.resolve("import.json");
124+
Files.createFile(importFile);
125+
126+
// Simulate command line parsing with only deprecated option
127+
String[] args = {
128+
"--config",
129+
configFile.toString(),
130+
"--file",
131+
importFile.toString(),
132+
"--namespace",
133+
"sample",
134+
"--table",
135+
"table",
136+
"--threads",
137+
"12"
138+
};
139+
ImportCommand command = new ImportCommand();
140+
CommandLine cmd = new CommandLine(command);
141+
cmd.parseArgs(args);
142+
143+
// Verify the deprecated value was parsed
144+
assertEquals(12, command.threadsDeprecated);
145+
146+
// Apply deprecated options (this is what the command does after validation)
147+
command.applyDeprecatedOptions();
148+
149+
// Verify the value was applied to maxThreads
150+
assertEquals(12, command.maxThreads);
151+
}
116152
}

0 commit comments

Comments
 (0)