2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.requestsdb;
23 import static org.junit.Assert.assertEquals;
25 import java.util.ArrayList;
26 import java.util.List;
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;
36 public class ArchiveInfraRequestsSchedulerTest extends RequestsAdapterBase {
39 private ArchiveInfraRequestsScheduler scheduler;
42 private InfraActiveRequestsRepository iarRepo;
45 private ArchivedInfraRequestsRepository archivedRepo;
47 @Value("${mso.infra-requests.archived.period}")
48 private int archivedPeriod;
52 public void testArchiveInfraRequests() throws Exception {
53 String requestId1 = "requestId1";
54 String requestId2 = "requestId2";
56 InfraActiveRequests iar1 = new InfraActiveRequests();
57 iar1.setRequestId(requestId1);
58 iar1.setAction("action1");
60 InfraActiveRequests iar2 = new InfraActiveRequests();
61 iar2.setRequestId(requestId2);
62 iar2.setAction("action2");
64 List<InfraActiveRequests> requests = new ArrayList<>();
67 iarRepo.saveAll(requests);
69 scheduler.archiveInfraRequests(requests);
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());