Skip to content

Commit

Permalink
Merge pull request #74 from orchitech/fix-tests
Browse files Browse the repository at this point in the history
Partial fix of opendj-server-legacy unit tests
  • Loading branch information
fyrbach authored Feb 8, 2023
2 parents 25212c0 + 7b54050 commit bd7cdc4
Show file tree
Hide file tree
Showing 71 changed files with 412 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.TreeSet;

import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;
import org.mockito.internal.util.Primitives;
import org.mockito.invocation.InvocationOnMock;

/**
Expand Down Expand Up @@ -89,6 +90,9 @@ public Object answer(InvocationOnMock invocation) {
if (defaultValue != null) {
return defaultValue;
}
if (Number.class.isAssignableFrom(invocation.getMethod().getReturnType())) {
return null; // Prevent Mockito's default behavior of returning wrapped 0
}
return answerFromDefaultMockitoBehavior(invocation);
} catch (Exception e) {
return answerFromDefaultMockitoBehavior(invocation);
Expand Down
114 changes: 64 additions & 50 deletions opendj-server-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,33 @@
<!-- General server-wide properties -->
<docgen.dir>${project.build.directory}/docgen</docgen.dir>
<jars.dir>${project.build.directory}/jars</jars.dir>

<!-- Product information properties -->
<patchFixIds />
<isDebugBuild>false</isDebugBuild>
<docHomepageUrl>https://opendj.forgerock.org/</docHomepageUrl>
<docWikiUrl>https://wrensecurity.org/projects/wrends/resources.html</docWikiUrl>
<docGuideRefUrl>http://opendj.forgerock.org/opendj-server-legacy/doc/bootstrap/admin-guide/</docGuideRefUrl>
<docGuideAdminUrl>http://opendj.forgerock.org/opendj-server-legacy/doc/bootstrap/admin-guide/</docGuideAdminUrl>

<!-- Other properties -->
<maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>

<!-- Additional OSGI import package for this module -->
<opendj.osgi.import.additional>
org.forgerock.opendj.*;provide:=true,
org.forgerock.json.*;provide:=true
</opendj.osgi.import.additional>
<product.archive.name>${product.name.lowercase}-${project.version}</product.archive.name>
<juel.version>2.2.7</juel.version>

<!-- maven-failsafe-plugin JVM arguments -->
<argLine>
-server -Xms1024M -Xmx2048M
--add-exports java.base/sun.security.x509=ALL-UNNAMED
--add-exports java.base/sun.security.tools.keytool=ALL-UNNAMED
--add-opens java.base/java.nio=ALL-UNNAMED
</argLine>
</properties>

<dependencies>
Expand Down Expand Up @@ -173,11 +184,6 @@
</dependency>

<!-- slf4j libraries -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
Expand Down Expand Up @@ -1087,57 +1093,65 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>

<configuration>
<testSourceDirectory>src/test/java</testSourceDirectory>
<forkedProcessTimeoutInSeconds>1800</forkedProcessTimeoutInSeconds>
<additionalClasspathElements>
<additionalClasspathElement>${jars.dir}/wrends-slf4j-adapter.jar</additionalClasspathElement>
<additionalClasspathElement>${jars.dir}/wrends-je-backend.jar</additionalClasspathElement>
</additionalClasspathElements>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.slf4j:slf4j-jdk14</classpathDependencyExclude>
</classpathDependencyExcludes>
<excludes>
<exclude>org/opends/server/snmp/**</exclude>
<exclude>org/opends/quicksetup/**</exclude>
<exclude>org/opends/quicksetup/**</exclude>
</excludes>
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
<include>**/*TestCases.java</include>
</includes>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.opends.server.TestListener</value>
</property>
<property>
<name>excludegroups</name>
<value>slow</value>
</property>
<property>
<name>configfailurepolicy</name>
<value>skip</value>
</property>
</properties>
<systemPropertyVariables>
<org.opends.server.BuildRoot>${basedir}</org.opends.server.BuildRoot>
<org.opends.server.BuildDir>${project.build.directory}</org.opends.server.BuildDir>
<org.opends.test.replicationDbImpl>LOG</org.opends.test.replicationDbImpl>
<!-- <jvmarg value="-Dorg.opends.server.snmp.opendmk=${opendmk.lib.dir}" /> -->
<org.opends.server.CleanupDirectories>true</org.opends.server.CleanupDirectories>
<org.opends.test.suppressOutput>true</org.opends.test.suppressOutput>
<org.opends.test.pauseOnFailure>false</org.opends.test.pauseOnFailure>
<org.opends.test.copyClassesToTestPackage>false</org.opends.test.copyClassesToTestPackage>
</systemPropertyVariables>
</configuration>

