Skip to content

Commit d67022a

Browse files
committed
example main entry point and test to invoke it
1 parent 8bdeb70 commit d67022a

4 files changed

Lines changed: 102 additions & 6 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.nuix.innovation.enginewrapper;
2+
3+
import nuix.Utilities;
4+
import org.joda.time.DateTime;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.lang.management.ManagementFactory;
11+
import java.lang.management.RuntimeMXBean;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
public class App {
16+
private static final Logger log = LoggerFactory.getLogger(App.class);
17+
private static boolean logEnvDetails = true;
18+
19+
public static void main(String[] args) {
20+
logEnvDetails();
21+
22+
try (NuixEngine nuixEngine = constructNuixEngine()) {
23+
Utilities utilities = nuixEngine.getUtilities();
24+
25+
// This is where the magic happens. In this scope, Nuix should be licensed.
26+
// To run a test in the IDE, I recommend invoking from AppTest in the project tests.
27+
28+
log.info("Nuix Engine Version: {}", nuixEngine.getNuixVersionString());
29+
30+
} catch (Exception exc) {
31+
log.error("Uncaught exception, exiting", exc);
32+
}
33+
}
34+
35+
private static void logEnvDetails() {
36+
if (logEnvDetails) {
37+
System.out.println("JVM Arguments:");
38+
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
39+
List<String> jvmArgs = bean.getInputArguments();
40+
for (String arg : jvmArgs) {
41+
System.out.println(arg);
42+
}
43+
44+
System.out.println("Environment Variables:");
45+
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
46+
System.out.println(String.format("%s => %s", entry.getKey(), entry.getValue()));
47+
}
48+
}
49+
}
50+
51+
/***
52+
* Tests will generally call this method to construct the instance of NuixEngine they will use to perform
53+
* their given test. This allows you to customize it to your environment without having to alter all the tests.
54+
* @return A NuixEngine instance ready to use
55+
*/
56+
public static NuixEngine constructNuixEngine(String... additionalRequiredFeatures) throws IOException {
57+
List<String> features = List.of("CASE_CREATION");
58+
if (additionalRequiredFeatures != null && additionalRequiredFeatures.length > 0) {
59+
features.addAll(List.of(additionalRequiredFeatures));
60+
}
61+
62+
NuixLicenseResolver cloud = NuixLicenseResolver.fromCloud()
63+
.withLicenseCredentialsResolvedFromEnvVars()
64+
.withMinWorkerCount(4)
65+
.withRequiredFeatures(features);
66+
67+
NuixLicenseResolver dongle = NuixLicenseResolver.fromDongle()
68+
.withRequiredFeatures(features);
69+
70+
NuixLicenseResolver nms = NuixLicenseResolver.fromServer("<NMS HOST OR IP>")
71+
.withMinWorkerCount(4)
72+
.withRequiredFeatures(features)
73+
.withRequiredFeatures(features);
74+
75+
return NuixEngine.usingFirstAvailableLicense(cloud, nms, dongle)
76+
.setEngineDistributionDirectoryFromEnvVar()
77+
.setLogDirectory(new File("C:/NuixEngineLogs/", DateTime.now().toString("YYYY-MM-dd_HH-mm-ss")).getCanonicalFile());
78+
}
79+
}

IntelliJ/src/main/java/com/nuix/innovation/enginewrapper/NuixEngine.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,15 @@ private void checkPreConditions() throws Exception {
458458
}
459459
}
460460

461-
// Make sure PATH points to expected bin and bin/x86 subdirectories of our engine distribution
462-
String envPath = System.getenv("PATH");
461+
// Make sure PATH points to expected bin and bin/x86 subdirectories of our engine distribution. Since it seems
462+
// that case of the key "Path" vs "PATH" can matter, we will search for it in a case insensitive manner.
463+
String envPath = null;
464+
for(Map.Entry<String,String> envEntry : System.getenv().entrySet()) {
465+
if(envEntry.getKey().trim().equalsIgnoreCase("PATH")) {
466+
envPath = envEntry.getValue();
467+
break;
468+
}
469+
}
463470

464471
if (envPath == null || envPath.isBlank()) {
465472
if (!ignoreIssues) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import com.nuix.innovation.enginewrapper.App;
2+
import org.junit.jupiter.api.Test;
3+
4+
public class AppTest {
5+
@Test
6+
public void Test() throws Exception {
7+
App.main(new String[]{});
8+
}
9+
}

IntelliJ/src/test/java/CommonTestFunctionality.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import com.nuix.innovation.enginewrapper.NuixEngine;
22
import com.nuix.innovation.enginewrapper.NuixLicenseResolver;
33
import org.apache.commons.io.FileUtils;
4+
import org.joda.time.DateTime;
45
import org.junit.jupiter.api.AfterAll;
56
import org.junit.jupiter.api.BeforeAll;
67
import org.slf4j.Logger;
@@ -10,7 +11,7 @@
1011
import java.io.IOException;
1112
import java.lang.management.ManagementFactory;
1213
import java.lang.management.RuntimeMXBean;
13-
import java.util.*;
14+
import java.util.List;
1415

1516
public class CommonTestFunctionality {
1617
// Used in some tests, this is a simple class to hold
@@ -75,7 +76,7 @@ public static void breakdown() {
7576
* @return A NuixEngine instance ready to use
7677
*/
7778
public NuixEngine constructNuixEngine() throws IOException {
78-
return constructNuixEngine((String[])null);
79+
return constructNuixEngine((String[]) null);
7980
}
8081

8182
/***
@@ -85,7 +86,7 @@ public NuixEngine constructNuixEngine() throws IOException {
8586
*/
8687
public NuixEngine constructNuixEngine(String... additionalRequiredFeatures) throws IOException {
8788
List<String> features = List.of("CASE_CREATION");
88-
if(additionalRequiredFeatures != null && additionalRequiredFeatures.length > 0) {
89+
if (additionalRequiredFeatures != null && additionalRequiredFeatures.length > 0) {
8990
features.addAll(List.of(additionalRequiredFeatures));
9091
}
9192

@@ -99,6 +100,6 @@ public NuixEngine constructNuixEngine(String... additionalRequiredFeatures) thro
99100

100101
return NuixEngine.usingFirstAvailableLicense(caseCreationCloud, caseCreationDongle)
101102
.setEngineDistributionDirectoryFromEnvVar()
102-
.setLogDirectory(new File(testOutputDirectory, "Logs_"+System.currentTimeMillis()).getCanonicalFile());
103+
.setLogDirectory(new File(testOutputDirectory, DateTime.now().toString("YYYY-MM-dd_HH-mm-ss")).getCanonicalFile());
103104
}
104105
}

0 commit comments

Comments
 (0)