Skip to content

Commit a324539

Browse files
authored
Merge pull request #90 from simplelocalize/adjust-client-request
Adjust client request
2 parents 9ee0e8a + 09ae797 commit a324539

File tree

2 files changed

+149
-69
lines changed

2 files changed

+149
-69
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ jobs:
4040
- os: 'ubuntu-latest'
4141
label: 'linux'
4242
filename: 'simplelocalize-cli'
43+
downloadFilename: 'simplelocalize-cli-linux'
4344
- os: 'macos-latest'
4445
label: 'mac'
4546
filename: 'simplelocalize-cli'
47+
downloadFilename: 'simplelocalize-cli-mac'
4648
- os: 'windows-latest'
4749
label: 'windows'
4850
filename: 'simplelocalize-cli.exe'
51+
downloadFilename: 'simplelocalize-cli-windows.exe'
4952
runs-on: ${{ matrix.os }}
5053
steps:
5154
- uses: actions/checkout@v3
@@ -63,8 +66,10 @@ jobs:
6366
run: mvn -DskipTests -Pnative clean package
6467
- name: "Test executable"
6568
run: ./target/${{ matrix.filename }} --version
69+
- name: "Rename executable"
70+
run: mv ./target/${{ matrix.filename }} ./target/${{ matrix.downloadFilename }}
6671
- name: "Upload artifact"
6772
uses: actions/upload-artifact@v3
6873
with:
6974
name: simplelocalize-cli-${{ matrix.label }}
70-
path: ./target/${{ matrix.filename }}
75+
path: ./target/${{ matrix.downloadFilename }}

src/test/java/io/simplelocalize/cli/SimplelocalizeCliCommandTest.java

Lines changed: 143 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import org.junit.jupiter.api.BeforeAll;
66
import org.junit.jupiter.api.Test;
77
import org.junit.jupiter.api.extension.ExtendWith;
8-
import org.mockito.InjectMocks;
98
import org.mockito.junit.jupiter.MockitoExtension;
109
import org.mockserver.integration.ClientAndServer;
1110
import org.mockserver.matchers.Times;
11+
import picocli.CommandLine;
1212

1313
import java.io.IOException;
1414
import java.nio.charset.StandardCharsets;
@@ -17,7 +17,7 @@
1717
import java.util.List;
1818
import java.util.concurrent.TimeUnit;
1919

20-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
20+
import static org.junit.jupiter.api.Assertions.*;
2121
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
2222
import static org.mockserver.model.HttpRequest.request;
2323
import static org.mockserver.model.HttpResponse.response;
@@ -28,8 +28,6 @@ class SimplelocalizeCliCommandTest
2828

2929
private final static String MOCK_SERVER_BASE_URL = "http://localhost:1080";
3030
private static ClientAndServer mockServer;
31-
@InjectMocks
32-
private SimplelocalizeCliCommand sut;
3331

3432
@BeforeAll
3533
public static void startServer()
@@ -59,10 +57,21 @@ void extract()
5957
.withBody("{ 'msg': 'OK', data: { uniqueKeysProcessed: 1, processedWithWarnings: false } }")
6058
.withDelay(TimeUnit.MILLISECONDS, 200));
6159

60+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
61+
CommandLine commandLine = new CommandLine(app);
62+
String[] args = {"extract",
63+
"--apiKey", "my-api-key",
64+
"--baseUrl", MOCK_SERVER_BASE_URL,
65+
"--projectType", "yahoo/react-intl",
66+
"--searchDir", "./",
67+
};
68+
commandLine.parseArgs(args);
69+
6270
//when
63-
assertDoesNotThrow(() -> {
64-
sut.extract("my-api-key", "yahoo/react-intl", "./", MOCK_SERVER_BASE_URL);
65-
});
71+
int execute = commandLine.execute(args);
72+
73+
//then
74+
assertEquals(0, execute);
6675
}
6776

6877
@Test
@@ -98,22 +107,24 @@ void sync()
98107
);
99108

100109

