Skip to content

Commit 923d058

Browse files
Test Rule Page Back-end Status- Entry Point (#143)
* JMESPath REST API * JMESPath API with fixed reviews * partial work jmespath rest * JMESPath API with RAML 0.8 specification * remove componet comment * replace tab with spaces * fix usage examples * prepare for new asserts in flow test * fix unit tests * Subscription for individual events * pom file * subscription individual objects * pom * error removal * Subscription Individual Object * deleting unused import * jmespath comment correction * space removal and new clean build * review changes * review change file deleted * review change * review changes * log.info to log.error * required changes * raml * raml files * resolving conflict * self generated code raml * controllers auto generated * auto generated * removing ttl * adding ttl * copied pom * changes in app.properties * resolving conflict with upstream * adding more files * added time lapse variable * rebased... * new clone and update * reviewed changes * review changes-evasiba * review changes 2:evasiba * handling of authorization by Subscription REST API: 9584 * changing property name * pom updated * method change * reviewed changes-1 * some review changes regarding comments * some changes ´to get pass throguh tests * review changes * Update application.properties * Fix test * development * changes * code changes related to story 9561 * error * error removal * requested changes * reviewed change * reviewed changes * added random port in FunctionalTestBase * Add threading and waitlist tests - Still in progress * working code * changing test resources from location to properties * some changes in time units * Update ThreadingAndWaitlistRepeatSteps.java * Update ThreadingAndWaitlistRepeatSteps.java * Update ThreadingAndWaitlistRepeatSteps.java * timing related changes * reviewed changes * reviewed change * refactored functionaltest base class * reviewed changes * reviewed changes * reviewed changes:removing fields * resolving conflict due to latest commit * Test Rule Page Enabling: entry point and junit test * rebase from ericsson master (#3) rebase from ericsson master * temporary file to record log * reviewed changes * reviewed changes: test for each of default, true and false cases * test rule page: functional test added
1 parent a6c9f30 commit 923d058

File tree

8 files changed

+120
-35
lines changed

8 files changed

+120
-35
lines changed

src/functionaltests/java/com/ericsson/ei/rules/RuleCheckSteps.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,20 @@ public void get_content(String contentFileName) throws Throwable {
104104
assertEquals(expectedObject, responseObject, true);
105105
}
106106
}
107+
108+
@Then("^get request from REST API \"([^\"]*)\" return response code of (\\d+) and status as \"([^\"]*)\"$")
109+
public void get_request_from_REST_API_return_response_code_of_and_status_as(String endpoint, int statusCode, String status) throws Throwable {
110+
String responseBody = new JSONObject().put("status", Boolean.valueOf(status)).toString();
111+
HttpRequest getRequest = new HttpRequest(HttpMethod.GET);
112+
ResponseEntity<String> apiResponse = getRequest.setPort(applicationPort)
113+
.setHost(hostName)
114+
.setHeaders("content-type", "application/json")
115+
.setHeaders("Accept", "application/json")
116+
.setEndpoint(endpoint)
117+
.performRequest();
118+
119+
assertEquals(statusCode, apiResponse.getStatusCodeValue());
120+
assertEquals(responseBody, apiResponse.getBody());
121+
}
107122

108123
}

