From 81ec0c43ca5515c76084b1c04d0c8991a2258e3c Mon Sep 17 00:00:00 2001 From: xumakap Date: Wed, 1 Mar 2017 18:06:43 +0530 Subject: [PATCH] Implemented RoutingKey functionality for REMREM Semantics (#65) * Implemented RoutingKey functionality for REMREM Semantics * Added json files and modified testcases * Handled null condition of RoutingKey --- CHANGELOG.md | 3 + build.gradle | 4 +- .../publish/config/PropertiesConfig.java | 1 + .../remrem/publish/helper/PublishUtils.java | 16 +- .../service/MessageServiceRMQImpl.java | 15 +- .../ProducerControllerIntegrationTest.java | 38 ++++- .../EiffelActivityFinishedEvent.json | 38 +++++ .../resources/EiffelJobFinishedEvent.json | 47 ++++++ .../Invalid_EiffelActivityFinishedEvent.json | 37 +++++ .../resources/MultipleInvalidEvents.json | 148 ++++++++++++++++++ .../resources/MultipleValidEvents.json | 112 +++++++++++++ .../MessageServiceRMQImplUnitTest.java | 28 +++- 12 files changed, 463 insertions(+), 24 deletions(-) create mode 100644 publish-service/src/integration-test/resources/EiffelActivityFinishedEvent.json create mode 100644 publish-service/src/integration-test/resources/EiffelJobFinishedEvent.json create mode 100644 publish-service/src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json create mode 100644 publish-service/src/integration-test/resources/MultipleInvalidEvents.json create mode 100644 publish-service/src/integration-test/resources/MultipleValidEvents.json diff --git a/CHANGELOG.md b/CHANGELOG.md index eec15449..f6d9643f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.3.3 +- Implemented RoutingKey functionality for REMREM Semantics. + ## 0.3.2 - Added comments and removed unnecessary dependencies in build.gradle. diff --git a/build.gradle b/build.gradle index 89f4e3a5..3a6b40d7 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ subprojects { apply plugin: 'java' //Latest version for publish - version = "0.3.2" + version = "0.3.3" //Declare where to find the dependencies of project here repositories { @@ -100,7 +100,7 @@ subprojects { compile 'com.github.Ericsson:eiffel-remrem-shared:0.3.0' compile 'com.github.Ericsson:eiffel-remrem-protocol-interface:0.0.1' //For publishing eiffel2.0 events - compile 'com.github.Ericsson:eiffel-remrem-semantics:0.2.0' + compile 'com.github.Ericsson:eiffel-remrem-semantics:0.2.3' //Declare the dependency for your favourite test framework you want to use in your tests. //TestNG is also supported by the Gradle Test task. Just change the diff --git a/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/PropertiesConfig.java b/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/PropertiesConfig.java index 618f3f02..036d3f67 100644 --- a/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/PropertiesConfig.java +++ b/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/config/PropertiesConfig.java @@ -27,4 +27,5 @@ public class PropertiesConfig { public static final String SERVER_DOWN = "Internal Server Error"; public static final String SERVER_DOWN_MESSAGE = "Possible to try again later when server is up"; public static final String UNSUCCESSFUL_EVENT_CONTENT = "Please check previous event and try again later"; + public static final String PROTOCOL = "eiffel"; } diff --git a/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/PublishUtils.java b/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/PublishUtils.java index 5c426c4b..ab4897b7 100644 --- a/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/PublishUtils.java +++ b/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/helper/PublishUtils.java @@ -4,6 +4,8 @@ import org.slf4j.LoggerFactory; import com.ericsson.eiffel.remrem.protocol.MsgService; +import com.ericsson.eiffel.remrem.publish.config.PropertiesConfig; +import com.ericsson.eiffel.remrem.semantics.SemanticsService; import com.google.gson.JsonObject; import ch.qos.logback.classic.Logger; @@ -42,19 +44,23 @@ public static MsgService getMessageService(String mp, MsgService msgServices[]) * @param msgService the Messaging service. * @param json the eiffel event * @param userDomainSuffix is optional parameter, If user provide this it will add to the domainId. - * @return routing key or returns domain id if family and type not available. + * @return routing key or returns null if family and type not available. */ public static String prepareRoutingKey(MsgService msgService, JsonObject json, RMQHelper rmqHelper, String userDomainSuffix) { String domainId = rmqHelper.getDomainId(); + String family = msgService.getFamily(json); + String type = msgService.getType(json); if (StringUtils.isNotEmpty(userDomainSuffix)) { domainId = domainId + DOT + userDomainSuffix; } - if (msgService != null && StringUtils.isNotEmpty(msgService.getFamily(json)) - && StringUtils.isNotEmpty(msgService.getType(json))) { - return msgService.getFamily(json) + DOT + msgService.getType(json) + DOT + "notag" + DOT + domainId; + if (msgService != null && StringUtils.isNotEmpty(family) && StringUtils.isNotEmpty(type)) { + if (msgService instanceof SemanticsService) + return PropertiesConfig.PROTOCOL + DOT + family + DOT + type + DOT + "notag" + DOT + domainId; + else + return family + DOT + type + DOT + "notag" + DOT + domainId; } - return domainId; + return null; } } diff --git a/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImpl.java b/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImpl.java index a643294b..3f63b11e 100644 --- a/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImpl.java +++ b/publish-common/src/main/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImpl.java @@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.ComponentScan; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -79,10 +78,11 @@ public SendResult send(String jsonContent, MsgService msgService, String userDom Map map = new HashMap<>(); Map routingKeyMap = new HashMap<>(); String eventId = msgService.getEventId(json.getAsJsonObject()); - if (eventId != null) { + String routingKey = (eventId != null) ? (PublishUtils.prepareRoutingKey(msgService, + json.getAsJsonObject(), rmqHelper, userDomainSuffix)) : null; + if (eventId != null && routingKey != null) { map.put(eventId, json.toString()); - routingKeyMap.put(eventId, PublishUtils.prepareRoutingKey(msgService, json.getAsJsonObject(), - rmqHelper, userDomainSuffix)); + routingKeyMap.put(eventId, routingKey); } else { List events = new ArrayList<>(); createFailureResult(events); @@ -195,8 +195,11 @@ private void instantiateRmqHelper() { private void getAndCheckEvent(MsgService msgService, Map map, List events, JsonElement obj, Map routingKeyMap, String userDomainSuffix) { String eventId = msgService.getEventId(obj.getAsJsonObject()); - if (eventId != null) { - routingKeyMap.put(eventId, PublishUtils.prepareRoutingKey(msgService, obj.getAsJsonObject(), rmqHelper, userDomainSuffix)) ; + String routingKey = (eventId != null) + ? (PublishUtils.prepareRoutingKey(msgService, obj.getAsJsonObject(), rmqHelper, userDomainSuffix)) + : null; + if (eventId != null && routingKey != null) { + routingKeyMap.put(eventId, routingKey); map.put(eventId, obj.toString()); } } diff --git a/publish-service/src/integration-test/java/com/ericsson/eiffel/remrem/publish/controller/ProducerControllerIntegrationTest.java b/publish-service/src/integration-test/java/com/ericsson/eiffel/remrem/publish/controller/ProducerControllerIntegrationTest.java index 30bbbb2c..b7a9f3fd 100644 --- a/publish-service/src/integration-test/java/com/ericsson/eiffel/remrem/publish/controller/ProducerControllerIntegrationTest.java +++ b/publish-service/src/integration-test/java/com/ericsson/eiffel/remrem/publish/controller/ProducerControllerIntegrationTest.java @@ -3,8 +3,11 @@ import static com.jayway.restassured.RestAssured.given; import static org.junit.Assert.assertEquals; +import java.io.File; +import java.io.FileReader; import java.util.Base64; +import org.apache.commons.io.FileUtils; import org.apache.http.HttpStatus; import org.hamcrest.Matchers; import org.junit.Before; @@ -49,9 +52,9 @@ public void setUp() { public void testGetFamily() throws Exception { MsgService messageService = PublishUtils.getMessageService("eiffel3", msgServices); if (messageService != null) { - String jsonString = "{'eiffelMessageVersions': { '3.21.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': \"2011-11-02T02:50:12.208Z\", 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'resultDetails': { 'key': 0, 'description': 'The Result was Successful' }, 'logReferences': {}, 'flowContext': '', 'optionalParameters': {} } }, '2.3.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': '2016-09-01T08:23:57.894Z', 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'logReferences': {}, 'optionalParameters': {} } } } }"; + File file = new File("src/integration-test/resources/EiffelJobFinishedEvent.json"); JsonParser parser = new JsonParser(); - JsonElement json = parser.parse(jsonString); + JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject(); String family = messageService.getFamily(json.getAsJsonObject()); assertEquals("job", family); } @@ -62,19 +65,19 @@ public void testJsonOutput() throws Exception { MsgService msgService = PublishUtils.getMessageService("eiffel3", msgServices); if (msgService != null) { JsonArray jarray = new JsonArray(); - String jsonString = "{'eiffelMessageVersions': { '3.21.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': '2016-09-01T08:23:57.894Z', 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'resultDetails': { 'key': 0, 'description': 'The Result was Successful' }, 'logReferences': {}, 'flowContext': '', 'optionalParameters': {} } }, '2.3.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': '2016-09-01T08:23:57.894Z', 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'logReferences': {}, 'optionalParameters': {} } } } }"; + String jsonString = FileUtils.readFileToString(new File("src/integration-test/resources/EiffelJobFinishedEvent.json")); SendResult results = messageService.send(jsonString, msgService, "fem001"); for (PublishResultItem result : results.getEvents()) { jarray.add(result.toJsonObject()); } - String jsonArray = "[{\"id\":\"4ce1e9e1-21c4-458f-b8d1-ef26b82a5634\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]"; + String jsonArray = "[{\"id\":\"2930b40e-79dc-453c-b178-bc2bbde593ba\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]"; assertEquals(jsonArray, jarray.toString()); } } @Test public void testFailSingleEvent() throws Exception { - String body = "{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}}"; + String body = FileUtils.readFileToString(new File("src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json")); given().header("Authorization", credentials) .contentType("application/json").body(body).when().post("/producer/msg").then() @@ -83,5 +86,28 @@ public void testFailSingleEvent() throws Exception { .body("events[0].result", Matchers.equalTo(PropertiesConfig.INVALID_MESSAGE)).body("events[0].message", Matchers .equalTo("Invalid event content, client need to fix problem in event before submitting again")); } - + + @Test + public void testGetFamilyRoutingKey() throws Exception { + MsgService messageService = PublishUtils.getMessageService("", msgServices); + if (messageService != null) { + File file = new File("src/integration-test/resources/EiffelActivityFinishedEvent.json"); + JsonParser parser = new JsonParser(); + JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject(); + String family = messageService.getFamily(json.getAsJsonObject()); + assertEquals("activity", family); + } + } + + @Test + public void testGetTypeRoutingKey() throws Exception { + MsgService messageService = PublishUtils.getMessageService("", msgServices); + if (messageService != null) { + File file = new File("src/integration-test/resources/EiffelActivityFinishedEvent.json"); + JsonParser parser = new JsonParser(); + JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject(); + String type = messageService.getType(json.getAsJsonObject()); + assertEquals("finished", type); + } + } } \ No newline at end of file diff --git a/publish-service/src/integration-test/resources/EiffelActivityFinishedEvent.json b/publish-service/src/integration-test/resources/EiffelActivityFinishedEvent.json new file mode 100644 index 00000000..0d0142bf --- /dev/null +++ b/publish-service/src/integration-test/resources/EiffelActivityFinishedEvent.json @@ -0,0 +1,38 @@ +{ + "data": { + "outcome": { + "conclusion": "TIMED_OUT", + "description": "Compilation timed out." + }, + "persistentLogs": [{ + "name": "firstLog", + "uri": "http://myHost.com/firstLog" + }, { + "name": "otherLog", + "uri": "isbn:0-486-27557-4" + }] + }, + "links": { + "activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", + "flowContext": "flowContext", + "causes": ["cause1", "cause2"] + }, + "meta": { + "domainId": "TCS", + "id": "1afffd13-04ae-4638-97f1-aaeed78a28c7", + "type": "eiffelactivityfinished", + "version": "0.1.8", + "time": 1481628758807, + "tags": ["tag1", "tag2"], + "source": { + "host": "host", + "name": "name", + "uri": "http://java.sun.com/j2se/1.3/", + "serializer": { + "groupId": "G", + "artifactId": "A", + "version": "V" + } + } + } +} \ No newline at end of file diff --git a/publish-service/src/integration-test/resources/EiffelJobFinishedEvent.json b/publish-service/src/integration-test/resources/EiffelJobFinishedEvent.json new file mode 100644 index 00000000..20b01a50 --- /dev/null +++ b/publish-service/src/integration-test/resources/EiffelJobFinishedEvent.json @@ -0,0 +1,47 @@ +{ + "eiffelMessageVersions": { + "3.21.42.0.4": { + "domainId": "eiffel010.generator", + "eventId": "2930b40e-79dc-453c-b178-bc2bbde593ba", + "eventTime": "2016-12-09T05:05:27.797Z", + "eventType": "EiffelJobFinishedEvent", + "inputEventIds": [ + "5034777a-6f25-409e-abd2-39e592158c7f" + ], + "eventData": { + "jobInstance": "MessageGenerator", + "jobExecutionId": "114ad8ae-3f18-48bf-a672-2b068236845e", + "jobExecutionNumber": 24999, + "resultCode": "SUCCESS", + "logReferences": { + + }, + "flowContext": "", + "optionalParameters": { + "COUNT": "99995" + } + } + }, + "2.3.42.0.4": { + "domainId": "eiffel010.generator", + "eventId": "2930b40e-79dc-453c-b178-bc2bbde593ba", + "eventTime": "2016-12-09T05:05:27.797Z", + "eventType": "EiffelJobFinishedEvent", + "inputEventIds": [ + "5034777a-6f25-409e-abd2-39e592158c7f" + ], + "eventData": { + "jobInstance": "MessageGenerator", + "jobExecutionId": "114ad8ae-3f18-48bf-a672-2b068236845e", + "jobExecutionNumber": 24999, + "resultCode": "SUCCESS", + "logReferences": { + + }, + "optionalParameters": { + "COUNT": "99995" + } + } + } + } +} \ No newline at end of file diff --git a/publish-service/src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json b/publish-service/src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json new file mode 100644 index 00000000..02a00853 --- /dev/null +++ b/publish-service/src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json @@ -0,0 +1,37 @@ +{ + "data": { + "outcome": { + "conclusion": "TIMED_OUT", + "description": "Compilation timed out." + }, + "persistentLogs": [{ + "name": "firstLog", + "uri": "http://myHost.com/firstLog" + }, { + "name": "otherLog", + "uri": "isbn:0-486-27557-4" + }] + }, + "links": { + "activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", + "flowContext": "flowContext", + "causes": ["cause1", "cause2"] + }, + "meta": { + "domainId": "example.domain", + "type": "eiffelactivityfinished", + "version": "0.1.7", + "time": 1478780245184, + "tags": ["tag1", "tag2"], + "source": { + "host": "host", + "name": "name", + "uri": "http://java.sun.com/j2se/1.3/", + "serializer": { + "groupId": "G", + "artifactId": "A", + "version": "V" + } + } + } +} \ No newline at end of file diff --git a/publish-service/src/integration-test/resources/MultipleInvalidEvents.json b/publish-service/src/integration-test/resources/MultipleInvalidEvents.json new file mode 100644 index 00000000..7a73c53e --- /dev/null +++ b/publish-service/src/integration-test/resources/MultipleInvalidEvents.json @@ -0,0 +1,148 @@ +[{ + "eiffelMessageVersions": { + "3.21.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:08.464Z", + "eventType": "EiffelJobFinishedEvent", + "inputEventIds": ["c597aa70-8733-4930-a425-ea8992ae6c6f"], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "f011f05e-e371-45aa-961a-22fc585b4bc2", + "jobExecutionNumber": 10, + "resultCode": "SUCCESS", + "logReferences": {}, + "flowContext": "", + "optionalParameters": {} + }, + "eventSource": { + "hostName": "SE00208242", + "pid": 10344, + "name": "testComponent", + "url": "http://localhost:8080/job/IMPMessage/10/" + } + }, + "2.3.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:08.464Z", + "eventType": "EiffelJobFinishedEvent", + "inputEventIds": ["c597aa70-8733-4930-a425-ea8992ae6c6f"], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "f011f05e-e371-45aa-961a-22fc585b4bc2", + "jobExecutionNumber": 10, + "resultCode": "SUCCESS", + "logReferences": {}, + "optionalParameters": {} + } + } + } +}, { + "eiffelMessageVersions": { + "3.21.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:07.457Z", + "eventType": "EiffelJobStartedEvent", + "inputEventIds": ["50acee77-24ef-45d1-9ec4-2b4453cd6387", "14d38a89-ca6d-4d06-acdc-5a2cfb8c52f7"], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "f011f05e-e371-45aa-961a-22fc585b4bc2", + "jobExecutionNumber": 10, + "logReferences": {}, + "flowContext": "", + "optionalParameters": {} + }, + "eventSource": { + "hostName": "SE00208242", + "pid": 10344, + "name": "testComponent", + "url": "http://localhost:8080/job/IMPMessage/10/" + } + }, + "2.3.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:07.457Z", + "eventType": "EiffelJobStartedEvent", + "inputEventIds": ["50acee77-24ef-45d1-9ec4-2b4453cd6387", "14d38a89-ca6d-4d06-acdc-5a2cfb8c52f7"], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "f011f05e-e371-45aa-961a-22fc585b4bc2", + "jobExecutionNumber": 10, + "optionalParameters": {} + } + } + } +}, { + "eiffelMessageVersions": { + "3.21.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:06.558Z", + "eventType": "EiffelJobQueuedEvent", + "inputEventIds": [], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "e71c530b-97e1-42fa-b1bb-ce01bdd53f34", + "triggerCause": { + "type": "MANUAL", + "description": "Started by user anonymous" + }, + "logReferences": {}, + "flowContext": "", + "optionalParameters": {} + }, + "eventSource": { + "hostName": "SE00208242", + "pid": 10344, + "name": "testComponent", + "url": "http://localhost:8080/job/IMPMessage/" + } + }, + "2.3.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:06.558Z", + "eventType": "EiffelJobQueuedEvent", + "inputEventIds": [], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "e71c530b-97e1-42fa-b1bb-ce01bdd53f34", + "optionalParameters": {} + } + } + } +}, { + "eiffelMessageVersions": { + "3.21.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:06.780Z", + "eventType": "EiffelJobQueuedEvent", + "inputEventIds": [], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "f011f05e-e371-45aa-961a-22fc585b4bc2", + "triggerCause": { + "type": "MANUAL", + "description": "Started by user anonymous" + }, + "logReferences": {}, + "flowContext": "", + "optionalParameters": {} + }, + "eventSource": { + "hostName": "SE00208242", + "pid": 10344, + "name": "testComponent", + "url": "http://localhost:8080/job/IMPMessage/" + } + }, + "2.3.39.0.5": { + "domainId": "TCS", + "eventTime": "2016-09-28T11:51:06.780Z", + "eventType": "EiffelJobQueuedEvent", + "inputEventIds": [], + "eventData": { + "jobInstance": "IMPMessage", + "jobExecutionId": "f011f05e-e371-45aa-961a-22fc585b4bc2", + "optionalParameters": {} + } + } + } +}] \ No newline at end of file diff --git a/publish-service/src/integration-test/resources/MultipleValidEvents.json b/publish-service/src/integration-test/resources/MultipleValidEvents.json new file mode 100644 index 00000000..830a220f --- /dev/null +++ b/publish-service/src/integration-test/resources/MultipleValidEvents.json @@ -0,0 +1,112 @@ +[{ + "data": { + "outcome": { + "conclusion": "TIMED_OUT", + "description": "Compilation timed out." + }, + "persistentLogs": [{ + "name": "firstLog", + "uri": "http://myHost.com/firstLog" + }, { + "name": "otherLog", + "uri": "isbn:0-486-27557-4" + }] + }, + "links": { + "activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", + "flowContext": "flowContext", + "causes": ["cause1", "cause2"] + }, + "meta": { + "domainId": "example.domain", + "id": "9cdd0f68-df85-44b0-88bd-fc4163ac90a1", + "type": "eiffelactivityfinished", + "version": "0.1.7", + "time": 1478780245184, + "tags": ["tag1", "tag2"], + "source": { + "host": "host", + "name": "name", + "uri": "http://java.sun.com/j2se/1.3/", + "serializer": { + "groupId": "G", + "artifactId": "A", + "version": "V" + } + } + } +}, { + "data": { + "outcome": { + "conclusion": "TIMED_OUT", + "description": "Compilation timed out." + }, + "persistentLogs": [{ + "name": "firstLog", + "uri": "http://myHost.com/firstLog" + }, { + "name": "otherLog", + "uri": "isbn:0-486-27557-4" + }] + }, + "links": { + "activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", + "flowContext": "flowContext", + "causes": ["cause1", "cause2"] + }, + "meta": { + "domainId": "example.domain", + "id": "9cdd0f68-df85-44b0-88bd-fc4163ac90a2", + "type": "eiffelactivityfinished", + "version": "0.1.7", + "time": 1478780245184, + "tags": ["tag1", "tag2"], + "source": { + "host": "host", + "name": "name", + "uri": "http://java.sun.com/j2se/1.3/", + "serializer": { + "groupId": "G", + "artifactId": "A", + "version": "V" + } + } + } +}, { + "data": { + "outcome": { + "conclusion": "TIMED_OUT", + "description": "Compilation timed out." + }, + "persistentLogs": [{ + "name": "firstLog", + "uri": "http://myHost.com/firstLog" + }, { + "name": "otherLog", + "uri": "isbn:0-486-27557-4" + }] + }, + "links": { + "activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1", + "flowContext": "flowContext", + "causes": ["cause1", "cause2"] + }, + "meta": { + "domainId": "example.domain", + "id": "9cdd0f68-df85-44b0-88bd-fc4163ac90a3", + "type": "eiffelactivityfinished", + "version": "0.1.7", + "time": 1478780245184, + "tags": ["tag1", "tag2"], + "source": { + "host": "host", + "name": "name", + "uri": "http://java.sun.com/j2se/1.3/", + "serializer": { + "groupId": "G", + "artifactId": "A", + "version": "V" + } + } + } +}] \ No newline at end of file diff --git a/publish-service/src/test/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImplUnitTest.java b/publish-service/src/test/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImplUnitTest.java index 74dc9840..eb56eaaf 100644 --- a/publish-service/src/test/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImplUnitTest.java +++ b/publish-service/src/test/java/com/ericsson/eiffel/remrem/publish/service/MessageServiceRMQImplUnitTest.java @@ -5,10 +5,13 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,6 +25,8 @@ import com.ericsson.eiffel.remrem.publish.helper.PublishUtils; import com.ericsson.eiffel.remrem.publish.helper.RMQHelper; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) @@ -44,11 +49,11 @@ public class MessageServiceRMQImplUnitTest { } @Test public void testSingleSuccessfulEvent() throws Exception { - String body ="{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','id':'9cdd0f68-df85-44b0-88bd-fc4163ac90a0','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}}"; + String body = FileUtils.readFileToString(new File("src/integration-test/resources/EiffelActivityFinishedEvent.json")); JsonArray jarray = new JsonArray(); MsgService msgService = PublishUtils.getMessageService("eiffelsemantics", msgServices); SendResult result = messageService.send(body, msgService, "test"); - String Expected="[{\"id\":\"9cdd0f68-df85-44b0-88bd-fc4163ac90a0\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]"; + String Expected="[{\"id\":\"1afffd13-04ae-4638-97f1-aaeed78a28c7\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]"; for (PublishResultItem results : result.getEvents()) { jarray.add(results.toJsonObject()); } @@ -56,7 +61,7 @@ public class MessageServiceRMQImplUnitTest { } @Test public void testSingleFailedEvent() throws Exception { - String body ="{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}}"; + String body = FileUtils.readFileToString(new File("src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json")); MsgService msgService = PublishUtils.getMessageService("eiffelsemantics", msgServices); JsonArray jarray = new JsonArray(); SendResult result = messageService.send(body, msgService, "test"); @@ -68,7 +73,7 @@ public class MessageServiceRMQImplUnitTest { } @Test public void testMultipleFailedEvents() throws Exception { - String body ="[{'eiffelMessageVersions':{'3.21.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:08.464Z','eventType':'EiffelJobFinishedEvent','inputEventIds':['c597aa70-8733-4930-a425-ea8992ae6c6f'],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'f011f05e-e371-45aa-961a-22fc585b4bc2','jobExecutionNumber':10,'resultCode':'SUCCESS','logReferences':{},'flowContext':'','optionalParameters':{}},'eventSource':{'hostName':'SE00208242','pid':10344,'name':'testComponent','url':'http://localhost:8080/job/IMPMessage/10/'}},'2.3.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:08.464Z','eventType':'EiffelJobFinishedEvent','inputEventIds':['c597aa70-8733-4930-a425-ea8992ae6c6f'],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'f011f05e-e371-45aa-961a-22fc585b4bc2','jobExecutionNumber':10,'resultCode':'SUCCESS','logReferences':{},'optionalParameters':{}}}}},{'eiffelMessageVersions':{'3.21.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:07.457Z','eventType':'EiffelJobStartedEvent','inputEventIds':['50acee77-24ef-45d1-9ec4-2b4453cd6387','14d38a89-ca6d-4d06-acdc-5a2cfb8c52f7'],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'f011f05e-e371-45aa-961a-22fc585b4bc2','jobExecutionNumber':10,'logReferences':{},'flowContext':'','optionalParameters':{}},'eventSource':{'hostName':'SE00208242','pid':10344,'name':'testComponent','url':'http://localhost:8080/job/IMPMessage/10/'}},'2.3.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:07.457Z','eventType':'EiffelJobStartedEvent','inputEventIds':['50acee77-24ef-45d1-9ec4-2b4453cd6387','14d38a89-ca6d-4d06-acdc-5a2cfb8c52f7'],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'f011f05e-e371-45aa-961a-22fc585b4bc2','jobExecutionNumber':10,'optionalParameters':{}}}}},{'eiffelMessageVersions':{'3.21.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:06.558Z','eventType':'EiffelJobQueuedEvent','inputEventIds':[],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'e71c530b-97e1-42fa-b1bb-ce01bdd53f34','triggerCause':{'type':'MANUAL','description':'Started by user anonymous'},'logReferences':{},'flowContext':'','optionalParameters':{}},'eventSource':{'hostName':'SE00208242','pid':10344,'name':'testComponent','url':'http://localhost:8080/job/IMPMessage/'}},'2.3.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:06.558Z','eventType':'EiffelJobQueuedEvent','inputEventIds':[],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'e71c530b-97e1-42fa-b1bb-ce01bdd53f34','optionalParameters':{}}}}},{'eiffelMessageVersions':{'3.21.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:06.780Z','eventType':'EiffelJobQueuedEvent','inputEventIds':[],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'f011f05e-e371-45aa-961a-22fc585b4bc2','triggerCause':{'type':'MANUAL','description':'Started by user anonymous'},'logReferences':{},'flowContext':'','optionalParameters':{}},'eventSource':{'hostName':'SE00208242','pid':10344,'name':'testComponent','url':'http://localhost:8080/job/IMPMessage/'}},'2.3.39.0.5':{'domainId':'TCS','eventTime':'2016-09-28T11:51:06.780Z','eventType':'EiffelJobQueuedEvent','inputEventIds':[],'eventData':{'jobInstance':'IMPMessage','jobExecutionId':'f011f05e-e371-45aa-961a-22fc585b4bc2','optionalParameters':{}}}}}]"; + String body = FileUtils.readFileToString(new File("src/integration-test/resources/MultipleInvalidEvents.json")); JsonArray jarray = new JsonArray(); MsgService msgService = PublishUtils.getMessageService("eiffelsemantics", msgServices); SendResult result = messageService.send(body, msgService, "test"); @@ -80,7 +85,7 @@ public class MessageServiceRMQImplUnitTest { assertEquals(Expected, jarray.toString()); } @Test public void testMultipleSuccessfulEvents() throws Exception { - String body ="[{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','id':'9cdd0f68-df85-44b0-88bd-fc4163ac90a1','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}},{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','id':'9cdd0f68-df85-44b0-88bd-fc4163ac90a2','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}},{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','id':'9cdd0f68-df85-44b0-88bd-fc4163ac90a3','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}}]"; + String body = FileUtils.readFileToString(new File("src/integration-test/resources/MultipleValidEvents.json")); String Expected="[{\"id\":\"9cdd0f68-df85-44b0-88bd-fc4163ac90a1\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"},{\"id\":\"9cdd0f68-df85-44b0-88bd-fc4163ac90a2\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"},{\"id\":\"9cdd0f68-df85-44b0-88bd-fc4163ac90a3\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]"; JsonArray jarray = new JsonArray(); MsgService msgService = PublishUtils.getMessageService("eiffelsemantics", msgServices); @@ -105,4 +110,17 @@ public void testRabbitMQConnection() { fail(e.getMessage().toString()); } } + + @Test + public void testRoutingKey() throws Exception { + MsgService msgService = PublishUtils.getMessageService("", msgServices); + String routingKey; + if (msgService != null) { + File file = new File("src/integration-test/resources/EiffelActivityFinishedEvent.json"); + JsonParser parser = new JsonParser(); + JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject(); + routingKey = PublishUtils.prepareRoutingKey(msgService, json.getAsJsonObject(), rmqHelper, "fem001"); + assertEquals("eiffel.activity.finished.notag.eiffelxxx.fem001", routingKey); + } + } }