2c04e7bb8bb128f82cb7e55851b517998bcaaa60
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule;
18
19 import org.junit.Assert;
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.so.SOService;
27 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
28 import org.onap.usecaseui.intentanalysis.bean.models.*;
29 import org.onap.usecaseui.intentanalysis.service.ContextService;
30 import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService;
31 import org.springframework.boot.test.context.SpringBootTest;
32 import org.springframework.test.context.junit4.SpringRunner;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 import static org.mockito.ArgumentMatchers.any;
38 import static org.junit.jupiter.api.Assertions.*;
39
40 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
41 @RunWith(SpringRunner.class)
42 public class CLLDeliveryActuationModuleTest {
43     @InjectMocks
44     CLLDeliveryActuationModule cllDeliveryActuationModulel;
45     @Mock
46     private ExpectationObjectService expectationObjectService;
47     @Mock
48     private ContextService contextService;
49     @Mock
50     private SOService soService;
51     Intent originalIntent = new Intent();
52     IntentGoalBean intentGoalBean = new IntentGoalBean();
53
54     @Test
55     public void testUpdateIntentOperationInfo() {
56         List<Expectation> expectationList = new ArrayList<>();
57         Expectation exp = new Expectation();
58         ExpectationObject expectationObject = new ExpectationObject();
59         expectationObject.setObjectInstance("objectInstance");
60         exp.setExpectationObject(expectationObject);
61         expectationList.add(exp);
62         originalIntent.setIntentExpectations(expectationList);
63
64         List<Expectation> gbExpectationList = new ArrayList<>();
65         Expectation deliveryExpectation = new Expectation();
66
67         ExpectationObject deliveryExpectationObject = new ExpectationObject();
68         deliveryExpectationObject.setObjectInstance("deliveryObjectInstance");
69
70         deliveryExpectation.setExpectationObject(deliveryExpectationObject);
71         gbExpectationList.add(deliveryExpectation);
72         intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
73         Intent intent =new Intent();
74         intent.setIntentName("delivery intent");
75         intent.setIntentExpectations(gbExpectationList);
76         intentGoalBean.setIntent(intent);
77
78         //Mockito.doNothing().when(类对象).methodName();
79         Mockito.doNothing().when(expectationObjectService).updateExpectationObject(any(), any());
80         Mockito.doNothing().when(contextService).updateContextList(any(), any());
81         cllDeliveryActuationModulel.updateIntentOperationInfo(originalIntent,intentGoalBean);
82     }
83
84     @Test
85     public void testGetInstanceId(){
86         cllDeliveryActuationModulel.getInstanceId();
87         Assert.assertTrue(true);
88     }
89     @Test
90     public void testDirectOperation (){
91         intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
92         Intent intent = new Intent();
93         List<Expectation> expectationList = new ArrayList<>();
94         Expectation expectation = new Expectation();
95         expectation.setExpectationId("1234");
96         List<ExpectationTarget> targetList = new ArrayList<>();
97         ExpectationTarget target = new ExpectationTarget();
98
99         List<Condition> conditionList = new ArrayList<>();
100         Condition con = new Condition();
101         con.setConditionName("source");
102         conditionList.add(con);
103         target.setTargetConditions(conditionList);
104         targetList.add(target);
105         expectation.setExpectationTargets(targetList);
106         expectationList.add(expectation);
107         intent.setIntentExpectations(expectationList);
108         intentGoalBean.setIntent(intent);
109
110         //Mockito.doNothing().when(soService).createIntentInstance(any());
111         Mockito.when(expectationObjectService.getExpectationObject(any())).thenReturn(new ExpectationObject());
112         Mockito.doNothing().when(expectationObjectService).updateExpectationObject(any(),any());
113         cllDeliveryActuationModulel.fulfillIntent(intentGoalBean,null);
114         Assert.assertTrue(true);
115     }
116
117 }