replace all fixed wiremock ports
[so.git] / adapters / mso-requests-db-adapter / src / test / java / org / onap / so / adapters / requestsdb / ArchiveInfraRequestsSchedulerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.requestsdb;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.junit.Test;
29 import org.onap.so.db.request.beans.InfraActiveRequests;
30 import org.onap.so.db.request.data.repository.ArchivedInfraRequestsRepository;
31 import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.transaction.annotation.Transactional;
35
36 public class ArchiveInfraRequestsSchedulerTest extends RequestsAdapterBase {
37         
38         @Autowired
39         private ArchiveInfraRequestsScheduler scheduler;
40         
41         @Autowired
42         private InfraActiveRequestsRepository iarRepo;
43         
44         @Autowired
45         private ArchivedInfraRequestsRepository archivedRepo;
46         
47         @Value("${mso.infra-requests.archived.period}")
48         private int archivedPeriod;
49         
50         @Test 
51         @Transactional
52         public void testArchiveInfraRequests() throws Exception {
53                 String requestId1 = "requestId1";
54                 String requestId2 = "requestId2";
55                 
56                 InfraActiveRequests iar1 = new InfraActiveRequests();
57                 iar1.setRequestId(requestId1);
58                 iar1.setAction("action1");
59                 
60                 InfraActiveRequests iar2 = new InfraActiveRequests();
61                 iar2.setRequestId(requestId2);
62                 iar2.setAction("action2");
63                 
64                 List<InfraActiveRequests> requests = new ArrayList<>();
65                 requests.add(iar1);
66                 requests.add(iar2);
67                 iarRepo.saveAll(requests);
68                 
69                 scheduler.archiveInfraRequests(requests);
70                 
71                 assertEquals(2, archivedRepo.count());
72                 assertEquals(requestId1, archivedRepo.findById(requestId1)
73                         .orElseThrow( () -> new Exception("Request Not Found")).getRequestId());
74                 assertEquals(requestId2, archivedRepo.findById(requestId2).
75                         orElseThrow( () -> new Exception("Request Not Found")).getRequestId());
76         }
77
78 }