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

Added lenientValidation support to REMReM generate #170

Merged
merged 12 commits into from
Aug 14, 2020
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.0
- Updated REMReM Generate to support lenient validation for Eiffel Protocol.

## 2.0.17
- Fixed failed testcase in EiffelRemERLookupControllerUnitTest class.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class CLI implements CommandLineRunner {

@Autowired
private List<MsgService> msgServices;
//private MsgService[] msgServices;

public CLI(List<MsgService> msgServices) {
super();
Expand Down Expand Up @@ -176,7 +175,8 @@ private void handleJsonString(String jsonString, CommandLine commandLine) {
JsonParser parser = new JsonParser();
JsonObject jsonContent = parser.parse(jsonString).getAsJsonObject();
MsgService msgService = getMessageService(commandLine);
String returnJsonStr = msgService.generateMsg(msgType, jsonContent);
Boolean lv = commandLine.hasOption("lv")? Boolean.parseBoolean(commandLine.getOptionValue("lv")) : false;
String returnJsonStr = msgService.generateMsg(msgType, jsonContent, lv);
returnJsonStr = "[" + returnJsonStr + "]";
if (responseFilePath != null) {
try (PrintWriter out = new PrintWriter(responseFilePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public static Options createCLIOptions() {
options.addOption("r", "response_file", true, "file to store the response in, optional");
options.addOption("d", "debug", false, "enable debug traces");
options.addOption("mp", "messaging_protocol", true,
"name of messaging protocol to be used, e.g. eiffel3, eiffelsemantics");
"name of messaging protocol to be used, e.g. eiffelsemantics");
options.addOption("lv", "lenientValidation", true,
"lenientValidation will perform the only mandatory field validation and non-mandatory validation failures will place in Eiffel message as a new property(remremGenerateFailures)" +
"");
contentGroup = new OptionGroup();
contentGroup.addOption(new Option("f", "content_file", true, "message content file"));
contentGroup.addOption(new Option("json", "json_content", true, "json content"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ public void testRequiredOptionsGiven() throws Exception {
assertTrue(CLIOptions.getErrorCodes().isEmpty());
}

@Test
public void testlenientValidationGiven() throws Exception {
String[] args = {"-f", "input_file", "-t", "artifactpublished", "-lv", "true"};
CLIOptions.parse(args);
assertTrue(CLIOptions.getErrorCodes().isEmpty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,17 @@ public void testHandleMsgTypeEventArgsPass() throws Exception {
assertTrue(CLIOptions.getErrorCodes().isEmpty());
}

@Test
public void testHandlelenientValidationArgsPass() throws Exception {
URL url = getClass().getClassLoader().getResource("jsonTest.json");
String path = url.getPath().replace("%20"," ");
File file = new File(path);
String filePath = file.getAbsolutePath();

String[] args = {"-t", "eiffelactivityfinished", "-f", filePath, "-lv" , "true"};
CLIOptions.parse(args);
cli.run(args);
assertTrue(CLIOptions.getErrorCodes().isEmpty());
}

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</parent>

<properties>
<eiffel-remrem-generate.version>2.0.17</eiffel-remrem-generate.version>
<eiffel-remrem-generate.version>2.1.0</eiffel-remrem-generate.version>
<eiffel-remrem-shared.version>2.0.4</eiffel-remrem-shared.version>
<eiffel-remrem-semantics.version>2.0.13</eiffel-remrem-semantics.version>
<eiffel-remrem-semantics.version>2.1.0</eiffel-remrem-semantics.version>
</properties>
<artifactId>eiffel-remrem-generate</artifactId>
<version>${eiffel-remrem-generate.version}</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public final class RemremGenerateServiceConstants {
public static final String LOOKUP_IN_EXTERNAL_ERS = "Determines if external ER's should be used to compile the results of query."
+ "Use true to use External ER's.";

public static final String LenientValidation = "Lenient Validation true will perform the validation only on mandatory fields, non-mandatory validation failures add into eiffel message as property remremGenerateFailures";

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ public ResponseEntity<?> generate(
@ApiParam(value = "ER lookup result none found, Generate will fail") @RequestParam(value = "failIfNoneFound", required = false, defaultValue = "false") final Boolean failIfNoneFound,
@ApiParam(value = RemremGenerateServiceConstants.LOOKUP_IN_EXTERNAL_ERS) @RequestParam(value = "lookupInExternalERs", required = false, defaultValue = "false") final Boolean lookupInExternalERs,
@ApiParam(value = RemremGenerateServiceConstants.LOOKUP_LIMIT) @RequestParam(value = "lookupLimit", required = false, defaultValue = "1") final int lookupLimit,
@ApiParam(value = RemremGenerateServiceConstants.LenientValidation) @RequestParam(value = "lenientValidation", required = false, defaultValue = "false") final Boolean lenientValidation,
@ApiParam(value = "JSON message", required = true) @RequestBody JsonObject bodyJson) {

try {
bodyJson = erLookup(bodyJson, failIfMultipleFound, failIfNoneFound, lookupInExternalERs, lookupLimit);
MsgService msgService = getMessageService(msgProtocol);
String response;
if (msgService != null) {
response = msgService.generateMsg(msgType, bodyJson);
response = msgService.generateMsg(msgType, bodyJson, lenientValidation);
JsonElement parsedResponse = parser.parse(response);
if (!parsedResponse.getAsJsonObject().has(RemremGenerateServiceConstants.JSON_ERROR_MESSAGE_FIELD)) {
return new ResponseEntity<>(parsedResponse, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,37 @@ public void setUp() throws Exception {
String erlookupOptionsWithNoneFoundOutput = FileUtils
.readFileToString(new File(TEST_RESOURCES_PATH+"ErlookupOptionsWithNoneFoundOutput.json"), ENCODING);

Mockito.when(service.generateMsg(Mockito.eq("eiffelConfidenceLevelModified"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelConfidenceLevelModified"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(erlookupOptionsWithNoneFoundOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelconfidencelevel"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelconfidencelevel"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(confidenceLevelOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelartifactpublished"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelartifactpublished"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(artifactPublishedOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelcompositiondefined"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelcompositiondefined"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(compositionDefinedOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefined"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefined"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(compositionDefinedSCCreatedOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEvent"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEvent"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(compositionDefinedSCSubmittedOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelSCSubmitted"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelSCSubmitted"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(SCSubmittedOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefined"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefined"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(erLookupWithOptionsOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefinedEvent"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelEnvironmentDefinedEvent"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(erlookupOptionsWithEmptyResponseOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEventt"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelCompositionDefinedEventt"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(compositionDefinedOutput);

Mockito.when(service.generateMsg(Mockito.eq("eiffelTestCaseStarted"), Mockito.anyObject()))
Mockito.when(service.generateMsg(Mockito.eq("eiffelTestCaseStarted"), Mockito.anyObject(), Mockito.anyBoolean()))
.thenReturn(ErlookupFailedWithOptionsOutput);

ResponseEntity erresponse = new ResponseEntity(response, HttpStatus.OK);
Expand Down Expand Up @@ -222,7 +222,7 @@ public void testErlookupSuccesswithMultipleIds() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelconfidencelevel", false, false, true, 1, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

Expand All @@ -233,7 +233,7 @@ public void testErlookupMultipleFound() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelcompositiondefined", true, false, true, 1, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED);
}

Expand All @@ -243,7 +243,7 @@ public void testErlookupMultipleTraces() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelartifactpublished", false, true, true, 1, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
}

Expand All @@ -253,7 +253,7 @@ public void testErlookupSuccesswithOneId() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefined", true, true, true, 1, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

Expand All @@ -263,7 +263,7 @@ public void testErlookupNoneFound() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEvent", true, true, true, 1, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE);
}

Expand All @@ -273,7 +273,7 @@ public void testErlookupMultipleTrace() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelSCSubmitted", false, true, true, 1, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
}

Expand All @@ -283,7 +283,7 @@ public void testErlookupOptions() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefined", false, false, true, 2, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

Expand All @@ -293,7 +293,7 @@ public void testErlookupOptionsWithEmptyResponse() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelEnvironmentDefinedEvent", true, true, true, 2, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

Expand All @@ -303,7 +303,7 @@ public void testErlookupOptionsWithMultipleFound() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelCompositionDefinedEventt", false, false, true, 2, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.EXPECTATION_FAILED);
}

Expand All @@ -313,7 +313,7 @@ public void testErlookupOptionsWithNoneFound() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelConfidenceLevelModified", false, false, true, 2, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.NOT_ACCEPTABLE);
}

Expand All @@ -323,7 +323,7 @@ public void testErlookupFailedWithOptions() throws Exception {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(new FileReader(file)).getAsJsonObject();

ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, json);
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelTestCaseStarted", false, false, true, 2, false, json);
assertEquals(elem.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,53 +81,68 @@ public void setUp() throws Exception {
inputFilePath = jsonInputURL.getPath().replace("%20"," ");
jsonFile = new File(inputFilePath);
String errorOutput = new BufferedReader(new FileReader(jsonFile)).readLine();

URL lv_jsonInputURL = getClass().getClassLoader().getResource("lv_successInput.json");
String lv_inputFilePath = lv_jsonInputURL.getPath().replace("%20"," ");
File lv_jsonFile = new File(lv_inputFilePath);
String lv_successOutput = new BufferedReader(new FileReader(lv_jsonFile)).readLine();

Mockito.when(service.generateMsg(
Mockito.eq("eiffelactivityfinished"),
Mockito.anyObject())).thenReturn(successOutput);
Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(successOutput);

Mockito.when(service.generateMsg(
Mockito.eq("EiffelActivityFinished"),
Mockito.anyObject())).thenReturn(errorOutput);
Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(errorOutput);

Mockito.when(service2.generateMsg(
Mockito.eq("eiffelartifactnew"),
Mockito.anyObject())).thenReturn(successOutput);
Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(successOutput);

Mockito.when(service2.generateMsg(
Mockito.eq("eiffelartifactnewevent"),
Mockito.anyObject())).thenReturn(errorOutput);
Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(errorOutput);

Mockito.when(service.generateMsg(
Mockito.eq("EiffelArtifactCreatedEvent"),
Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(lv_successOutput);

}

@Test
public void testSemanticsSuccessEvent() throws Exception {
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, body.getAsJsonObject());
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "eiffelactivityfinished", false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

@Test
public void testSemanticsFailureEvent() throws Exception {
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, body.getAsJsonObject());
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "EiffelActivityFinished", false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
}

@Test
public void testEiffel3SuccessEvent() throws Exception {
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, body.getAsJsonObject());
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnew", false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

@Test
public void testEiffel3FailureEvent() throws Exception {
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, body.getAsJsonObject());
ResponseEntity<?> elem = unit.generate("eiffel3", "eiffelartifactnewevent", false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.BAD_REQUEST);
}

@Test
public void testMessageServiceUnavailableEvent() throws Exception {
ResponseEntity<?> elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, body.getAsJsonObject());
ResponseEntity<?> elem = unit.generate("other", "EiffelActivityFinishedEvent", false, false, true, 1, false, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.SERVICE_UNAVAILABLE);
}

@Test
public void testlenientValidation() throws Exception {
ResponseEntity<?> elem = unit.generate("eiffelsemantics", "EiffelArtifactCreatedEvent", false, false, true, 1, true, body.getAsJsonObject());
assertEquals(elem.getStatusCode(), HttpStatus.OK);
}

}
Loading