瀏覽代碼

junit test refactoring and removal of deprecated methods/classes

jrivard@gmail.com 6 年之前
父節點
當前提交
6b2a108b6e

+ 2 - 3
server/src/manual-test/java/password/pwm/manual/LocalDBLoggerTest.java

@@ -22,7 +22,6 @@
 
 
 package password.pwm.manual;
 package password.pwm.manual;
 
 
-import junit.framework.TestCase;
 import password.pwm.AppProperty;
 import password.pwm.AppProperty;
 import password.pwm.config.Configuration;
 import password.pwm.config.Configuration;
 import password.pwm.config.PwmSetting;
 import password.pwm.config.PwmSetting;
@@ -75,7 +74,7 @@ public class LocalDBLoggerTest extends TestCase {
     private Date startTime;
     private Date startTime;
 
 
 
 
-    @Override
+    @BeforeClass
     protected void setUp() throws Exception {
     protected void setUp() throws Exception {
         super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
         super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
         TestHelper.setupLogging();
         TestHelper.setupLogging();
@@ -113,6 +112,7 @@ public class LocalDBLoggerTest extends TestCase {
         System.out.println(JavaHelper.toIsoDate(new Date())+ " " + output);
         System.out.println(JavaHelper.toIsoDate(new Date())+ " " + output);
     }
     }
 
 
+    @Test
     public void testBulkAddEvents() throws InterruptedException {
     public void testBulkAddEvents() throws InterruptedException {
         out("starting bulk add...  ");
         out("starting bulk add...  ");
         out("settings=" + JsonUtil.serialize(settings));
         out("settings=" + JsonUtil.serialize(settings));
@@ -143,7 +143,6 @@ public class LocalDBLoggerTest extends TestCase {
         outputDebugInfo();
         outputDebugInfo();
     }
     }
 
 
-
     private class PopulatorThread extends Thread {
     private class PopulatorThread extends Thread {
         public void run() {
         public void run() {
             final RandomValueMaker randomValueMaker = new RandomValueMaker(settings.valueLength);
             final RandomValueMaker randomValueMaker = new RandomValueMaker(settings.valueLength);

+ 11 - 4
server/src/manual-test/java/password/pwm/manual/LocalDBStoredQueueTest.java

@@ -22,7 +22,6 @@
 
 
 package password.pwm.manual;
 package password.pwm.manual;
 
 
-import junit.framework.TestCase;
 import password.pwm.util.java.JavaHelper;
 import password.pwm.util.java.JavaHelper;
 import password.pwm.util.localdb.LocalDB;
 import password.pwm.util.localdb.LocalDB;
 import password.pwm.util.localdb.LocalDBFactory;
 import password.pwm.util.localdb.LocalDBFactory;
@@ -33,14 +32,14 @@ import java.io.File;
 import java.util.Iterator;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.NoSuchElementException;
 
 
-public class LocalDBStoredQueueTest extends TestCase {
+public class LocalDBStoredQueueTest {
 
 
     private static final int SIZE = 5;
     private static final int SIZE = 5;
 
 
     private LocalDBStoredQueue storedQueue;
     private LocalDBStoredQueue storedQueue;
     private LocalDB localDB;
     private LocalDB localDB;
 
 
-    @Override
+    @BeforeClass
     protected void setUp() throws Exception {
     protected void setUp() throws Exception {
 
 
         super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
         super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
@@ -63,11 +62,13 @@ public class LocalDBStoredQueueTest extends TestCase {
     /**
     /**
      * isEmpty is true before add, false after
      * isEmpty is true before add, false after
      */
      */
+    @Test
     public void testEmpty() {
     public void testEmpty() {
         storedQueue.clear();
         storedQueue.clear();
         assertTrue(storedQueue.isEmpty());
         assertTrue(storedQueue.isEmpty());
     }
     }
 
 
+    @Test
     public void testRemove() {
     public void testRemove() {
         storedQueue.clear();
         storedQueue.clear();
         storedQueue.add("value1");
         storedQueue.add("value1");
@@ -92,6 +93,7 @@ public class LocalDBStoredQueueTest extends TestCase {
         assertEquals(0, storedQueue.size());
         assertEquals(0, storedQueue.size());
     }
     }
 
 
+    @Test
     public void testDequeue() {
     public void testDequeue() {
         storedQueue.clear();
         storedQueue.clear();
         assertEquals(0,storedQueue.size());
         assertEquals(0,storedQueue.size());
@@ -143,6 +145,7 @@ public class LocalDBStoredQueueTest extends TestCase {
     /**
     /**
      * size changes when elements added and removed
      * size changes when elements added and removed
      */
      */
+    @Test
     public void testSize() {
     public void testSize() {
         storedQueue.clear();
         storedQueue.clear();
         assertTrue(storedQueue.isEmpty());
         assertTrue(storedQueue.isEmpty());
@@ -163,6 +166,7 @@ public class LocalDBStoredQueueTest extends TestCase {
     /**
     /**
      * Offer succeeds
      * Offer succeeds
      */
      */
+    @Test
     public void testOffer() {
     public void testOffer() {
         storedQueue.clear();
         storedQueue.clear();
         assertTrue(storedQueue.isEmpty());
         assertTrue(storedQueue.isEmpty());
@@ -175,6 +179,7 @@ public class LocalDBStoredQueueTest extends TestCase {
     /**
     /**
      * add succeeds
      * add succeeds
      */
      */
+    @Test
     public void testAdd() {
     public void testAdd() {
         storedQueue.clear();
         storedQueue.clear();
         assertTrue(storedQueue.isEmpty());
         assertTrue(storedQueue.isEmpty());
@@ -188,6 +193,7 @@ public class LocalDBStoredQueueTest extends TestCase {
     /**
     /**
      * poll succeeds unless empty
      * poll succeeds unless empty
      */
      */
+    @Test
     public void testPoll() {
     public void testPoll() {
         storedQueue.clear();
         storedQueue.clear();
         assertTrue(storedQueue.isEmpty());
         assertTrue(storedQueue.isEmpty());
@@ -205,6 +211,7 @@ public class LocalDBStoredQueueTest extends TestCase {
     /**
     /**
      * peek returns next element, or null if empty
      * peek returns next element, or null if empty
      */
      */
+    @Test
     public void testPeek() {
     public void testPeek() {
         storedQueue.clear();
         storedQueue.clear();
         assertTrue(storedQueue.isEmpty());
         assertTrue(storedQueue.isEmpty());
@@ -216,7 +223,7 @@ public class LocalDBStoredQueueTest extends TestCase {
         assertEquals(initialSize, storedQueue.size());
         assertEquals(initialSize, storedQueue.size());
     }
     }
 
 
-    @Override
+    @AfterClass
     protected void tearDown() throws Exception {
     protected void tearDown() throws Exception {
         System.out.println("tearing down");
         System.out.println("tearing down");
         super.tearDown();
         super.tearDown();

+ 7 - 7
server/src/manual-test/java/password/pwm/manual/LocalDBTest.java

@@ -22,8 +22,6 @@
 
 
 package password.pwm.manual;
 package password.pwm.manual;
 
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
 import password.pwm.util.java.TimeDuration;
 import password.pwm.util.java.TimeDuration;
 import password.pwm.util.localdb.LocalDB;
 import password.pwm.util.localdb.LocalDB;
 import password.pwm.util.localdb.LocalDBException;
 import password.pwm.util.localdb.LocalDBException;
@@ -31,13 +29,13 @@ import password.pwm.util.localdb.LocalDBFactory;
 
 
 import java.io.File;
 import java.io.File;
 
 
-public class LocalDBTest extends TestCase {
+public class LocalDBTest {
 
 
     private final LocalDB.DB TEST_DB = LocalDB.DB.TEMP;
     private final LocalDB.DB TEST_DB = LocalDB.DB.TEMP;
     private LocalDB pwmDB;
     private LocalDB pwmDB;
 
 
-    @Override
-    protected void setUp() throws Exception {
+    @Before
+    public void setUp() throws Exception {
         super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
         super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
         TestHelper.setupLogging();
         TestHelper.setupLogging();
         final File fileLocation = new File(TestHelper.getParameter("pwmDBlocation"));
         final File fileLocation = new File(TestHelper.getParameter("pwmDBlocation"));
@@ -46,12 +44,14 @@ public class LocalDBTest extends TestCase {
         Assert.assertEquals(0,pwmDB.size(TEST_DB));
         Assert.assertEquals(0,pwmDB.size(TEST_DB));
     }
     }
 
 
+    @Test
     public void testPut() throws LocalDBException {
     public void testPut() throws LocalDBException {
         Assert.assertNull(pwmDB.get(TEST_DB,"testKey1"));
         Assert.assertNull(pwmDB.get(TEST_DB,"testKey1"));
         pwmDB.put(TEST_DB,"testKey1","testValue1");
         pwmDB.put(TEST_DB,"testKey1","testValue1");
         Assert.assertEquals(pwmDB.get(TEST_DB,"testKey1"),"testValue1");
         Assert.assertEquals(pwmDB.get(TEST_DB,"testKey1"),"testValue1");
     }
     }
 
 
+    @Test
     public void testSize() throws LocalDBException {
     public void testSize() throws LocalDBException {
         final long startTime = System.currentTimeMillis();
         final long startTime = System.currentTimeMillis();
         for (final LocalDB.DB loopDB : LocalDB.DB.values()) {
         for (final LocalDB.DB loopDB : LocalDB.DB.values()) {
@@ -61,8 +61,8 @@ public class LocalDBTest extends TestCase {
         System.out.println("total duration: " + TimeDuration.fromCurrent(startTime).asLongString());
         System.out.println("total duration: " + TimeDuration.fromCurrent(startTime).asLongString());
     }
     }
 
 
-    @Override
-    protected void tearDown() throws Exception {
+    @After
+    public void tearDown() throws Exception {
         super.tearDown();
         super.tearDown();
         if (pwmDB != null) {
         if (pwmDB != null) {
             pwmDB.close();
             pwmDB.close();

+ 1 - 2
server/src/test/java/javax/mail/internet/InternetAddressTest.java

@@ -22,8 +22,7 @@
 
 
 package javax.mail.internet;
 package javax.mail.internet;
 
 
-import junit.framework.Assert;
-
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.Test;
 
 
 /**
 /**

+ 1 - 2
server/src/test/java/password/pwm/AppPropertyTest.java

@@ -22,7 +22,6 @@
 
 
 package password.pwm;
 package password.pwm;
 
 
-import junit.framework.TestCase;
 import org.junit.Assert;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.Test;
 
 
@@ -31,7 +30,7 @@ import java.util.HashSet;
 import java.util.ResourceBundle;
 import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.Set;
 
 
-public class AppPropertyTest extends TestCase {
+public class AppPropertyTest {
     @Test
     @Test
     public void testValues()
     public void testValues()
             throws Exception
             throws Exception

+ 1 - 2
server/src/test/java/password/pwm/error/PwmErrorTest.java

@@ -22,14 +22,13 @@
 
 
 package password.pwm.error;
 package password.pwm.error;
 
 
-import junit.framework.TestCase;
 import org.junit.Test;
 import org.junit.Test;
 import password.pwm.PwmConstants;
 import password.pwm.PwmConstants;
 
 
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Set;
 
 
-public class PwmErrorTest extends TestCase {
+public class PwmErrorTest {
 
 
     @Test
     @Test
     public void testPwmErrorNumbers() throws Exception {
     public void testPwmErrorNumbers() throws Exception {

+ 0 - 101
server/src/test/java/password/pwm/svc/event/SyslogAuditServiceTest.java

@@ -1,101 +0,0 @@
-/*
- * Password Management Servlets (PWM)
- * http://www.pwm-project.org
- *
- * Copyright (c) 2006-2009 Novell, Inc.
- * Copyright (c) 2009-2018 The PWM Project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package password.pwm.svc.event;
-
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.mockito.Mockito;
-import password.pwm.AppProperty;
-import password.pwm.PwmApplication;
-import password.pwm.bean.UserIdentity;
-import password.pwm.config.Configuration;
-import password.pwm.config.stored.StoredConfigurationImpl;
-import password.pwm.util.secure.PwmRandom;
-
-import java.lang.reflect.Method;
-
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-public class SyslogAuditServiceTest {
-    @Rule
-    public WireMockRule wm = new WireMockRule(wireMockConfig()
-            .dynamicPort());
-
-    @Test
-    public void test_convertAuditRecordToSyslogMessage() throws Exception {
-        {
-            final int maxLength = 1024;
-            final AuditRecord record = new AuditRecordFactory(Mockito.mock(PwmApplication.class)).createUserAuditRecord(
-                    AuditEvent.AUTHENTICATE,
-                    new UserIdentity("cn=user,o=org","default"),
-                    PwmRandom.getInstance().alphaNumericString(maxLength),
-                    "127.0.0.1",
-                    "localhost"
-            );
-            String msg = invokeConvertAuditRecordToSyslogMessage(record, maxLength);
-            Assert.assertTrue(msg.length() <= maxLength);
-            Assert.assertTrue(msg.length() > maxLength - 100);
-        }
-
-        { // msg copied to narrative, so more work for method to do.
-            final int maxLength = 1024;
-            final AuditRecord record = new AuditRecordFactory(Mockito.mock(PwmApplication.class)).createSystemAuditRecord(
-                    AuditEvent.MODIFY_CONFIGURATION,
-                    PwmRandom.getInstance().alphaNumericString(maxLength)
-            );
-            String msg = invokeConvertAuditRecordToSyslogMessage(record, maxLength);
-            Assert.assertTrue(msg.length() <= maxLength);
-            Assert.assertTrue(msg.length() > maxLength - 100);
-        }
-
-        {
-            final int maxLength = 2048;
-            final AuditRecord record = new AuditRecordFactory(Mockito.mock(PwmApplication.class)).createSystemAuditRecord(
-                    AuditEvent.MODIFY_CONFIGURATION,
-                    PwmRandom.getInstance().alphaNumericString(maxLength)
-            );
-            String msg = invokeConvertAuditRecordToSyslogMessage(record, maxLength);
-            Assert.assertTrue(msg.length() <= maxLength);
-            Assert.assertTrue(msg.length() > maxLength - 100);
-        }
-    }
-
-    private String invokeConvertAuditRecordToSyslogMessage(final AuditRecord record, final int maxMsgLength)
-            throws Exception
-    {
-        final Method method = SyslogAuditService.class.getDeclaredMethod(
-                "convertAuditRecordToSyslogMessage",
-                AuditRecord.class,
-                Configuration.class
-        );
-        method.setAccessible(true);
-        final Configuration configuration = spy(new Configuration(StoredConfigurationImpl.newStoredConfiguration()));
-        when(configuration.readAppProperty(AppProperty.AUDIT_SYSLOG_MAX_MESSAGE_LENGTH)).thenReturn(Integer.toString(maxMsgLength));
-
-        return (String)method.invoke(null, record, configuration);
-    }
-}

+ 9 - 4
server/src/test/java/password/pwm/tests/MakeSelfSignedCertTest.java

@@ -22,19 +22,24 @@
 
 
 package password.pwm.tests;
 package password.pwm.tests;
 
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.junit.Assert;
+import org.junit.Test;
 import password.pwm.util.secure.HttpsServerCertificateManager;
 import password.pwm.util.secure.HttpsServerCertificateManager;
 
 
-import java.security.*;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
 import java.security.cert.X509Certificate;
 import java.security.cert.X509Certificate;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
-public class MakeSelfSignedCertTest extends TestCase
+public class MakeSelfSignedCertTest
 {
 {
    private static final Provider BC_PROVIDER = new BouncyCastleProvider();
    private static final Provider BC_PROVIDER = new BouncyCastleProvider();
 
 
+   @Test
    public void testSelfSignedCert() throws Exception
    public void testSelfSignedCert() throws Exception
    {
    {
       Security.addProvider(BC_PROVIDER);
       Security.addProvider(BC_PROVIDER);

+ 5 - 4
server/src/test/java/password/pwm/tests/PwmPasswordJudgeTest.java

@@ -22,19 +22,20 @@
 
 
 package password.pwm.tests;
 package password.pwm.tests;
 
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
 import org.mockito.Mockito;
 import org.mockito.Mockito;
 import password.pwm.config.Configuration;
 import password.pwm.config.Configuration;
 import password.pwm.config.PwmSetting;
 import password.pwm.config.PwmSetting;
 import password.pwm.config.option.StrengthMeterType;
 import password.pwm.config.option.StrengthMeterType;
-import password.pwm.util.java.JavaHelper;
 import password.pwm.util.operations.PasswordUtility;
 import password.pwm.util.operations.PasswordUtility;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 
 
-public class PwmPasswordJudgeTest extends TestCase {
+public class PwmPasswordJudgeTest
+{
+    @Test
     public void testJudgePassword() throws Exception {
     public void testJudgePassword() throws Exception {
         final Configuration configuration = Mockito.mock(Configuration.class);
         final Configuration configuration = Mockito.mock(Configuration.class);
         Mockito.when(configuration.readSettingAsEnum(PwmSetting.PASSWORD_STRENGTH_METER_TYPE, StrengthMeterType.class)).thenReturn(StrengthMeterType.PWM);
         Mockito.when(configuration.readSettingAsEnum(PwmSetting.PASSWORD_STRENGTH_METER_TYPE, StrengthMeterType.class)).thenReturn(StrengthMeterType.PWM);

+ 1 - 1
server/src/test/java/password/pwm/util/queue/EmailQueueManagerTest.java

@@ -22,8 +22,8 @@
 
 
 package password.pwm.util.queue;
 package password.pwm.util.queue;
 
 
-import junit.framework.Assert;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.mockito.Mockito;
 import password.pwm.AppProperty;
 import password.pwm.AppProperty;