From daf79793fe27b5194d1dee338f3a9f12e18f023d Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Wed, 27 Jun 2007 14:05:11 +0000
Subject: [PATCH] Reenabling the quicksetup tests. The problems encountered last week have apparently been resolved. All tests pass when performing a complete run of the tests using the 'testall' target along with the BUILD_NUMBER system property.
---
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/ConfigurationTest.java | 26 +-
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/TestUtilities.java | 15
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/ServerControllerTest.java | 18
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/QuickSetupTestCase.java | 6
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/FileManagerTest.java | 502 +++++++++++++++++++++++++++++++++++++++++++++
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/InstallationTest.java | 80 +++---
6 files changed, 574 insertions(+), 73 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/ConfigurationTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/ConfigurationTest.java
index 567db29..6efc4a2 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/ConfigurationTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/ConfigurationTest.java
@@ -36,67 +36,67 @@
/**
* Configuration Tester.
*/
-@Test(enabled=false, groups = {"slow"})
+@Test(groups = {"slow"})
public class ConfigurationTest extends QuickSetupTestCase {
Configuration config;
@BeforeClass
public void setUp() throws Exception {
- config = Utils.getInstallation().getCurrentConfiguration();
+ config = TestUtilities.getInstallation().getCurrentConfiguration();
}
- @Test(enabled=false)
+ @Test
public void testGetDirectoryManagerDns() throws IOException {
Set<String> dns = config.getDirectoryManagerDns();
assertTrue(dns.size() > 0);
}
- @Test(enabled=false)
+ @Test
public void testGetPort() throws IOException {
- assertTrue(Utils.ldapPort.equals(config.getPort()));
+ assertTrue(TestUtilities.ldapPort.equals(config.getPort()));
}
- @Test(enabled=false)
+ @Test
public void testGetSecurePort() throws IOException {
// TODO: something more useful
config.getSecurePort();
}
- @Test(enabled=false)
+ @Test
public void testGetLogPaths() throws IOException {
// TODO: something more useful
config.getLogPaths();
}
- @Test(enabled=false)
+ @Test
public void testHasBeenModified() throws IOException {
assertTrue(config.hasBeenModified());
}
- @Test(enabled=false)
+ @Test
public void testGetOutsideLogs() throws IOException {
// TODO: something more useful
config.getOutsideLogs();
}
- @Test(enabled=false)
+ @Test
public void testGetOutsideDbs() throws IOException {
// TODO: something more useful
config.getOutsideDbs();
}
- @Test(enabled=false)
+ @Test
public void testGetContents() throws IOException {
assertNotNull(config.getContents());
}
- @Test(enabled=false)
+ @Test
public void testGetDatabasePaths() throws IOException {
assertTrue(config.getDatabasePaths().size() > 0);
}
- @Test(enabled=false)
+ @Test
public void testLoad() {
//TODO: need way to verify reload
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/InstallationTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/InstallationTest.java
index c3753b7..ab363e2 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/InstallationTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/InstallationTest.java
@@ -36,28 +36,28 @@
/**
* Installation Tester.
*/
-@Test(enabled=false, groups = {"slow"})
+@Test(groups = {"slow"})
public class InstallationTest extends QuickSetupTestCase {
Installation installation;
@BeforeClass
public void setUp() throws Exception {
- installation = Utils.getInstallation();
+ installation = TestUtilities.getInstallation();
}
/**
* Tests to make sure installation is valid.
*/
- @Test(enabled=false)
+ @Test
public void testValidateRootDirectory() {
- Installation.validateRootDirectory(Utils.getQuickSetupTestServerRootDir());
+ Installation.validateRootDirectory(TestUtilities.getQuickSetupTestServerRootDir());
}
/**
* Tests that installation root directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetRootDirectory() {
assertNotNull(installation.getRootDirectory());
}
@@ -65,7 +65,7 @@
/**
* Tests that the installation root directory can be set.
*/
- @Test(enabled=false)
+ @Test
public void testSetRootDirectory() {
File root = installation.getRootDirectory();
installation.setRootDirectory(root);
@@ -74,7 +74,7 @@
/**
* Tests that the installation root is valid.
*/
- @Test(enabled=false)
+ @Test
public void testIsValid() {
assertTrue(installation.isValid());
}
@@ -83,7 +83,7 @@
* Tests that an installation directory missing required directories
* is considered invalid.
*/
- @Test(enabled=false)
+ @Test
public void testIsValid2() {
assertTrue(installation.isValid());
File x = new File(installation.getRootDirectory(), "x");
@@ -102,7 +102,7 @@
/**
* Tests the configuration is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetCurrentConfiguration() {
assertNotNull(installation.getCurrentConfiguration());
}
@@ -110,7 +110,7 @@
/**
* Tests the base configuration is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetBaseConfiguration() throws ApplicationException {
assertNotNull(installation.getBaseConfiguration());
}
@@ -118,7 +118,7 @@
/**
* Tests the status is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetStatus() {
assertNotNull(installation.getStatus());
}
@@ -126,7 +126,7 @@
/**
* Tests the lib directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetLibrariesDirectory() {
assertExistentFile(installation.getLibrariesDirectory());
}
@@ -134,7 +134,7 @@
/**
* Tests the schema concat file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetSchemaConcatFile() {
assertNonexistentFile(installation.getSchemaConcatFile());
}
@@ -142,7 +142,7 @@
/**
* Tests the base schema file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetBaseSchemaFile() throws ApplicationException {
assertExistentFile(installation.getBaseSchemaFile());
}
@@ -150,7 +150,7 @@
/**
* Tests the base config file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetBaseConfigurationFile() throws ApplicationException {
assertExistentFile(installation.getBaseConfigurationFile());
}
@@ -158,7 +158,7 @@
/**
* Tests the SVN rev number is discernable.
*/
- @Test(enabled=false)
+ @Test
public void testGetSvnRev() throws ApplicationException {
assertNotNull(installation.getSvnRev());
}
@@ -166,7 +166,7 @@
/**
* Tests the config file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetCurrentConfigurationFile() {
assertExistentFile(installation.getCurrentConfigurationFile());
}
@@ -174,7 +174,7 @@
/**
* Tests the bin/bat directory is available and platform appropriate.
*/
- @Test(enabled=false)
+ @Test
public void testGetBinariesDirectory() {
File binariesDir;
assertExistentFile(binariesDir = installation.getBinariesDirectory());
@@ -190,7 +190,7 @@
/**
* Tests the db directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetDatabasesDirectory() {
assertExistentFile(installation.getDatabasesDirectory());
}
@@ -198,7 +198,7 @@
/**
* Tests the backup directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetBackupDirectory() {
assertExistentFile(installation.getBackupDirectory());
}
@@ -206,7 +206,7 @@
/**
* Tests the config directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetConfigurationDirectory() {
assertExistentFile(installation.getConfigurationDirectory());
}
@@ -214,7 +214,7 @@
/**
* Tests the logs directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetLogsDirectory() {
assertExistentFile(installation.getLogsDirectory());
}
@@ -222,7 +222,7 @@
/**
* Tests the locks directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetLocksDirectory() {
assertExistentFile(installation.getLocksDirectory());
}
@@ -230,7 +230,7 @@
/**
* Tests the tmp directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetTemporaryDirectory() {
assertNonexistentFile(installation.getTemporaryDirectory());
}
@@ -238,7 +238,7 @@
/**
* Tests the history directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetHistoryDirectory() {
assertNonexistentFile(installation.getHistoryDirectory());
}
@@ -246,7 +246,7 @@
/**
* Tests a historical backup directory can be created.
*/
- @Test(enabled=false)
+ @Test
public void testCreateHistoryBackupDirectory() throws IOException {
assertExistentFile(installation.createHistoryBackupDirectory());
assertExistentFile(installation.getHistoryDirectory());
@@ -256,7 +256,7 @@
/**
* Tests the history log file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetHistoryLogFile() {
assertNonexistentFile(installation.getHistoryLogFile());
}
@@ -264,7 +264,7 @@
/**
* Tests the config upgrade directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetConfigurationUpgradeDirectory() {
assertExistentFile(installation.getConfigurationUpgradeDirectory());
}
@@ -272,7 +272,7 @@
/**
* Tests the tmp/upgrade directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetTemporaryUpgradeDirectory() {
assertNonexistentFile(installation.getTemporaryUpgradeDirectory());
}
@@ -280,7 +280,7 @@
/**
* Tests getting a command file works.
*/
- @Test(enabled=false)
+ @Test
public void testGetCommandFile() {
assertExistentFile(installation.getCommandFile(
Installation.UNIX_START_FILE_NAME));
@@ -289,7 +289,7 @@
/**
* Tests the start server command is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetServerStartCommandFile() {
assertExistentFile(installation.getServerStartCommandFile());
}
@@ -297,7 +297,7 @@
/**
* Tests the stop server command is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetServerStopCommandFile() {
assertExistentFile(installation.getServerStopCommandFile());
}
@@ -305,7 +305,7 @@
/**
* Tests the ldif directory is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetLdifDirectory() {
assertExistentFile(installation.getLdifDirectory());
}
@@ -313,7 +313,7 @@
/**
* Tests the quicksetup jar is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetQuicksetupJarFile() {
assertExistentFile(installation.getQuicksetupJarFile());
}
@@ -321,7 +321,7 @@
/**
* Tests the OpenDS jar is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetOpenDSJarFile() {
assertExistentFile(installation.getOpenDSJarFile());
}
@@ -329,7 +329,7 @@
/**
* Tests the uninstall file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetUninstallBatFile() {
assertExistentFile(installation.getUninstallBatFile());
}
@@ -337,7 +337,7 @@
/**
* Tests the status panel command file is available.
*/
- @Test(enabled=false)
+ @Test
public void testGetStatusPanelCommandFile() {
assertExistentFile(installation.getStatusPanelCommandFile());
}
@@ -345,7 +345,7 @@
/**
* Tests the build information is discernable.
*/
- @Test(enabled=false)
+ @Test
public void testGetBuildInformation() throws ApplicationException {
assertNotNull(installation.getBuildInformation());
}
@@ -353,7 +353,7 @@
/**
* Tests the build information is discernable.
*/
- @Test(enabled=false)
+ @Test
public void testGetBuildInformation1() throws ApplicationException {
assertNotNull(installation.getBuildInformation(true));
assertNotNull(installation.getBuildInformation(false));
@@ -362,7 +362,7 @@
/**
* Test string representation is possible.
*/
- @Test(enabled=false)
+ @Test
public void testToString() {
assertNotNull(installation.toString());
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/QuickSetupTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/QuickSetupTestCase.java
index 70fb06a..3b8bd7e 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/QuickSetupTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/QuickSetupTestCase.java
@@ -38,7 +38,6 @@
*/
public class QuickSetupTestCase {
-/*
@BeforeSuite
public final void suppressOutput() {
TestCaseUtils.suppressOutput();
@@ -48,14 +47,13 @@
public final void initServer()
throws IOException, ApplicationException, InterruptedException
{
- Utils.initServer();
+ TestUtilities.initServer();
}
@AfterSuite
public final void shutdownServer() throws ApplicationException {
- Utils.stopServer();
+ TestUtilities.stopServer();
TestCaseUtils.unsupressOutput();
}
-*/
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/TestUtilities.java
similarity index 93%
rename from opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java
rename to opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/TestUtilities.java
index cba2d36..d6120a6 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/TestUtilities.java
@@ -29,6 +29,7 @@
import org.opends.quicksetup.util.ZipExtractor;
import org.opends.quicksetup.util.ServerController;
+import org.opends.quicksetup.util.FileManager;
import org.opends.server.TestCaseUtils;
import org.opends.server.types.OperatingSystem;
@@ -42,7 +43,7 @@
/**
*
*/
-public class Utils {
+public class TestUtilities {
/**
* The name of the system property that specifies the server build root.
@@ -64,9 +65,7 @@
if (!initialized) {
if (qsServerRoot.exists()) {
stopServer();
- if (!qsServerRoot.delete()) {
- throw new IllegalStateException("cannot delete stale installation");
- }
+ new FileManager().deleteRecursively(qsServerRoot);
}
ZipExtractor extractor = new ZipExtractor(getInstallPackageFile());
extractor.extract(qsServerRoot);
@@ -76,7 +75,7 @@
}
static public Installation getInstallation() {
- return new Installation(Utils.getQuickSetupTestServerRootDir());
+ return new Installation(getQuickSetupTestServerRootDir());
}
static private void setupServer() throws IOException, InterruptedException {
@@ -139,11 +138,15 @@
return installPackageFile;
}
- static public File getQuickSetupTestServerRootDir() {
+ static public File getQuickSetupTestWorkspace() {
String buildRoot = System.getProperty(PROPERTY_BUILD_ROOT);
File buildDir = new File(buildRoot, "build");
File unitRootDir = new File(buildDir, "unit-tests");
return new File(unitRootDir, "quicksetup");
}
+ static public File getQuickSetupTestServerRootDir() {
+ return new File(getQuickSetupTestWorkspace(), "OpenDS");
+ }
+
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/FileManagerTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/FileManagerTest.java
new file mode 100644
index 0000000..13f9665
--- /dev/null
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/FileManagerTest.java
@@ -0,0 +1,502 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Portions Copyright 2006-2007 Sun Microsystems, Inc.
+ */
+
+package org.opends.quicksetup.util;
+
+import static org.testng.Assert.*;
+import org.testng.annotations.*;
+import org.opends.quicksetup.QuickSetupTestCase;
+import org.opends.quicksetup.TestUtilities;
+import org.opends.quicksetup.Constants;
+import org.opends.quicksetup.ApplicationException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileWriter;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.FileFilter;
+
+/**
+ * FileManager Tester.
+ */
+@Test(groups = {"slow"})
+public class FileManagerTest extends QuickSetupTestCase {
+
+ File fmWorkspace = null;
+ FileManager fileManager = null;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ fileManager = new FileManager();
+ fmWorkspace = new File(TestUtilities.getQuickSetupTestWorkspace(),
+ "filemanagertests");
+ if (fmWorkspace.exists()) {
+ fileManager.deleteRecursively(fmWorkspace);
+ }
+ if (!fmWorkspace.mkdir()) {
+ throw new IllegalStateException("cannot create FileManagerTest workspace");
+ }
+ }
+
+ @AfterMethod
+ public void cleanupWorkspace() throws Exception {
+ String[] children = fmWorkspace.list();
+ if (children != null) {
+ for (String child : children) {
+ fileManager.deleteRecursively(new File(fmWorkspace, child));
+ }
+ }
+ }
+
+ /**
+ * Tests synchronized.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testSynchronize() throws Exception {
+ File s = new File(fmWorkspace, "s");
+ File t = new File(fmWorkspace, "t");
+
+ String childOfS = "child of s";
+ String childOfT = "child of t";
+
+ createSourceFiles(s, childOfS);
+ createSourceFiles(t, childOfT);
+
+ File t_d1 = new File(t, "d1");
+ File t_f1a = new File(t_d1, "f1a");
+ File t_f1b = new File(t_d1, "f1b");
+
+ File t_d2 = new File(t, "d2");
+ File t_f2a = new File(t_d2, "f2a");
+ File t_d2b = new File(t_d2, "d2b");
+ File t_f2b1 = new File(t_d2b, "f2b1");
+
+ assertTrue(t_d1.exists());
+ assertTrue(t_f1a.exists());
+ assertTrue(t_f1b.exists());
+
+ assertTrue(t_d2.exists());
+ assertTrue(t_f2a.exists());
+ assertTrue(t_d2b.exists());
+ assertTrue(t_f2b1.exists());
+
+ assertTrue(t_f2b1.delete());
+ assertTrue(t_d2b.delete());
+ assertTrue(t_f1a.delete());
+
+ fileManager.synchronize(s, t);
+
+ // Make sure files we deleted above were copied from the source dir
+ assertTrue(t_f2b1.exists());
+ assertTrue(childOfS.equals(contentsOf(t_f2b1)));
+
+ assertTrue(t_d2b.exists());
+
+ assertTrue(t_f1a.exists());
+ assertTrue(childOfS.equals(contentsOf(t_f1a)));
+
+ // Make sure files that pre-existed didn't get touched
+ assertTrue(childOfT.equals(contentsOf(t_f1b)));
+ assertTrue(childOfT.equals(contentsOf(t_f2a)));
+ }
+
+ /**
+ * Tests basic move.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testMove() throws Exception {
+
+ File fromDir = new File(fmWorkspace, "from");
+ fromDir.mkdir();
+
+ File toDir = new File(fmWorkspace, "to");
+ toDir.mkdir();
+
+ createSourceFiles(fromDir, "abc");
+
+ fileManager.move(fromDir, toDir);
+
+ assertFalse(fromDir.exists());
+ assertTrue(new File(toDir, fromDir.getName()).exists());
+ }
+
+ /**
+ * Tests basic move with filtering.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testMove2() throws Exception {
+ File fromDir = new File(fmWorkspace, "from");
+ fromDir.mkdir();
+
+ File toDir = new File(fmWorkspace, "to");
+ toDir.mkdir();
+
+ createSourceFiles(fromDir, "abc");
+
+ // Create a filter that should reject the operation
+ FileFilter filter = new FileFilter() {
+ public boolean accept(File pathname) {
+ return false;
+ }
+ };
+ fileManager.move(fromDir, toDir, filter);
+
+ assertTrue(fromDir.exists());
+ assertFalse(new File(toDir, fromDir.getName()).exists());
+ }
+
+ /**
+ * Tests basic delete.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testDelete() throws Exception {
+ File dir = new File(fmWorkspace, "dir");
+ dir.mkdir();
+ assertTrue(dir.exists());
+ fileManager.delete(dir);
+ assertFalse(dir.exists());
+
+ File file = new File(fmWorkspace, "file");
+ writeContents(file, "abc");
+ assertTrue(file.exists());
+ fileManager.delete(file);
+ assertFalse(file.exists());
+ }
+
+ /**
+ * Tests basic delete with filtering.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testDelete2() throws Exception {
+
+ // Create a filter that should reject the operation
+ FileFilter filter = new FileFilter() {
+ public boolean accept(File pathname) {
+ return false;
+ }
+ };
+
+ File dir = new File(fmWorkspace, "dir");
+ dir.mkdir();
+ assertTrue(dir.exists());
+ fileManager.delete(dir, filter);
+ assertTrue(dir.exists());
+
+ File file = new File(fmWorkspace, "file");
+ writeContents(file, "abc");
+ assertTrue(file.exists());
+ fileManager.delete(file, filter);
+ assertTrue(file.exists());
+ }
+
+ /**
+ * Test recursive delete.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testDeleteRecursively() throws Exception {
+ File dir = new File(fmWorkspace, "dir");
+ createSourceFiles(dir, "abc");
+ assertTrue(dir.exists());
+ fileManager.deleteRecursively(dir);
+ assertFalse(dir.exists());
+ }
+
+ /**
+ * Test recursive delete with filtering.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testDeleteRecursively1() throws Exception {
+ File dir = new File(fmWorkspace, "dir");
+ createSourceFiles(dir, "abc");
+ File d2 = new File(dir, "d2");
+ File d2b = new File(d2, "d2b");
+ final File f2b1 = new File(d2b, "f2b1");
+
+ // Test that a filter can stop a delete altogether
+ FileFilter rejectOpFilter = new FileFilter() {
+ public boolean accept(File pathname) {
+ return false;
+ }
+ };
+ int childCount = countSelfAndAllChildren(dir);
+ assertTrue(dir.exists());
+ fileManager.deleteRecursively(dir, rejectOpFilter,
+ FileManager.DeletionPolicy.DELETE_IMMEDIATELY);
+ assertTrue(dir.exists());
+ // Make sure we didn't lose any kids
+ assertTrue(childCount == countSelfAndAllChildren(dir));
+
+ // Test that using a filter to delete one file works
+ FileFilter killChildFileFilter = new FileFilter() {
+ public boolean accept(File f) {
+ return f.equals(f2b1);
+ }
+ };
+ assertTrue(dir.exists());
+ assertTrue(f2b1.exists());
+ fileManager.deleteRecursively(dir, killChildFileFilter,
+ FileManager.DeletionPolicy.DELETE_IMMEDIATELY);
+ assertTrue(dir.exists());
+ assertTrue((childCount -1) == countSelfAndAllChildren(dir));
+ assertFalse(f2b1.exists());
+ }
+
+ /**
+ * Test basic copy.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testCopy() throws Exception {
+ File file = new File(fmWorkspace, "file");
+ writeContents(file, "abc");
+ File dir = new File(fmWorkspace, "dir");
+ String[] children = dir.list();
+ assertTrue(children == null || children.length == 0);
+ fileManager.copy(file, dir);
+ assertTrue(file.exists());
+ assertTrue(dir.list().length == 1);
+ }
+
+ /**
+ * Make sure things fail if target is a file and not a directory.
+ * @throws Exception if something unexpected
+ */
+ @Test(expectedExceptions = ApplicationException.class)
+ public void testCopy1() throws Exception {
+ File file = new File(fmWorkspace, "file");
+ writeContents(file, "abc");
+ File file2 = new File(fmWorkspace, "file2");
+ writeContents(file2, "abc");
+ fileManager.copy(file, file2);
+ }
+
+ /**
+ * Make sure things fail if target is a file and not a directory.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testCopy2() throws Exception {
+ File file = new File(fmWorkspace, "file");
+ String NEW_CHILD_CONTENT = "new";
+ writeContents(file, NEW_CHILD_CONTENT);
+ File dir = new File(fmWorkspace, "dir");
+ dir.mkdir();
+ File dirChild = new File(dir, "file");
+ String ORIGINAL_CHILD_CONTENT = "orinld";
+ writeContents(dirChild, ORIGINAL_CHILD_CONTENT);
+
+ // Try a copy without overwriting and make sure the original
+ // file didn't get replaced.
+ fileManager.copy(file, dir, false);
+ assertTrue(contentsOf(dirChild).equals(ORIGINAL_CHILD_CONTENT));
+
+ // New try a copy with overwrite true and make sure the original
+ // file got replaced.
+ fileManager.copy(file, dir, true);
+ assertTrue(contentsOf(dirChild).equals(NEW_CHILD_CONTENT));
+ }
+
+ /**
+ * Test copy recursively.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testCopyRecursively() throws Exception {
+ File source = new File(fmWorkspace, "source");
+ createSourceFiles(source, "abc");
+ int count = countSelfAndAllChildren(source);
+
+ File dest = new File(fmWorkspace, "dest");
+ fileManager.copyRecursively(source, dest);
+
+ File copiedSource = new File(dest, "source");
+ assertTrue(copiedSource.exists());
+ assertTrue(count == countSelfAndAllChildren(copiedSource));
+ }
+
+ /**
+ * Tests copy recursively with filtering.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testCopyRecursively1() throws Exception {
+ // Test that a filter can stop a delete altogether
+ FileFilter rejectOpFilter = new FileFilter() {
+ public boolean accept(File pathname) {
+ return false;
+ }
+ };
+
+ File source = new File(fmWorkspace, "source");
+ createSourceFiles(source, "abc");
+ File d2 = new File(source, "d2");
+ File d2b = new File(d2, "d2b");
+ final File f2b1 = new File(d2b, "f2b1");
+ File dest = new File(fmWorkspace, "dest");
+
+ // Make sure a copy with a rejection filter doesn't do anything
+ fileManager.copyRecursively(source, dest, rejectOpFilter);
+
+ File copiedSource = new File(dest, "source");
+ assertFalse(copiedSource.exists());
+ assertTrue(countSelfAndAllChildren(dest) == 1);
+
+ // Test that using a filter to delete one file works
+ FileFilter copyChildFileFilter = new FileFilter() {
+ public boolean accept(File f) {
+ return f.equals(f2b1);
+ }
+ };
+ fileManager.copyRecursively(source, dest, copyChildFileFilter);
+ File copiedD2 = new File(copiedSource, "d2");
+ File copiedD2b = new File(d2, "d2b");
+ final File copiedF2b1 = new File(d2b, "f2b1");
+ assertTrue(copiedSource.exists());
+ assertTrue(countSelfAndAllChildren(copiedSource) == 4);
+ assertTrue(copiedD2.exists());
+ assertTrue(countSelfAndAllChildren(copiedD2) == 3);
+ assertTrue(copiedD2b.exists());
+ assertTrue(countSelfAndAllChildren(copiedD2b) == 2);
+ assertTrue(copiedF2b1.exists());
+ }
+
+ /**
+ * Tests copy recursively with filtering and overwrite.
+ * @throws Exception if something unexpected
+ */
+ @Test
+ public void testCopyRecursively2() throws Exception {
+ File source = new File(fmWorkspace, "source");
+ String FILES_TO_COPY = "to copy";
+ createSourceFiles(source, FILES_TO_COPY);
+ File d2 = new File(source, "d2");
+ File d2b = new File(d2, "d2b");
+ final File f2b1 = new File(d2b, "f2b1");
+ File dest = new File(fmWorkspace, "dest");
+
+ File copiedSource = new File(dest, "source");
+ File copiedD2 = new File(copiedSource, "d2");
+ copiedD2.mkdir();
+ File copiedD2b = new File(d2, "d2b");
+ copiedD2b.mkdir();
+ final File copiedF2b1 = new File(d2b, "f2b1");
+ String ORIGINAL = "original";
+ writeContents(copiedF2b1, ORIGINAL);
+
+ // Test that using a filter to delete one file works
+ FileFilter copyChildFileFilter = new FileFilter() {
+ public boolean accept(File f) {
+ return f.equals(f2b1);
+ }
+ };
+ // With overwrite off make sure it doesn't get replaced
+ fileManager.copyRecursively(source, dest, copyChildFileFilter, false);
+ assertTrue(ORIGINAL.equals(contentsOf(copiedF2b1)));
+
+ // Now with overwrite make sure it gets replaced.
+ fileManager.copyRecursively(source, dest, copyChildFileFilter, true);
+ assertTrue(ORIGINAL.equals(contentsOf(copiedF2b1)));
+ }
+
+ /**
+ * Creates a set of file for testing.
+ * @param parent of the files.
+ * @param childContent content of non-directory files.
+ * @throws IOException if something unexpected
+ */
+ private void createSourceFiles(File parent, String childContent)
+ throws IOException {
+ if (!parent.exists()) {
+ parent.mkdir();
+ }
+ File d1 = new File(parent, "d1");
+ File f1a = new File(d1, "f1a");
+ File f1b = new File(d1, "f1b");
+
+ File d2 = new File(parent, "d2");
+ File f2a = new File(d2, "f2a");
+ File d2b = new File(d2, "d2b");
+ File f2b1 = new File(d2b, "f2b1");
+
+ d1.mkdir();
+ d2.mkdir();
+ d2b.mkdir();
+
+ writeContents(f1a, childContent);
+ writeContents(f1b, childContent);
+ writeContents(f2a, childContent);
+ writeContents(f2b1, childContent);
+ }
+
+ private void writeContents(File f, String content) throws IOException {
+ if (!f.exists()) f.createNewFile();
+ FileWriter fw = new FileWriter(f);
+ fw.write(content);
+ fw.flush();
+ fw.close();
+ }
+
+ private String contentsOf(File f) throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader(f));
+ StringBuilder sb = new StringBuilder();
+ String s;
+ s = br.readLine();
+ while (s != null) {
+ sb.append(s);
+ s = br.readLine();
+ if (s != null) {
+ sb.append(Constants.LINE_SEPARATOR);
+ }
+ }
+ br.close();
+ return sb.toString();
+ }
+
+ private int countSelfAndAllChildren(File f) {
+ int count = 0;
+ if (f != null) {
+ count = 1;
+ if (f.isDirectory()) {
+ File[] children = f.listFiles();
+ if (children != null) {
+ for (File child : children) {
+ count += countSelfAndAllChildren(child);
+ }
+ }
+ }
+ }
+ return count;
+ }
+}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/ServerControllerTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/ServerControllerTest.java
index 4c34942..7547757 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/ServerControllerTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/ServerControllerTest.java
@@ -30,31 +30,29 @@
import org.testng.annotations.*;
import org.opends.quicksetup.*;
-import org.opends.quicksetup.Utils;
-import org.opends.server.TestCaseUtils;
-
-import java.io.FileNotFoundException;
+import org.opends.quicksetup.TestUtilities;
/**
* ServerController Tester.
*/
-@Test(enabled=false, groups = {"slow"})
+@Test(groups = {"slow"})
public class ServerControllerTest extends QuickSetupTestCase {
+
ServerController controller;
Status status;
@BeforeClass
public void setUp() throws Exception {
-// Installation installation = Utils.getInstallation();
-// controller = new ServerController(installation);
-// status = installation.getStatus();
+ Installation installation = TestUtilities.getInstallation();
+ controller = new ServerController(installation);
+ status = installation.getStatus();
}
/**
* Tests ability to stop the server.
* @throws ApplicationException
*/
- @Test(enabled=false)
+ @Test
public void testStopServer() throws ApplicationException {
if (!status.isServerRunning()) {
controller.startServer();
@@ -68,7 +66,7 @@
* Tests ability to start the server.
* @throws ApplicationException
*/
- @Test(enabled=false)
+ @Test
public void testStartServer() throws ApplicationException {
if (status.isServerRunning()) {
controller.stopServer();
--
Gitblit v1.10.0