src/functionaltests/java/com/ericsson/ei/threadingAndWaitlistRepeat/ThreadingAndWaitlistRepeatSteps.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@Ignore
3333
public class ThreadingAndWaitlistRepeatSteps extends FunctionalTestBase {
3434

35-
private static final String LOGFILE = "src/functionaltests/resources/logfile.txt";
35+
private File tempLogFile;
3636
private static final String EIFFEL_EVENTS_JSON_PATH = "src/functionaltests/resources/eiffel_events_for_thread_testing.json";
3737

3838
@Value("${threads.corePoolSize}")
@@ -46,14 +46,9 @@ public class ThreadingAndWaitlistRepeatSteps extends FunctionalTestBase {
4646

4747
@Before("@ThreadingAndWaitlistRepeatScenario")
4848
public void beforeScenario() throws IOException {
49-
File logfile = new File(LOGFILE);
50-
logfile.createNewFile();
51-
System.setOut(new PrintStream(logfile));
52-
}
53-
54-
@After("@ThreadingAndWaitlistRepeatScenario")
55-
public void afterScenario() throws IOException {
56-
Files.deleteIfExists(Paths.get(LOGFILE));
49+
tempLogFile = File.createTempFile("logfile", ".tmp");
50+
tempLogFile.deleteOnExit();
51+
System.setOut(new PrintStream(tempLogFile));
5752
}
5853

5954
@Given("^that eiffel events are sent$")
@@ -75,11 +70,11 @@ public void no_event_is_aggregated() throws Throwable {
7570
assertEquals("aggregatedObjectExists was true, should be false, ", false, aggregatedObjectExists);
7671
}
7772

78-
@Then("^the waitlist will try to resent the events at given time interval$")
79-
public void the_waitlist_will_try_to_resent_the_events_at_given_time_interval() throws Throwable {
73+
@Then("^the waitlist will try to resend the events at given time interval$")
74+
public void the_waitlist_will_try_to_resend_the_events_at_given_time_interval() throws Throwable {
8075
TimeUnit.SECONDS.sleep(5);
81-
List<String> resentEvents = new ArrayList<String>();
82-
List<String> lines = new ArrayList<String>(Files.readAllLines(Paths.get(LOGFILE)));
76+
List<String> resentEvents = new ArrayList<>();
77+
List<String> lines = new ArrayList<>(Files.readAllLines(tempLogFile.toPath()));
8378

8479
for (String line : lines) {
8580
Pattern pattern = Pattern.compile("\\[EIFFEL EVENT RESENT\\] id:([a-zA-Z\\d-]+)");

src/functionaltests/resources/features/ruleCheck.feature

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ Feature: Test Rules Checker
4646
Given rules checking is not enabled
4747
And file with JMESPath rules "/AggregateListRules.json" and file with events "/AggregateListEvents.json"
4848
When make a POST request to the REST API "/rules/rule-check/aggregation"
49-
Then get response code of 503
49+
Then get response code of 503
50+
51+
#@tag5
52+
Scenario: Check status of test rule page using REST API
53+
When rules checking is enabled
54+
Then get request from REST API "/rules/rule-check/testRulePageEnabled" return response code of 200 and status as "true"
55+
When rules checking is not enabled
56+
Then get request from REST API "/rules/rule-check/testRulePageEnabled" return response code of 200 and status as "false"
57+

src/functionaltests/resources/features/threadingAndWaitlistRepeat.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Feature: Subscription trigger test
2424
Given that eiffel events are sent
2525
Then waitlist should not be empty
2626
And no event is aggregated
27-
And the waitlist will try to resent the events at given time interval
27+
And the waitlist will try to resend the events at given time interval
2828
And correct amount of threads should be spawned
2929
And after the time to live has ended, the waitlist should be empty

src/main/java/com/ericsson/ei/controller/RuleCheckController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ public ResponseEntity<?> updateAggregation(
4242
@RequestBody
4343
RuleCheckBody ruleCheckBody);
4444

45+
/**
46+
* This call for the current status of test rule entry point, we get status as output
47+
*
48+
*/
49+
@RequestMapping(value = "/testRulePageEnabled", method = RequestMethod.GET)
50+
public ResponseEntity<?> getTestRulePageEnabled();
51+
4552
}

src/main/java/com/ericsson/ei/controller/RuleCheckControllerImpl.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
package com.ericsson.ei.controller;
1818

1919
import java.io.IOException;
20+
import java.util.ArrayList;
2021

2122
import com.ericsson.ei.controller.model.RuleCheckBody;
23+
import com.ericsson.ei.exception.SubscriptionNotFoundException;
2224
import com.ericsson.ei.jmespath.JmesPathInterface;
2325
import com.ericsson.ei.services.IRuleCheckService;
2426
import io.swagger.annotations.Api;
2527
import io.swagger.annotations.ApiOperation;
2628
import io.swagger.annotations.ApiParam;
29+
import lombok.Setter;
30+
2731
import org.json.JSONArray;
2832
import org.json.JSONException;
2933
import org.json.JSONObject;
@@ -68,17 +72,17 @@ public class RuleCheckControllerImpl implements RuleCheckController {
6872

6973
@Autowired
7074
private IRuleCheckService ruleCheckService;
71-
75+
76+
@Setter
7277
@Value("${testaggregated.enabled:false}")
7378
private Boolean testEnable;
7479

7580
/**
76-
* This method interacts with JmesPathInterface class method runRuleOnEvent
77-
* to evaluate a rule on JSON object.
81+
* This method interacts with JmesPathInterface class method runRuleOnEvent to
82+
* evaluate a rule on JSON object.
7883
*
7984
* @param rule-
80-
* takes a String as a rule that need to be evaluated on JSON
81-
* content
85+
* takes a String as a rule that need to be evaluated on JSON content
8286
* @param jsonContent-
8387
* takes JSON object as a String
8488
* @return a String object
@@ -87,8 +91,9 @@ public class RuleCheckControllerImpl implements RuleCheckController {
8791
@Override
8892
@CrossOrigin
8993
@ApiOperation(value = "To execute rule on JSON", response = String.class)
90-
public ResponseEntity<?> updateRulesRuleCheck(@ApiParam(value = "JMESPath rule", required = true) @RequestParam String rule,
91-
@ApiParam(value = "JSON object", required = true) @RequestBody String jsonContent) {
94+
public ResponseEntity<?> updateRulesRuleCheck(
95+
@ApiParam(value = "JMESPath rule", required = true) @RequestParam String rule,
96+
@ApiParam(value = "JSON object", required = true) @RequestBody String jsonContent) {
9297
try {
9398
JSONObject jsonObj = new JSONObject(jsonContent);
9499
String res = jmesPathInterface.runRuleOnEvent(rule, jsonObj.toString()).toString();
@@ -104,11 +109,12 @@ public ResponseEntity<?> updateRulesRuleCheck(@ApiParam(value = "JMESPath rule",
104109
@Override
105110
@CrossOrigin
106111
@ApiOperation(value = "To execute the list of rules on list of Eiffel events. Return the aggregated object(s)", response = String.class)
107-
public ResponseEntity<?> updateAggregation(@ApiParam(value = "Object that include list of rules and list of Eiffel events", required = true)
108-
@RequestBody RuleCheckBody body) {
112+
public ResponseEntity<?> updateAggregation(
113+
@ApiParam(value = "Object that include list of rules and list of Eiffel events", required = true) @RequestBody RuleCheckBody body) {
109114
if (testEnable) {
110115
try {
111-
String aggregatedObject = ruleCheckService.prepareAggregatedObject(new JSONArray(body.getListRulesJson()), new JSONArray(body.getListEventsJson()));
116+
String aggregatedObject = ruleCheckService.prepareAggregatedObject(
117+
new JSONArray(body.getListRulesJson()), new JSONArray(body.getListEventsJson()));
112118
if (aggregatedObject != null && !aggregatedObject.equals("[]")) {
113119
return new ResponseEntity<>(aggregatedObject, HttpStatus.OK);
114120
} else {
@@ -123,11 +129,24 @@ public ResponseEntity<?> updateAggregation(@ApiParam(value = "Object that includ
123129
}
124130
} else {
125131
String errorMessage = "Test Rules functionality is disabled in backend server. "
126-
+ "Configure \"testaggregated.controller.enabled\" setting in backend servers properties "
127-
+ "to enable this functionality. This should normally only be enabled in backend test servers.";
132+
+ "Configure \"testaggregated.controller.enabled\" setting in backend servers properties "
133+
+ "to enable this functionality. This should normally only be enabled in backend test servers.";
128134
LOGGER.error(errorMessage);
129135
return new ResponseEntity<>(errorMessage, HttpStatus.SERVICE_UNAVAILABLE);
130136
}
131137
}
132138

139+
@Override
140+
@CrossOrigin
141+
@ApiOperation(value = "To get Rules Check Srvice enabled status", response = String.class)
142+
public ResponseEntity<?> getTestRulePageEnabled() {
143+
LOGGER.debug("Getting Enabling Status of Rules Check Service");
144+
try {
145+
return new ResponseEntity<>(new JSONObject().put("status", testEnable).toString(), HttpStatus.OK);
146+
} catch (Exception e) {
147+
String errorMessage = "Failed to get Status. Error message:\n" + e.getMessage();
148+
LOGGER.error(errorMessage, e);
149+
return new ResponseEntity<>(errorMessage, HttpStatus.INTERNAL_SERVER_ERROR);
150+
}
151+
}
133152
}

src/main/resources/public/raml/rules.raml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@
3535
responses:
3636
200:
3737
body:
38-
application/string:
38+
application/string:
39+
40+
/testRulePageEnabled:
41+
get:
42+
description: This call for the current status of test rule entry point, we get status as output
43+
displayName: findTestRuleServiceStatus
44+
responses:
45+
200:
46+
body:
47+
application/string:
48+
example: "status: false"

src/test/java/com/ericsson/ei/rules/test/TestRulesRestAPI.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.ericsson.ei.rules.test;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
21+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2022

2123
import java.io.File;
2224

@@ -37,6 +39,7 @@
3739
import org.springframework.boot.test.mock.mockito.MockBean;
3840
import org.springframework.http.HttpStatus;
3941
import org.springframework.http.MediaType;
42+
import org.springframework.http.ResponseEntity;
4043
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
4144
import org.springframework.test.web.servlet.MockMvc;
4245
import org.springframework.test.web.servlet.MvcResult;
@@ -45,13 +48,12 @@
4548
import org.springframework.util.SocketUtils;
4649

4750
import com.ericsson.ei.App;
51+
import com.ericsson.ei.controller.RuleCheckControllerImpl;
4852
import com.ericsson.ei.services.IRuleCheckService;
4953

5054
@RunWith(SpringJUnit4ClassRunner.class)
51-
@SpringBootTest(classes = {
52-
App.class,
53-
EmbeddedMongoAutoConfiguration.class // <--- Don't forget THIS
54-
})
55+
@SpringBootTest(classes = { App.class, EmbeddedMongoAutoConfiguration.class // <--- Don't forget THIS
56+
})
5557
@AutoConfigureMockMvc
5658
public class TestRulesRestAPI {
5759

@@ -70,7 +72,7 @@ public class TestRulesRestAPI {
7072

7173
@Value("${testaggregated.enabled:false}")
7274
private Boolean testEnable;
73-
75+
7476
@BeforeClass
7577
public static void init() {
7678
int port = SocketUtils.findAvailableTcpPort();
@@ -113,8 +115,10 @@ public void testAggregationRestApi() throws Exception {
113115
} catch (Exception e) {
114116
LOGGER.error(e.getMessage(), e);
115117
}
116-
String body = "{\"listRulesJson\":" + extractionRules_test.toString() + ",\"listEventsJson\":" + jsonInput.toString() + "}";
117-
Mockito.when(ruleCheckService.prepareAggregatedObject(Mockito.any(JSONArray.class), Mockito.any(JSONArray.class)))
118+
String body = "{\"listRulesJson\":" + extractionRules_test.toString() + ",\"listEventsJson\":"
119+
+ jsonInput.toString() + "}";
120+
Mockito.when(
121+
ruleCheckService.prepareAggregatedObject(Mockito.any(JSONArray.class), Mockito.any(JSONArray.class)))
118122
.thenReturn(aggregatedResult);
119123
RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/rules/rule-check/aggregation")
120124
.accept(MediaType.ALL).content(body).contentType(MediaType.APPLICATION_JSON);
@@ -127,7 +131,34 @@ public void testAggregationRestApi() throws Exception {
127131
} else {
128132
assertEquals(HttpStatus.SERVICE_UNAVAILABLE.value(), result.getResponse().getStatus());
129133
}
134+
}
130135

136+
@Test
137+
public void testGetTestRulePageEnabledAPI_setPropertyDefult() throws Exception {
138+
String responseBody = new JSONObject().put("status", false).toString();
139+
mockMvc.perform(MockMvcRequestBuilders.get("/rules/rule-check/testRulePageEnabled")
140+
.accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
141+
.andExpect(content().string(responseBody)).andReturn();
131142
}
132143

144+
@Test
145+
public void testGetTestRulePageEnabledAPI_setPropertyTrue() throws Exception {
146+
String responseBody = new JSONObject().put("status", true).toString();
147+
RuleCheckControllerImpl ruleCheckControllerImpl = new RuleCheckControllerImpl();
148+
ruleCheckControllerImpl.setTestEnable(true);
149+
ResponseEntity<?> responseEntity = ruleCheckControllerImpl.getTestRulePageEnabled();
150+
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
151+
assertEquals(responseBody, responseEntity.getBody().toString());
152+
153+
}
154+
155+
@Test
156+
public void testGetTestRulePageEnabledAPI_setPropertyFalse() throws Exception {
157+
String responseBody = new JSONObject().put("status", false).toString();
158+
RuleCheckControllerImpl ruleCheckControllerImpl = new RuleCheckControllerImpl();
159+
ruleCheckControllerImpl.setTestEnable(false);
160+
ResponseEntity<?> responseEntity = ruleCheckControllerImpl.getTestRulePageEnabled();
161+
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
162+
assertEquals(responseBody, responseEntity.getBody().toString());
163+
}
133164
}

0 commit comments

Comments
 (0)