mirror of
https://github.com/corda/corda.git
synced 2025-02-06 11:09:18 +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:
parent
0c0101948b
commit
603da3eeff
@ -158,11 +158,6 @@ dependencies {
|
|||||||
compile "org.hibernate:hibernate-core:$hibernate_version"
|
compile "org.hibernate:hibernate-core:$hibernate_version"
|
||||||
compile "org.hibernate:hibernate-java8:$hibernate_version"
|
compile "org.hibernate:hibernate-java8:$hibernate_version"
|
||||||
|
|
||||||
// Capsule is a library for building independently executable fat JARs.
|
|
||||||
// We only need this dependency to compile our Caplet against.
|
|
||||||
compileOnly "co.paralleluniverse:capsule:$capsule_version"
|
|
||||||
testCompile "co.paralleluniverse:capsule:$capsule_version"
|
|
||||||
|
|
||||||
// OkHTTP: Simple HTTP library.
|
// OkHTTP: Simple HTTP library.
|
||||||
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
|
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
|
||||||
|
|
||||||
|
@ -16,15 +16,17 @@ configurations {
|
|||||||
dependencies {
|
dependencies {
|
||||||
// TypeSafe Config: for simple and human friendly config files.
|
// TypeSafe Config: for simple and human friendly config files.
|
||||||
capsuleRuntime "com.typesafe:config:$typesafe_config_version"
|
capsuleRuntime "com.typesafe:config:$typesafe_config_version"
|
||||||
}
|
compileOnly "com.typesafe:config:$typesafe_config_version"
|
||||||
|
testRuntimeOnly "com.typesafe:config:$typesafe_config_version"
|
||||||
|
|
||||||
// Force the Caplet to target Java 6. This ensures that running 'java -jar corda.jar' on any Java 6 VM upwards
|
// Capsule is a library for building independently executable fat JARs.
|
||||||
// will get as far as the Capsule version checks, meaning that if your JVM is too old, you will at least get
|
// We only need this dependency to compile our Caplet against.
|
||||||
// a sensible error message telling you what to do rather than a bytecode version exception that doesn't.
|
compileOnly "co.paralleluniverse:capsule:$capsule_version"
|
||||||
// If we introduce .java files into this module that need Java 8+ then we will have to push the caplet into
|
testCompile "co.paralleluniverse:capsule:$capsule_version"
|
||||||
// its own module so its target can be controlled individually, but for now this suffices.
|
|
||||||
sourceCompatibility = 1.6
|
testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}"
|
||||||
targetCompatibility = 1.6
|
testImplementation "junit:junit:$junit_version"
|
||||||
|
}
|
||||||
|
|
||||||
jar.enabled = false
|
jar.enabled = false
|
||||||
|
|
||||||
@ -38,13 +40,12 @@ task buildCordaJAR(type: FatCapsule, dependsOn: project(':node').tasks.jar) {
|
|||||||
applicationSource = files(
|
applicationSource = files(
|
||||||
project(':node').configurations.runtimeClasspath,
|
project(':node').configurations.runtimeClasspath,
|
||||||
project(':node').tasks.jar,
|
project(':node').tasks.jar,
|
||||||
project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet.class',
|
|
||||||
project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet$1.class',
|
|
||||||
project(':node').buildDir.toString() + '/resources/main/reference.conf',
|
project(':node').buildDir.toString() + '/resources/main/reference.conf',
|
||||||
"$rootDir/config/dev/log4j2.xml",
|
"$rootDir/config/dev/log4j2.xml",
|
||||||
'NOTICE' // Copy CDDL notice
|
'NOTICE' // Copy CDDL notice
|
||||||
)
|
)
|
||||||
from configurations.capsuleRuntime.files.collect { zipTree(it) }
|
from configurations.capsuleRuntime.files.collect { zipTree(it) }
|
||||||
|
with jar
|
||||||
|
|
||||||
capsuleManifest {
|
capsuleManifest {
|
||||||
applicationVersion = corda_release_version
|
applicationVersion = corda_release_version
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user