|
1 | 1 | package com.marklogic.client.ext.schemasloader.impl;
|
2 | 2 |
|
| 3 | +import com.marklogic.client.FailedRequestException; |
3 | 4 | import com.marklogic.client.ext.batch.RestBatchWriter;
|
4 | 5 | import com.marklogic.client.ext.file.DocumentFile;
|
5 | 6 | import com.marklogic.client.ext.helper.ClientHelper;
|
|
9 | 10 | import java.nio.file.Paths;
|
10 | 11 | import java.util.List;
|
11 | 12 |
|
12 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
13 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 13 | +import static org.junit.jupiter.api.Assertions.*; |
14 | 14 |
|
15 | 15 | public class LoadSchemasTest extends AbstractSchemasTest {
|
16 | 16 |
|
17 | 17 | @Test
|
18 | 18 | public void test() {
|
19 | 19 | DefaultSchemasLoader loader = new DefaultSchemasLoader(client);
|
20 |
| - RestBatchWriter writer = (RestBatchWriter)loader.getBatchWriter(); |
| 20 | + RestBatchWriter writer = (RestBatchWriter) loader.getBatchWriter(); |
21 | 21 | assertEquals(1, writer.getThreadCount(), "Should default to 1 so that any error from loading a document " +
|
22 | 22 | "into a schemas database is immediately thrown to the client");
|
23 | 23 |
|
@@ -57,4 +57,25 @@ public void testTemplateBatchInsert() {
|
57 | 57 | assertTrue(handle.getPermissions().get("rest-writer").contains(DocumentMetadataHandle.Capability.UPDATE),
|
58 | 58 | "Permissions defined in permissions.properties should be applied on the document");
|
59 | 59 | }
|
| 60 | + |
| 61 | + @Test |
| 62 | + public void invalidClientAndNoFilesToLoad() { |
| 63 | + DefaultSchemasLoader loader = new DefaultSchemasLoader(newClient("invalid-database-doesnt-exist")); |
| 64 | + List<DocumentFile> files = loader.loadSchemas(Paths.get("src", "test", "resources", "no-schemas").toString()); |
| 65 | + assertEquals(0, files.size(), |
| 66 | + "When there aren't any files to load, then no error should be thrown when the client is invalid (which in " + |
| 67 | + "this scenario is due to a missing database); instead, an empty list should be returned"); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void invalidClientWithFilesToLoad() { |
| 72 | + DefaultSchemasLoader loader = new DefaultSchemasLoader(newClient("invalid-database-doesnt-exist")); |
| 73 | + FailedRequestException ex = assertThrows(FailedRequestException.class, |
| 74 | + () -> loader.loadSchemas(Paths.get("src", "test", "resources", "good-schemas").toString())); |
| 75 | + |
| 76 | + String message = ex.getServerMessage(); |
| 77 | + assertTrue(message.startsWith("XDMP-NOSUCHDB: No such database invalid-database-doesnt-exist"), |
| 78 | + "Because there are files to load and the client points to a database that doesn't exist, an error " + |
| 79 | + "should be thrown with no files loaded; actual message: " + message); |
| 80 | + } |
60 | 81 | }
|
0 commit comments