110+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
111+
CommandLine commandLine = new CommandLine(app);
112+
String[] args = {"sync",
113+
"--apiKey", "my-api-key",
114+
"--baseUrl", MOCK_SERVER_BASE_URL,
115+
"--uploadPath", "./junit/mock-server/test.json",
116+
"--uploadFormat", "multi-language-json",
117+
"--downloadPath", "./junit/mock-server/test.json",
118+
"--downloadFormat", "java-properties",
119+
"--downloadOptions", "SPLIT_BY_NAMESPACES"
120+
};
121+
commandLine.parseArgs(args);
122+
101123
//when
102-
assertDoesNotThrow(() -> {
103-
sut.sync(
104-
"my-api-key",
105-
"./junit/mock-server/test.json",
106-
"multi-language-json",
107-
List.of(),
108-
"./junit/mock-server/test.json",
109-
"java-properties",
110-
List.of("SPLIT_BY_NAMESPACES"),
111-
null,
112-
null,
113-
null,
114-
MOCK_SERVER_BASE_URL
115-
);
116-
});
124+
int execute = commandLine.execute(args);
125+
126+
//then
127+
assertEquals(0, execute);
117128
}
118129

119130
@Test
@@ -134,21 +145,22 @@ void upload()
134145
.withDelay(TimeUnit.MILLISECONDS, 200)
135146
);
136147

148+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
149+
CommandLine commandLine = new CommandLine(app);
150+
String[] args = {"upload",
151+
"--apiKey", "my-api-key",
152+
"--baseUrl", MOCK_SERVER_BASE_URL,
153+
"--uploadPath", "./junit/mock-server/test.json",
154+
"--uploadFormat", "multi-language-json",
155+
"--uploadOptions", "SPLIT_BY_NAMESPACES"
156+
};
157+
commandLine.parseArgs(args);
158+
137159
//when
138-
assertDoesNotThrow(() -> {
139-
sut.upload(
140-
"my-api-key",
141-
"./junit/mock-server/test.json",
142-
"multi-language-json",
143-
false,
144-
false,
145-
false,
146-
List.of("SPLIT_BY_NAMESPACES"),
147-
null,
148-
null,
149-
MOCK_SERVER_BASE_URL
150-
);
151-
});
160+
int execute = commandLine.execute(args);
161+
162+
//then
163+
assertEquals(0, execute);
152164
}
153165

154166
@Test
@@ -168,20 +180,22 @@ void download()
168180
.withBody("{ \"files\": [{\"namespace\": \"my-file\", \"url\": \"https://simplelocalize.io\"}] }")
169181
.withDelay(TimeUnit.MILLISECONDS, 200)
170182
);
183+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
184+
CommandLine commandLine = new CommandLine(app);
185+
String[] args = {"download",
186+
"--apiKey", "my-api-key",
187+
"--baseUrl", MOCK_SERVER_BASE_URL,
188+
"--downloadPath", "./junit/mock-server/test.json",
189+
"--downloadFormat", "java-properties",
190+
"--downloadOptions", "SPLIT_BY_NAMESPACES"
191+
};
192+
commandLine.parseArgs(args);
171193

172194
//when
173-
assertDoesNotThrow(() -> {
174-
sut.download(
175-
"my-api-key",
176-
"./junit/mock-server/test.json",
177-
"java-properties",
178-
List.of("SPLIT_BY_NAMESPACES"),
179-
null,
180-
null,
181-
null,
182-
MOCK_SERVER_BASE_URL
183-
);
184-
});
195+
int execute = commandLine.execute(args);
196+
197+
//then
198+
assertEquals(0, execute);
185199
}
186200

187201
@Test
@@ -202,10 +216,21 @@ void pull() throws IOException
202216
.withDelay(TimeUnit.MILLISECONDS, 200)
203217
);
204218

219+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
220+
CommandLine commandLine = new CommandLine(app);
221+
String[] args = {"pull",
222+
"--apiKey", "my-api-key",
223+
"--baseUrl", MOCK_SERVER_BASE_URL,
224+
"--pullPath", "./my-path",
225+
"--environment", "latest",
226+
};
227+
commandLine.parseArgs(args);
228+
205229
//when
206-
assertDoesNotThrow(() -> {
207-
sut.pull("my-api-key", "./my-path", "latest", null, MOCK_SERVER_BASE_URL);
208-
});
230+
int execute = commandLine.execute(args);
231+
232+
//then
233+
assertEquals(0, execute);
209234
}
210235

211236
@Test
@@ -226,9 +251,16 @@ void status() throws IOException
226251
.withDelay(TimeUnit.MILLISECONDS, 200)
227252
);
228253

