11
11
import org .junit .Ignore ;
12
12
import org .slf4j .Logger ;
13
13
import org .slf4j .LoggerFactory ;
14
+
15
+ import com .fasterxml .jackson .core .JsonParser .Feature ;
14
16
import com .fasterxml .jackson .databind .JsonNode ;
15
17
import com .fasterxml .jackson .databind .ObjectMapper ;
16
18
@@ -45,6 +47,8 @@ public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
45
47
private static final String QUERY_4_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject4.json" ;
46
48
private static final String QUERY_5_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject5.json" ;
47
49
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
+
48
52
49
53
@ LocalServerPort
50
54
private int applicationPort ;
@@ -70,9 +74,10 @@ public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
70
74
private String missedNotificationObj ;
71
75
72
76
private ObjectMapper objMapper ;
73
-
77
+
74
78
public QueryAggregatedObjectsTestSteps () {
75
79
objMapper = new ObjectMapper ();
80
+ objMapper .configure (Feature .ALLOW_UNQUOTED_CONTROL_CHARS , true );
76
81
77
82
try {
78
83
aggrObj = FileUtils .readFileToString (new File (AGGREGATED_OBJ_JSON_PATH ), "UTF-8" );
@@ -83,11 +88,19 @@ public QueryAggregatedObjectsTestSteps() {
83
88
e .printStackTrace ();
84
89
}
85
90
}
86
-
91
+
87
92
@ Given ("^Aggregated object is created$" )
88
93
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 );
91
104
}
92
105
93
106
@ Given ("^Missed Notification object is created$" )
@@ -384,6 +397,40 @@ public void perform__query_and_filter_with_part_of_path() throws Throwable {
384
397
}
385
398
}
386
399
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
+ "\n Response: " + 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
+
387
434
/**
388
435
* Method that creates a document in MongoDb database.
389
436
*
@@ -400,5 +447,4 @@ private boolean createDocumentInMongoDb(String databaseName, String collectionNa
400
447
+ "\n Document to be inserted\n : " + objToBeInserted );
401
448
return mongoDBHandler .insertDocument (databaseName , collectionName , objToBeInserted );
402
449
}
403
-
404
450
}
0 commit comments