2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 - 2019 Nokia. 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=========================================================
20 package org.onap.vid.services;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.mockito.MockitoAnnotations;
25 import org.onap.vid.dal.AsyncInstantiationRepository;
26 import org.onap.vid.model.JobAuditStatus;
27 import org.onap.vid.mso.RestMsoImplementation;
28 import org.onap.vid.mso.RestObject;
29 import org.onap.vid.mso.rest.AsyncRequestStatus;
30 import org.onap.vid.mso.rest.AsyncRequestStatusList;
31 import org.onap.vid.testUtils.TestUtils;
32 import org.testng.annotations.BeforeMethod;
33 import org.testng.annotations.Test;
35 import java.util.List;
37 import static org.hamcrest.MatcherAssert.assertThat;
38 import static org.hamcrest.Matchers.equalTo;
39 import static org.mockito.ArgumentMatchers.eq;
40 import static org.mockito.Mockito.when;
42 public class AuditServiceImplTest {
45 private RestMsoImplementation restMso;
47 private AsyncInstantiationRepository asyncInstantiationRepository;
50 private AuditServiceImpl auditService;
55 asyncInstantiationRepository = null;
57 MockitoAnnotations.initMocks(this);
61 public void testGetRequestsIdsByServiceIdAndRequestTypeAndScope() throws Exception {
63 String instanceId = "d40c8a82-cc04-45e5-a0f6-0c9394c8f8d2";
64 //the request id in multipleOrchestrationRequestsServiceInstance.json
65 String expectedRequestId = "fab854bf-e53c-415e-b3cc-b6fcce8414b2";
66 String msoBasePath = "/someMsoPath/v2019?";
68 AsyncRequestStatusList asyncRequestStatusList = TestUtils.readJsonResourceFileAsObject(
69 "/responses/mso/multipleOrchestrationRequestsServiceInstance.json",
70 AsyncRequestStatusList.class);
71 RestObject<AsyncRequestStatusList> msoResponse = new RestObject<>();
72 msoResponse.set(asyncRequestStatusList);
73 msoResponse.setStatusCode(200);
74 when(restMso.GetForObject(eq(msoBasePath + "filter=serviceInstanceId:EQUALS:" + instanceId),
75 eq(AsyncRequestStatusList.class)))
76 .thenReturn(msoResponse);
77 TestUtils.testWithSystemProperty("mso.restapi.get.orc.reqs", msoBasePath, () -> {
78 List<AsyncRequestStatus.Request> result = auditService
79 .retrieveRequestsFromMsoByServiceIdAndRequestTypeAndScope(instanceId, "createInstance", "service");
80 assertThat(result.size(), equalTo(1));
81 assertThat(result.get(0).requestId, equalTo(expectedRequestId));
82 assertThat(result.get(0).startTime, equalTo("Mon, 04 Mar 2019 20:47:15 GMT"));
87 public void nextOrdinalAfter_givenNull_returnZero() {
89 auditService.nextOrdinalAfter(null),
95 public void nextOrdinalAfter_givenX_returnXplus1() {
97 final JobAuditStatus jobAuditStatus = new JobAuditStatus();
98 jobAuditStatus.setOrdinal(x);
101 auditService.nextOrdinalAfter(jobAuditStatus),