Include impacted changes for APPC-346,APPC-348
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / test / java / org / onap / appc / requesthandler / impl / LocalRequestValidatorImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.requesthandler.impl;
26
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.runners.MockitoJUnitRunner;
33 import org.onap.appc.domainmodel.lcm.ActionLevel;
34 import org.onap.appc.domainmodel.lcm.RuntimeContext;
35 import org.onap.appc.domainmodel.lcm.VNFOperation;
36 import org.onap.appc.exceptions.InvalidInputException;
37 import org.onap.appc.requesthandler.LCMStateManager;
38 import org.onap.appc.requesthandler.exceptions.DuplicateRequestException;
39 import org.onap.appc.requesthandler.exceptions.LCMOperationsDisabledException;
40
41 import static org.powermock.api.mockito.PowerMockito.spy;
42
43 /**
44  * Test class for LocalRequestValidatorImpl
45  */
46 @RunWith(MockitoJUnitRunner.class)
47 public class LocalRequestValidatorImplTest implements LocalRequestHanlderTestHelper {
48
49     @Mock
50     private LCMStateManager lcmStateManager;
51
52     LocalRequestValidatorImpl requestValidator;
53
54     @Before
55     public void setUp() throws Exception {
56         requestValidator = spy(new LocalRequestValidatorImpl());
57         requestValidator.setLcmStateManager(lcmStateManager);
58
59         Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(true);
60     }
61
62     @Test(expected = LCMOperationsDisabledException.class)
63     public void validateRequestLCMDisabled() throws Exception {
64         Mockito.when(lcmStateManager.isLCMOperationEnabled()).thenReturn(false);
65         requestValidator.validateRequest(createRequestValidatorInput());
66     }
67     //TODO needs to be fixed
68     /*@Test
69     public void validateRequestSuccess() throws Exception {
70         requestValidator.validateRequest(createRequestValidatorInput());
71     }
72
73     @Test(expected = DuplicateRequestException.class)
74     public void validateRequestDuplicateReqFailure() throws Exception {
75         requestValidator.validateRequest(createRequestValidatorInput());
76     }
77
78     @Test(expected = InvalidInputException.class)
79     public void validateRequestPayloadFail() throws Exception {
80         String incorrectPayload = "{\"RequestId\":\"requestToCheck\"}";
81         RuntimeContext context = createRequestValidatorInput();
82         context.getRequestContext().setPayload(incorrectPayload);
83         requestValidator.validateRequest(context);
84     }*/
85
86     private RuntimeContext createRequestValidatorInput() {
87         return createRequestHandlerRuntimeContext("VSCP", "{\"request-id\":\"request-id\"}");
88     }
89 }