<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<testSourceDirectory>src/test/java</testSourceDirectory>
<forkedProcessTimeoutInSeconds>1800</forkedProcessTimeoutInSeconds>
<excludes>
<exclude>org/opends/server/snmp/**</exclude>
<exclude>org/opends/quicksetup/**</exclude>
<exclude>org/opends/quicksetup/**</exclude>
</excludes>
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
<include>**/*TestCases.java</include>
</includes>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.opends.server.TestListener</value>
</property>
<property>
<name>excludegroups</name>
<value>slow</value>
</property>
<property>
<name>configfailurepolicy</name>
<value>skip</value>
</property>
</properties>
<systemPropertyVariables>
<org.opends.server.BuildRoot>${basedir}</org.opends.server.BuildRoot>
<org.opends.server.BuildDir>${project.build.directory}</org.opends.server.BuildDir>
<org.opends.test.replicationDbImpl>LOG</org.opends.test.replicationDbImpl>
<!-- <jvmarg value="-Dorg.opends.server.snmp.opendmk=${opendmk.lib.dir}" /> -->
<org.opends.server.CleanupDirectories>true</org.opends.server.CleanupDirectories>
<org.opends.test.suppressOutput>true</org.opends.test.suppressOutput>
<org.opends.test.pauseOnFailure>false</org.opends.test.pauseOnFailure>
<org.opends.test.copyClassesToTestPackage>false</org.opends.test.copyClassesToTestPackage>
</systemPropertyVariables>
<argLine>-server -Xms1024M -Xmx2048M -XX:MaxPermSize=256m</argLine>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -172,7 +171,7 @@ private <K, V> Map<K, V> newMapIfNull(Map<K, V> map)
{
return map;
}
return new HashMap<>();
return new LinkedHashMap<>();
}


