Skip to content

Commit c6bc53f

Browse files
External rules (#282)
* Allows for http(s) and file URI to be used as rule.path. * Exits the application if the rules file fails to load or content is empty.
1 parent f0502b5 commit c6bc53f

36 files changed

+355
-398
lines changed

.mvn/maven.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--settings ./.mvn/project-settings.xml

.mvn/project-settings.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
6+
<!-- Repositories from additional providers -->
7+
<!-- WARNING: Changes made here must also be made in pom.xml -->
8+
<mirrors>
9+
<mirror>
10+
<id>jboss-public-repository-group</id>
11+
<mirrorOf>JBoss Public Maven Repository Group</mirrorOf>
12+
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
13+
</mirror>
14+
<mirror>
15+
<id>jitpack.io</id>
16+
<mirrorOf>jitpack.io</mirrorOf>
17+
<url>https://jitpack.io</url>
18+
</mirror>
19+
<mirror>
20+
<id>oracleReleases</id>
21+
<mirrorOf>Oracle Released Java Packages</mirrorOf>
22+
<url>http://download.oracle.com/maven</url>
23+
</mirror>
24+
</mirrors>
25+
26+
</settings>

pom.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@
5050
</plugins>
5151
</reporting>
5252

53+
<!-- Repositories from additional providers -->
54+
<!-- WARNING: Changes made here must also be made in .mvn/project-settings.xml -->
5355
<repositories>
54-
<repository>
55-
<id>hortonworks.com</id>
56-
<url>http://nexus-private.hortonworks.com:8081/nexus/content/groups/public</url>
57-
</repository>
5856
<repository>
5957
<id>jboss-public-repository-group</id>
6058
<name>JBoss Public Maven Repository Group</name>
@@ -64,6 +62,12 @@
6462
<id>jitpack.io</id>
6563
<url>https://jitpack.io</url>
6664
</repository>
65+
<repository>
66+
<id>oracleReleases</id>
67+
<name>Oracle Released Java Packages</name>
68+
<url>http://download.oracle.com/maven</url>
69+
<layout>default</layout>
70+
</repository>
6771
</repositories>
6872

6973
<dependencies>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.ericsson.ei.rules;
2+
3+
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
4+
import static org.mockserver.model.HttpRequest.request;
5+
import static org.mockserver.model.HttpResponse.response;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
import org.junit.Ignore;
11+
import org.mockserver.client.MockServerClient;
12+
import org.mockserver.integration.ClientAndServer;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
import org.springframework.util.SocketUtils;
16+
17+
import cucumber.api.java.After;
18+
import cucumber.api.java.Before;
19+
import cucumber.api.java.en.Given;
20+
import cucumber.api.java.en.Then;
21+
22+
@Ignore
23+
public class RulesHandlerSteps {
24+
25+
private ClientAndServer restServer;
26+
private MockServerClient mockClient;
27+
private RulesHandler rulesHandler;
28+
private String rulesPath = "";
29+
private int port = -1;
30+
31+
private static final String HOST = "localhost";
32+
private static final String ROUTE_RULES_FILE = "/some/route/MyRules.json";
33+
private static final String ROUTE_RULES_FILE_EMPTY = "/some/route/EmptyRules.json";
34+
private static final String BODY = "{}";
35+
private static final String EMPTY = "";
36+
37+
private static final Logger LOGGER = LoggerFactory.getLogger(RulesHandlerSteps.class);
38+
39+
@Before("@RulesHandlerHttpURI")
40+
public void beforeScenario() throws IOException {
41+
LOGGER.debug("Setting up Mock Server and Endpoints");
42+
setupRestEndpoints();
43+
}
44+
45+
@After("@RulesHandlerHttpURI")
46+
public void afterScenario() throws IOException {
47+
LOGGER.debug("Stopping Mock Server");
48+
restServer.stop();
49+
mockClient.close();
50+
}
51+
52+
@Given("^a file with path \"([^\"]*)\"$")
53+
public void file_with_path(String rulesPath) {
54+
this.rulesPath = rulesPath.replace("{port}", String.valueOf(port));
55+
}
56+
57+
@Given("^path is made absolute$")
58+
public void path_is_absolute() {
59+
rulesPath = new File(rulesPath).getAbsolutePath();
60+
}
61+
62+
@Given("^path is URI with \"([^\"]*)\" scheme$")
63+
public void path_is_uri(String scheme) {
64+
rulesPath = scheme + "://" + rulesPath;
65+
}
66+
67+
@Then("^rules are loaded$")
68+
public void rules_are_loaded() throws Exception {
69+
initializeRulesHandler();
70+
}
71+
72+
@Then("^rules are loaded with expected exception$")
73+
public void rules_are_loaded_with_exception() throws Exception {
74+
try {
75+
initializeRulesHandler();
76+
} catch (Exception e) {
77+
LOGGER.debug("Expected exception occurred");
78+
}
79+
}
80+
81+
/**
82+
* Create a new instance of RulesHandler using a rules.path
83+
* set by the rulesPath variable.
84+
*
85+
* @throws Exception
86+
*/
87+
private void initializeRulesHandler() throws Exception {
88+
LOGGER.debug("Rules Path: " + rulesPath);
89+
System.setProperty("rules.path", rulesPath);
90+
rulesHandler = new RulesHandler();
91+
rulesHandler.init();
92+
}
93+
94+
/**
95+
* Setting up the needed endpoints for the functional test.
96+
*/
97+
private void setupRestEndpoints() {
98+
port = SocketUtils.findAvailableTcpPort();
99+
restServer = startClientAndServer(port);
100+
101+
LOGGER.debug("Setting up endpoints on host '" + HOST + "' and port '" + port + "'");
102+
mockClient = new MockServerClient(HOST, port);
103+
mockClient.when(request().withMethod("GET").withPath(ROUTE_RULES_FILE)).respond(response().withStatusCode(201).withBody(BODY));
104+
mockClient.when(request().withMethod("GET").withPath(ROUTE_RULES_FILE_EMPTY)).respond(response().withStatusCode(201).withBody(EMPTY));
105+
}
106+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ericsson.ei.rules;
2+
3+
import cucumber.api.CucumberOptions;
4+
import cucumber.api.junit.Cucumber;
5+
import org.junit.runner.RunWith;
6+
7+
@RunWith(Cucumber.class)
8+
@CucumberOptions(features = "src/functionaltests/resources/features/rulesHandler.feature", glue = {
9+
"com.ericsson.ei.rules" }, plugin = { "pretty", "html:target/cucumber-reports/TestRulesHandlerRunner" })
10+
public class TestRulesHandlerRunner {
11+
12+
}

src/functionaltests/java/com/ericsson/ei/subscriptions/repeatHandler/SubscriptionRepeatHandlerSteps.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import org.springframework.boot.web.server.LocalServerPort;
1919
import org.springframework.http.HttpStatus;
2020
import org.springframework.http.ResponseEntity;
21+
import org.springframework.test.context.TestPropertySource;
2122

2223
import com.ericsson.ei.controller.model.Subscription;
2324
import com.ericsson.ei.handlers.MongoDBHandler;
24-
import com.ericsson.ei.rules.RulesHandler;
2525
import com.ericsson.ei.services.ISubscriptionService;
2626
import com.ericsson.ei.subscription.RunSubscription;
2727
import com.ericsson.ei.utils.FunctionalTestBase;
@@ -38,12 +38,11 @@
3838
import gherkin.deps.com.google.gson.JsonParser;
3939

4040
@Ignore
41+
@TestPropertySource(properties = {"rules.path=src/test/resources/TestExecutionObjectRules.json"})
4142
public class SubscriptionRepeatHandlerSteps extends FunctionalTestBase {
4243

4344
private static final String AGGREGATED_OBJECT_FILE_PATH = "src/functionaltests/resources/aggregatedObject.json";
44-
private static final String AGGREGATED_OBJECT_FINAL_FILE_PATH = "src/functionaltests/resources/aggregatedObjectFinal.json";
4545
private static final String EVENTS_FILE_PATH = "src/test/resources/TestExecutionTestEvents.json";
46-
private static final String RULES_FILE_PATH = "src/test/resources/TestExecutionObjectRules.json";
4746
private static final String REPEAT_FLAG_SUBSCRIPTION_COLLECTIONS_WITH_ONE_MATCH = "src/functionaltests/resources/subscriptionRepeatHandlerOneMatch.json";
4847
private static final String REPEAT_FLAG_SUBSCRIPTION_COLLECTIONS_WITH_TWO_MATCH = "src/functionaltests/resources/subscriptionRepeatHandlerTwoMatch.json";
4948
private static final String AGGREGATED_OBJECT_ID = "b46ef12d-25gb-4d7y-b9fd-8763re66de47";
@@ -71,9 +70,6 @@ public class SubscriptionRepeatHandlerSteps extends FunctionalTestBase {
7170
@Autowired
7271
private MongoDBHandler mongoDBHandler;
7372

74-
@Autowired
75-
private RulesHandler rulesHandler;
76-
7773
@Autowired
7874
private ISubscriptionService subscriptionService;
7975

@@ -95,7 +91,6 @@ public void beforeScenario() throws IOException, JSONException {
9591

9692
@Given("^Publish events on Message Bus$")
9793
public void publish_events_on_Message_Bus() throws IOException, InterruptedException {
98-
rulesHandler.setRulePath(RULES_FILE_PATH);
9994
List<String> eventNamesToSend = getEventNamesToSend();
10095
eventManager.sendEiffelEvents(EVENTS_FILE_PATH, eventNamesToSend);
10196
List<String> arguments = new ArrayList<>();

src/functionaltests/resources/features/authentication.feature

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
#Author: valentin.tyhonov@ericsson.com, christoffer.cortes.sjowall@ericsson.com
2-
#Keywords Summary :
3-
#Feature: List of scenarios.
4-
#Scenario: Business rule through list of steps with arguments.
5-
#Given: Some precondition step
6-
#When: Some key actions
7-
#Then: To observe outcomes or validation
8-
#And,But: To enumerate more Given,When,Then steps
9-
#Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
10-
#Examples: Container for s table
11-
#Background: List of steps run before each of the scenarios
12-
#""" (Doc Strings)
13-
#| (Data Tables)
14-
#@ (Tags/Labels):To group Scenarios
15-
#<> (placeholder)
16-
#""
17-
## (Comments)
18-
#Sample Feature Definition Template
2+
3+
@Authentication
194
Feature: Test Authentication
205

216
@RESTWithoutCredentials

src/functionaltests/resources/features/downloadFiles.feature

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
#Author:
2-
#Keywords Summary :
3-
#Feature: List of scenarios.
4-
#Scenario: Business rule through list of steps with arguments.
5-
#Given: Some precondition step
6-
#When: Some key actions
7-
#Then: To observe outcomes or validation
8-
#And,But: To enumerate more Given,When,Then steps
9-
#Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
10-
#Examples: Container for s table
11-
#Background: List of steps run before each of the scenarios
12-
#""" (Doc Strings)
13-
#| (Data Tables)
14-
#@ (Tags/Labels):To group Scenarios
15-
#<> (placeholder)
16-
#""
17-
## (Comments)
18-
19-
@tag
20-
Feature: DownloadFilesTests
1+
@DownloadFiles
2+
Feature: Test Download Files
213

4+
@DownloadFilesScenario
225
Scenario: Test DownloadFiles Entrypoints
236
Given Eiffel Intelligence instance is up and running
247
Then List available files

src/functionaltests/resources/features/queryAggregatedObjects.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
2-
@tag
3-
Feature: QueryAggregatedObjectsTestSteps
1+
@QueryAggregatedObjects
2+
Feature: Test Query Aggregated Objects
43

54
@QueryAggregatedObjectsTestSteps
65
Scenario: Test QueryAggregatedObjectsTestSteps

src/functionaltests/resources/features/rabbitMQTestConnection.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
@RabbitMQConnection
2+
Feature: Test Rabbit MQ Connection
13

2-
Feature: RabbitMQConnection
3-
4+
@RabbitMQConnectionScenario
45
Scenario: Testing to automatically reconnect to Message Bus
56
Given We are connected to message bus
67
When Message bus goes down

0 commit comments

Comments
 (0)