254+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
255+
CommandLine commandLine = new CommandLine(app);
256+
String[] args = {"status", "--apiKey", "my-api-key", "--baseUrl", MOCK_SERVER_BASE_URL};
257+
commandLine.parseArgs(args);
258+
229259
//when
230-
sut.status("my-api-key", MOCK_SERVER_BASE_URL);
260+
int execute = commandLine.execute(args);
231261

262+
//then
263+
assertEquals(0, execute);
232264
}
233265

234266
@Test
@@ -266,13 +298,20 @@ void purge() throws IOException
266298
""")
267299
.withDelay(TimeUnit.MILLISECONDS, 200)
268300
);
269-
301+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
302+
CommandLine commandLine = new CommandLine(app);
303+
String[] args = {"purge",
304+
"--apiKey", "my-api-key",
305+
"--baseUrl", MOCK_SERVER_BASE_URL,
306+
"--force"
307+
};
308+
commandLine.parseArgs(args);
270309

271310
//when
272-
assertDoesNotThrow(() -> {
273-
sut.purge("my-api-key", MOCK_SERVER_BASE_URL, true);
274-
});
311+
int execute = commandLine.execute(args);
275312

313+
//then
314+
assertEquals(0, execute);
276315
}
277316

278317
@Test
@@ -305,10 +344,20 @@ void publishLatest() throws IOException
305344
.withDelay(TimeUnit.MILLISECONDS, 200)
306345
);
307346

347+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
348+
CommandLine commandLine = new CommandLine(app);
349+
String[] args = {"publish",
350+
"--apiKey", "my-api-key",
351+
"--baseUrl", MOCK_SERVER_BASE_URL,
352+
"--environment", "_latest"
353+
};
354+
commandLine.parseArgs(args);
355+
308356
//when
309-
assertDoesNotThrow(() -> {
310-
sut.publish("my-api-key", "_latest", MOCK_SERVER_BASE_URL);
311-
});
357+
int execute = commandLine.execute(args);
358+
359+
//then
360+
assertEquals(0, execute);
312361
}
313362

314363
@Test
@@ -339,11 +388,20 @@ void publishProduction() throws IOException
339388
.withBody("{}")
340389
.withDelay(TimeUnit.MILLISECONDS, 200)
341390
);
391+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
392+
CommandLine commandLine = new CommandLine(app);
393+
String[] args = {"publish",
394+
"--apiKey", "my-api-key",
395+
"--baseUrl", MOCK_SERVER_BASE_URL,
396+
"--environment", "_production"
397+
};
398+
commandLine.parseArgs(args);
342399

343400
//when
344-
assertDoesNotThrow(() -> {
345-
sut.publish("my-api-key", "_production", MOCK_SERVER_BASE_URL);
346-
});
401+
int execute = commandLine.execute(args);
402+
403+
//then
404+
assertEquals(0, execute);
347405
}
348406

349407
@Test
@@ -386,11 +444,20 @@ void startAutoTranslation()
386444
""")
387445
.withDelay(TimeUnit.MILLISECONDS, 200)
388446
);
447+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
448+
CommandLine commandLine = new CommandLine(app);
449+
String[] args = {"auto-translate",
450+
"--apiKey", "my-api-key",
451+
"--baseUrl", MOCK_SERVER_BASE_URL,
452+
"--languageKeys", "pl,en"
453+
};
454+
commandLine.parseArgs(args);
389455

390456
//when
391-
assertDoesNotThrow(() -> {
392-
sut.startAutoTranslation("my-api-key", List.of("pl", "en"), MOCK_SERVER_BASE_URL);
393-
});
457+
int execute = commandLine.execute(args);
458+
459+
//then
460+
assertEquals(0, execute);
394461
}
395462

396463
@Test
@@ -410,10 +477,18 @@ void init()
410477
""")
411478
.withDelay(TimeUnit.MILLISECONDS, 200)
412479
);
480+
481+
SimplelocalizeCliCommand app = new SimplelocalizeCliCommand();
482+
CommandLine commandLine = new CommandLine(app);
483+
String[] args = {"init"};
484+
commandLine.parseArgs(args);
485+
486+
//then
487+
int execute = commandLine.execute(args);
488+
413489
//then
414-
assertDoesNotThrow(() -> {
415-
sut.init();
416-
});
490+
assertEquals(0, execute);
491+
assertTrue(Files.exists(Path.of("simplelocalize.yml")));
417492
}
418493

419494
}

0 commit comments

Comments
 (0)