Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at containerizing unit tests #35

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
USE_SYSTEM_ENV=true
buildDir=.
baseOkapEndpoint=https://okapi-cornell-training.folio.ebsco.com/
okapi_username=CHANGE ME
okapi_password=CHANGE ME
Expand Down
17 changes: 16 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
FROM maven:3.6.3-openjdk-15-slim as maven

# Some env vars are needed during build to run tests
ARG USE_SYSTEM_ENV=true
ENV USE_SYSTEM_ENV $USE_SYSTEM_ENV
ARG buildDir=.
ENV buildDir $buildDir
ARG baseOkapEndpoint
ENV baseOkapEndpoint $baseOkapEndpoint
ARG okapi_username
ENV okapi_username $okapi_username
ARG okapi_password
ENV okapi_password $okapi_password
ARG tenant
ENV tenant $tenant

COPY ./pom.xml ./pom.xml
COPY ./src ./src
COPY ./marc-test-files ./marc-test-files

RUN mvn dependency:go-offline -B
RUN mvn package -DskipTests=true
RUN mvn package

FROM jetty

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ services:
order-import-poc:
build:
context: .
args:
- USE_SYSTEM_ENV=${USE_SYSTEM_ENV}
- buildDir=${buildDir}
- baseOkapEndpoint=${baseOkapEndpoint}
- okapi_username=${okapi_username}
- okapi_password=${okapi_password}
- tenant=${tenant}
environment:
- USE_SYSTEM_ENV=true
- baseOkapEndpoint=${baseOkapEndpoint}
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/org/olf/folio/order/services/ApiBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@ public void init() {
config.setProperty("materialType", System.getenv("materialType"));

} else {
try {
props.load(ClassLoader.getSystemResourceAsStream("application.properties"));
this.apiUsername = (String) props.getProperty("okapi_username");
this.apiPassword = (String) props.getProperty("okapi_password");
this.tenant = (String) props.getProperty("tenant");
this.baseOkapEndpoint = (String) props.getProperty("baseOkapEndpoint");
} catch (ConfigurationException e) {
throw new RuntimeException("Could not load application.properties file");
}
config.addConfiguration(props);
}

this.setApiService(new ApiService(this.tenant));
try {
props.load(ClassLoader.getSystemResourceAsStream("application.properties"));
} catch (ConfigurationException e) {
throw new RuntimeException("Could not load application.properties file");
}
config.addConfiguration(props);
}

this.apiUsername = (String) config.getProperty("okapi_username");
this.apiPassword = (String) config.getProperty("okapi_password");
this.tenant = (String) config.getProperty("tenant");
this.baseOkapEndpoint = (String) config.getProperty("baseOkapEndpoint");

this.setApiService(new ApiService(this.tenant));

