Skip to content
Open
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
364 changes: 164 additions & 200 deletions common/client/src/test/java/zingg/common/client/TestArguments.java

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions common/client/src/test/java/zingg/common/client/TestClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zingg.common.client;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

import org.apache.commons.logging.Log;
Expand All @@ -12,25 +13,19 @@ public class TestClient {
public static final Log LOG = LogFactory.getLog(TestClient.class);

@Test
public void testValidPhase() {
public void testValidPhase() throws ZinggClientException {
String phase = "train";
try {
ZinggOptions.verifyPhase(phase);
} catch (ZinggClientException e1) {
fail("No exception was expected as it is a valid phase: " + phase);
}
ZinggOptions.verifyPhase(phase);
}

@Test
public void testInvalidPhase() {
String phase = "tain";
try {

assertThrows(ZinggClientException.class, () -> {
ZinggOptions.verifyPhase(phase);
fail("An exception should have been thrown for an invalid phase");
} catch (ZinggClientException e1) {
LOG.info("Expected exception as it is an invalid phase: " + phase);
}
});
}


}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package zingg.common.client;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;

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

public class TestClientOption {


Expand All @@ -27,34 +24,28 @@ public void testParseArguments() {

@Test
public void testParseUnsupportedArgumentsConf() {
try {
String[] args = {"--phase", "train",
"--conf1", "conf.json",
"--zinggDir", "/tmp/z_main",
"--email", "zingg@zingg.ai",
"--license", "zinggLicense.txt"};

ClientOptions co = new ClientOptions(args);
fail("exception should have been raised due to invalid conf option");
} catch (Exception e) {
assertTrue(true);
}
String[] args = {"--phase", "train",
"--conf1", "conf.json",
"--zinggDir", "/tmp/z_main",
"--email", "zingg@zingg.ai",
"--license", "zinggLicense.txt"};

assertThrows(UnsupportedOperationException.class, () -> {
new ClientOptions(args);
});
}

@Test
public void testParseUnsupportedArgumentsPhase() {
try {
String[] args = {"--phase1", "train",
"--conf1", "conf.json",
"--zinggDir", "/tmp/z_main",
"--email", "zingg@zingg.ai",
"--license", "zinggLicense.txt"};

ClientOptions co = new ClientOptions(args);
fail("exception should have been raised due to invalid phase option");
} catch (Exception e) {
assertTrue(true);
}
String[] args = {"--phase1", "train",
"--conf1", "conf.json",
"--zinggDir", "/tmp/z_main",
"--email", "zingg@zingg.ai",
"--license", "zinggLicense.txt"};

assertThrows(UnsupportedOperationException.class, () -> {
new ClientOptions(args);
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.rmi.NoSuchObjectException;
import java.util.List;

import org.apache.commons.logging.Log;
Expand All @@ -27,23 +28,13 @@ public TestFieldDefUtil() {


@Test
public void testMatchTypeFilter() {
IArguments args;
try {
args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configTestDontUse.json").getFile());
List<? extends FieldDefinition> dontUseList = fieldDefUtil.getFieldDefinitionDontUse(args.getFieldDefinition());
assertEquals(dontUseList.size(), 3);

List<? extends FieldDefinition> matchList = fieldDefUtil.getFieldDefinitionToUse(args.getFieldDefinition());
assertEquals(matchList.size(), 4);

} catch (Exception | ZinggClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Could not read config");
}

public void testMatchTypeFilter() throws NoSuchObjectException, ZinggClientException {
IArguments args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configTestDontUse.json").getFile());
List<? extends FieldDefinition> dontUseList = fieldDefUtil.getFieldDefinitionDontUse(args.getFieldDefinition());
assertEquals(dontUseList.size(), 3);

List<? extends FieldDefinition> matchList = fieldDefUtil.getFieldDefinitionToUse(args.getFieldDefinition());
assertEquals(matchList.size(), 4);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@ public class TestFieldDefinition {
public static final Log LOG = LogFactory.getLog(TestFieldDefinition.class);

@Test
public void testConvertAListOFMatchTypesIntoString() {
try {
List<IMatchType> matchType = Arrays.asList(MatchTypes.EMAIL, MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
String expectedString = "EMAIL,FUZZY,NULL_OR_BLANK";
String strMatchType = FieldDefinition.MatchTypeSerializer.getStringFromMatchType(matchType);
assertEquals(expectedString, strMatchType);
} catch (Exception | ZinggClientException e) {
e.printStackTrace();
}
public void testConvertAListOFMatchTypesIntoString() throws ZinggClientException {
List<IMatchType> matchType = Arrays.asList(MatchTypes.EMAIL, MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
String expectedString = "EMAIL,FUZZY,NULL_OR_BLANK";
String strMatchType = FieldDefinition.MatchTypeSerializer.getStringFromMatchType(matchType);
assertEquals(expectedString, strMatchType);
}

@Test
public void testConvertAListOFStringIntoMatchTypes() {
try{
String mtString = "FUZZY,NULL_OR_BLANK";
List<IMatchType> expectedString = Arrays.asList(MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
List<IMatchType> matchTypeString = FieldDefinition.MatchTypeDeserializer.getMatchTypeFromString(mtString);
assertEquals(expectedString, matchTypeString);
} catch (Exception | ZinggClientException e) {
e.printStackTrace();
}
public void testConvertAListOFStringIntoMatchTypes() throws ZinggClientException, Exception {
String mtString = "FUZZY,NULL_OR_BLANK";
List<IMatchType> expectedString = Arrays.asList(MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
List<IMatchType> matchTypeString = FieldDefinition.MatchTypeDeserializer.getMatchTypeFromString(mtString);
assertEquals(expectedString, matchTypeString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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

import java.rmi.NoSuchObjectException;
import java.util.Map;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -38,16 +38,10 @@ public void initialize(Context<S, D, R, C, T> context) throws ZinggClientExcepti
protected abstract DataDocumenter<S,D,R,C,T> getDataDocumenter(IContext<S,D,R,C,T> context, IArguments args, ClientOptions options);

@BeforeEach
public void setUp(){
try {
String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
IArgumentService<Arguments> argsUtil = new ArgumentServiceImpl<>(Arguments.class);
docArguments = argsUtil.loadArguments(configPath);
} catch (Throwable e) {
e.printStackTrace();
LOG.info("Unexpected exception received " + e.getMessage());
fail(e.getMessage());
}
public void setUp() throws NoSuchObjectException, ZinggClientException {
String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
IArgumentService<Arguments> argsUtil = new ArgumentServiceImpl<>(Arguments.class);
docArguments = argsUtil.loadArguments(configPath);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.rmi.NoSuchObjectException;
import java.util.Collections;
import java.util.Map;

Expand Down Expand Up @@ -41,30 +42,21 @@ public void initialize(Context<S, D, R, C, T> context) throws ZinggClientExcepti
}

@BeforeEach
public void setUp(){

try {
String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
IArgumentService<Arguments> argsUtil = new ArgumentServiceImpl<>(Arguments.class);
docArguments = argsUtil.loadArguments(configPath);
String zinggDirPath = getClass().getResource("../../../../"+docArguments.getZinggDir()).getFile();
docArguments.setZinggDir(zinggDirPath);
} catch (Throwable e) {
e.printStackTrace();
LOG.info("Unexpected exception received " + e.getMessage());
fail(e.getMessage());
}
public void setUp() throws NoSuchObjectException, ZinggClientException {
String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
IArgumentService<Arguments> argsUtil = new ArgumentServiceImpl<>(Arguments.class);
docArguments = argsUtil.loadArguments(configPath);
String zinggDirPath = getClass().getResource("../../../../"+docArguments.getZinggDir()).getFile();
docArguments.setZinggDir(zinggDirPath);
}

@Test
public void testIfModelDocumenterGeneratedDocFile() throws Throwable {
public void testIfModelDocumenterGeneratedDocFile() throws IOException, ZinggClientException {

ModelDocumenter<S,D,R,C,T> modelDoc = getModelDocumenter(context, docArguments, new ClientOptions());
try {
Files.deleteIfExists(Paths.get(modelDoc.getModelHelper().getZinggModelDocFile(docArguments)));
} catch (IOException e) {
e.printStackTrace();
}

Files.deleteIfExists(Paths.get(modelDoc.getModelHelper().getZinggModelDocFile(docArguments)));

modelDoc.createModelDocument();

assertTrue(Files.exists(Paths.get(modelDoc.getModelHelper().getZinggModelDocFile(docArguments))), "Model documentation file is not generated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,13 @@ public void init(S s) throws ZinggClientException, IOException {
//public abstract void tearDown();

@Test
public void testExecutors() throws ZinggClientException {
try {
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();
}
} catch (Exception e) {
throw new ZinggClientException("Exception occurred while running one or more test executors, ", e);
public void testExecutors() throws ZinggClientException, IOException, NoSuchMethodException {
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();
}

}

//model id getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package zingg.common.core.recommender;

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -22,6 +18,8 @@
import zingg.common.core.recommender.model.Records;
import zingg.common.core.recommender.model.WordByCount;

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

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

public static final Log LOG = LogFactory.getLog(TestStopWordsRecommenderBase.class);
Expand All @@ -43,17 +41,15 @@ public void initialize(DFObjectUtil<S, D, R, C> dfObjectUtil, Context<S,D,R,C,T>
this.recommender = getRecommender(context,arguments);
}

@Test
public void testWithNegativefCuttoff() throws Throwable{
try {
LOG.info("Test with stopCutoff = -1");
stopwordList = getStopWordList(-1.0f);
fail("Exception should not have been thrown when stopCutoff is negative");
}
catch(ZinggClientException e) {
}
@Test
public void testWithNegativeCutoff() {

LOG.info("Test with stopCutoff = -1");

}
assertThrows(ZinggClientException.class, () -> {
getStopWordList(-1.0f);
});
}

@Test
public void testWithCuttoffOne() throws Throwable {
Expand Down
41 changes: 0 additions & 41 deletions spark/core/src/test/java/zingg/spark/core/TestDocumenter.java

This file was deleted.

Loading
Loading