opends/ext/testng/testng.xml
@@ -10,6 +10,7 @@ <package name="org.opends.server.protocols.jmx"/> <package name="org.opends.server.util"/> <package name="org.opends.server.schema"/> <package name="org.opends.server.monitors"/> </packages> </test> opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/DatabaseEnvironmentMonitorTestCase.java
New file @@ -0,0 +1,72 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.opends.server.api.MonitorProvider; import org.opends.server.core.DirectoryServer; /** * This class defines a set of tests for the * org.opends.server.monitors.DatabaseEnvironmentMonitor class. */ public class DatabaseEnvironmentMonitorTestCase extends GenericMonitorTestCase { /** * Creates a new instance of this test case class. * * @throws Exception If an unexpected problem occurred. */ public DatabaseEnvironmentMonitorTestCase() throws Exception { super(null); } /** * Retrieves an initialized instance of the associated monitor provider. * * @return An initialized instance of the associated monitor provider. * * @throws Exception If an unexpected problem occurs. */ public MonitorProvider getMonitorInstance() throws Exception { String monitorName = "userroot database environment"; MonitorProvider provider = DirectoryServer.getMonitorProvider(monitorName); provider.initializeMonitorProvider(null); return provider; } } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/GenericMonitorTestCase.java
New file @@ -0,0 +1,163 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.testng.annotations.Test; import org.opends.server.TestCaseUtils; import org.opends.server.DirectoryServerTestCase; import org.opends.server.api.MonitorProvider; import org.opends.server.config.ConfigEntry; import org.opends.server.core.DirectoryServer; import org.opends.server.types.DN; import static org.testng.Assert.*; /** * An abstract base class for all monitor test cases in which most tests are * performed in a generic manner. */ public abstract class GenericMonitorTestCase extends MonitorTestCase { // The configuration entry for this test case. protected ConfigEntry configEntry; /** * Creates a new instance of this monitor test case. * * @param dnString The DN of the configuration entry for this test case, or * <CODE>null</CODE> if there is none. * * @throws Exception If an unexpected problem occurs. */ protected GenericMonitorTestCase(String dnString) throws Exception { super(); TestCaseUtils.startServer(); if (dnString != null) { DN dn = DN.decode(dnString); configEntry = DirectoryServer.getConfigEntry(dn); assertNotNull(configEntry); } } /** * Retrieves an initialized instance of the associated monitor provider. * * @return An initialized instance of the associated monitor provider. * * @throws Exception If an unexpected problem occurs. */ public abstract MonitorProvider getMonitorInstance() throws Exception; /** * Creates an instance of the stack trace monitor and performs basic * initialization for it. * * @throws Exception If an unexpected problem occurs. */ @Test() public void testInitialization() throws Exception { MonitorProvider monitorProvider = getMonitorInstance(); assertNotNull(monitorProvider); } /** * Tests the <CODE>getMonitorInstanceName</CODE> method. * * @throws Exception If an unexpected problem occurs. */ @Test() public void testGetMonitorInstanceName() throws Exception { getMonitorInstance().getMonitorInstanceName(); } /** * Tests the <CODE>getUpdateInterval</CODE> method. * * @throws Exception If an unexpected problem occurs. */ @Test() public void testGetUpdateInterval() throws Exception { getMonitorInstance().getUpdateInterval(); } /** * Tests the <CODE>getUpdateMonitorData</CODE> method. * * @throws Exception If an unexpected problem occurs. */ @Test() public void testUpdateMonitorData() throws Exception { getMonitorInstance().updateMonitorData(); } /** * Tests the <CODE>getMonitorData</CODE> method. * * @throws Exception If an unexpected problem occurs. */ @Test() public void testGetMonitorData() throws Exception { getMonitorInstance().getMonitorData(); } } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/InternalSearchMonitorTestCase.java
New file @@ -0,0 +1,134 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import java.util.ArrayList; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.opends.server.TestCaseUtils; import org.opends.server.core.DirectoryServer; import org.opends.server.protocols.internal.InternalClientConnection; import org.opends.server.protocols.internal.InternalSearchOperation; import org.opends.server.types.DN; import org.opends.server.types.ResultCode; import org.opends.server.types.SearchScope; import org.opends.server.types.SearchFilter; import static org.testng.Assert.*; /** * Interacts with the Directory Server monitor providers by retrieving the * monitor entries with internal searches. */ public class InternalSearchMonitorTestCase extends MonitorTestCase { /** * Ensures that the Directory Server is started. * * @throws Exception If an unexpected problem occurs. */ @BeforeClass() public void startServer() throws Exception { TestCaseUtils.startServer(); } /** * Uses an internal subtree search to retrieve the monitor entries. * * @throws Exception If an unexpected problem occurs. */ public void testWithSubtreeMonitorSearch() throws Exception { InternalClientConnection conn = InternalClientConnection.getRootConnection(); InternalSearchOperation searchOperation = conn.processSearch(DN.decode("cn=monitor"), SearchScope.WHOLE_SUBTREE, SearchFilter.createFilterFromString("(objectClass=*)")); assertEquals(ResultCode.SUCCESS, searchOperation.getResultCode()); } /** * Retrieves the names of the monitor providers registered with the server. * * @return The names of the monitor providers registered with the server. */ @DataProvider(name = "monitorNames") public Object[][] getMonitorNames() { ArrayList<String> monitorNames = new ArrayList<String>(); for (String name : DirectoryServer.getMonitorProviders().keySet()) { monitorNames.add(name); } Object[][] nameArray = new Object[monitorNames.size()][1]; for (int i=0; i < nameArray.length; i++) { nameArray[i] = new Object[] { monitorNames.get(i) }; } return nameArray; } /** * Uses a set of internal base-level searches to retrieve the monitor entries. * * @param monitorName The name of the monitor entry to retrieve. * * @throws Exception If an unexpected problem occurs. */ @Test(dataProvider = "monitorNames") public void testWithBaseObjectMonitorSearch(String monitorName) throws Exception { InternalClientConnection conn = InternalClientConnection.getRootConnection(); InternalSearchOperation searchOperation = conn.processSearch(DN.decode("cn=" + monitorName + ",cn=monitor"), SearchScope.BASE_OBJECT, SearchFilter.createFilterFromString("(objectClass=*)")); assertEquals(ResultCode.SUCCESS, searchOperation.getResultCode()); } } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/MonitorTestCase.java
New file @@ -0,0 +1,46 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.testng.annotations.Test; import org.opends.server.DirectoryServerTestCase; /** * An abstract base class for all monitor test cases. */ @Test(groups = { "precommit", "monitor" }) public abstract class MonitorTestCase extends DirectoryServerTestCase { // No implementation required. } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/StackTraceMonitorTestCase.java
New file @@ -0,0 +1,70 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.opends.server.api.MonitorProvider; /** * This class defines a set of tests for the * org.opends.server.monitors.StackTraceMonitorProvider class. */ public class StackTraceMonitorTestCase extends GenericMonitorTestCase { /** * Creates a new instance of this test case class. * * @throws Exception If an unexpected problem occurred. */ public StackTraceMonitorTestCase() throws Exception { super("cn=JVM Stack Trace,cn=Monitor Providers,cn=config"); } /** * Retrieves an initialized instance of the associated monitor provider. * * @return An initialized instance of the associated monitor provider. * * @throws Exception If an unexpected problem occurs. */ public MonitorProvider getMonitorInstance() throws Exception { StackTraceMonitorProvider monitorProvider = new StackTraceMonitorProvider(); monitorProvider.initializeMonitorProvider(configEntry); return monitorProvider; } } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/SystemInfoMonitorTestCase.java
New file @@ -0,0 +1,70 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.opends.server.api.MonitorProvider; /** * This class defines a set of tests for the * org.opends.server.monitors.SystemInfoMonitorProvider class. */ public class SystemInfoMonitorTestCase extends GenericMonitorTestCase { /** * Creates a new instance of this test case class. * * @throws Exception If an unexpected problem occurred. */ public SystemInfoMonitorTestCase() throws Exception { super("cn=System Info,cn=Monitor Providers,cn=config"); } /** * Retrieves an initialized instance of the associated monitor provider. * * @return An initialized instance of the associated monitor provider. * * @throws Exception If an unexpected problem occurs. */ public MonitorProvider getMonitorInstance() throws Exception { SystemInfoMonitorProvider monitorProvider = new SystemInfoMonitorProvider(); monitorProvider.initializeMonitorProvider(configEntry); return monitorProvider; } } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/TraditionalWorkQueueMonitorTestCase.java
New file @@ -0,0 +1,70 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.opends.server.api.MonitorProvider; import org.opends.server.core.DirectoryServer; /** * This class defines a set of tests for the * org.opends.server.monitors.TraditionalWorkQueueMonitor class. */ public class TraditionalWorkQueueMonitorTestCase extends GenericMonitorTestCase { /** * Creates a new instance of this test case class. * * @throws Exception If an unexpected problem occurred. */ public TraditionalWorkQueueMonitorTestCase() throws Exception { super(null); } /** * Retrieves an initialized instance of the associated monitor provider. * * @return An initialized instance of the associated monitor provider. * * @throws Exception If an unexpected problem occurs. */ public MonitorProvider getMonitorInstance() throws Exception { String monitorName = "work queue"; return DirectoryServer.getMonitorProvider(monitorName); } } opends/tests/unit-tests-testng/src/server/org/opends/server/monitors/VersionMonitorTestCase.java
New file @@ -0,0 +1,70 @@ /* * 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 Sun Microsystems, Inc. */ package org.opends.server.monitors; import org.opends.server.api.MonitorProvider; /** * This class defines a set of tests for the * org.opends.server.monitors.VersionMonitorProvider class. */ public class VersionMonitorTestCase extends GenericMonitorTestCase { /** * Creates a new instance of this test case class. * * @throws Exception If an unexpected problem occurred. */ public VersionMonitorTestCase() throws Exception { super("cn=Version,cn=Monitor Providers,cn=config"); } /** * Retrieves an initialized instance of the associated monitor provider. * * @return An initialized instance of the associated monitor provider. * * @throws Exception If an unexpected problem occurs. */ public MonitorProvider getMonitorInstance() throws Exception { VersionMonitorProvider monitorProvider = new VersionMonitorProvider(); monitorProvider.initializeMonitorProvider(configEntry); return monitorProvider; } }