Skip to content

Commit 55977d2

Browse files
authored
Add test for query confidence levels (#173)
* Add test for query confidence levels - Added a test to verify that it is possible to get the latest sucessfull confidence level for a specific commit.
1 parent 604b2e9 commit 55977d2

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

src/functionaltests/java/com/ericsson/ei/query/QueryAggregatedObjectsTestSteps.java

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.junit.Ignore;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
14+
15+
import com.fasterxml.jackson.core.JsonParser.Feature;
1416
import com.fasterxml.jackson.databind.JsonNode;
1517
import com.fasterxml.jackson.databind.ObjectMapper;
1618

@@ -45,6 +47,8 @@ public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
4547
private static final String QUERY_4_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject4.json";
4648
private static final String QUERY_5_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject5.json";
4749
private static final String QUERY_6_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject6.json";
50+
private static final String QUERY_7_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject7.json";
51+
4852

4953
@LocalServerPort
5054
private int applicationPort;
@@ -70,9 +74,10 @@ public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
7074
private String missedNotificationObj;
7175

7276
private ObjectMapper objMapper;
73-
77+
7478
public QueryAggregatedObjectsTestSteps() {
7579
objMapper = new ObjectMapper();
80+
objMapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
7681

7782
try {
7883
aggrObj = FileUtils.readFileToString(new File(AGGREGATED_OBJ_JSON_PATH), "UTF-8");
@@ -83,11 +88,19 @@ public QueryAggregatedObjectsTestSteps() {
8388
e.printStackTrace();
8489
}
8590
}
86-
91+
8792
@Given("^Aggregated object is created$")
8893
public void aggregated_object_is_created() throws Throwable {
89-
LOGGER.debug("Creating aggregated object in MongoDb");
90-
assertEquals(true, createDocumentInMongoDb(eiDatabaseName, aggrCollectionName, aggrObj));
94+
List<String> aggregatedObject = mongoDBHandler.find(
95+
eiDatabaseName, aggrCollectionName, "{\"aggregatedObject.id\": \"6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43\"}"
96+
);
97+
98+
boolean aggregatedObjectExists = aggregatedObject.size() > 0;
99+
if (!aggregatedObjectExists) {
100+
aggregatedObjectExists = createDocumentInMongoDb(eiDatabaseName, aggrCollectionName, aggrObj);
101+
}
102+
103+
assertEquals(true, aggregatedObjectExists);
91104
}
92105

93106
@Given("^Missed Notification object is created$")
@@ -384,6 +397,40 @@ public void perform__query_and_filter_with_part_of_path() throws Throwable {
384397
}
385398
}
386399

400+
@Then("^perform query to retrieve and filter out confidence level information$")
401+
public void perform_query_to_retrieve_and_filter_out_confidence_level_information() throws Throwable {
402+
final String aggrId = "6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43";
403+
final String entryPoint = "/query";
404+
405+
String query = FileUtils.readFileToString(new File(QUERY_7_FILE_NAME), "UTF-8");
406+
407+
LOGGER.debug("Freestyle querying for the AggregatedObject with criteria: " + query);
408+
409+
JsonNode queryJson = objMapper.readValue(query, JsonNode.class);
410+
String formatedQuery = queryJson.toString();
411+
412+
HttpRequest postRequest = new HttpRequest(HttpMethod.POST);
413+
response = postRequest.setPort(applicationPort)
414+
.setHost(hostName)
415+
.addHeader("content-type", "application/json")
416+
.addHeader("Accept", "application/json")
417+
.setEndpoint(entryPoint)
418+
.setBody(formatedQuery)
419+
.performRequest();
420+
421+
LOGGER.debug("Response of /query RestApi, Status Code: " + response.getStatusCodeValue() +
422+
"\nResponse: " + response.getBody().toString());
423+
424+
JsonNode jsonNodeResult = objMapper.readValue(response.getBody().toString(), JsonNode.class);
425+
JsonNode aggrObjResponse = objMapper.readTree(jsonNodeResult.get(0).get(aggrId).asText());
426+
427+
JsonNode confidenceLevels = aggrObjResponse.get("confidenceLevels").get(1);
428+
429+
assertEquals(HttpStatus.OK.toString(), Integer.toString(response.getStatusCodeValue()));
430+
assertEquals("Failed to retrieve the latest confidence level.","readyForDelivery", confidenceLevels.get("name").asText());
431+
assertEquals("Failed to retrieve the latest confidence level.","SUCCESS", confidenceLevels.get("value").asText());
432+
}
433+
387434
/**
388435
* Method that creates a document in MongoDb database.
389436
*
@@ -400,5 +447,4 @@ private boolean createDocumentInMongoDb(String databaseName, String collectionNa
400447
+ "\nDocument to be inserted\n: " + objToBeInserted);
401448
return mongoDBHandler.insertDocument(databaseName, collectionName, objToBeInserted);
402449
}
403-
404450
}

src/functionaltests/resources/features/queryAggregatedObjects.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ Feature: QueryAggregatedObjectsTestSteps
1313
And Check missed notification has been returned
1414
And Perform a query on created Aggregated object with filter
1515
And Perform a query and filter with part of path
16+
17+
Scenario: Test QueryConfidenceLevelModified
18+
Given Aggregated object is created
19+
Then perform query to retrieve and filter out confidence level information
20+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"criteria": {
3+
"$where" : "function() {
4+
var searchKey = 'id';
5+
var value = 'JIRA-1234';
6+
return searchInObj(obj);
7+
function searchInObj(obj){
8+
for (var k in obj){
9+
if (obj[k] == value && k == searchKey) {
10+
return true;
11+
}
12+
13+
if (isObject(obj[k]) && obj[k] !== null) {
14+
if (searchInObj(obj[k])) {
15+
return true;
16+
}
17+
}
18+
}
19+
return false;
20+
}
21+
}"
22+
},
23+
"filter": "{id: aggregatedObject.id, artifactGav:aggregatedObject.gav, confidenceLevels:aggregatedObject.confidenceLevels[?value=='SUCCESS'].{name: name, value: value}}"
24+
25+
}

src/main/java/com/ericsson/ei/mongodbhandler/MongoDBHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private MongoCollection<Document> getMongoCollection(String dataBaseName, String
318318
MongoCollection<Document> collection = db.getCollection(collectionName);
319319
return collection;
320320
}
321-
321+
322322
public void dropCollection(String dataBaseName, String collectionName) {
323323
MongoDatabase db = mongoClient.getDatabase(dataBaseName);
324324
MongoCollection<Document> mongoCollection = db.getCollection(collectionName);

0 commit comments

Comments
 (0)