/** The 'force_overwrite' parameter forces existing files to be overwritten. */ @Test public void testForceOverwrite() { // make sure target directory exists and is empty File dumpDir = new File("/tmp/forceDump"); if (dumpDir.exists()) { for (File c : dumpDir.listFiles()) { c.delete(); } dumpDir.delete(); } dumpDir.mkdir(); // initial dump to target directory ExportResponse response = executeDumpRequest("{\"directory\": \"/tmp/forceDump\"}"); List<Map<String, Object>> infos = getExports(response); assertEquals(2, infos.size()); assertEquals(0, response.getShardFailures().length); // second attempt to dump will fail response = executeDumpRequest("{\"directory\": \"/tmp/forceDump\"}"); infos = getExports(response); assertEquals(0, infos.size()); assertEquals(2, response.getShardFailures().length); // if force_overwrite == true a second dump will succeed response = executeDumpRequest("{\"directory\": \"/tmp/forceDump\", \"force_overwrite\":true}"); infos = getExports(response); assertEquals(2, infos.size()); assertEquals(0, response.getShardFailures().length); }
/** Invalid parameters lead to an error response. */ @Test public void testBadParserArgument() { ExportResponse response = executeDumpRequest("{\"badparam\":\"somevalue\"}"); List<Map<String, Object>> infos = getExports(response); assertEquals(0, infos.size()); assertEquals(2, response.getShardFailures().length); assertTrue( response.getShardFailures()[0].reason().contains("No parser for element [badparam]")); assertTrue( response.getShardFailures()[1].reason().contains("No parser for element [badparam]")); }
/** The target directory must exist */ @Test public void testDirMustExist() { ExportResponse response = executeDumpRequest("{\"directory\": \"/tmp/doesnotexist\"}"); List<Map<String, Object>> infos = getExports(response); assertEquals(0, infos.size()); assertEquals(2, response.getShardFailures().length); assertTrue( response .getShardFailures()[0] .reason() .contains("Target folder /tmp/doesnotexist does not exist")); assertTrue( response .getShardFailures()[1] .reason() .contains("Target folder /tmp/doesnotexist does not exist")); }