|
1 | 1 | package com.marklogic.appdeployer.command.schemas;
|
2 | 2 |
|
3 |
| -import org.junit.After; |
4 |
| -import org.junit.Test; |
5 |
| - |
6 | 3 | import com.marklogic.appdeployer.AbstractAppDeployerTest;
|
7 | 4 | import com.marklogic.appdeployer.command.Command;
|
8 | 5 | import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand;
|
9 | 6 | import com.marklogic.appdeployer.command.databases.DeploySchemasDatabaseCommand;
|
10 | 7 | import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand;
|
11 |
| -import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand; |
12 | 8 | import com.marklogic.client.DatabaseClient;
|
13 | 9 | import com.marklogic.client.document.GenericDocumentManager;
|
14 | 10 | import com.marklogic.client.io.DocumentMetadataHandle;
|
| 11 | +import org.junit.After; |
| 12 | +import org.junit.Test; |
| 13 | + |
| 14 | +import java.io.File; |
| 15 | +import java.io.FileFilter; |
15 | 16 |
|
16 | 17 | public class LoadSchemasTest extends AbstractAppDeployerTest {
|
17 | 18 |
|
18 |
| - @Test |
19 |
| - public void testSchemaLoading() { |
20 |
| - initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(), |
21 |
| - new DeployContentDatabasesCommand(1), new DeployRestApiServersCommand(), newCommand()); |
22 |
| - appDeployer.deploy(appConfig); |
| 19 | + @Test |
| 20 | + public void testSchemaLoading() { |
| 21 | + initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(), |
| 22 | + new DeployContentDatabasesCommand(1), newCommand()); |
| 23 | + appDeployer.deploy(appConfig); |
| 24 | + |
| 25 | + DatabaseClient client = appConfig.newSchemasDatabaseClient(); |
23 | 26 |
|
24 |
| - DatabaseClient client = appConfig.newSchemasDatabaseClient(); |
| 27 | + GenericDocumentManager docMgr = client.newDocumentManager(); |
25 | 28 |
|
26 |
| - GenericDocumentManager docMgr = client.newDocumentManager(); |
| 29 | + assertNull("Rules document loaded", docMgr.exists("notExists")); |
| 30 | + assertNotNull("Rules document loaded", docMgr.exists("/my.rules").getUri()); |
| 31 | + assertNotNull("XSD document loaded", docMgr.exists("/x.xsd").getUri()); |
| 32 | + assertNull(docMgr.exists("/.do-not-load")); |
| 33 | + assertNull(docMgr.exists(".do-not-load")); |
| 34 | + } |
27 | 35 |
|
28 |
| - assertNull("Rules document loaded", docMgr.exists("notExists")); |
29 |
| - assertNotNull("Rules document loaded", docMgr.exists("/my.rules").getUri()); |
30 |
| - assertNotNull("XSD document loaded", docMgr.exists("/x.xsd").getUri()); |
31 |
| - } |
| 36 | + @Test |
| 37 | + public void testCustomSchemasPathWithCustomFileFilter() { |
| 38 | + initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(), |
| 39 | + new DeployContentDatabasesCommand(1), newCommand()); |
32 | 40 |
|
33 |
| - @Test |
34 |
| - public void testSchemaCustomSchemasPath() { |
35 |
| - initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(), |
36 |
| - new DeployContentDatabasesCommand(1), new DeployRestApiServersCommand(), newCommand()); |
37 |
| - appConfig.setSchemasPath("src/test/resources/schemas-marklogic9"); |
38 |
| - appDeployer.deploy(appConfig); |
| 41 | + appConfig.setSchemasPath("src/test/resources/schemas-marklogic9"); |
| 42 | + appConfig.setSchemasFileFilter(new CustomFileFilter()); |
| 43 | + appDeployer.deploy(appConfig); |
39 | 44 |
|
40 |
| - DatabaseClient client = appConfig.newSchemasDatabaseClient(); |
| 45 | + DatabaseClient client = appConfig.newSchemasDatabaseClient(); |
41 | 46 |
|
42 |
| - GenericDocumentManager docMgr = client.newDocumentManager(); |
| 47 | + GenericDocumentManager docMgr = client.newDocumentManager(); |
43 | 48 |
|
44 |
| - assertNotNull("TDEXML document loaded", docMgr.exists("/x.tdex").getUri()); |
45 |
| - assertNotNull("TDEJSON document loaded", docMgr.exists("/x.tdej").getUri()); |
| 49 | + assertNotNull("TDEXML document loaded", docMgr.exists("/x.tdex").getUri()); |
| 50 | + assertNotNull("TDEJSON document loaded", docMgr.exists("/x.tdej").getUri()); |
| 51 | + assertNull(docMgr.exists("/to-be-ignored/test.xml")); |
| 52 | + assertNull(docMgr.exists("to-be-ignored/test.xml")); |
46 | 53 |
|
47 |
| - for (String uri : new String[] { "/x.tdex", "/x.tdej" }) { |
48 |
| - DocumentMetadataHandle h = docMgr.readMetadata(uri, new DocumentMetadataHandle()); |
49 |
| - assertEquals("Files ending in tdex and tdej go into a special collection", "http://marklogic.com/xdmp/tde", |
50 |
| - h.getCollections().iterator().next()); |
51 |
| - } |
52 |
| - } |
| 54 | + for (String uri : new String[]{"/x.tdex", "/x.tdej"}) { |
| 55 | + DocumentMetadataHandle h = docMgr.readMetadata(uri, new DocumentMetadataHandle()); |
| 56 | + assertEquals("Files ending in tdex and tdej go into a special collection", "http://marklogic.com/xdmp/tde", |
| 57 | + h.getCollections().iterator().next()); |
| 58 | + } |
| 59 | + } |
53 | 60 |
|
54 |
| - @After |
55 |
| - public void cleanup() { |
56 |
| - undeploySampleApp(); |
57 |
| - } |
| 61 | + @After |
| 62 | + public void cleanup() { |
| 63 | + undeploySampleApp(); |
| 64 | + } |
58 | 65 |
|
59 |
| - private Command newCommand() { |
60 |
| - return new LoadSchemasCommand(); |
61 |
| - } |
| 66 | + private Command newCommand() { |
| 67 | + return new LoadSchemasCommand(); |
| 68 | + } |
| 69 | + |
| 70 | +} |
62 | 71 |
|
| 72 | +class CustomFileFilter implements FileFilter { |
| 73 | + @Override |
| 74 | + public boolean accept(File pathname) { |
| 75 | + return !(pathname.isDirectory() && "to-be-ignored".equals(pathname.getName())); |
| 76 | + } |
63 | 77 | }
|
0 commit comments