2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.requesthandler.impl;
26 import org.mockito.Mockito;
27 import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
28 import org.onap.appc.domainmodel.lcm.ActionLevel;
29 import org.onap.appc.domainmodel.lcm.CommonHeader;
30 import org.onap.appc.domainmodel.lcm.Flags;
31 import org.onap.appc.domainmodel.lcm.RequestContext;
32 import org.onap.appc.domainmodel.lcm.RequestStatus;
33 import org.onap.appc.domainmodel.lcm.ResponseContext;
34 import org.onap.appc.domainmodel.lcm.RuntimeContext;
35 import org.onap.appc.domainmodel.lcm.VNFOperation;
36 import org.onap.appc.lockmanager.api.LockManager;
37 import org.onap.appc.requesthandler.RequestHandler;
38 import org.onap.appc.transactionrecorder.TransactionRecorder;
39 import org.osgi.framework.Bundle;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.FrameworkUtil;
42 import org.osgi.framework.ServiceReference;
43 import org.powermock.api.mockito.PowerMockito;
44 import static org.mockito.Matchers.any;
45 import static org.mockito.Matchers.anyCollectionOf;
46 import static org.mockito.Matchers.anyString;
47 import static org.mockito.Mockito.mock;
48 import static org.powermock.api.mockito.PowerMockito.mockStatic;
49 import java.util.Arrays;
50 import java.util.Date;
51 import java.util.List;
54 * Creates RequestContextInput for ActionStatus JUnits
56 public interface LocalRequestHanlderTestHelper {
57 default RuntimeContext createRequestHandlerRuntimeContext(String vnfId, String payload) {
58 RuntimeContext context = new RuntimeContext();
60 RequestContext requestContext = createRequestContext(VNFOperation.ActionStatus, "requestId1",
61 vnfId, ActionLevel.MGMT, payload);
62 context.setRequestContext(requestContext);
64 ResponseContext resContext = new ResponseContext();
65 resContext.setCommonHeader(context.getRequestContext().getCommonHeader());
66 context.setResponseContext(resContext);
71 default RequestContext createRequestContext(VNFOperation operation, String requestId, String vnfId,
72 ActionLevel level, String payload) {
73 RequestContext reqContext = new RequestContext();
74 reqContext.setCommonHeader(getCommonHeader(requestId, "2.0.0", "originatorId"));
75 reqContext.setActionLevel(level);
76 reqContext.setAction(operation);
77 reqContext.setPayload(payload);
78 reqContext.setActionIdentifiers(getActionIdentifiers(vnfId, null, null));
83 default ActionIdentifiers getActionIdentifiers(String vnfId, String vnfcId, String vserverId) {
84 ActionIdentifiers builder = new ActionIdentifiers();
85 builder.setVnfId(vnfId);
86 builder.setVnfcName(vnfcId);
87 builder.setvServerId(vserverId);
91 default CommonHeader getCommonHeader(String requestId, String apiVer, String originatorId) {
92 CommonHeader builder = new CommonHeader();
93 builder.setRequestId(requestId);
94 builder.setApiVer(apiVer);
95 builder.setOriginatorId(originatorId);
96 builder.setTimestamp(new Date(System.currentTimeMillis()));
100 default CommonHeader getCommonHeader(String requestId, Date date) {
101 CommonHeader builder = new CommonHeader();
102 builder.setRequestId(requestId);
103 builder.setTimestamp(date);
104 Flags flags = new Flags();
106 builder.setFlags(flags);
110 default void setupForHandlerImplTests() {
111 mockStatic(FrameworkUtil.class);
112 Bundle myBundle = mock(Bundle.class);
113 PowerMockito.when(FrameworkUtil.getBundle(any())).thenReturn(myBundle);
115 BundleContext myBundleContext = mock(BundleContext.class);
116 Mockito.when(myBundle.getBundleContext()).thenReturn(myBundleContext);