Skip to content

Commit bafedf2

Browse files
Christoffer-Cortesvasile-baluta
authored andcommitted
add method to get available eiffel event types as string collection (#59)
Add method to get available Eiffel event types as string collection
1 parent 2d3a194 commit bafedf2

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ allprojects {
4848

4949
jar {
5050
baseName = 'eiffel-remrem-semantics'
51-
version = '0.3.2'
51+
version = '0.3.3'
5252
manifest {
5353
attributes('remremVersionKey': 'semanticsVersion')
5454
attributes('semanticsVersion': version)
@@ -95,7 +95,7 @@ repositories {
9595
install.dependsOn shadowJar
9696

9797
dependencies {
98-
compile 'com.github.Ericsson:eiffel-remrem-protocol-interface:0.0.5'
98+
compile 'com.github.Ericsson:eiffel-remrem-protocol-interface:0.0.6'
9999
compile('com.github.fge:json-schema-validator:2.2.6')
100100
{
101101
// we need to exclude jackson-databind here and add a

src/main/java/com/ericsson/eiffel/remrem/semantics/SemanticsService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ARTIFACT_REUSED;
4747

4848
import java.util.ArrayList;
49+
import java.util.Collection;
4950
import java.util.HashMap;
51+
import java.util.List;
5052
import java.util.Map;
5153

5254
import javax.annotation.PostConstruct;
@@ -283,6 +285,11 @@ public String getEventType(JsonObject json) {
283285
}
284286
return null;
285287
}
288+
289+
@Override
290+
public Collection<String> getSupportedEventTypes() {
291+
return supportedEventTypes;
292+
}
286293

287294
/**
288295
* Returns Family Routing Key Word from the messaging library based on the

src/test/java/com/ericsson/eiffel/remrem/semantics/ServiceTest.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import java.io.FileNotFoundException;
2525
import java.io.FileReader;
2626
import java.net.URL;
27+
import java.util.ArrayList;
28+
import java.util.Collection;
29+
import java.util.List;
2730
import java.util.jar.Attributes;
2831
import java.util.jar.Manifest;
2932

@@ -37,6 +40,8 @@
3740
import com.ericsson.eiffel.remrem.protocol.ValidationResult;
3841
import com.ericsson.eiffel.remrem.semantics.util.ManifestHandler;
3942
import com.ericsson.eiffel.semantics.events.Gav;
43+
import com.google.gson.JsonArray;
44+
import com.google.gson.JsonElement;
4045
import com.google.gson.JsonIOException;
4146
import com.google.gson.JsonObject;
4247
import com.google.gson.JsonParser;
@@ -65,8 +70,6 @@ public static void readManifestGav() {
6570
manifestGav.setGroupId(attributes1.getValue("groupId"));
6671
manifestGav.setArtifactId(attributes1.getValue("artifactId"));
6772
manifestGav.setVersion(attributes1.getValue("semanticsVersion"));
68-
} catch (FileNotFoundException e) {
69-
e.printStackTrace();
7073
} catch (Exception e) {
7174
e.printStackTrace();
7275
}
@@ -148,11 +151,7 @@ public void validateMessage() {
148151
try {
149152
input = parser.parse(new FileReader(file)).getAsJsonObject();
150153
msg = service.validateMsg(ACTIVITY_FINISHED, input);
151-
} catch (JsonIOException e) {
152-
e.printStackTrace();
153-
} catch (JsonSyntaxException e) {
154-
e.printStackTrace();
155-
} catch (FileNotFoundException e) {
154+
} catch (Exception e) {
156155
e.printStackTrace();
157156
}
158157
Assert.assertNotNull(msg);
@@ -169,11 +168,7 @@ public void testGetEventType() {
169168
try {
170169
input = parser.parse(new FileReader(file)).getAsJsonObject();
171170
eventType = service.getEventType(input);
172-
} catch (JsonIOException e) {
173-
e.printStackTrace();
174-
} catch (JsonSyntaxException e) {
175-
e.printStackTrace();
176-
} catch (FileNotFoundException e) {
171+
} catch (Exception e) {
177172
e.printStackTrace();
178173
}
179174
assertEquals("EiffelActivityFinishedEvent", eventType);
@@ -189,11 +184,7 @@ public void testGenerateRoutingKey() {
189184
try {
190185
input = parser.parse(new FileReader(file)).getAsJsonObject();
191186
routingKey = service.generateRoutingKey(input, null, null, null);
192-
} catch (JsonIOException e) {
193-
e.printStackTrace();
194-
} catch (JsonSyntaxException e) {
195-
e.printStackTrace();
196-
} catch (FileNotFoundException e) {
187+
} catch (Exception e) {
197188
e.printStackTrace();
198189
}
199190
assertEquals("eiffel.activity.finished.notag.domainID", routingKey);
@@ -219,4 +210,28 @@ public void testInvalidPathRemremSemanticsGav() throws Exception {
219210
manifestGav.setVersion(attributes1.getValue("semanticsVersion"));
220211

221212
}
213+
214+
@Test
215+
public void testGetSupportedEventTypes() {
216+
URL url = getClass().getClassLoader().getResource("EventTypes.json");
217+
String path = url.getPath().replace("%20", " ");
218+
File file = new File(path);
219+
JsonObject input = null;
220+
boolean checkValue = false;
221+
try {
222+
Collection<String> types = service.getSupportedEventTypes();
223+
input = parser.parse(new FileReader(file)).getAsJsonObject();
224+
JsonArray eventTypes = input.getAsJsonArray("eventTypes");
225+
List<String> matchingCollection = new ArrayList<>();
226+
if (eventTypes != null) {
227+
for (JsonElement event : eventTypes) {
228+
matchingCollection.add(event.getAsString());
229+
}
230+
}
231+
checkValue = types.containsAll(matchingCollection);
232+
} catch (Exception e) {
233+
e.printStackTrace();
234+
}
235+
assertEquals(true,checkValue);
236+
}
222237
}

src/test/resources/EventTypes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"eventTypes":["EiffelCompositionDefinedEvent","EiffelTestSuiteStartedEvent","EiffelActivityCanceledEvent","EiffelActivityTriggeredEvent","EiffelAnnouncementPublishedEvent","EiffelTestCaseFinishedEvent","EiffelIssueVerifiedEvent","EiffelActivityFinishedEvent","EiffelFlowContextDefinedEvent","EiffelConfidenceLevelModifiedEvent","EiffelSourceChangeSubmittedEvent","EiffelTestCaseCanceledEvent","EiffelTestExecutionRecipeCollectionCreatedEvent","EiffelEnvironmentDefinedEvent","EiffelActivityStartedEvent","EiffelTestCaseTriggeredEvent","EiffelArtifactReusedEvent","EiffelSourceChangeCreatedEvent","EiffelTestSuiteFinishedEvent","EiffelArtifactPublishedEvent","EiffelArtifactCreatedEvent","EiffelTestCaseStartedEvent"]}

0 commit comments

Comments
 (0)