7
7
import java .io .IOException ;
8
8
import java .util .ArrayList ;
9
9
import java .util .List ;
10
+ import java .util .concurrent .TimeUnit ;
10
11
11
12
import org .apache .commons .io .FileUtils ;
12
13
import org .json .JSONArray ;
21
22
import org .springframework .beans .factory .annotation .Autowired ;
22
23
import org .springframework .beans .factory .annotation .Value ;
23
24
import org .springframework .boot .web .server .LocalServerPort ;
24
- import org .springframework .test .context .ContextConfiguration ;
25
25
import org .springframework .test .context .TestPropertySource ;
26
26
import org .springframework .util .SocketUtils ;
27
27
31
31
import com .ericsson .ei .utils .FunctionalTestBase ;
32
32
import com .ericsson .ei .utils .HttpRequest ;
33
33
import com .ericsson .ei .utils .HttpRequest .HttpMethod ;
34
- import com .ericsson .ei .utils .TestContextInitializer ;
35
34
import com .fasterxml .jackson .databind .JsonNode ;
36
35
import com .fasterxml .jackson .databind .ObjectMapper ;
37
36
43
42
44
43
@ Ignore
45
44
@ TestPropertySource (properties = { "notification.ttl.value:1" , "aggregated.collection.ttlValue:1" ,
46
- "notification.failAttempt:1" })
47
- @ ContextConfiguration (initializers = TestContextInitializer .class )
45
+ "notification.failAttempt:1" , "spring.data.mongodb.database: TestTTLSteps" ,
46
+ "rabbitmq.exchange.name: TestTTLSteps-exchange" ,
47
+ "rabbitmq.consumerName: TestTTLStepsConsumer" ,
48
+ "missedNotificationDataBaseName: TestTTLStepsMissedNotification" })
48
49
public class TestTTLSteps extends FunctionalTestBase {
49
50
private static final Logger LOGGER = LoggerFactory .getLogger (TestTTLSteps .class );
50
51
private static final String BASE_URL = "localhost" ;
@@ -63,7 +64,7 @@ public class TestTTLSteps extends FunctionalTestBase {
63
64
private static final String SUBSCRIPTION_FILE_PATH_CREATION = "src/functionaltests/resources/subscription_single_ttlTest.json" ;
64
65
private static final String EIFFEL_EVENTS_JSON_PATH = "src/functionaltests/resources/eiffel_events_for_test.json" ;
65
66
66
- private static final long MAX_WAIT_TIME = 65000 ;
67
+ private static final long MAX_WAIT_TIME = 120000 ;
67
68
68
69
private static JsonNode subscriptionObject ;
69
70
@@ -147,9 +148,12 @@ public void a_subscription_is_created_at_the_end_point_with_non_existent_notific
147
148
String readFileToString = FileUtils .readFileToString (new File (SUBSCRIPTION_FILE_PATH_CREATION ), "UTF-8" );
148
149
JSONArray jsonArr = new JSONArray (readFileToString );
149
150
httpRequest = new HttpRequest (HttpMethod .POST );
150
- httpRequest .setHost (hostName ).setPort (applicationPort ).setEndpoint (endPoint )
151
- .addHeader ("content-type" , "application/json" ).addHeader ("Accept" , "application/json" )
152
- .setBody (jsonArr .toString ());
151
+ httpRequest .setHost (hostName )
152
+ .setPort (applicationPort )
153
+ .setEndpoint (endPoint )
154
+ .addHeader ("content-type" , "application/json" )
155
+ .addHeader ("Accept" , "application/json" )
156
+ .setBody (jsonArr .toString ());
153
157
httpRequest .performRequest ();
154
158
}
155
159
@@ -158,8 +162,8 @@ public void eiffel_events_are_sent() throws Throwable {
158
162
LOGGER .debug ("Sending an Eiffel event" );
159
163
List <String > eventNamesToSend = getEventNamesToSend ();
160
164
eventManager .sendEiffelEvents (EIFFEL_EVENTS_JSON_PATH , eventNamesToSend );
161
- List <String > missingEventIds = dbManager
162
- . verifyEventsInDB ( eventManager .getEventsIdList (EIFFEL_EVENTS_JSON_PATH , eventNamesToSend ));
165
+ List <String > missingEventIds = dbManager . verifyEventsInDB (
166
+ eventManager .getEventsIdList (EIFFEL_EVENTS_JSON_PATH , eventNamesToSend ), 0 );
163
167
assertEquals ("The following events are missing in mongoDB: " + missingEventIds .toString (), 0 ,
164
168
missingEventIds .size ());
165
169
LOGGER .debug ("Eiffel event is sent" );
@@ -196,15 +200,17 @@ public void the_Notification_document_should_be_deleted_from_the_database() thro
196
200
197
201
@ Then ("^Aggregated Object document should be deleted from the database$" )
198
202
public void the_Aggregated_Object_document_should_be_deleted_from_the_database () throws Throwable {
199
- LOGGER .debug ("Checking delition of aggregated object in db" );
203
+ LOGGER .debug ("Checking deletion of aggregated object in db" );
200
204
List <String > allObjects = null ;
205
+ // To be sure at least one minute has passed since creation of aggregated object
206
+ TimeUnit .MINUTES .sleep (1 );
201
207
allObjects = mongoDBHandler .getAllDocuments (dataBase , collection );
202
208
assertEquals ("Database is not empty." , true , allObjects .isEmpty ());
203
209
}
204
210
205
211
/**
206
- * Setting up mock server to receive calls on one endpoint and respond with
207
- * 500 to trigger retries of POST request
212
+ * Setting up mock server to receive calls on one endpoint and respond with 500
213
+ * to trigger retries of POST request
208
214
*/
209
215
private void setUpMockServer () {
210
216
int port = SocketUtils .findAvailableTcpPort ();
@@ -214,7 +220,7 @@ private void setUpMockServer() {
214
220
215
221
// set up expectations on mock server to get calls on this endpoint
216
222
mockServerClient .when (request ().withMethod ("POST" ).withPath (ENDPOINT ))
217
- .respond (HttpResponse .response ().withStatusCode (500 ));
223
+ .respond (HttpResponse .response ().withStatusCode (500 ));
218
224
}
219
225
220
226
/**
@@ -231,7 +237,8 @@ private int getNotificationForExpectedSize(int expectedSize, String condition) {
231
237
List <String > notificationExist = null ;
232
238
233
239
while (System .currentTimeMillis () < maxTime ) {
234
- notificationExist = mongoDBHandler .find (missedNotificationDatabase , missedNotificationCollection , condition );
240
+ notificationExist = mongoDBHandler .find (missedNotificationDatabase , missedNotificationCollection ,
241
+ condition );
235
242
236
243
if (notificationExist .size () == expectedSize ) {
237
244
return notificationExist .size ();
0 commit comments