MCPcopy Create free account
hub / github.com/BaseXdb/basex / DbModuleTest

Class DbModuleTest

basex-core/src/test/java/org/basex/query/func/DbModuleTest.java:30–1242  ·  view source on GitHub ↗

This class tests the functions of the Database Module. @author BaseX Team, BSD License @author Christian Gruen

Source from the content-addressed store, hash-verified

28 * @author Christian Gruen
29 */
30public final class DbModuleTest extends SandboxTest {
31 /** Invalid characters for database names. */
32 private static final char[] INVALID = ",*?;\\/:\"<>|".toCharArray();
33 /** Test file. */
34 private static final String XML = "src/test/resources/input.xml";
35 /** Test file. */
36 private static final String CSV = "src/test/resources/input.csv";
37 /** Test folder. */
38 private static final String FLDR = "src/test/resources/dir/";
39 /** Number of XML files for folder. */
40 private static final int XMLFILES;
41
42 static {
43 int files = 0;
44 for(final IOFile file : new IOFile(FLDR).children()) {
45 if(file.name().endsWith(IO.XMLSUFFIX)) ++files;
46 }
47 XMLFILES = files;
48 }
49
50 /** Initializes a test. */
51 @BeforeEach public void initTest() {
52 execute(new CreateDB(NAME, XML));
53 }
54
55 /** Finalizes a test. */
56 @AfterEach public void finish() {
57 set(MainOptions.TEXTINCLUDE, "");
58 set(MainOptions.ATTRINCLUDE, "");
59 set(MainOptions.TOKENINCLUDE, "");
60 set(MainOptions.FTINCLUDE, "");
61 execute(new DropDB(NAME));
62 }
63
64 /** Test method. */
65 @Test public void add() {
66 final Function func = _DB_ADD;
67 query("count(" + COLLECTION.args(NAME) + ")", 1);
68 query(func.args(NAME, XML));
69 query("count(" + COLLECTION.args(NAME) + ")", 2);
70
71 query(func.args(NAME, " <root/>", "t1.xml"));
72 query("count(" + COLLECTION.args(NAME + "/t1.xml") + "/root)", 1);
73
74 query(func.args(NAME, " document { <root/> }", "t2.xml"));
75 query("count(" + COLLECTION.args(NAME + "/t2.xml") + "/root)", 1);
76
77 query(func.args(NAME, " <root/>", "test/t3.xml"));
78 query("count(" + COLLECTION.args(NAME + "/test/t3.xml") + "/root)", 1);
79
80 query(func.args(NAME, XML, "in/"));
81 query("count(" + COLLECTION.args(NAME + "/in/input.xml") + "/html)", 1);
82
83 query(func.args(NAME, XML, "test/t4.xml"));
84 query("count(" + COLLECTION.args(NAME + "/test/t4.xml") + "/html)", 1);
85
86 query(func.args(NAME, FLDR, "test/dir"));
87 query("count(" + COLLECTION.args(NAME + "/test/dir") + ")", XMLFILES);

Callers

nothing calls this directly

Calls 3

nameMethod · 0.65
childrenMethod · 0.45
endsWithMethod · 0.45

Tested by

no test coverage detected