mirror of
https://github.com/corda/corda.git
synced 2025-06-22 00:57:21 +00:00
CORDA-2984 Re-instate CordaCaplet tests and move CordaCaplet code into :node:cap… (#5197)
* Re-instate CordaCaplet tests and move CordaCaplet code into :node:capsule module. * Clean-up verbose IntelliJ refactoring. * Updated buildCordaJAR task references to resolve CordaCaplet from :node:capsule project. * Incorporating feedback from PR review.
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class CordaCapletBaseDirectoryParsingFailureTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> CombinationsToTest() {
|
||||
return Arrays.asList(
|
||||
new Object[][]{
|
||||
{new String[]{"--base-directory", "--another-option"}},
|
||||
{new String[]{"--base-directory=", "-a"}},
|
||||
{new String[]{"-b", "--another-option"}},
|
||||
{new String[]{"-b=", "-a"}}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private String[] cmdLineArguments;
|
||||
|
||||
public CordaCapletBaseDirectoryParsingFailureTest(String[] baseOption) {
|
||||
this.cmdLineArguments = baseOption;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatBaseDirectoryFallsBackToCurrentWhenBaseDirectoryIsNotSupplied() {
|
||||
final CordaCaplet caplet = CordaCapletTestUtils.getCaplet();
|
||||
final String returnPath = caplet.getBaseDirectory(Arrays.asList(cmdLineArguments));
|
||||
final String expected = Paths.get(".").toAbsolutePath().normalize().toString();
|
||||
Assert.assertEquals(expected, returnPath);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class CordaCapletBaseDirectoryParsingTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> CombinationsToTest() {
|
||||
return Arrays.asList(
|
||||
new Object[][]{
|
||||
{new String[]{"--base-directory", "blah"}},
|
||||
{new String[]{"--base-directory=blah"}},
|
||||
{new String[]{"-b", "blah"}},
|
||||
{new String[]{"-b=blah"}}
|
||||
});
|
||||
}
|
||||
|
||||
private String[] cmdLineArguments;
|
||||
|
||||
public CordaCapletBaseDirectoryParsingTest(String[] arr) {
|
||||
this.cmdLineArguments = arr;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatBaseDirectoryParameterIsRecognised() {
|
||||
final CordaCaplet caplet = CordaCapletTestUtils.getCaplet();
|
||||
final String returnPath = caplet.getBaseDirectory(Arrays.asList(cmdLineArguments));
|
||||
final String expected = Paths.get(".").resolve("blah").toAbsolutePath().normalize().toString();
|
||||
assertEquals(expected, returnPath);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class CordaCapletConfigFileParsingFailureTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> CombinationsToTest() {
|
||||
return Arrays.asList(
|
||||
new Object[][]{
|
||||
{new String[]{"--config-file", "--another-option"}},
|
||||
{new String[]{"--config-file=", "-a"}},
|
||||
{new String[]{"-f", "--another-option"}},
|
||||
{new String[]{"-f=", "-a"}}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private String[] cmdLineArguments;
|
||||
|
||||
public CordaCapletConfigFileParsingFailureTest(String[] baseOption) {
|
||||
this.cmdLineArguments = baseOption;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatBaseDirectoryFallsBackToDefaultWhenConfigFileIsNotSupplied() {
|
||||
final CordaCaplet caplet = CordaCapletTestUtils.getCaplet();
|
||||
final File returnPath = caplet.getConfigFile(Arrays.asList(cmdLineArguments), CordaCapletTestUtils.getBaseDir());
|
||||
final File expected = Paths.get(".").resolve("node.conf").toAbsolutePath().normalize().toFile();
|
||||
Assert.assertEquals(expected, returnPath);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class CordaCapletConfigFileParsingTest {
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> CombinationsToTest() {
|
||||
return Arrays.asList(
|
||||
new Object[][]{
|
||||
{new String[]{"--config-file", "blah.conf"}},
|
||||
{new String[]{"--config-file=blah.conf"}},
|
||||
{new String[]{"-f", "blah.conf"}},
|
||||
{new String[]{"-f=blah.conf"}}
|
||||
});
|
||||
}
|
||||
|
||||
private String[] cmdLineArguments;
|
||||
|
||||
public CordaCapletConfigFileParsingTest(String[] arr) {
|
||||
this.cmdLineArguments = arr;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatConfigFileParameterIsRecognised() {
|
||||
final CordaCaplet caplet = CordaCapletTestUtils.getCaplet();
|
||||
final File returnPath = caplet.getConfigFile(Arrays.asList(cmdLineArguments), CordaCapletTestUtils.getBaseDir());
|
||||
final File expected = Paths.get(".").resolve("blah.conf").toAbsolutePath().normalize().toFile();
|
||||
assertEquals(expected, returnPath.getAbsoluteFile());
|
||||
}
|
||||
}
|
||||
|
16
node/capsule/src/test/java/CordaCapletTestUtils.java
Normal file
16
node/capsule/src/test/java/CordaCapletTestUtils.java
Normal file
@ -0,0 +1,16 @@
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
class CordaCapletTestUtils {
|
||||
static CordaCaplet getCaplet() {
|
||||
final String path = System.getProperty("user.dir") + File.separator + ".." + File.separator + "build" + File.separator + "libs" + File.separator;
|
||||
final File jar = Arrays.stream(Objects.requireNonNull(new File(path).listFiles())).filter(x -> x.getName().startsWith("corda-node") && x.getName().endsWith(".jar")).findFirst().get();
|
||||
return new CordaCaplet(new Capsule(jar.toPath()));
|
||||
}
|
||||
|
||||
static String getBaseDir() {
|
||||
return Paths.get(".").toAbsolutePath().normalize().toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user