2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.requesthandler.impl;
25 // import com.att.eelf.configuration.EELFLogger;
26 // import com.att.eelf.configuration.EELFManager;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.Matchers;
33 import org.mockito.runners.MockitoJUnitRunner;
34 import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
35 import org.onap.appc.domainmodel.lcm.ActionLevel;
36 import org.onap.appc.domainmodel.lcm.RuntimeContext;
37 import org.onap.appc.domainmodel.lcm.VNFOperation;
38 import org.onap.appc.exceptions.InvalidInputException;
39 import org.onap.appc.requesthandler.LCMStateManager;
40 import org.onap.appc.requesthandler.exceptions.DuplicateRequestException;
41 import org.onap.appc.requesthandler.exceptions.LCMOperationsDisabledException;
42 import org.onap.appc.transactionrecorder.TransactionRecorder;
44 import static org.powermock.api.mockito.PowerMockito.spy;
47 * Test class for LocalRequestValidatorImpl
49 @RunWith(MockitoJUnitRunner.class)
50 public class LocalRequestValidatorImplTest implements LocalRequestHanlderTestHelper {
52 // protected final EELFLogger logger = EELFManager.getInstance().getLogger(LocalRequestValidatorImplTest.class);
55 private LCMStateManager lcmStateManager;
58 private TransactionRecorder transactionRecorder;
60 LocalRequestValidatorImpl requestValidator;
63 public void setUp() throws Exception {
64 requestValidator = spy(new LocalRequestValidatorImpl());
65 requestValidator.setLcmStateManager(lcmStateManager);
66 requestValidator.setTransactionRecorder(transactionRecorder);
68 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(true);
69 Mockito.when(transactionRecorder.isTransactionDuplicate(Matchers.anyObject())).thenReturn(false);
72 @Test(expected = LCMOperationsDisabledException.class)
73 public void validateRequestLCMDisabled() throws Exception {
74 Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(false);
75 requestValidator.validateRequest(createRequestValidatorInput());
78 @Test(expected = DuplicateRequestException.class)
79 public void validateRequestDuplicateReqFailure() throws Exception {
80 Mockito.when(transactionRecorder.isTransactionDuplicate(Matchers.anyObject())).thenReturn(true);
81 requestValidator.validateRequest(createRequestValidatorInput());
85 public void validateRequestSuccess() throws Exception {
86 requestValidator.validateRequest(createRequestValidatorInput());
89 @Test(expected = InvalidInputException.class)
90 public void validateRequestPayloadFail() throws Exception {
91 String incorrectPayload = "{\"RequestId\":\"requestToCheck\"}";
92 RuntimeContext context = createRequestValidatorInput();
93 context.getRequestContext().setPayload(incorrectPayload);
94 requestValidator.validateRequest(context);
97 @Test(expected = InvalidInputException.class)
98 public void validateRequestActionIdentifiersNullVnfIdFail() throws Exception {
99 RuntimeContext context = createRequestValidatorInput();
100 ActionIdentifiers ai = context.getRequestContext().getActionIdentifiers();
102 // logger.warn("Set vnfId in ActionIdentifiers extracted from createRequestValidatorInput's RequestContext to null");
103 requestValidator.validateRequest(context);
107 public void validateRequestUnsupportedAction() throws Exception {
108 RuntimeContext context = createRequestValidatorInput();
109 context.getRequestContext().setAction(VNFOperation.AttachVolume);
110 requestValidator.validateRequest(context);
113 private RuntimeContext createRequestValidatorInput() {
114 return createRequestHandlerRuntimeContext("VSCP", "{\"request-id\":\"request-id\"}");