Skip to content

Commit

Permalink
junits for testers
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalgoyal committed Nov 8, 2024
1 parent 65190c1 commit 28b60e9
Show file tree
Hide file tree
Showing 21 changed files with 113 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import zingg.common.client.ArgumentsUtil;
import zingg.common.client.ClientOptions;
import zingg.common.client.ZinggClientException;
import zingg.common.client.pipe.Pipe;
import zingg.common.core.executor.validate.ExecutorValidator;

public class ExecutorTester<S, D, R, C, T>{

Expand All @@ -18,28 +20,32 @@ public class ExecutorTester<S, D, R, C, T>{
public ExecutorValidator<S, D, R, C, T> validator;
protected IArguments args;
protected String configFile;
protected String phase;

public ExecutorTester(ZinggBase<S, D, R, C, T> executor,ExecutorValidator<S, D, R, C, T> validator, IArguments args, String configFile, String phase) throws ZinggClientException, IOException {
public ExecutorTester(ZinggBase<S, D, R, C, T> executor,ExecutorValidator<S, D, R, C, T> validator, String configFile) throws ZinggClientException, IOException {
this.executor = executor;
this.validator = validator;
this.args = setupArgs(configFile, phase);
this.configFile = setupConfigFile(configFile, phase);
this.configFile = configFile;
setupArgs();
}

public IArguments setupArgs(String configFile, String phase) throws ZinggClientException, IOException {
args = new ArgumentsUtil().createArgumentsFromJSON(getClass().getClassLoader().getResource(configFile).getFile(), phase);
for (Pipe p: args.getData()) {
if (p.getProps().containsKey("location")) {
String testOneFile = getClass().getClassLoader().getResource(p.get("location")).getFile();
// correct the location of test data
p.setProp("location", testOneFile);
}
}
return args;
}

public String setupConfigFile(String configFile, String phase) throws ZinggClientException, IOException {
String config = getClass().getClassLoader().getResource(configFile).getFile();
args = new ArgumentsUtil().createArgumentsFromJSON(config, phase);
return config;
public void setupArgs() throws ZinggClientException, IOException{
this.args = setupArgs(configFile, "");
}

public void initAndExecute(IArguments args, S session, ClientOptions c) throws ZinggClientException {
executor.init(args,session, c);
public void initAndExecute(S session) throws ZinggClientException {
executor.init(args,session, new ClientOptions());
executor.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import zingg.common.client.ClientOptions;
import zingg.common.client.ZinggClientException;
import zingg.common.core.executor.validate.FindAndLabelValidator;
import zingg.common.core.executor.validate.TrainMatchValidator;

public abstract class TestExecutorsCompound<S, D, R, C, T> extends TestExecutorsGeneric<S, D, R, C, T> {

Expand All @@ -21,24 +23,13 @@ public TestExecutorsCompound() {
public List<ExecutorTester<S, D, R, C, T>> getExecutors() throws ZinggClientException, IOException{
FindAndLabeller<S, D, R, C, T> findAndLabel = getFindAndLabeller();
FindAndLabelValidator<S, D, R, C, T> falValidator = new FindAndLabelValidator<S, D, R, C, T>(findAndLabel);
ExecutorTester<S, D, R, C, T> et = new ExecutorTester<S, D, R, C, T>(findAndLabel, falValidator, args, getConfigFile(), "findAndLabel");
ExecutorTester<S, D, R, C, T> et = new ExecutorTester<S, D, R, C, T>(findAndLabel, falValidator,getConfigFile());
executorTesterList.add(et);
executorTesterList.add(et);
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(getTrainMatcher(),getTrainMatchValidator(getTrainMatcher()), args, getConfigFile(), "trainMatch"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(getTrainMatcher(),getTrainMatchValidator(getTrainMatcher()), getConfigFile()));
return executorTesterList;
}

@Test
public void testExecutors() throws ZinggClientException, IOException {

List<ExecutorTester<S, D, R, C, T>> executorTesterList = getExecutors();

for (ExecutorTester<S, D, R, C, T> executorTester : executorTesterList) {
executorTester.initAndExecute(args,session, new ClientOptions());
executorTester.validateResults();
}

}

public abstract String getConfigFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;

import zingg.common.client.ClientOptions;
import zingg.common.client.IArguments;
Expand All @@ -14,11 +15,9 @@
public abstract class TestExecutorsGeneric<S, D, R, C, T> {

public static final Log LOG = LogFactory.getLog(TestExecutorsGeneric.class);

protected IArguments args;
protected IArguments linkerArgs;

protected S session;
protected ClientOptions options;
List<ExecutorTester<S, D, R, C, T>> executorTesterList = new ArrayList<ExecutorTester<S, D, R, C, T>>();

public TestExecutorsGeneric() {

Expand All @@ -32,11 +31,24 @@ public void init(S s) throws ZinggClientException, IOException {
this.session = s;
}

List<ExecutorTester<S, D, R, C, T>> executorTesterList = new ArrayList<ExecutorTester<S, D, R, C, T>>();


public abstract List<ExecutorTester<S, D, R, C, T>> getExecutors() throws ZinggClientException, IOException;

public abstract void tearDown();
//public abstract void tearDown();

@Test
public void testExecutors() throws ZinggClientException, IOException {

List<ExecutorTester<S, D, R, C, T>> executorTesterList = getExecutors();

for (ExecutorTester<S, D, R, C, T> executorTester : executorTesterList) {
executorTester.setupArgs();
executorTester.initAndExecute(session);
executorTester.validateResults();
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

import zingg.common.client.ClientOptions;
import zingg.common.client.ZinggClientException;
import zingg.common.core.executor.validate.BlockerValidator;
import zingg.common.core.executor.validate.LabellerValidator;
import zingg.common.core.executor.validate.LinkerValidator;
import zingg.common.core.executor.validate.MatcherValidator;
import zingg.common.core.executor.validate.TrainerValidator;
import zingg.common.core.executor.validate.TrainingDataFinderValidator;
import zingg.common.core.executor.verifyblocking.VerifyBlocking;

public abstract class TestSingleExecutors<S, D, R, C, T> extends TestExecutorsGeneric<S, D, R, C, T> {
Expand All @@ -23,43 +29,33 @@ public TestSingleExecutors(){
@Override
public List<ExecutorTester<S, D, R, C, T>> getExecutors() throws ZinggClientException, IOException{
TrainingDataFinder<S, D, R, C, T> tdf = getTrainingDataFinder();
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(tdf, new TrainingDataFinderValidator<S, D, R, C, T>(tdf),args,getConfigFile(),"findTrainingData"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(tdf, new TrainingDataFinderValidator<S, D, R, C, T>(tdf),getConfigFile()));

Labeller<S, D, R, C, T> labeler = getLabeller();
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(labeler, new LabellerValidator<S, D, R, C, T>(labeler),args,getConfigFile(),"label"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(labeler, new LabellerValidator<S, D, R, C, T>(labeler),getConfigFile()));

executorTesterList.add(new ExecutorTester<S, D, R, C, T>(tdf, new TrainingDataFinderValidator<S, D, R, C, T>(tdf),args,getConfigFile(),"findTrainingData"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(labeler, new LabellerValidator<S, D, R, C, T>(labeler),args,getConfigFile(),"label"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(tdf, new TrainingDataFinderValidator<S, D, R, C, T>(tdf),getConfigFile()));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(labeler, new LabellerValidator<S, D, R, C, T>(labeler),getConfigFile()));

executorTesterList.add(new ExecutorTester<S, D, R, C, T>(tdf, new TrainingDataFinderValidator<S, D, R, C, T>(tdf),args,getConfigFile(),"findTrainingData"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(labeler, new LabellerValidator<S, D, R, C, T>(labeler),args,getConfigFile(),"label"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(tdf, new TrainingDataFinderValidator<S, D, R, C, T>(tdf),getConfigFile()));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(labeler, new LabellerValidator<S, D, R, C, T>(labeler),getConfigFile()));

Trainer<S, D, R, C, T> trainer = getTrainer();
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(trainer,getTrainerValidator(trainer),args,getConfigFile(),"train"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(trainer,getTrainerValidator(trainer),getConfigFile()));

VerifyBlocking<S, D, R, C, T> verifyBlocker = getVerifyBlocker();
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(verifyBlocker, new BlockerValidator<S, D, R, C, T>(verifyBlocker),args,getConfigFile(),"verifyBlocking"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(verifyBlocker, new BlockerValidator<S, D, R, C, T>(verifyBlocker),getConfigFile()));

Matcher<S, D, R, C, T> matcher = getMatcher();
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(matcher,new MatcherValidator<S, D, R, C, T>(matcher),args,getConfigFile(),"match"));
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(matcher,new MatcherValidator<S, D, R, C, T>(matcher),getConfigFile()));

Linker<S, D, R, C, T> linker = getLinker();
executorTesterList.add(new ExecutorTester<S, D, R, C, T>(linker,new LinkerValidator<S, D, R, C, T>(linker),linkerArgs,getLinkerConfigFile(),"link"));
//executorTesterList.add(new LinkerExecutorTester<S, D, R, C, T>(linker,new LinkerValidator<S, D, R, C, T>(linker),getLinkerConfigFile()));

return executorTesterList;
}

@Test
public void testExecutors() throws ZinggClientException, IOException {

List<ExecutorTester<S, D, R, C, T>> executorTesterList = getExecutors();

for (ExecutorTester<S, D, R, C, T> executorTester : executorTesterList) {
executorTester.initAndExecute(args,session, new ClientOptions());
executorTester.validateResults();
}

}


public abstract String getConfigFile();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package zingg.common.core.executor;
package zingg.common.core.executor.labeller;

import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.client.options.ZinggOptions;
import zingg.common.client.util.ColName;
import zingg.common.client.util.ColValues;
import zingg.common.core.context.Context;
import zingg.common.core.executor.Labeller;

public class ProgrammaticLabeller<S,D,R,C,T> extends Labeller<S,D,R,C,T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import zingg.common.client.ZinggClientException;
import zingg.common.core.executor.ZinggBase;

public abstract class ExecutorValidator<S, D, R, C, T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

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

Expand All @@ -8,6 +8,7 @@
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.client.util.ColName;
import zingg.common.core.executor.FindAndLabeller;

public class FindAndLabelValidator<S, D, R, C, T> extends ExecutorValidator<S, D, R, C, T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

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

Expand All @@ -8,6 +8,7 @@
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.client.util.ColName;
import zingg.common.core.executor.Labeller;

public class LabellerValidator<S, D, R, C, T> extends ExecutorValidator<S, D, R, C, T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.core.executor.Matcher;

public class LinkerValidator<S, D, R, C, T> extends MatcherValidator<S, D, R, C, T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

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

Expand All @@ -8,6 +8,7 @@
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.client.util.ColName;
import zingg.common.core.executor.Matcher;

public class MatcherValidator<S, D, R, C, T> extends ExecutorValidator<S, D, R, C, T> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

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

Expand All @@ -9,19 +9,17 @@
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.client.util.ColName;
import zingg.common.core.executor.TrainMatcher;

public class TrainMatchValidator<S, D, R, C, T> extends ExecutorValidator<S, D, R, C, T> {

public static final Log LOG = LogFactory.getLog(TrainMatchValidator.class);

protected IArguments args;
TrainerValidator<S, D, R, C, T> tv;
MatcherValidator<S, D, R, C, T> mv;

public TrainMatchValidator(TrainMatcher<S, D, R, C, T> executor, IArguments args) {
public TrainMatchValidator(TrainMatcher<S, D, R, C, T> executor) {
super(executor);
this.args = args;
tv = new TrainerValidator<S, D, R, C, T>(executor.getTrainer(), args);
tv = new TrainerValidator<S, D, R, C, T>(executor.getTrainer());
mv = new MatcherValidator<S, D, R, C, T>(executor.getMatcher());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import zingg.common.client.IArguments;
import zingg.common.client.ZinggClientException;
import zingg.common.core.executor.Trainer;

public class TrainerValidator<S, D, R, C, T> extends ExecutorValidator<S, D, R, C, T> {

public static final Log LOG = LogFactory.getLog(TrainerValidator.class);

protected IArguments args;

public TrainerValidator(Trainer<S, D, R, C, T> executor,IArguments args) {
public TrainerValidator(Trainer<S, D, R, C, T> executor) {
super(executor);
this.args = args;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package zingg.common.core.executor;
package zingg.common.core.executor.validate;

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

Expand All @@ -7,6 +7,7 @@

import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.core.executor.TrainingDataFinder;

public class TrainingDataFinderValidator<S, D, R, C, T> extends ExecutorValidator<S, D, R, C, T> {

Expand Down
Loading

0 comments on commit 28b60e9

Please sign in to comment.