Support 7.2.1 VES in TCAGEN2
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-tca-web / src / test / java / org / onap / dcae / analytics / tca / web / controller / TcaRestControllerTest.java
1 /*
2  * ============LICENSE_START====================================================================
3  * Copyright (c) 2019 IBM Intellectual Property. All rights reserved.
4  * Copyright (c) 2022 Wipro Limited Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  *
19  */
20
21 package org.onap.dcae.analytics.tca.web.controller;
22
23 import java.time.ZonedDateTime;
24 import java.util.Arrays;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import static org.assertj.core.api.Assertions.assertThat;
29 import org.junit.jupiter.api.Test;
30 import org.mockito.Mockito;
31 import org.onap.dcae.analytics.model.common.ConfigSource;
32 import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
33 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
34 import org.onap.dcae.analytics.tca.model.restapi.TcaExecutionRequest;
35 import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
36 import org.onap.dcae.analytics.tca.web.service.TcaProcessingService;
37
38 public class TcaRestControllerTest {
39
40   @Test
41   void getTcaPolicyResponseTest() throws Exception {
42   TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
43     TcaProcessingService tcaProcessingService = Mockito.mock(TcaProcessingService.class);
44     TcaPolicy tcaPolicy = Mockito.mock(TcaPolicy.class);
45     List<TcaPolicy> TcaList = new ArrayList<TcaPolicy>();
46     TcaList.add(tcaPolicy);
47     Mockito.when(tcaPolicyWrapper.getConfigSource()).thenReturn(ConfigSource.valueOf("MONGO"));
48     Mockito.when(tcaPolicyWrapper.getTcaPolicy()).thenReturn(TcaList);
49     Mockito.when(tcaPolicyWrapper.getCreationTime()).thenReturn(ZonedDateTime.now());
50     TcaRestController restcontroller = new TcaRestController(tcaProcessingService, tcaPolicyWrapper);
51     restcontroller.getTcaPolicy();
52     restcontroller.setTcaPolicy(TcaList);
53     assertThat(TcaList).isNotNull();
54     assertThat(restcontroller.getTcaPolicy()).isNotNull();
55     assertThat(restcontroller.setTcaPolicy(TcaList).getStatusCodeValue()).isEqualTo(200);
56     
57   }
58
59   @Test
60   void getTcaExecutionResponseTest() throws Exception {
61     TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
62     TcaExecutionRequest tcaExecutionRequest = Mockito.mock(TcaExecutionRequest.class);
63     TcaProcessingService tcaProcessingService = Mockito.mock(TcaProcessingService.class);
64     TcaExecutionContext tcaExecutionContext = Mockito.mock(TcaExecutionContext.class);
65     List<String> cefMessages = Arrays.asList("Test1", "Test2");
66     List<TcaExecutionContext> executionContexts = Arrays.asList(tcaExecutionContext, tcaExecutionContext);
67     Mockito.when(tcaProcessingService.getTcaExecutionResults("requestId", "transactioId", tcaPolicyWrapper, cefMessages))
68            .thenReturn(executionContexts);
69     TcaRestController restcontroller = new TcaRestController(tcaProcessingService, tcaPolicyWrapper);
70     restcontroller.execute(tcaExecutionRequest);
71     assertThat(restcontroller.execute(tcaExecutionRequest).getStatusCodeValue()).isEqualTo(200);
72   }
73
74 }