2  * ================================================================================
 
   3  * Copyright (c) 2019 IBM Intellectual Property. All rights reserved.
 
   4  * ================================================================================
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  16  * ============LICENSE_END=========================================================
 
  20 package org.onap.dcae.analytics.tca.web.controller;
 
  22 import java.time.ZonedDateTime;
 
  23 import java.util.Arrays;
 
  24 import java.util.List;
 
  26 import org.junit.jupiter.api.Test;
 
  27 import org.mockito.Mockito;
 
  28 import org.onap.dcae.analytics.model.common.ConfigSource;
 
  29 import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
 
  30 import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
 
  31 import org.onap.dcae.analytics.tca.model.restapi.TcaExecutionRequest;
 
  32 import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
 
  33 import org.onap.dcae.analytics.tca.web.service.TcaProcessingService;
 
  35 public class TcaRestControllerTest {
 
  38   void getTcaPolicyResponseTest() throws Exception {
 
  39   TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
 
  40     TcaProcessingService tcaProcessingService = Mockito.mock(TcaProcessingService.class);
 
  41     TcaPolicy tcaPolicy = Mockito.mock(TcaPolicy.class);
 
  42     Mockito.when(tcaPolicyWrapper.getConfigSource()).thenReturn(ConfigSource.valueOf("MONGO"));
 
  43     Mockito.when(tcaPolicyWrapper.getTcaPolicy()).thenReturn(tcaPolicy);
 
  44     Mockito.when(tcaPolicyWrapper.getCreationTime()).thenReturn(ZonedDateTime.now());
 
  45     TcaRestController restcontroller = new TcaRestController(tcaProcessingService, tcaPolicyWrapper);
 
  46     restcontroller.getTcaPolicy();
 
  47     restcontroller.setTcaPolicy(tcaPolicy);
 
  51   void getTcaExecutionResponseTest() throws Exception {
 
  52     TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
 
  53     TcaExecutionRequest tcaExecutionRequest = Mockito.mock(TcaExecutionRequest.class);
 
  54     TcaProcessingService tcaProcessingService = Mockito.mock(TcaProcessingService.class);
 
  55     TcaExecutionContext tcaExecutionContext = Mockito.mock(TcaExecutionContext.class);
 
  56     List<String> cefMessages = Arrays.asList("Test1", "Test2");
 
  57     List<TcaExecutionContext> executionContexts = Arrays.asList(tcaExecutionContext, tcaExecutionContext);
 
  58     Mockito.when(tcaProcessingService.getTcaExecutionResults("requestId", "transactioId", tcaPolicyWrapper, cefMessages))
 
  59            .thenReturn(executionContexts);
 
  60     TcaRestController restcontroller = new TcaRestController(tcaProcessingService, tcaPolicyWrapper);
 
  61     restcontroller.execute(tcaExecutionRequest);