diff options
author | cmrizhangzhen <781953240@qq.com> | 2022-11-30 16:02:02 +0800 |
---|---|---|
committer | cmrizhangzhen <781953240@qq.com> | 2022-11-30 16:02:36 +0800 |
commit | a1b14f857e4e9abe0350ae27a4d747481ebd86c3 (patch) | |
tree | 7043d548246eb4b52da8bcfb86ff963a1173fe2f /intentanalysis/src | |
parent | cd41bad219919c18e9c0c65be9f32bad7e9c773a (diff) |
intentAnalysis add coverage
Issue-ID: USECASEUI-762
Signed-off-by: cmrizhangzhen <781953240@qq.com>
Change-Id: I8ba564e3457b122bc32e50b3fc76287502756971
Diffstat (limited to 'intentanalysis/src')
3 files changed, 219 insertions, 10 deletions
diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml index b08d88a..ae7274a 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml @@ -10,7 +10,7 @@ </select> <select id="selectIntentList" resultType="org.onap.usecaseui.intentanalysis.bean.models.Intent"> - select intent_id intentId, intent_name intentName intent_generateType intentGenerateType from intent + select intent_id intentId, intent_name intentName, intent_generateType intentGenerateType from intent </select> <insert id="insertIntent"> diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModuleTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModuleTest.java index e5adc01..6664a29 100644 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModuleTest.java +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessDecisionModuleTest.java @@ -18,6 +18,7 @@ package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule; +import org.apache.ibatis.annotations.Many; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -33,6 +34,7 @@ import org.onap.usecaseui.intentanalysis.bean.models.*; import org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.CLLAssuranceIntentManagementFunction; import org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.CLLDeliveryIntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService; import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; @@ -42,6 +44,9 @@ import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; + @SpringBootTest(classes = IntentAnalysisApplicationTests.class) @RunWith(SpringRunner.class) public class CLLBusinessDecisionModuleTest { @@ -52,9 +57,11 @@ public class CLLBusinessDecisionModuleTest { private ImfRegInfoService imfRegInfoService; @Mock private ApplicationContext applicationContext; - + @Mock + private IntentContextService intentContextService; IntentGoalBean intentGoalBean = new IntentGoalBean(); Intent intent = new Intent(); + @Before public void before() throws Exception { intent.setIntentName("cllIntent"); @@ -87,8 +94,9 @@ public class CLLBusinessDecisionModuleTest { intentGoalBean.setIntent(intent); intentGoalBean.setIntentGoalType(IntentGoalType.CREATE); } + @Test - public void testNeedDecompostion(){ + public void testNeedDecompostion() { // IntentManagementFunctionRegInfo imfRegInfo = new IntentManagementFunctionRegInfo(); // // imfRegInfo.setSupportArea("cll"); @@ -101,27 +109,28 @@ public class CLLBusinessDecisionModuleTest { cllBusinessDecisionModule.needDecompostion(intentGoalBean); Assert.assertTrue(true); } + @Test - public void testIntentDecomposition(){ + public void testIntentDecomposition() { cllBusinessDecisionModule.intentDecomposition(intentGoalBean); Assert.assertTrue(true); } @Test - public void testIntentOrchestration(){ - List<IntentGoalBean> intentGoalBeanList=new ArrayList<>(); - IntentGoalBean delivery=new IntentGoalBean(); + public void testIntentOrchestration() { + List<IntentGoalBean> intentGoalBeanList = new ArrayList<>(); + IntentGoalBean delivery = new IntentGoalBean(); - Intent deliveryIntent= new Intent(); + Intent deliveryIntent = new Intent(); deliveryIntent.setIntentName("delivery"); delivery.setIntentGoalType(IntentGoalType.CREATE); delivery.setIntent(deliveryIntent); intentGoalBeanList.add(delivery); - IntentGoalBean assurance=new IntentGoalBean(); + IntentGoalBean assurance = new IntentGoalBean(); - Intent assuranceIntent= new Intent(); + Intent assuranceIntent = new Intent(); deliveryIntent.setIntentName("assurance"); assurance.setIntentGoalType(IntentGoalType.CREATE); @@ -131,4 +140,59 @@ public class CLLBusinessDecisionModuleTest { cllBusinessDecisionModule.intentOrchestration(intentGoalBeanList); Assert.assertTrue(true); } + + @Test + public void testInvestigationCreateProcess() { + + IntentManagementFunctionRegInfo imfInfo = new IntentManagementFunctionRegInfo(); + imfInfo.setHandleName("CLLBusinessIntentManagementFunction"); + Mockito.when(imfRegInfoService.getImfRegInfo(any())).thenReturn(imfInfo); + cllBusinessDecisionModule.investigationCreateProcess(intentGoalBean); + Assert.assertTrue(true); + } + + @Test + public void testInvestigationUpdateProcess() { + Expectation deliveryExpectation = new Expectation(); + deliveryExpectation.setExpectationName("CLL Delivery Expectation"); + + List<Expectation> expectationList = new ArrayList<>(); + expectationList.add(deliveryExpectation); + Intent originalIntent = new Intent(); + originalIntent.setIntentExpectations(expectationList); + IntentGoalBean originIntentGoal = new IntentGoalBean(originalIntent, IntentGoalType.UPDATE); + + + CLLDeliveryIntentManagementFunction cllDeliveryImf = new CLLDeliveryIntentManagementFunction(); + Mockito.when(intentContextService.getHandlerInfo(any())).thenReturn(cllDeliveryImf); + List<Intent> subIntentList = new ArrayList<>(); + Intent deliveryIntent = new Intent(); + deliveryIntent.setIntentName("CLL Delivery intent"); + subIntentList.add(deliveryIntent); + + Intent assuranceIntent = new Intent(); + assuranceIntent.setIntentName("CLL Assurance intent"); + subIntentList.add(assuranceIntent); + + Mockito.when(intentContextService.getSubIntentInfoFromContext(any())).thenReturn(subIntentList); + + Mockito.doNothing().when(intentContextService).deleteSubIntentContext(any(), any()); + cllBusinessDecisionModule.investigationUpdateProcess(originIntentGoal); + Assert.assertTrue(true); + } + + @Test + public void testInvestigationDeleteProcess() { + IntentGoalBean intentGoalBean = new IntentGoalBean(new Intent(),IntentGoalType.DELETE); + List<Intent> subIntentList = new ArrayList<>(); + Intent deliveryIntent = new Intent(); + deliveryIntent.setIntentName("CLL Delivery intent"); + subIntentList.add(deliveryIntent); + + Mockito.when(intentContextService.getSubIntentInfoFromContext(any())).thenReturn(subIntentList); + + CLLDeliveryIntentManagementFunction cllDeliveryImf = new CLLDeliveryIntentManagementFunction(); + Mockito.when(intentContextService.getHandlerInfo(any())).thenReturn(cllDeliveryImf); + cllBusinessDecisionModule.investigationDeleteProcess(intentGoalBean); + } }
\ No newline at end of file diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/controller/IntentControllerTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/controller/IntentControllerTest.java new file mode 100644 index 0000000..fb30aaa --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/controller/IntentControllerTest.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.onap.usecaseui.intentanalysis.controller; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGenerateType; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; +import org.onap.usecaseui.intentanalysis.common.ResponseConsts; +import org.onap.usecaseui.intentanalysis.exception.CommonException; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService; +import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class IntentControllerTest { + + @InjectMocks + IntentController intentController; + @Mock + IntentService intentService; + @Mock + IntentProcessService intentProcessService; + @Mock + FormatIntentInputManagementFunction formatIntentInputManagementFunction; + + + @Test + public void testGetIntentList() { + intentController.getIntentList(); + verify(intentService, times(1)).getIntentList(); + } + + @Test + public void testGetIntentById() { + intentController.getIntentById(anyString()); + verify(intentService, times(1)).getIntent(anyString()); + } + + @Test + public void testCreateIntent() { + Intent intent = new Intent(); + intent.setIntentName("cllBussinessIntent"); + IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE); + Mockito.when(intentProcessService.intentProcess(any())).thenReturn(intentGoalBean); + intentController.createIntent(intent); + verify(intentProcessService, times(1)).intentProcess(any()); + verify(intentService, times(1)).createIntent(any()); + + } + + @Test + public void testCreateIntentCommonException() { + Intent intent = new Intent(); + intent.setIntentName("cllBussinessIntent"); + IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE); + //Mockito.when(intentProcessService.intentProcess(any())).thenReturn(intentGoalBean); + when(intentProcessService.intentProcess(any())).thenThrow(new CommonException("MSG", ResponseConsts.RET_UPDATE_DATA_FAIL)); + intentController.createIntent(intent); + Assert.assertTrue(true); + } + @Test + public void testUpdateIntentById(){ + Intent intent = new Intent(); + intent.setIntentName("cllBussinessIntent"); + IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE); + + Mockito.when(intentProcessService.intentProcess(any())).thenReturn(intentGoalBean); + intentController.updateIntentById(any(),any()); + verify(intentProcessService, times(1)).intentProcess(any()); + } + @Test + public void testUpdateIntentByIdCommonException() { + Intent intent = new Intent(); + intent.setIntentName("cllBussinessIntent"); + IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE); + //Mockito.when(intentProcessService.intentProcess(any())).thenReturn(intentGoalBean); + when(intentProcessService.intentProcess(any())).thenThrow(new CommonException("MSG", ResponseConsts.RET_UPDATE_DATA_FAIL)); + intentController.updateIntentById(any(),any()); + Assert.assertTrue(true); + } + + @Test + public void testRemoveIntentById(){ + Intent intent = new Intent(); + intent.setIntentName("cllBussinessIntent"); + String id = "intentId"; + IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE); + + Mockito.when(intentService.getIntent(any())).thenReturn(intent); + Mockito.when(intentProcessService.intentProcess(any())).thenReturn(intentGoalBean); + intentController.removeIntentById(id); + verify(intentProcessService, times(1)).intentProcess(any()); + } + + @Test + public void testRemoveIntentByIdCommonException() { + Intent intent = new Intent(); + intent.setIntentName("cllBussinessIntent"); + IntentGoalBean intentGoalBean = new IntentGoalBean(intent, IntentGoalType.CREATE); + //Mockito.when(intentProcessService.intentProcess(any())).thenReturn(intentGoalBean); + when(intentProcessService.intentProcess(any())).thenThrow(new CommonException("MSG", ResponseConsts.RET_UPDATE_DATA_FAIL)); + intentController.removeIntentById("intentId"); + Assert.assertTrue(true); + } + + @Test + public void testGetIntentListByIntentGenerateType(){ + intentController.getIntentListByIntentGenerateType(anyString()); + verify(intentService, times(1)).getIntentListByUserInput(anyString()); + } + @Test + public void testGetIntentListByIntentGenerateTypeCommoExcption(){ + when(intentService.getIntentListByUserInput(any())).thenThrow(new CommonException("MSG", ResponseConsts.RET_UPDATE_DATA_FAIL)); + intentController.getIntentListByIntentGenerateType(anyString()); + Assert.assertTrue(true); + } +}
\ No newline at end of file |