#4319: FromXmlTest.java

tools/org.projectforge.tools.schemaexp/src/test/java/org/projectforge/tools/schemaexp/FromXmlTest.java

Path: tools/org.projectforge.tools.schemaexp/src/test/java/org/projectforge/tools/schemaexp/FromXmlTest.java

Type: Manual dev test · Lines: 13

Purpose: Developer utility for importing an XML dump into a clean PostgreSQL database. Uses postgres2 (secondary instance) to avoid destroying the primary development database.

Source: GitHub

13 lines · 10 code · 2 comments · 1 blank
CommitDateMessage
9ebb885222016-07-18Initial commit
DESTRUCTIVE: Uses -cleardb — drops ALL tables before import. Only run against postgres2, never postgres.

What it does

The import counterpart of ToXmlTest. Forces the postgres2 data source (a separate, disposable PostgreSQL instance), then invokes SchemaExpMain with three flags: -imp (import), -cleardb (drop all tables first), and -insertall (insert all entities from XML). The current code imports from init-test-data-new.xml — the pre-generated test data file distributed with the webapp. An older commented-out line shows the same test importing from target/pf-dump.xml (the output of ToXmlTest).

//  @Test
public void testImp() {
  System.getProperties().setProperty("projectForgeDs", "postgres2");
  //SchemaExpMain.main(new String[] { "-imp", "-cleardb", "-insertall", "target/pf-dump.xml" });
  SchemaExpMain.main(new String[] { "-imp", "-cleardb", "-insertall",
      "../../projectforge-webapp/src/main/resources/data/init-test-data-new.xml" });
}

Line 8: postgres2 — deliberately a DIFFERENT database from the export test's postgres. This prevents accidentally destroying your primary development database.

Line 10: The commented-out alternate path documents the export→import workflow: first run ToXmlTest to generate pf-dump.xml, then run this test to import it.

Lines 10-11: Imports from init-test-data-new.xml — the canonical test seed file. When a user selects "Test system" during ProjectForge setup, the wizard imports this exact file to populate the database with sample data. This test validates that the import pipeline correctly handles real-world seed data.

Path traversal: ../../projectforge-webapp/src/main/resources/data/ — navigates from tools/org.projectforge.tools.schemaexp/ up two directories, then into the webapp module. Fragile relative path — depends on the working directory being the tool's root.