2f91691ccb7514490c65f17e23226ab36efca51e
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2023 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 package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt;
17
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.bean.enums.ExpectationType;
27 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
28 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
29 import org.onap.usecaseui.intentanalysis.bean.models.*;
30 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule.CLLBusinessActuationModule;
31 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule.CLLBusinessDecisionModule;
32 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule.CLLBusinessKnowledgeModule;
33 import org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.CLLDeliveryIntentManagementFunction;
34 import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputActuationModule;
35 import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputDecisionModule;
36 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
37 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
38 import org.onap.usecaseui.intentanalysis.intentBaseService.intentEventRecord.IntentEventRecordService;
39 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
40 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
41 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
42 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
43 import org.onap.usecaseui.intentanalysis.service.ContextService;
44 import org.onap.usecaseui.intentanalysis.service.IntentService;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.boot.test.context.SpringBootTest;
47 import org.springframework.context.ApplicationContext;
48 import org.springframework.test.context.junit4.SpringRunner;
49
50 import java.util.ArrayList;
51 import java.util.LinkedHashMap;
52 import java.util.List;
53
54 import static org.mockito.ArgumentMatchers.any;
55 import static org.mockito.Mockito.mock;
56
57 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
58 @RunWith(SpringRunner.class)
59 public class CLLBusinessIntentManagementFunctionTest {
60     @InjectMocks
61     CLLBusinessIntentManagementFunction cllBusinessIntentManagementFunction;
62     KnowledgeModule knowledgeModule = mock(CLLBusinessKnowledgeModule.class);
63     DecisionModule decisionModule = mock(CLLBusinessDecisionModule.class);
64     ActuationModule actuationModule = mock(CLLBusinessActuationModule.class);
65     @Mock
66     CLLDeliveryIntentManagementFunction cllDeliveryIntentManagementFunction;
67     @Mock
68     public IntentContextService intentContextService;
69     @Mock
70     IntentInterfaceService intentInterfaceService;
71     @Mock
72     ApplicationContext applicationContext;
73     @Mock
74     ContextService contextService;
75     @Mock
76     IntentService intentService;
77     @Mock
78     IntentEventRecordService intentEventRecordService;
79
80     Intent intent = new Intent();
81     IntentGoalBean intentGoalBean = new IntentGoalBean();
82
83     @Before
84     public void before() throws Exception {
85         intent.setIntentName("cllIntent");
86         intent.setIntentId("12345");
87         List<Expectation> expectationList = new ArrayList<>();
88
89         Expectation delivery = new Expectation();
90         delivery.setExpectationId("12345-delivery");
91         delivery.setExpectationName("deliveryExpectation");
92         delivery.setExpectationType(ExpectationType.DELIVERY);
93         ExpectationObject expectationObject = new ExpectationObject();
94         expectationObject.setObjectType(ObjectType.SLICING);
95         //expetationTarget  Context  FulfilmentInfo is empty
96         delivery.setExpectationObject(expectationObject);
97         expectationList.add(delivery);
98
99         Expectation assurance = new Expectation();
100         assurance.setExpectationId("12345-assurance");
101         assurance.setExpectationName("assuranceExpectation");
102         assurance.setExpectationType(ExpectationType.ASSURANCE);
103         ExpectationObject expectationObject1 = new ExpectationObject();
104         expectationObject1.setObjectType(ObjectType.CCVPN);
105         //expetationTarget  Context  FulfilmentInfo  is empty
106         assurance.setExpectationObject(expectationObject1);
107         expectationList.add(assurance);
108
109         intent.setIntentExpectations(expectationList);
110         intentGoalBean.setIntent(intent);
111         intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
112     }
113
114     @Test
115     public void testDetection() {
116         cllBusinessIntentManagementFunction.detection(intentGoalBean);
117         Assert.assertTrue(true);
118     }
119     @Test
120     public void testInvestigation() {
121         cllBusinessIntentManagementFunction.investigation(intentGoalBean);
122         Assert.assertTrue(true);
123     }
124     @Test
125     public void testImplementIntentCreate() { // TODO: 2023/3/30  
126         LinkedHashMap<IntentGoalBean, IntentManagementFunction> map = new LinkedHashMap<>();
127         map.put(intentGoalBean, cllDeliveryIntentManagementFunction);
128         Mockito.when(decisionModule.intentObjectDefine(any(),any())).thenReturn(intent);
129         cllBusinessIntentManagementFunction.implementIntent(intent, map);
130         Assert.assertTrue(true);
131     }
132     @Test
133     public void testImplementIntentUpdate() {
134         LinkedHashMap<IntentGoalBean, IntentManagementFunction> map = new LinkedHashMap<>();
135         intentGoalBean.setIntentGoalType(IntentGoalType.UPDATE);
136         map.put(intentGoalBean, cllDeliveryIntentManagementFunction);
137         cllBusinessIntentManagementFunction.implementIntent(intent, map);
138         Assert.assertTrue(true);
139     }
140
141     @Test
142     public void testImplementIntentDelete() {
143         LinkedHashMap<IntentGoalBean, IntentManagementFunction> map = new LinkedHashMap<>();
144         intentGoalBean.setIntentGoalType(IntentGoalType.DELETE);
145         map.put(intentGoalBean, cllDeliveryIntentManagementFunction);
146         cllBusinessIntentManagementFunction.implementIntent(intent, map);
147         Assert.assertTrue(true);
148     }
149
150 }