JSONObject jsonObject = new JSONObject();
jsonObject.put("username", this.apiUsername);
Expand Down
44 changes: 22 additions & 22 deletions src/test/java/org/olf/folio/order/util/LookupUtilBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
public class LookupUtilBaseTest {


private LookupUtil util;
private String apiUsername;
private LookupUtil util;
private String apiUsername;
private String apiPassword;
private String tenant;
private String baseOkapEndpoint;
private String token;
private ApiService apiService;


private String token;
private ApiService apiService;

public LookupUtil getUtil() {
return util;
}
Expand Down Expand Up @@ -85,10 +84,10 @@ public LookupUtilBaseTest() {

}

public void init() {
CompositeConfiguration config = new CompositeConfiguration();
PropertiesConfiguration props = new PropertiesConfiguration();
public void init() {
CompositeConfiguration config = new CompositeConfiguration();
PropertiesConfiguration props = new PropertiesConfiguration();
String use_env = System.getenv("USE_SYSTEM_ENV");
if (StringUtils.isNotEmpty(use_env) && StringUtils.equals(use_env, "true")) {
config.setProperty("baseOkapEndpoint", System.getenv("baseOkapEndpoint"));
Expand All @@ -105,19 +104,20 @@ public void init() {
config.setProperty("materialType", System.getenv("materialType"));

} else {
try {
props.load(ClassLoader.getSystemResourceAsStream("application.properties"));
this.apiUsername = (String) props.getProperty("okapi_username");
this.apiPassword = (String) props.getProperty("okapi_password");
this.tenant = (String) props.getProperty("tenant");
this.baseOkapEndpoint = (String) props.getProperty("baseOkapEndpoint");
} catch (ConfigurationException e) {
throw new RuntimeException("Could not load application.properties file");
}
config.addConfiguration(props);
try {
props.load(ClassLoader.getSystemResourceAsStream("application.properties"));
} catch (ConfigurationException e) {
throw new RuntimeException("Could not load application.properties file");
}
config.addConfiguration(props);
}

this.setApiService(new ApiService(this.tenant));

this.apiUsername = (String) config.getProperty("okapi_username");
this.apiPassword = (String) config.getProperty("okapi_password");
this.tenant = (String) config.getProperty("tenant");
this.baseOkapEndpoint = (String) config.getProperty("baseOkapEndpoint");

this.setApiService(new ApiService(this.tenant));

JSONObject jsonObject = new JSONObject();
jsonObject.put("username", this.apiUsername);
Expand Down
96 changes: 48 additions & 48 deletions src/test/java/org/olf/folio/order/util/MarcUtilsBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,59 @@
*/
public class MarcUtilsBaseTest {

private String buildDir;
private String buildDir;

protected String harrass;
protected String casalini;
protected String physical;
protected String amazonFO;
protected String coutts;
protected String requestors;
protected String singleharrass;
protected String harrassowitz;
protected String harrass;
protected String casalini;
protected String physical;
protected String amazonFO;
protected String coutts;
protected String requestors;
protected String singleharrass;
protected String harrassowitz;

MarcUtils marcUtils = new MarcUtils();
MarcUtils marcUtils = new MarcUtils();

public MarcUtilsBaseTest() {
init();
this.harrass = this.buildDir + "/marc-test-files/harrass.mrc";
this.casalini = this.buildDir + "/marc-test-files/Casalini.1.mrc";
this.physical = this.buildDir + "/marc-test-files/physical.mrc";
this.amazonFO = this.buildDir + "/marc-test-files/AmazonFO.1.mrc";
this.coutts = this.buildDir + "/marc-test-files/CouttsUKFO.1.mrc";
this.requestors = this.buildDir + "/marc-test-files/requesters_5-records_2021-03-11.mrc";
this.singleharrass = this.buildDir + "/marc-test-files/singleharrass.mrc";
this.harrassowitz = this.buildDir + "/marc-test-files/harrasowitz_9-records_2021-03-10.mrc";
}
public MarcUtilsBaseTest() {
init();
this.harrass = this.buildDir + "/marc-test-files/harrass.mrc";
this.casalini = this.buildDir + "/marc-test-files/Casalini.1.mrc";
this.physical = this.buildDir + "/marc-test-files/physical.mrc";
this.amazonFO = this.buildDir + "/marc-test-files/AmazonFO.1.mrc";
this.coutts = this.buildDir + "/marc-test-files/CouttsUKFO.1.mrc";
this.requestors = this.buildDir + "/marc-test-files/requesters_5-records_2021-03-11.mrc";
this.singleharrass = this.buildDir + "/marc-test-files/singleharrass.mrc";
this.harrassowitz = this.buildDir + "/marc-test-files/harrasowitz_9-records_2021-03-10.mrc";
}

public List<Record> getRecords(String fname) throws Exception {
List<Record> records = new ArrayList<Record>();
FileInputStream in = new FileInputStream(fname);
MarcReader reader = new MarcStreamReader(in);
Record record = null;
while (reader.hasNext()) {
record = reader.next();
records.add(record);
}
return records;
}
public List<Record> getRecords(String fname) throws Exception {
List<Record> records = new ArrayList<Record>();
FileInputStream in = new FileInputStream(fname);
MarcReader reader = new MarcStreamReader(in);
Record record = null;
while (reader.hasNext()) {
record = reader.next();
records.add(record);
}
return records;
}

public void init() {
CompositeConfiguration config = new CompositeConfiguration();
PropertiesConfiguration props = new PropertiesConfiguration();
public void init() {
CompositeConfiguration config = new CompositeConfiguration();
PropertiesConfiguration props = new PropertiesConfiguration();

String use_env = System.getenv("USE_SYSTEM_ENV");
if (StringUtils.isNotEmpty(use_env) && StringUtils.equals(use_env, "true")) {
config.setProperty("buildDir", System.getenv("buildDir"));
String use_env = System.getenv("USE_SYSTEM_ENV");
if (StringUtils.isNotEmpty(use_env) && StringUtils.equals(use_env, "true")) {
config.setProperty("buildDir", System.getenv("buildDir"));
} else {
try {
props.load(ClassLoader.getSystemResourceAsStream("application.properties"));
} catch (ConfigurationException e) {
throw new RuntimeException("Could not load application.properties file");
}
config.addConfiguration(props);
}

} else {
try {
props.load(ClassLoader.getSystemResourceAsStream("application.properties"));
this.buildDir = (String) props.getProperty("buildDir");
} catch (ConfigurationException e) {
throw new RuntimeException("Could not load application.properties file");
}
config.addConfiguration(props);
}
}
this.buildDir = (String) config.getProperty("buildDir");
}
}