Changed the way the test are executed. The matched defined for a certain
rule are use to test that they does not match other rules
This commit is contained in:
parent
c09944d4e9
commit
aac55d6a34
|
@ -3,6 +3,7 @@ package org.gcube.accounting.datamodel.validations.validators;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FilenameFilter;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.documentstore.records.DSMapper;
|
||||
|
@ -18,52 +19,19 @@ public class TestRules {
|
|||
|
||||
@Test
|
||||
public void testAllRules() throws Exception {
|
||||
|
||||
String[] aggregationTests = new String[]{
|
||||
"AuthorizationService-generate",
|
||||
"AuthorizationService-retrieve",
|
||||
"AuthorizationService-scopes",
|
||||
"Catalogue-WS-licenses",
|
||||
"Catalogue-WS-organizations",
|
||||
"Catalogue-WS-UNKNOWN",
|
||||
"CkanConnector-connect",
|
||||
"CkanConnector-disconnect",
|
||||
"data-transfer-service-getCapabilities",
|
||||
"data-transfer-service-upload",
|
||||
"FullTextIndexNode-delete",
|
||||
"FullTextIndexNode-dropCollection",
|
||||
"FullTextIndexNode-insert",
|
||||
"FullTextIndexNode-listCollections",
|
||||
"FullTextIndexNode-search",
|
||||
"geoanalytics-main-service-UNKNOWN",
|
||||
"GeoNetwork-login",
|
||||
"GRSFPublisher-create",
|
||||
"GRSFPublisher-delete",
|
||||
"GRSFPublisher-getURLandIdFromName",
|
||||
"GRSFPublisher-UNKNOWN",
|
||||
"GRSFPublisher-update",
|
||||
"RConnector-connect",
|
||||
"RConnector-UNKNOWN",
|
||||
"ShareLatex-connect",
|
||||
"ShareLatex-disconnect",
|
||||
"SimulFishGrowthData-BroodstockQuality",
|
||||
"SimulFishGrowthData-CurrentRating",
|
||||
"SimulFishGrowthData-FeedQuality",
|
||||
"SimulFishGrowthData-Modeler",
|
||||
"SimulFishGrowthData-OxygenRating",
|
||||
"SimulFishGrowthData-Region",
|
||||
"SimulFishGrowthData-Scenario",
|
||||
"SimulFishGrowthData-Site",
|
||||
"SimulFishGrowthData-Species",
|
||||
"SimulFishGrowthData-UNKNOWN",
|
||||
"storage-UNKNOWN",
|
||||
"TagMe-tag"
|
||||
|
||||
File rulesDirectory = getRulesDirectory();
|
||||
FilenameFilter filenameFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".json");
|
||||
}
|
||||
};
|
||||
File[] rulesFiles = rulesDirectory.listFiles(filenameFilter);
|
||||
|
||||
for(String aggregationTest : aggregationTests) {
|
||||
testRule(aggregationTest);
|
||||
for(File rulesFile : rulesFiles) {
|
||||
testRule(rulesFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public File getRulesDirectory() throws Exception {
|
||||
|
@ -73,15 +41,17 @@ public class TestRules {
|
|||
return new File(resourcesDirectory, "rules");
|
||||
}
|
||||
|
||||
public void testRule(String rulePrefix) throws Exception {
|
||||
File rulesDirectory = getRulesDirectory();
|
||||
public void testRule(File rulesFile) throws Exception {
|
||||
logger.info("-----------------------------------------------------------------------------------------------------");
|
||||
logger.info("Analisyng rule from file {}\n", rulesFile.getAbsolutePath());
|
||||
File rulesDirectory = rulesFile.getParentFile();
|
||||
|
||||
File rulesFile = new File(rulesDirectory, rulePrefix + ".json");
|
||||
ObjectMapper mapper = DSMapper.getObjectMapper();
|
||||
MatcherReplace matcherReplace = mapper.readValue(rulesFile, MatcherReplace.class);
|
||||
Replacer replacer = matcherReplace.getReplacer();
|
||||
|
||||
File elaborationFile = new File(rulesDirectory,rulePrefix + ".csv");
|
||||
final String requiredMatchesFileName = rulesFile.getName().replaceAll(".json", ".csv");
|
||||
File elaborationFile = new File(rulesDirectory,requiredMatchesFileName);
|
||||
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFile))) {
|
||||
for(String line; (line = br.readLine()) != null;) {
|
||||
String[] splittedLine = line.split(",");
|
||||
|
@ -97,11 +67,43 @@ public class TestRules {
|
|||
} catch(Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
FilenameFilter filenameFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
boolean accept = name.endsWith(".csv");
|
||||
return name.compareTo(requiredMatchesFileName)!=0 && accept;
|
||||
}
|
||||
};
|
||||
File[] elaborationFilesNoMatch = rulesDirectory.listFiles(filenameFilter);
|
||||
|
||||
for(File elaborationFileNoMatch : elaborationFilesNoMatch) {
|
||||
logger.trace("\n\nComparing examples which must not match from file {}", elaborationFileNoMatch.getAbsolutePath());
|
||||
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFileNoMatch))) {
|
||||
for(String line; (line = br.readLine()) != null;) {
|
||||
String[] splittedLine = line.split(",");
|
||||
boolean matched = matcherReplace.check(splittedLine[0],splittedLine[1],splittedLine[2]);
|
||||
if(matched) {
|
||||
logger.error("{} match {} but it should NOT. This MUST not occur.", line, matcherReplace.getMultiMatcher().toString());
|
||||
throw new Exception();
|
||||
} else {
|
||||
logger.info("{} does NOT match as requested", line, replacer.getServiceClass(), replacer.getServiceName(), replacer.getCalledMethod());
|
||||
}
|
||||
|
||||
}
|
||||
} catch(Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
logger.info("-----------------------------------------------------------------------------------------------------\n\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleRule() throws Exception {
|
||||
testRule("GRSFPublisher-update");
|
||||
File rulesDirectory = getRulesDirectory();
|
||||
File rulesFile = new File(rulesDirectory, "SmartExecutor-UNKNOWN.json");
|
||||
testRule(rulesFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue