2 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.cllassurancemodule;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.mockito.Mockito;
25 import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
26 import org.onap.usecaseui.intentanalysis.adapters.policy.PolicyService;
27 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
28 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
29 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
30 import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType;
31 import org.onap.usecaseui.intentanalysis.bean.models.*;
32 import org.onap.usecaseui.intentanalysis.service.ContextService;
33 import org.onap.usecaseui.intentanalysis.service.IntentService;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.test.context.junit4.SpringRunner;
38 import java.util.ArrayList;
39 import java.util.List;
41 import static org.junit.jupiter.api.Assertions.*;
42 import static org.mockito.ArgumentMatchers.any;
43 import static org.mockito.Mockito.times;
44 import static org.mockito.Mockito.verify;
46 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
47 @RunWith(SpringRunner.class)
48 public class CLLAssuranceActuationModuleTest {
50 CLLAssuranceActuationModule cllAssuranceActuationModule;
52 IntentService intentService;
54 private PolicyService policyService;
56 private ContextService contextService;
57 Intent intent = new Intent();
60 public void before() throws Exception {
61 intent.setIntentName("CLL Delivery Intent");
62 List<Expectation> expectationList = new ArrayList<>();
63 Expectation deliveryExpectation = new Expectation();
64 deliveryExpectation.setExpectationName("CLL Delivery Expectation");
65 deliveryExpectation.setExpectationType(ExpectationType.DELIVERY);
66 ExpectationObject expectationObject = new ExpectationObject();
67 expectationObject.setObjectInstance("");
68 deliveryExpectation.setExpectationObject(expectationObject);
70 List<ExpectationTarget> targetList = new ArrayList<>();
71 ExpectationTarget target1 = new ExpectationTarget();
72 target1.setTargetName("bandwidth");
74 List<Condition> conditionList = new ArrayList<>();
75 Condition con = new Condition();
76 con.setConditionName("condition of the cll service bandwidth");
77 con.setOperator(OperatorType.EQUALTO);
78 con.setConditionValue("1000");
79 conditionList.add(con);
81 target1.setTargetConditions(conditionList);
82 targetList.add(target1);
84 deliveryExpectation.setExpectationTargets(targetList);
86 expectationList.add(deliveryExpectation);
88 Expectation assuranceExceptation = new Expectation();
89 assuranceExceptation.setExpectationType(ExpectationType.ASSURANCE);
90 ExpectationObject expectationObject2 = new ExpectationObject();
91 expectationObject2.setObjectInstance("");
92 assuranceExceptation.setExpectationObject(expectationObject2);
93 expectationList.add(assuranceExceptation);
94 intent.setIntentExpectations(expectationList);
98 public void testDirectOperation(){
99 // Mockito.doNothing().when(policyService).updateIntentConfigPolicy(any(), any(),any());
100 IntentGoalBean intentGoalBean = new IntentGoalBean(intent,IntentGoalType.DELETE);
101 List<Intent> intentList = new ArrayList<>();
102 intentList.add(intent);
104 Mockito.when(intentService.getIntentByName(any())).thenReturn(intentList);
106 cllAssuranceActuationModule.directOperation(intentGoalBean);
107 Assert.assertTrue(true);
110 public void testUpdateIntentOperationInfo(){
111 // updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){
112 Intent originIntent = new Intent();
113 originIntent.setIntentContexts(new ArrayList<>());
114 originIntent.setIntentId("12345");
115 cllAssuranceActuationModule.updateIntentOperationInfo(originIntent,new IntentGoalBean());
116 verify(contextService, times(1)).updateContextList(originIntent.getIntentContexts(), originIntent.getIntentId());
119 public void testDeleteIntentToDb(){
120 Intent intent = new Intent();
121 intent.setIntentId("1234");
122 Mockito.when(intentService.getSubIntentList(any())).thenReturn(new ArrayList<>());
123 cllAssuranceActuationModule.deleteIntentToDb(intent);
124 verify(intentService, times(1)).deleteIntent(any());