Expand Down Expand Up @@ -2350,14 +2349,14 @@ public void setAttachment(Object attachment)
*/
public Entry duplicate(boolean processVirtual)
{
Map<ObjectClass, String> objectClassesCopy = new HashMap<>(objectClasses);
Map<ObjectClass, String> objectClassesCopy = new LinkedHashMap<>(objectClasses);

Map<AttributeType, List<Attribute>> userAttrsCopy = new HashMap<>(userAttributes.size());
Map<AttributeType, List<Attribute>> userAttrsCopy = new LinkedHashMap<>(userAttributes.size());
deepCopy(userAttributes, userAttrsCopy, false, false, false,
true, false);

Map<AttributeType, List<Attribute>> operationalAttrsCopy =
new HashMap<>(operationalAttributes.size());
new LinkedHashMap<>(operationalAttributes.size());
deepCopy(operationalAttributes, operationalAttrsCopy, false,
false, false, true, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.StaticUtils.*;

import com.google.common.collect.Maps;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -226,9 +227,9 @@ public Entry readEntry(boolean checkSchema)

private Entry createEntry(DN entryDN, List<StringBuilder> lines, boolean checkSchema) throws LDIFException
{
Map<ObjectClass, String> objectClasses = new HashMap<>();
Map<AttributeType, List<AttributeBuilder>> userAttrBuilders = new HashMap<>();
Map<AttributeType, List<AttributeBuilder>> operationalAttrBuilders = new HashMap<>();
Map<ObjectClass, String> objectClasses = new LinkedHashMap<>();
Map<AttributeType, List<AttributeBuilder>> userAttrBuilders = new LinkedHashMap<>();
Map<AttributeType, List<AttributeBuilder>> operationalAttrBuilders = new LinkedHashMap<>();
for (StringBuilder line : lines)
{
readAttribute(lines, line, entryDN, objectClasses, userAttrBuilders, operationalAttrBuilders, checkSchema);
Expand Down Expand Up @@ -311,7 +312,7 @@ private void validateAgainstSchemaIfNeeded(boolean checkSchema, final Entry entr
*/
protected Map<AttributeType, List<Attribute>> toAttributesMap(Map<AttributeType, List<AttributeBuilder>> attrBuilders)
{
Map<AttributeType, List<Attribute>> attributes = new HashMap<>(attrBuilders.size());
Map<AttributeType, List<Attribute>> attributes = new LinkedHashMap<>(attrBuilders.size());
for (Map.Entry<AttributeType, List<AttributeBuilder>> attrTypeEntry : attrBuilders.entrySet())
{
AttributeType attrType = attrTypeEntry.getKey();
Expand Down Expand Up @@ -1285,8 +1286,8 @@ private ChangeRecordEntry parseDeleteChangeRecordEntry(DN entryDN,
private ChangeRecordEntry parseAddChangeRecordEntry(DN entryDN,
List<StringBuilder> lines) throws LDIFException
{
Map<ObjectClass, String> objectClasses = new HashMap<>();
Map<AttributeType, List<AttributeBuilder>> attrBuilders = new HashMap<>();
Map<ObjectClass, String> objectClasses = new LinkedHashMap<>();
Map<AttributeType, List<AttributeBuilder>> attrBuilders = new LinkedHashMap<>();
for(StringBuilder line : lines)
{
readAttribute(lines, line, entryDN, objectClasses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
* Portions Copyright 2013 Manuel Gaupp
* Portions Copyright 2023 Wren Security
*/
package org.opends.server;

Expand Down Expand Up @@ -402,8 +403,8 @@ private static void deployDirectoryDirsAndFiles() throws IOException
"org", "forgerock", "opendj", "ldif").toAbsolutePath().toFile();
File serverClassesDir = new File(paths.buildDir, "classes");
File unitClassesDir = new File(paths.unitRoot, "classes");
File libDir = new File(paths.buildDir.getPath() + "/package/opendj/lib");
File upgradeDir = new File(paths.buildDir.getPath() + "/package/opendj/template/config/upgrade");
File libDir = new File(paths.buildDir.getPath() + "/package/wrends/lib");
File upgradeDir = new File(paths.buildDir.getPath() + "/package/wrends/template/config/upgrade");
System.out.println("libDir=" + libDir);
File resourceDir = new File(paths.buildRoot, "resource");
File testResourceDir = new File(paths.testSrcRoot, "resource");
Expand Down Expand Up @@ -1924,25 +1925,20 @@ public static String generateThreadDump() {
return dump.toString();
}

/** FIXME Replace with {@link Assert#assertNotEquals(Object, Object)} once we upgrade to testng >= 6.1. */
public static void assertNotEquals(Object actual1, Object actual2)
/**
* {@link Object#equals} based assertion to workaround sneaky TestNG overloaded method.
*/
public static void assertObjectEquals(Object actual, Object expected)
{
assertNotEquals(actual1, actual2, null);
Assert.assertEquals(actual, expected);
}

/** FIXME Replace with {@link Assert#assertNotEquals(Object, Object, String)} once we upgrade to testng >= 6.1. */
public static void assertNotEquals(Object actual1, Object actual2, String message)
/**
* {@link Object#equals} based assertion to workaround sneaky TestNG overloaded method.
*/
public static void assertObjectEquals(Object actual, Object expected, String message)
{
try
{
Assert.assertEquals(actual1, actual2);
Assert.fail(message);
}
catch (AssertionError e)
{
// this is good: they are not equals
return;
}
Assert.assertEquals(actual, expected, message);
}

public static int runLdapSearchTrustCertificateForSession(final String[] args)
Expand All @@ -1969,4 +1965,5 @@ public static int runLdapSearchTrustCertificateForSession(final PrintStream out,
System.setIn(stdin);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import static org.forgerock.opendj.ldap.ModificationType.DELETE;
import static org.forgerock.opendj.ldap.ModificationType.REPLACE;
import static org.forgerock.opendj.ldap.requests.Requests.newModifyRequest;
import static org.opends.server.TestCaseUtils.assertNotEquals;
import static org.opends.server.TestCaseUtils.getServerLdapPort;
import static org.opends.server.TestCaseUtils.restartServer;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ public void testGetPluginEntryDN()
nullPlugin.initializeInternal(DirectoryServer.getInstance().getServerContext(),
configuration.dn(), pluginTypes,
configuration.isInvokeForInternalOperations());
assertEquals(nullPlugin.getPluginEntryDN(), pluginEntryDN);
TestCaseUtils.assertObjectEquals(nullPlugin.getPluginEntryDN(), pluginEntryDN);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package org.opends.server.authorization.dseecompat;

import static org.opends.server.TestCaseUtils.assertNotEquals;
import static org.opends.server.config.ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI;
import static org.opends.server.util.CollectionUtils.newArrayList;
import static org.opends.server.util.CollectionUtils.newHashSet;
import static org.opends.server.util.ServerConstants.EOL;
import static org.opends.server.util.ServerConstants.OID_PROXIED_AUTH_V2;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package org.opends.server.authorization.dseecompat;

import static org.opends.server.TestCaseUtils.assertNotEquals;
import static org.opends.server.config.ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI;
import static org.opends.server.util.ServerConstants.OID_GET_EFFECTIVE_RIGHTS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.opends.server.authorization.dseecompat;

import static org.opends.server.TestCaseUtils.assertNotEquals;
import static org.opends.server.config.ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package org.opends.server.authorization.dseecompat;

import static org.opends.server.TestCaseUtils.assertNotEquals;
import static org.opends.server.config.ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;

import java.util.Map;
Expand Down
Loading

0 comments on commit bd7cdc4

Please sign in to comment.