4
4
5
5
import java .io .File ;
6
6
import java .io .IOException ;
7
+ import java .util .ArrayList ;
8
+ import java .util .List ;
9
+
7
10
import org .apache .commons .io .FileUtils ;
8
11
import org .junit .Ignore ;
9
12
import org .slf4j .Logger ;
16
19
import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
17
20
import org .springframework .boot .web .server .LocalServerPort ;
18
21
import org .springframework .http .HttpStatus ;
19
- import org .springframework .http .MediaType ;
20
22
import org .springframework .http .ResponseEntity ;
21
- import org .springframework .test .web .servlet .MockMvc ;
22
- import org .springframework .test .web .servlet .MvcResult ;
23
- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
24
23
25
24
import cucumber .api .java .en .And ;
26
25
import cucumber .api .java .en .Given ;
@@ -38,10 +37,10 @@ public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
38
37
39
38
private static final Logger LOGGER = LoggerFactory .getLogger (QueryAggregatedObjectsTestSteps .class );
40
39
41
-
42
40
private static final String AGGREGATED_OBJ_JSON_PATH = "src/test/resources/AggregatedDocument.json" ;
43
41
private static final String MISSED_NOTIFICATION_JSON_PATH = "src/test/resources/MissedNotification.json" ;
44
-
42
+ private static final String QUERY_1_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject1.json" ;
43
+ private static final String QUERY_2_FILE_NAME = "src/functionaltests/resources/queryAggregatedObject2.json" ;
45
44
46
45
@ LocalServerPort
47
46
private int applicationPort ;
@@ -154,37 +153,46 @@ public void perform_invalid_query_on_created_aggregated_object() throws Throwabl
154
153
expectedResponse , responseAsString );
155
154
}
156
155
157
- @ And ("^Perform valid freestyle query on created Aggregated object$" )
158
- public void perform_valid_freestyle_query_on_created_aggregated_object () throws Throwable {
156
+ @ Then ("^Perform several valid freestyle queries on created Aggregated objects$" )
157
+ public void perform_several_valid_freestyle_queries_on_created_Aggregated_objects () throws Throwable {
158
+
159
159
final String expectedAggrId = "6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43" ;
160
160
final String entryPoint = "/query" ;
161
- final String queryAggrObj = "{\" criteria\" :{\" aggregatedObject.id\" : \" " + expectedAggrId + "\" , \" aggregatedObject.gav.groupId\" : \" com.mycompany.myproduct\" }}" ;
162
161
163
- LOGGER .debug ("Freestyle querying for the AggregatedObject with criteria: " + queryAggrObj );
162
+ String query1 = FileUtils .readFileToString (new File (QUERY_1_FILE_NAME ), "UTF-8" );
163
+ String query2 = FileUtils .readFileToString (new File (QUERY_2_FILE_NAME ), "UTF-8" );
164
164
165
- HttpRequest getRequest = new HttpRequest (HttpMethod .GET );
166
- response = getRequest .setPort (applicationPort )
167
- .setHost (hostName )
168
- .addHeader ("content-type" , "application/json" )
169
- .addHeader ("Accept" , "application/json" )
170
- .setEndpoint (entryPoint )
171
- .addParam ("request" , queryAggrObj )
172
- .performRequest ();
165
+ List <String > queries = new ArrayList <>();
166
+ queries .add (query1 );
167
+ queries .add (query2 );
173
168
174
- LOGGER . debug ( "Response of / query RestApi, Status Code: " + response . getStatusCodeValue () +
175
- " \n Response : " + response . getBody (). toString () );
169
+ for ( String query : queries ) {
170
+ LOGGER . debug ( "Freestyle querying for the AggregatedObject with criteria : " + query );
176
171
177
- JsonNode jsonNodeResult = objMapper .readValue (response .getBody ().toString (), JsonNode .class );
178
- JsonNode aggrObjResponse = objMapper .readValue (jsonNodeResult .get (0 ).get ("aggregatedObject" ).toString (), JsonNode .class );
172
+ HttpRequest postRequest = new HttpRequest (HttpMethod .POST );
173
+ response = postRequest .setPort (applicationPort )
174
+ .setHost (hostName )
175
+ .addHeader ("content-type" , "application/json" )
176
+ .addHeader ("Accept" , "application/json" )
177
+ .setEndpoint (entryPoint )
178
+ .addParam ("request" , query )
179
+ .performRequest ();
179
180
180
- String actualAggrObjId = aggrObjResponse . get ( "id" ). asText ();
181
- LOGGER . debug ( "AggregatedObject id from Response : " + actualAggrObjId );
181
+ LOGGER . debug ( "Response of /query RestApi, Status Code: " + response . getStatusCodeValue () +
182
+ " \n Response : " + response . getBody (). toString () );
182
183
184
+ JsonNode jsonNodeResult = objMapper .readValue (response .getBody ().toString (), JsonNode .class );
185
+ JsonNode aggrObjResponse = objMapper .readValue (jsonNodeResult .get (0 ).get ("aggregatedObject" ).toString (), JsonNode .class );
183
186
184
- assertEquals (HttpStatus .OK .toString (), Integer .toString (response .getStatusCodeValue ()));
185
- assertEquals ("Failed to compare actual Aggregated Object Id:\n " + actualAggrObjId
186
- + "\n with expected Aggregated Object Id:\n " + expectedAggrId ,
187
- expectedAggrId , actualAggrObjId );
187
+ String actualAggrObjId = aggrObjResponse .get ("id" ).asText ();
188
+ LOGGER .debug ("AggregatedObject id from Response: " + actualAggrObjId );
189
+
190
+
191
+ assertEquals (HttpStatus .OK .toString (), Integer .toString (response .getStatusCodeValue ()));
192
+ assertEquals ("Failed to compare actual Aggregated Object Id:\n " + actualAggrObjId
193
+ + "\n with expected Aggregated Object Id:\n " + expectedAggrId ,
194
+ expectedAggrId , actualAggrObjId );
195
+ }
188
196
}
189
197
190
198
@ And ("^Perform an invalid freesyle query on Aggregated object$" )
@@ -196,7 +204,7 @@ public void perform_invalid_freestyle_query_on_created_aggregated_object() throw
196
204
197
205
LOGGER .debug ("Trying an invalid query on /query RestApi with invalid criteria query: " + queryAggrObj );
198
206
199
- HttpRequest getRequest = new HttpRequest (HttpMethod .GET );
207
+ HttpRequest getRequest = new HttpRequest (HttpMethod .POST );
200
208
response = getRequest .setPort (applicationPort )
201
209
.setHost (hostName )
202
210
.addHeader ("content-type" , "application/json" )
@@ -309,4 +317,4 @@ private boolean createDocumentInMongoDb(String databaseName, String collectionNa
309
317
return mongoDBHandler .insertDocument (databaseName , collectionName , objToBeInserted );
310
318
}
311
319
312
- }
320
+ }
0 commit comments