/** * Test that exporting twice overrides the previous files * * @throws Exception */ @Test public void testExportOverridesPreviousExport() throws Exception { closeFileHandlesInEtc(); resetInitialState(); String firstExportMessage = console.runCommand(EXPORT_COMMAND); File firstExport = getExportSubDirectory(getDefaultExportDirectory(), "system.properties").toFile(); long firstLength = firstExport.length(); FileUtils.copyFile(SYSTEM_PROPERTIES.toFile(), SYSTEM_PROPERTIES_COPY.toFile()); FileUtils.writeStringToFile(SYSTEM_PROPERTIES.toFile(), "testtesttest", true); String secondExportMessage = console.runCommand(EXPORT_COMMAND); File secondExport = getExportSubDirectory(getDefaultExportDirectory(), "system.properties").toFile(); long secondLength = secondExport.length(); assertThat( "The first export failed to export", firstExportMessage, not(containsString("Failed to export all configurations"))); assertThat( "The second export failed to export", secondExportMessage, not(containsString("Failed to export all configurations"))); assertThat( "The second failed to modify the first export's files.", firstLength, is(not(equalTo(secondLength)))); }
@Test public void testExport() throws Exception { closeFileHandlesInEtc(); resetInitialState(); console.runCommand(EXPORT_COMMAND); assertExportContents(getDefaultExportDirectory()); }
@Test public void testExportMetacards() throws Exception { closeFileHandlesInEtc(); resetInitialState(); List<String> metacardIds = ingestMetacardsForExport(); console.runCommand(EXPORT_COMMAND); assertExportCatalog(getDefaultExportDirectory().resolve("ddf.metacards")); console.runCommand(CATALOG_REMOVE_ALL_COMMAND, new RolePrincipal("admin")); console.runCommand( String.format( "%s \"%s\"", CATALOG_INGEST_COMMAND, getDefaultExportDirectory().resolve("ddf.metacards")), new RolePrincipal("admin")); assertMetacardsIngested(metacardIds.size()); }
@Test public void testConfigStatusImportSuccessful() throws Exception { closeFileHandlesInEtc(); resetInitialState(); addConfigurationFileAndWaitForSuccessfulProcessing( VALID_CONFIG_FILE_1, getFileContentAsStream(VALID_CONFIG_FILE_1)); String output = console.runCommand(STATUS_COMMAND); assertThat(output, containsString(SUCCESSFUL_IMPORT_MESSAGE)); assertThat(Files.exists(getPathToProcessedDirectory().resolve(VALID_CONFIG_FILE_1)), is(true)); }
@Test public void testConfigStatusFailedImportReimportSuccessful() throws Exception { closeFileHandlesInEtc(); resetInitialState(); InputStream is = getFileContentAsStream(VALID_CONFIG_FILE_1); InputStream invalidConfigFileAsInputStream = replaceTextInResource(is, "service.pid", "invalid"); String invalidConfigFileName = VALID_CONFIG_FILE_1; addConfigurationFileAndWaitForFailedProcessing( invalidConfigFileName, invalidConfigFileAsInputStream); String output1 = console.runCommand(STATUS_COMMAND); assertThat( output1, containsString(String.format(FAILED_IMPORT_MESSAGE, invalidConfigFileName))); assertThat(Files.exists(getPathToFailedDirectory().resolve(invalidConfigFileName)), is(true)); SECONDS.sleep(11); addConfigurationFileAndWaitForSuccessfulProcessing( VALID_CONFIG_FILE_1, getFileContentAsStream(VALID_CONFIG_FILE_1)); String output2 = console.runCommand(STATUS_COMMAND); assertThat(output2, containsString(SUCCESSFUL_IMPORT_MESSAGE)); assertThat(Files.exists(getPathToProcessedDirectory().resolve(VALID_CONFIG_FILE_1)), is(true)); }
@Test public void testExportToDirectory() throws Exception { closeFileHandlesInEtc(); resetInitialState(); String response = console.runCommand(EXPORT_COMMAND + " \"" + temporaryFolder.getRoot() + "\""); assertThat( String.format("Exporting current configurations to %s.", temporaryFolder.toString()), response, containsString("Successfully exported all configurations.")); assertExportContents(temporaryFolder.getRoot().toPath()); }
/** Tests that when ws-security directory is missing, export fails */ @Test public void testExportFailureWithoutWSSecurityDirectory() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.moveDirectory(WS_SECURITY.toFile(), WS_SECURITY_COPY.toFile()); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Should not have been able to export to %s.", getDefaultExportDirectory()), response, containsString("An error was encountered while executing this command.")); }
@Test public void testExportOnTopOfFile() throws Exception { closeFileHandlesInEtc(); resetInitialState(); File file = getDefaultExportDirectory().toFile(); file.createNewFile(); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Should not have been able to export to %s.", getDefaultExportDirectory()), response, containsString("Unable to create export directories.")); }
@Test public void testConfigStatusFailedImports() throws Exception { closeFileHandlesInEtc(); resetInitialState(); addConfigurationFileAndWaitForFailedProcessing( INVALID_CONFIG_FILE_1, getFileContentAsStream(INVALID_CONFIG_FILE_1)); addConfigurationFileAndWaitForFailedProcessing( INVALID_CONFIG_FILE_2, getFileContentAsStream(INVALID_CONFIG_FILE_2)); String output = console.runCommand(STATUS_COMMAND); assertThat(output, containsString(String.format(FAILED_IMPORT_MESSAGE, INVALID_CONFIG_FILE_1))); assertThat(output, containsString(String.format(FAILED_IMPORT_MESSAGE, INVALID_CONFIG_FILE_2))); assertThat(Files.exists(getPathToFailedDirectory().resolve(INVALID_CONFIG_FILE_1)), is(true)); assertThat(Files.exists(getPathToFailedDirectory().resolve(INVALID_CONFIG_FILE_2)), is(true)); }
/** * Tests that absolute path pointing outside ddfHome causes a warning * * @throws Exception */ @Test public void testExportWarningForAbsolutePathOutsideDdfHome() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.copyFile(SYSTEM_PROPERTIES.toFile(), new File(TEST_FILE)); System.setProperty(KEYSTORE_PROPERTY, ddfHome + File.separator + TEST_FILE); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Should not have been able to export to %s.", getDefaultExportDirectory()), response, containsString( String.format( "Failed to export all configurations to %s", getDefaultExportDirectory()))); }
/** * Tests that a saved configuration will be exported * * @throws Exception */ @Test public void testExportAfterSavingAConfiguration() throws Exception { closeFileHandlesInEtc(); resetInitialState(); managedServiceNewConfig1.addConfigurationFileAndWait(configAdmin); console.runCommand(EXPORT_COMMAND); assertThat( "Saved configuration should be exported.", getPathToExportedConfig(getDefaultExportDirectory(), managedServiceNewConfig1.pid) .toFile() .isFile(), is(true)); }
/** * Tests that when system properties file is missing, export fails * * @throws Exception */ @Test public void testExportFailureWithoutPDPDirectory() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.moveDirectory(PDP.toFile(), PDP_COPY.toFile()); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format( "Warning should have been returned when exporting to %s.", getDefaultExportDirectory()), response, containsString( "Path [etc" + FILE_SEPARATOR + "pdp] does not exist or cannot be read; therefore, it will not be included in the export.")); }
public void resetInitialState() throws Exception { FileUtils.deleteQuietly(getDefaultExportDirectory().toFile()); FileUtils.deleteQuietly(new File(TEST_FILE)); FileUtils.deleteQuietly(symbolicLink.toFile()); FileUtils.cleanDirectory(getPathToProcessedDirectory().toFile()); FileUtils.cleanDirectory(getPathToFailedDirectory().toFile()); restoreBackup(SYSTEM_PROPERTIES_COPY, SYSTEM_PROPERTIES); restoreBackup(USERS_PROPERTIES_COPY, USERS_PROPERTIES); restoreBackup(WS_SECURITY_COPY, WS_SECURITY); restoreBackup(PDP_COPY, PDP); System.setProperty( KEYSTORE_PROPERTY, "etc" + File.separator + "keystores" + File.separator + "serverKeystore.jks"); disableCrls(); console.runCommand(CATALOG_REMOVE_ALL_COMMAND, new RolePrincipal("admin")); }
/** * Tests that absolute path pointing inside ddfHome causes a warning * * @throws Exception */ @Test public void testExportWarningForAbsolutePathInsideDdfHome() throws Exception { closeFileHandlesInEtc(); resetInitialState(); System.setProperty( KEYSTORE_PROPERTY, ddfHome + File.separator + "etc" + File.separator + "keystores" + File.separator + "serverKeystore.jks"); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Should not have been able to export to %s.", getDefaultExportDirectory()), response, containsString( String.format( "Failed to export all configurations to %s", getDefaultExportDirectory()))); }
/** * Tests that paths containing symbolic links cause a warning * * @throws Exception */ @Test public void testExportWarningForSymbolicLinkPath() throws Exception { if (System.getProperty("os.name").startsWith("Win")) { // can't create symlinks in windows (borrowed from Apache commonsio) return; } resetInitialState(); FileUtils.copyFile(SYSTEM_PROPERTIES.toFile(), new File(TEST_FILE)); Files.createSymbolicLink(symbolicLink, Paths.get(TEST_FILE)); System.setProperty(KEYSTORE_PROPERTY, symbolicLink.toString()); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Should not have been able to export to %s.", getDefaultExportDirectory()), response, containsString( String.format( "Failed to export all configurations to %s", getDefaultExportDirectory()))); }