Skip to content

Commit

Permalink
Migrate tests to junit5.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshilliard committed Jul 14, 2019
1 parent 1543dfb commit 8c3caa4
Show file tree
Hide file tree
Showing 36 changed files with 314 additions and 302 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ subprojects {
}
}
}
test {
useJUnitPlatform()
}
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
Expand All @@ -112,7 +115,7 @@ subprojects {
}

dependencies {
testCompile libraries.junit
testImplementation libraries.junit
//Java 10 support
testCompile('com.sun.xml.bind:jaxb-impl:2.1.2')
testCompile('com.sun.activation:javax.activation:1.2.0')
Expand Down
2 changes: 1 addition & 1 deletion libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ext {

libraries = [
//jUnit (Tests)
junit: 'junit:junit:4.12',
junit: 'org.junit.jupiter:junit-jupiter:5.5.0',

//jPOS
jpos: "org.jpos:jpos:${jposVersion}",
Expand Down
32 changes: 18 additions & 14 deletions modules/binlog/src/test/java/org/jpos/binlog/BinLogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,42 @@

import org.jpos.iso.ISOUtil;
import org.jpos.util.TPS;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;


@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestMethodOrder(OrderAnnotation.class)
public class BinLogTest implements Runnable {
public static File dir;
private AtomicLong cnt = new AtomicLong();

@Before
@BeforeEach
public void before () {
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows")); //Skip Tests for BinLog if on MS Windows
Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows")); //Skip Tests for BinLog if on MS Windows
}

@BeforeClass
@BeforeAll
public static void setup () throws IOException {
dir = File.createTempFile("binlog-", "");
dir.delete();
System.out.println ("TEMP=" + dir);
// dir = new File("/tmp/binlog");
}
@Test
@Order(1)
public void test000_Write() throws IOException {
try (BinLogWriter w = new BinLogWriter(dir)) { }
for (int i=0; i<10; i++) {
Expand All @@ -65,7 +69,7 @@ public void test000_Write() throws IOException {
if ((i % 1000) == 0)
System.out.println(i + " " + new String(b));
}
assertEquals("Invalid number of entries", 100000, i);
assertEquals(100000, i, "Invalid number of entries");
}
}

Expand All @@ -86,7 +90,7 @@ public void run() {
}
}

@AfterClass
@AfterAll
public static void cleanup() throws IOException {
if (dir.listFiles() != null) {
for (File f : dir.listFiles()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

package org.jpos.crypto;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class SensitiveStringTest {
@Test
public void testSS() throws Exception {
String s = this.toString();
for (int i=0; i<15; i++) {
SensitiveString ss = new SensitiveString(s);
assertEquals("Should be equal", s, ss.get());
assertEquals(s, ss.get(), "Should be equal");
s = s + System.lineSeparator() + s;
}
}
Expand All @@ -38,6 +38,6 @@ public void testSSEquals() throws Exception {
String s = "The quick brown fox jumps over the lazy dog";
SensitiveString ss0 = new SensitiveString(s);
SensitiveString ss1 = new SensitiveString(s);
assertEquals ("Equals should be true", ss0, ss1);
assertEquals (ss0, ss1, "Equals should be true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@

package org.jpos.rest;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

@SuppressWarnings("unused")
public class APIAuthenticationTest {
SecretKey secretKey;

@Before
@BeforeEach
public void setUp() throws NoSuchAlgorithmException {
KeyGenerator gen = KeyGenerator.getInstance(APIAuthentication.HASH_ALGORITHM);
secretKey = gen.generateKey();
Expand All @@ -51,7 +51,7 @@ public void testInvalidTimestamp () throws AssertionError, NoSuchAlgorithmExcept
secretKey, "".getBytes()
);
} catch (IllegalArgumentException e) {
assertTrue ("Returned " + e.getMessage() + " instead of 'invalid.timestamp'", "invalid.timestamp".equals(e.getMessage()));
assertTrue ("invalid.timestamp".equals(e.getMessage()), "Returned " + e.getMessage() + " instead of 'invalid.timestamp'");
return;
}
fail ("Validation failed to catch invalid.timestamp");
Expand All @@ -73,7 +73,7 @@ public void testInvalidValid () throws AssertionError, NoSuchAlgorithmException,
badSecretKey, payLoad
);
} catch (IllegalArgumentException e) {
assertTrue ("Returned " + e.getMessage() + " instead of 'invalid.hash'", "invalid.hash".equals(e.getMessage()));
assertTrue ("invalid.hash".equals(e.getMessage()), "Returned " + e.getMessage() + " instead of 'invalid.hash'");
return;
}
fail ("Validation failed to catch invalid.hash");
Expand All @@ -96,7 +96,7 @@ public void testValidHash () throws AssertionError, NoSuchAlgorithmException, In
.nonce(cred.getNonce())
.hash(APIAuthentication.computeHash(cred, secretKey, payLoad)).build(), secretKey, payLoad);
} catch (IllegalArgumentException e) {
assertTrue ("Returned " + e.getMessage() + " instead of 'invalid.hash'", "invalid.hash".equals(e.getMessage()));
assertTrue ("invalid.hash".equals(e.getMessage()), "Returned " + e.getMessage() + " instead of 'invalid.hash'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.jpos.q2.Q2;
import org.jpos.space.Space;
import org.jpos.space.SpaceFactory;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;

import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
Expand All @@ -40,14 +40,14 @@
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SuppressWarnings("unchecked")
public abstract class APITestSupport {
static Q2 q2;
static Space sp;

@BeforeClass
@BeforeAll
public static void setUp() {
RestAssured.baseURI = APITest.BASE_URL;
RestAssured.requestSpecification = new RequestSpecBuilder().build().contentType(MediaType.APPLICATION_JSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.jpos.rest;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.security.InvalidKeyException;
Expand Down
66 changes: 33 additions & 33 deletions modules/eeuser/src/test/java/org/jpos/ee/EEUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

package org.jpos.ee;

import org.jpos.util.Chronometer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class EEUserTest {
DB db;
@Before
@BeforeEach
public void setUp() throws Exception {
db = new DB();
db.createSchema("schema.sql", true);
Expand Down Expand Up @@ -80,49 +79,50 @@ public void checkUser() throws Exception {
db.beginTransaction();
UserManager mgr = new UserManager(db, HashVersion.ZERO);
User u = mgr.getUserByNick("admin");
assertNotNull("User can't be null", u);
assertTrue("User has 'login' permission", u.hasPermission("login"));
assertTrue("User has 'admin' permission", u.hasPermission("admin"));
assertTrue("User has 'admin' role", u.hasPermission("role.admin"));
assertNotNull(u, "User can't be null");
assertTrue(u.hasPermission("login"), "User has 'login' permission");
assertTrue(u.hasPermission("admin"), "User has 'admin' permission");
assertTrue(u.hasPermission("role.admin"), "User has 'admin' role");

// for (Role r : u.getRoles()) {
// System.out.println("Role " + r.getName() + "-> " + r.getActivePermissions());
// }

assertTrue("User has 'TEST:testread", u.hasPermission("TEST:testread"));
assertTrue("User has 'TEST:admin", u.hasPermission("TEST:admin"));
assertTrue(u.hasPermission("TEST:testread"), "User has 'TEST:testread");
assertTrue(u.hasPermission("TEST:admin"), "User has 'TEST:admin");

assertTrue("User has all permissions TEST:role.tester, TEST:testread, TEST:testwrite, TEST:admin, TEST:login",
assertTrue(
u.hasAllPermissions(
new String[] {"TEST:role.tester", "TEST:testread", "TEST:testwrite", "TEST:admin", "TEST:login"})
);
assertTrue("User has all permissions", u.hasAllPermissions(new String[]{"login", "admin", "role.admin"}));
assertTrue("User has any permissions", u.hasAnyPermission(new String[]{"nologin", "admin", "role.admin"}));
assertFalse("User don't have 'superuser' permission", u.hasPermission("superuser"));

assertTrue("User password is 'test'", mgr.checkPassword(u, "test"));
assertEquals("User hash is correct", "ee89026a6c5603c51b4504d218ac60f6874b7750", u.getPasswordHash());
assertFalse("Password has to be in history", mgr.checkNewPassword(u, "test"));
new String[] {"TEST:role.tester", "TEST:testread", "TEST:testwrite", "TEST:admin", "TEST:login"}
),
"User has all permissions TEST:role.tester, TEST:testread, TEST:testwrite, TEST:admin, TEST:login");
assertTrue(u.hasAllPermissions(new String[]{"login", "admin", "role.admin"}), "User has all permissions");
assertTrue(u.hasAnyPermission(new String[]{"nologin", "admin", "role.admin"}), "User has any permissions");
assertFalse(u.hasPermission("superuser"), "User don't have 'superuser' permission");

assertTrue(mgr.checkPassword(u, "test"), "User password is 'test'");
assertEquals("ee89026a6c5603c51b4504d218ac60f6874b7750", u.getPasswordHash(), "User hash is correct");
assertFalse(mgr.checkNewPassword(u, "test"), "Password has to be in history");
mgr.upgradePassword(u, "test");
assertNotEquals("User hash has changed", "ee89026a6c5603c51b4504d218ac60f6874b7750", u.getPasswordHash());
assertTrue("User password is still 'test'", mgr.checkPassword(u, "test"));
assertNotEquals("User hash has changed", "ee89026a6c5603c51b4504d218ac60f6874b7750", u.getPasswordHash());
assertFalse("Password has to be in history", mgr.checkNewPassword(u, "test"));
assertNotEquals("ee89026a6c5603c51b4504d218ac60f6874b7750", u.getPasswordHash(), "User hash has changed");
assertTrue(mgr.checkPassword(u, "test"), "User password is still 'test'");
assertNotEquals("ee89026a6c5603c51b4504d218ac60f6874b7750", u.getPasswordHash(), "User hash has changed");
assertFalse(mgr.checkNewPassword(u, "test"), "Password has to be in history");
mgr.setPassword(u, "test1");
mgr.setPassword(u, "test2");
mgr.setPassword(u, "test3");
assertFalse("Password 1 has to be in history", mgr.checkNewPassword(u, "test1"));
assertFalse("Password 2 has to be in history", mgr.checkNewPassword(u, "test2"));
assertFalse("Password 3 has to be in history", mgr.checkNewPassword(u, "test3"));
assertTrue("User password is now 'test3'", mgr.checkPassword(u, "test3"));
assertFalse(mgr.checkNewPassword(u, "test1"), "Password 1 has to be in history");
assertFalse(mgr.checkNewPassword(u, "test2"), "Password 2 has to be in history");
assertFalse(mgr.checkNewPassword(u, "test3"), "Password 3 has to be in history");
assertTrue(mgr.checkPassword(u, "test3"), "User password is now 'test3'");
mgr.setPassword(u, "test");
assertTrue("User password is back to 'test'", mgr.checkPassword(u, "test"));
assertEquals ("History size is ", 5, u.getPasswordhistory().size());
assertTrue(mgr.checkPassword(u, "test"), "User password is back to 'test'");
assertEquals (5, u.getPasswordhistory().size(), "History size is ");
db.commit();
}


@After
@AfterEach
public void tearDown() {
db.close();
}
Expand Down
24 changes: 12 additions & 12 deletions modules/eeuser/src/test/java/org/jpos/ee/HashVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

package org.jpos.ee;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HashVersionTest {
@Test
public void testV0() throws Exception {
String hash = "31c1ffc755678596c7d76756b45b157f8dbda90a";
assertEquals ("version is ZERO", HashVersion.ZERO, HashVersion.getVersion(hash));
assertEquals("V0 hash", hash, HashVersion.ZERO.hash("17", "test", null));
assertTrue ("V0 check", HashVersion.ZERO.check ("17", "test", hash));
assertEquals (HashVersion.ZERO, HashVersion.getVersion(hash), "version is ZERO");
assertEquals(hash, HashVersion.ZERO.hash("17", "test", null), "V0 hash");
assertTrue (HashVersion.ZERO.check ("17", "test", hash), "V0 check");
}

@Test
Expand All @@ -38,12 +38,12 @@ public void testV1() throws Exception {
String h1 = "ARQ4ElU1RyJ2gULoUhqJXYu8EYYM6bJa1FE0sGR2O3NpcWT65t925nCv2SUL11vnObEgS4ZsbQ/ZUQ6CO9G0VzkPaHOj2IE2q1oa+IAbFab+W81o6QdY9ejjkZaQXzAOOXABtO+1v/iOvRGsne9nUaNjsrBqma4oi9gKcECO9ekEi2rZ1cY3Rt6iL92GTI6YH2x4yyLfZ0KXXC469zl6Cc8R9MgncX7LqawpxRQlMv3JXgodnjUxVQG+o/d46TCNGEDW4s45vS3G73Zp+wr3cK9A9sm5DWsBotvI2inI2BTEBgJ1v5xbc2YPFx9KfGIVaERwgLefet85kcyWc83myFxiODAkcVhlyzxOAjHE5BFC";
String h2 = "AQAAAAAAAAAAAAAAAAAAAACN+69cqNcdLS2Y2qJV7sCiDI+1C90wJm6OIgGjgKLDiOwmGLgjNTHwAvf8BBJ6Hv1vAfbiSKk7wWqatZZxugEKydBUgiHp5oB7hAAK5JsN72GZCwqbOPkgeaXLyNVBNEg8UUkhPV5RVkHcf4MpQ3UML59zepEcxY9Cfv0Dy1/q5vFvd5mbRzaTi0B8ayLRQN/zXerQuAryne4FPHaudODi6wes6dObTJXHUiwe9FR4yzCxp5D/4tTFpFKc6NTVz92x4DP+ZSXtCvQaTDgpr/zXqXkB3i3/6/Gnx8Kk8j2527wKIQhW92OwXVXHWflFUWs9deXLkuOoi6oqxXHDiJ3A";

assertEquals ("h0 version is ONE", HashVersion.ONE, HashVersion.getVersion(h0));
assertEquals ("h1 version is ONE", HashVersion.ONE, HashVersion.getVersion(h1));
assertEquals ("h2 version is ONE", HashVersion.ONE, HashVersion.getVersion(h2));
assertEquals (HashVersion.ONE, HashVersion.getVersion(h0), "h0 version is ONE");
assertEquals (HashVersion.ONE, HashVersion.getVersion(h1), "h1 version is ONE");
assertEquals (HashVersion.ONE, HashVersion.getVersion(h2), "h2 version is ONE");

assertTrue("V1 check (h0)", HashVersion.ONE.check ("", "test", h0));
assertTrue("V1 check (h1)", HashVersion.ONE.check ("", "test", h1));
assertTrue("V1 check (h2)", HashVersion.ONE.check ("", "test2", h2));
assertTrue(HashVersion.ONE.check ("", "test", h0), "V1 check (h0)");
assertTrue(HashVersion.ONE.check ("", "test", h1), "V1 check (h1)");
assertTrue(HashVersion.ONE.check ("", "test2", h2), "V1 check (h2)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

package org.jpos.fsdpackager;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.jpos.iso.AsciiInterpreter;
import org.jpos.iso.ISOException;
import org.jpos.iso.LiteralInterpreter;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class BranchFieldPackagerTest {

Expand Down
Loading

0 comments on commit 8c3caa4

Please sign in to comment.