Springboot 2.0 upgrade
[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 import static org.junit.Assert.assertTrue;
25
26 import java.util.ArrayList;
27 import java.util.Calendar;
28 import java.util.Date;
29 import java.util.List;
30
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
35 import org.onap.so.db.request.beans.InfraActiveRequests;
36 import org.onap.so.db.request.data.repository.ArchivedInfraRequestsRepository;
37 import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.boot.test.context.SpringBootTest;
41 import org.springframework.data.domain.PageRequest;
42 import org.springframework.test.context.ActiveProfiles;
43 import org.springframework.test.context.junit4.SpringRunner;
44 import org.springframework.transaction.annotation.Transactional;
45
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
48 @ActiveProfiles("test")
49 @Transactional
50 public class ArchiveInfraRequestsSchedulerTest {
51         
52         @Autowired
53         private ArchiveInfraRequestsScheduler scheduler;
54         
55         @Autowired
56         private InfraActiveRequestsRepository iarRepo;
57         
58         @Autowired
59         private ArchivedInfraRequestsRepository archivedRepo;
60         
61         @Value("${mso.infra-requests.archived.period}")
62         private int archivedPeriod;
63         
64         @Test 
65         @Transactional
66         public void testArchiveInfraRequests() throws Exception {
67                 String requestId1 = "requestId1";
68                 String requestId2 = "requestId2";
69                 
70                 InfraActiveRequests iar1 = new InfraActiveRequests();
71                 iar1.setRequestId(requestId1);
72                 iar1.setAction("action1");
73                 
74                 InfraActiveRequests iar2 = new InfraActiveRequests();
75                 iar2.setRequestId(requestId2);
76                 iar2.setAction("action2");
77                 
78                 List<InfraActiveRequests> requests = new ArrayList<>();
79                 requests.add(iar1);
80                 requests.add(iar2);
81                 iarRepo.saveAll(requests);
82                 
83                 scheduler.archiveInfraRequests(requests);
84                 
85                 assertEquals(2, archivedRepo.count());
86                 assertEquals(requestId1, archivedRepo.findById(requestId1)
87                         .orElseThrow( () -> new Exception("Request Not Found")).getRequestId());
88                 assertEquals(requestId2, archivedRepo.findById(requestId2).
89                         orElseThrow( () -> new Exception("Request Not Found")).getRequestId());
90         }
91
92 }