diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e576a8..de43e1cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## 2.1.5 +- Made changes to fix the test-failures - Updated eiffel-remrem-parent version from 2.0.6 to 2.0.7 - updated eiffel-remrem-semantics version from 2.2.1 to 2.2.2 - Introduced new (/message_protocols) Endpoint which returns the available message protocols list and their respective edition names. diff --git a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java index 58e4023d..416f04fa 100644 --- a/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java +++ b/service/src/main/java/com/ericsson/eiffel/remrem/generate/controller/RemremGenerateController.java @@ -120,9 +120,6 @@ public ResponseEntity generate( bodyJson = erLookup(bodyJson, failIfMultipleFound, failIfNoneFound, lookupInExternalERs, lookupLimit); MsgService msgService = getMessageService(msgProtocol); String response; - if (bodyJson == null) { - return new ResponseEntity<>(parser.parse(RemremGenerateServiceConstants.NO_ER),HttpStatus.SERVICE_UNAVAILABLE); - } if (msgService != null) { response = msgService.generateMsg(msgType, bodyJson, isLenientEnabled(okToLeaveOutInvalidOptionalFields)); JsonElement parsedResponse = parser.parse(response); @@ -148,6 +145,11 @@ else if (e1.getMessage().contains(Integer.toString(HttpStatus.EXPECTATION_FAILED else if (e1.getMessage().contains(Integer.toString(HttpStatus.EXPECTATION_FAILED.value()))) { return new ResponseEntity<>(parser.parse(e1.getMessage()), HttpStatus.EXPECTATION_FAILED); } + else if (e1.getMessage() + .contains(Integer.toString(HttpStatus.SERVICE_UNAVAILABLE.value()))) { + return new ResponseEntity<>(parser.parse(RemremGenerateServiceConstants.NO_ER), + HttpStatus.SERVICE_UNAVAILABLE); + } else { return new ResponseEntity<>(parser.parse(e1.getMessage()), HttpStatus.UNPROCESSABLE_ENTITY); } @@ -184,7 +186,10 @@ private JsonObject erLookup(final JsonObject bodyJson, Boolean failIfMultipleFou } } catch (Exception e) { log.error("unable to connect configured Event Repository URL" + e.getMessage()); - return null; + response = null; + } + if (response == null) { + throw new REMGenerateException(RemremGenerateServiceConstants.NO_ER); } String responseBody = response.getBody(); ids = ERLookupController.getIdsfromResponseBody(responseBody); diff --git a/service/src/test/java/com/ericsson/eiffel/remrem/generate/integrationtest/EiffelRemremControllerIT.java b/service/src/test/java/com/ericsson/eiffel/remrem/generate/integrationtest/EiffelRemremControllerIT.java index 55a66963..9eea317d 100644 --- a/service/src/test/java/com/ericsson/eiffel/remrem/generate/integrationtest/EiffelRemremControllerIT.java +++ b/service/src/test/java/com/ericsson/eiffel/remrem/generate/integrationtest/EiffelRemremControllerIT.java @@ -52,8 +52,8 @@ public class EiffelRemremControllerIT { @Value("${local.server.port}") private int port; - private String artifactPublishedFileName = "ArtifactPublished.json"; - private String artifactPublishedBody; + private String artifactCreatedFileName = "ArtifactCreated.json"; + private String artifactCreatedBody; private String activityFinishedFileName = "ActivityFinished.json"; private String activityFinishedBody; @@ -73,8 +73,8 @@ public class EiffelRemremControllerIT { @Before public void setUp() throws IOException { RestAssured.port = port; - artifactPublishedBody = loadEventBody(artifactPublishedFileName); activityFinishedBody = loadEventBody(activityFinishedFileName); + artifactCreatedBody = loadEventBody(artifactCreatedFileName); if (version == null) { version = getMessagingVersion(); @@ -123,7 +123,7 @@ public static String getMessagingVersion() { public void testUnauthenticatedNotAllowed() throws Exception { given() .contentType("application/json") - .body(artifactPublishedBody) + .body(artifactCreatedBody) .when() .post("/eiffelsemantics?msgType=eiffelartifactpublished") .then() @@ -131,16 +131,16 @@ public void testUnauthenticatedNotAllowed() throws Exception { } @Test - public void testSendArtifactPublished() throws Exception { + public void testSendArtifactCreated() throws Exception { given() .header("Authorization", credentials) .contentType("application/json") - .body(artifactPublishedBody) + .body(artifactCreatedBody) .when() - .post("/eiffelsemantics?msgType=EiffelArtifactPublishedEvent") + .post("/eiffelsemantics?msgType=EiffelArtifactCreatedEvent") .then() .statusCode(HttpStatus.SC_OK) - .body("meta.type", Matchers.is("EiffelArtifactPublishedEvent")) + .body("meta.type", Matchers.is("EiffelArtifactCreatedEvent")) .body("meta.version", Matchers.is(version)); } diff --git a/service/src/test/resources/ArtifactCreated.json b/service/src/test/resources/ArtifactCreated.json new file mode 100644 index 00000000..aa5c8d64 --- /dev/null +++ b/service/src/test/resources/ArtifactCreated.json @@ -0,0 +1,68 @@ +{ + "msgParams": { + "meta": { + "type": "EiffelArtifactCreatedEvent", + "version": "3.0.0", + "tags": [ + "tag1", + "tag2" + ], + "source": { + "domainId": "domainID", + "host": "host", + "name": "name", + "uri": "http:\/\/java.sun.com\/j2se\/1.3\/", + "serializer":"pkg:maven" + }, + "security": { + "authorIdentity": "test", + "encryptedDigest": "sample" + } + } + }, + "eventParams": { + "data": { + "gav": { + "groupId": "G", + "artifactId": "A", + "version": "V" + }, + "fileInformation": [{ + "name":"name" + }], + "buildCommand": "trigger", + "requiresImplementation": "NONE", + "name": "event", + "dependsOn": [ + ], + "implement": [ + ], + "identity":"pkg:abc", + "customData": [{ + "key": "firstLog", + "value": "http:\/\/myHost.com\/firstLog" + }, + { + "key": "otherLog", + "value": "http:\/\/myHost.com\/firstLog33" + } + ] + }, + "links": [{ + "type": "CAUSE", + "target": "aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1" + }, + { + "type": "PREVIOUS_VERSION", + "target": "aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee2" + }, + { + "type": "COMPOSITION", + "target": "aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee1" + }, + { + "type": "ENVIRONMENT", + "target": "aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee3" + }] + } +} diff --git a/service/src/test/resources/ArtifactPublished.json b/service/src/test/resources/ArtifactPublished.json index af467246..a7f6f4b4 100644 --- a/service/src/test/resources/ArtifactPublished.json +++ b/service/src/test/resources/ArtifactPublished.json @@ -35,4 +35,4 @@ } ] } -} \ No newline at end of file +} diff --git a/service/src/test/resources/ErlookupArtifactPublishedInput.json b/service/src/test/resources/ErlookupArtifactPublishedInput.json index 5e0ec800..4d1dc269 100644 --- a/service/src/test/resources/ErlookupArtifactPublishedInput.json +++ b/service/src/test/resources/ErlookupArtifactPublishedInput.json @@ -39,4 +39,4 @@ } ] } -} \ No newline at end of file +}