Skip to content

Commit 329494c

Browse files
authored
Eiffel2.0 events links validation based on the Bordeaux edition of protocol (#47)
* Eiffel2.0 events links validation based on the Bordeaux edition of protocol * Added mandatory link type "TEST_CASE_EXECUTION" in links in TestCaseStarted.json * Added custom link type validation * Modified getRequiredLinks and getOptionalLinks methods in LinksConfiguration file * Modified EiffelOutputValidatorFactory class to get required and optional links based on event * Added java doc for methods and classes and modified target values in the links in all events * Added java doc for the method getLinkTypesFromConfiguration and removed unused code
1 parent eca019d commit 329494c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+769
-154
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.2.6
2+
- Added links validation to events based on the Bordeaux edition of protocol
3+
14
## 0.2.5
25
- added copyright headers to the source code
36

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ allprojects {
4848

4949
jar {
5050
baseName = 'eiffel-remrem-semantics'
51-
version = '0.2.5'
51+
version = '0.2.6'
5252
manifest {
5353
attributes('remremVersionKey': 'semanticsVersion')
5454
attributes('semanticsVersion': version)
@@ -64,7 +64,7 @@ jar {
6464

6565
shadowJar {
6666
baseName = 'eiffel-remrem-semantics'
67-
version = '0.2.5'
67+
version = '0.2.6'
6868
classifier = ''
6969
}
7070

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

+20-11
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,32 @@ public enum EiffelEventType {
4141
ISSUE_VERIFIED("eiffelissueverified"),
4242
ARTIFACT_REUSED("eiffelartifactreused");
4343

44-
private String id;
44+
private String eventType;
4545

46-
EiffelEventType(String id) {
47-
this.id = id;
46+
EiffelEventType(String eventType) {
47+
this.eventType = eventType;
4848
}
4949

50-
static HashMap<String, EiffelEventType> idMap = new HashMap<String, EiffelEventType>();
50+
static HashMap<String, EiffelEventType> eventTypeMap = new HashMap<String, EiffelEventType>();
5151

52-
public static EiffelEventType fromString(String id) {
53-
if (idMap.size() == 0) {
52+
/**
53+
* This method used to get EiffelEventType Enum constant based on event type
54+
* @param eventType of an eiffel event
55+
* @return Enum constant of EiffelEventType
56+
*/
57+
public static EiffelEventType fromString(String eventType) {
58+
if (eventTypeMap.size() == 0) {
5459
for (EiffelEventType type : values())
55-
idMap.put(type.id, type);
60+
eventTypeMap.put(type.eventType, type);
5661
}
57-
return idMap.get(id);
62+
return eventTypeMap.get(eventType);
5863
}
59-
60-
String getEventName() {
61-
return id;
64+
65+
/**
66+
* This method used to get event type of an eiffel event based on Enum constant
67+
* @return event type of an eiffel event
68+
*/
69+
public String getEventName() {
70+
return eventType;
6271
}
6372
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
package com.ericsson.eiffel.remrem.semantics;
16+
17+
import com.ericsson.eiffel.remrem.semantics.schemas.EiffelConstants;
18+
19+
/**
20+
* This class contains list of link types and multiple tracability for those link types.
21+
*
22+
*/
23+
public enum LinkType {
24+
25+
CAUSE(EiffelConstants.MULTIPLE_ALLOWED),
26+
CONTEXT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
27+
FLOW_CONTEXT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
28+
ACTIVITY_EXECUTION(EiffelConstants.MULTIPLE_NOT_ALLOWED),
29+
PREVIOUS_ACTIVITY_EXECUTION(EiffelConstants.MULTIPLE_NOT_ALLOWED),
30+
PREVIOUS_VERSION(EiffelConstants.MULTIPLE_ALLOWED),
31+
COMPOSITION(EiffelConstants.MULTIPLE_NOT_ALLOWED),
32+
ENVIRONMENT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
33+
ARTIFACT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
34+
SUBJECT(EiffelConstants.MULTIPLE_ALLOWED),
35+
ELEMENT(EiffelConstants.MULTIPLE_ALLOWED),
36+
BASE(EiffelConstants.MULTIPLE_NOT_ALLOWED),
37+
CHANGE(EiffelConstants.MULTIPLE_NOT_ALLOWED),
38+
TEST_SUITE_EXECUTION(EiffelConstants.MULTIPLE_NOT_ALLOWED),
39+
TEST_CASE_EXECUTION(EiffelConstants.MULTIPLE_NOT_ALLOWED),
40+
IUT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
41+
TERC(EiffelConstants.MULTIPLE_NOT_ALLOWED),
42+
MODIFIED_ANNOUNCEMENT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
43+
SUB_CONFIDENCE_LEVEL(EiffelConstants.MULTIPLE_ALLOWED),
44+
REUSED_ARTIFACT(EiffelConstants.MULTIPLE_NOT_ALLOWED),
45+
VERIFICATION_BASIS(EiffelConstants.MULTIPLE_ALLOWED);
46+
47+
private final boolean multipleAllowed;
48+
49+
LinkType(boolean multipleAllowed) {
50+
this.multipleAllowed = multipleAllowed;
51+
}
52+
53+
/**
54+
* This method checks multiple traces allowed for a link type
55+
* @return true if multiple traces allowed for the link type
56+
* false if multiple traces not allowed for the link type
57+
*/
58+
public boolean isMultipleAllowed() {
59+
return multipleAllowed;
60+
}
61+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ private void outputValidate(EiffelEventType eiffelType, String jsonStringInput)
184184
EiffelValidator validator = EiffelOutputValidatorFactory.getEiffelValidator(eiffelType);
185185
JsonObject jsonObject = new JsonParser().parse(jsonStringInput).getAsJsonObject();
186186
validator.validate(jsonObject);
187+
//custom validations on an event which is not covered in schema.
188+
validator.customValidation(jsonObject);
187189
}
188190

189191
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
package com.ericsson.eiffel.remrem.semantics.config;
16+
17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
import java.util.List;
20+
import java.util.Locale;
21+
import java.util.MissingResourceException;
22+
import java.util.ResourceBundle;
23+
import java.util.stream.Collectors;
24+
import java.util.stream.Stream;
25+
26+
import com.ericsson.eiffel.remrem.semantics.LinkType;
27+
28+
/**
29+
* This class is used to read required and optional link types from linksValidation.properties file
30+
*
31+
*/
32+
33+
public class LinksConfiguration {
34+
35+
private ResourceBundle links;
36+
private List<String> allLinkTypes;
37+
private final String REQUIRED_LINKS = "requiredLinks";
38+
private final String OPTIONAL_LINKS = "optionalLinks";
39+
private final String DOT = ".";
40+
41+
/**
42+
* Initializes links of type ResourceBundle from linksValidation property file and
43+
* allLinkTypes of type list from LinkType Enum class
44+
*/
45+
public LinksConfiguration() {
46+
links = ResourceBundle.getBundle("linksValidation", Locale.getDefault());
47+
allLinkTypes = Stream.of(LinkType.values()).map(LinkType::name).collect(Collectors.toList());
48+
}
49+
50+
/**
51+
* This method is used to get required link types based on event type
52+
* @param eventType of an Eiffel event
53+
* For Eg: eiffelartifactpublished, eiffelactivityfinished
54+
* @return list of link types required for an event else return an empty list
55+
*/
56+
public List<String> getRequiredLinkTypes(String eventType) {
57+
String key = eventType + DOT + REQUIRED_LINKS;
58+
return getLinkTypesFromConfiguration(key);
59+
}
60+
61+
/**
62+
* This method is used to get optional link types based on event type
63+
* @param eventType of an Eiffel event
64+
* For Eg: eiffelartifactpublished, eiffelactivityfinished
65+
* @return list of optional link types for an event else return an empty list
66+
*/
67+
public List<String> getOptionalLinkTypes(String eventType) {
68+
String key = eventType + DOT + OPTIONAL_LINKS;
69+
return getLinkTypesFromConfiguration(key);
70+
}
71+
72+
/**
73+
* This method is used to get link types based on key
74+
* @param key is <eventType>.requiredLinks or <eventType>.optionalLinks
75+
* For Eg: eiffelactivitycanceled.requiredLinks, eiffelactivitycanceled.optionalLinks
76+
* @return list of link types for an event else return an empty list
77+
*/
78+
private List<String> getLinkTypesFromConfiguration(String key) {
79+
List<String> linkTypeList = new ArrayList<String>();
80+
try {
81+
if (!links.getString(key).isEmpty()) {
82+
linkTypeList = Arrays.asList(links.getString(key).split(","));
83+
}
84+
return linkTypeList;
85+
} catch (MissingResourceException e) {
86+
return linkTypeList;
87+
}
88+
}
89+
90+
/**
91+
* This method is used to get all link types from LinkTypes Enum
92+
* @return list of all link types
93+
*/
94+
public List<String> getAllLinkTypes() {
95+
return allLinkTypes;
96+
}
97+
}

0 commit comments

Comments
 (0)