636N/A/*
636N/A * CDDL HEADER START
636N/A *
636N/A * The contents of this file are subject to the terms of the
636N/A * Common Development and Distribution License, Version 1.0 only
636N/A * (the "License"). You may not use this file except in compliance
636N/A * with the License.
636N/A *
636N/A * You can obtain a copy of the license at
636N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
636N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
636N/A * See the License for the specific language governing permissions
636N/A * and limitations under the License.
636N/A *
636N/A * When distributing Covered Code, include this CDDL HEADER in each
636N/A * file and include the License file at
636N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
636N/A * add the following below this CDDL HEADER, with the fields enclosed
873N/A * by brackets "[]" replaced with your own identifying information:
636N/A * Portions Copyright [yyyy] [name of copyright owner]
636N/A *
636N/A * CDDL HEADER END
636N/A *
636N/A *
3215N/A * Copyright 2006-2008 Sun Microsystems, Inc.
636N/A */
636N/Apackage org.opends.server.backends;
636N/A
636N/A
636N/A
636N/Aimport java.util.ArrayList;
636N/A
636N/Aimport org.testng.annotations.BeforeClass;
636N/Aimport org.testng.annotations.DataProvider;
636N/Aimport org.testng.annotations.Test;
636N/A
636N/Aimport org.opends.server.TestCaseUtils;
636N/Aimport org.opends.server.api.Backend;
636N/Aimport org.opends.server.core.DirectoryServer;
636N/Aimport org.opends.server.types.DN;
636N/A
636N/Aimport static org.testng.Assert.*;
636N/A
636N/A
636N/A/**
636N/A * A set of generic test cases that apply to all Directory Server backends.
636N/A */
636N/Apublic class GenericBackendTestCase
636N/A extends BackendTestCase
636N/A{
636N/A /**
636N/A * Ensures that the Directory Server is running.
636N/A *
636N/A * @throws Exception If an unexpected problem occurs.
636N/A */
636N/A @BeforeClass()
636N/A public void startServer()
636N/A throws Exception
636N/A {
636N/A TestCaseUtils.startServer();
636N/A TestCaseUtils.initializeTestBackend(true);
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Retrieves the backends defined in the server.
636N/A *
636N/A * @return The backends defined in the server.
636N/A */
636N/A @DataProvider(name = "backends")
636N/A public Object[][] getBackends()
636N/A {
636N/A ArrayList<Backend> backendList = new ArrayList<Backend>();
636N/A backendList.addAll(DirectoryServer.getBackends().values());
636N/A
636N/A Object[][] objectArray = new Object[backendList.size()][1];
636N/A for (int i=0; i < objectArray.length; i++)
636N/A {
636N/A objectArray[i][0] = backendList.get(i);
636N/A }
636N/A
636N/A return objectArray;
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getBaseDNs} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetBaseDNs(Backend b)
636N/A {
636N/A DN[] baseDNs = b.getBaseDNs();
636N/A assertNotNull(baseDNs);
636N/A assertFalse(baseDNs.length == 0);
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code isLocal} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testIsLocal(Backend b)
636N/A {
636N/A b.isLocal();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getSupportedControls} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetSupportedControls(Backend b)
636N/A {
636N/A assertNotNull(b.getSupportedControls());
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code supportsControl} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testSupportsControl(Backend b)
636N/A {
636N/A assertFalse(b.supportsControl("1.2.3.4"));
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getSupportedFeatures} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetSupportedFeatures(Backend b)
636N/A {
698N/A assertNotNull(b.getSupportedFeatures());
636N/A b.getSupportedFeatures();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code supportsFeature} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testSupportsFeature(Backend b)
636N/A {
636N/A assertFalse(b.supportsFeature("1.2.3.4"));
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code supportsLDIFExport} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testSupportsLDIFExport(Backend b)
636N/A {
636N/A b.supportsLDIFExport();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code supportsLDIFImport} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testSupportsLDIFImport(Backend b)
636N/A {
636N/A b.supportsLDIFImport();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code supportsBackup} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testSupportsBackup(Backend b)
636N/A {
636N/A b.supportsBackup();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code supportsRestore} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testSupportsRestore(Backend b)
636N/A {
636N/A b.supportsRestore();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getBackendID} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetBackendID(Backend b)
636N/A {
636N/A assertNotNull(b.getBackendID());
636N/A assertTrue(b.getBackendID().length() > 0);
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code isPrivateBackend} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testIsPrivateBackend(Backend b)
636N/A {
636N/A b.isPrivateBackend();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getWritabilityMode} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetWritabilityMode(Backend b)
636N/A {
636N/A assertNotNull(b.getWritabilityMode());
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getBackendMonitor} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetBackendMonitor(Backend b)
636N/A {
636N/A assertNotNull(b.getBackendMonitor());
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getEntryCount} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetEntryCount(Backend b)
636N/A {
636N/A b.getEntryCount();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getParentBackend} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetParentBackend(Backend b)
636N/A {
636N/A b.getParentBackend();
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code getSubordinateBackends} method for the provided backend.
636N/A *
636N/A * @param b The backend to test.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testGetSubordinateBackends(Backend b)
636N/A {
636N/A assertNotNull(b.getSubordinateBackends());
636N/A }
636N/A
636N/A
636N/A
636N/A /**
636N/A * Tests the {@code handlesEntry} method for the provided backend for each
636N/A * of the declared base DNs.
636N/A *
636N/A * @param b The backend to test.
636N/A *
636N/A * @throws Exception If an unexpected problem occurs.
636N/A */
636N/A @Test(dataProvider = "backends")
636N/A public void testHandlesEntry(Backend b)
636N/A throws Exception
636N/A {
636N/A for (DN baseDN : b.getBaseDNs())
636N/A {
636N/A assertTrue(b.handlesEntry(baseDN));
636N/A assertTrue(b.handlesEntry(DN.decode("cn=child," + baseDN.toString())));
636N/A }
636N/A }
636N/A}
636N/A