diff options
author | cmrizhangzhen <781953240@qq.com> | 2022-11-30 21:21:02 +0800 |
---|---|---|
committer | cmrizhangzhen <781953240@qq.com> | 2022-11-30 21:21:13 +0800 |
commit | ea55b438a05738ef18d756c01141a0c77f42410e (patch) | |
tree | 852b8d67aeadf8819c85170eebf284ee1dcd3e14 /intentanalysis | |
parent | a1b14f857e4e9abe0350ae27a4d747481ebd86c3 (diff) |
add intentAnalysis coverage
Issue-ID: USECASEUI-762
Signed-off-by: cmrizhangzhen <781953240@qq.com>
Change-Id: I84b2cfd69e3429d58d8f35d0351f2ff0e7e70a28
Diffstat (limited to 'intentanalysis')
6 files changed, 234 insertions, 19 deletions
diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModuleTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModuleTest.java new file mode 100644 index 0000000..d77367e --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModuleTest.java @@ -0,0 +1,52 @@ +/* + * 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.cllBusinessIntentMgt.cllBusinessModule; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.onap.usecaseui.intentanalysis.bean.models.Context; +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class CLLBusinessActuationModuleTest { + @InjectMocks + CLLBusinessActuationModule cllBusinessActuationModule; + @Mock + IntentService intentService; + @Test + public void testSaveIntentToDb(){ + List<Context> intentContexts = new ArrayList<>(); + Intent intent = new Intent(); + intent.setIntentContexts(intentContexts); + cllBusinessActuationModule.saveIntentToDb(intent); + + verify(intentService, times(1)).createIntent(intent); + } +}
\ No newline at end of file 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 6664a29..a7a997b 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 @@ -1,19 +1,17 @@ /* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. * - * * 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. + * 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.cllBusinessIntentMgt.cllBusinessModule; diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModuleTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModuleTest.java new file mode 100644 index 0000000..fbb560b --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/cllassuranceIntentmgt/cllassurancemodule/CLLAssuranceActuationModuleTest.java @@ -0,0 +1,127 @@ +/* + * 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.cllassuranceIntentmgt.cllassurancemodule; + +import org.junit.Assert; +import org.junit.Before; +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.adapters.policy.PolicyService; +import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; +import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; +import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType; +import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType; +import org.onap.usecaseui.intentanalysis.bean.models.*; +import org.onap.usecaseui.intentanalysis.service.ContextService; +import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +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.Mockito.times; +import static org.mockito.Mockito.verify; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class CLLAssuranceActuationModuleTest { + @InjectMocks + CLLAssuranceActuationModule cllAssuranceActuationModule; + @Mock + IntentService intentService; + @Mock + private PolicyService policyService; + @Mock + private ContextService contextService; + Intent intent = new Intent(); + + @Before + public void before() throws Exception { + intent.setIntentName("CLL Delivery Intent"); + List<Expectation> expectationList = new ArrayList<>(); + Expectation deliveryExpectation = new Expectation(); + deliveryExpectation.setExpectationName("CLL Delivery Expectation"); + deliveryExpectation.setExpectationType(ExpectationType.DELIVERY); + ExpectationObject expectationObject = new ExpectationObject(); + expectationObject.setObjectInstance(""); + deliveryExpectation.setExpectationObject(expectationObject); + + List<ExpectationTarget> targetList = new ArrayList<>(); + ExpectationTarget target1 = new ExpectationTarget(); + target1.setTargetName("bandwidth"); + + List<Condition> conditionList = new ArrayList<>(); + Condition con = new Condition(); + con.setConditionName("condition of the cll service bandwidth"); + con.setOperator(OperatorType.EQUALTO); + con.setConditionValue("1000"); + conditionList.add(con); + + target1.setTargetConditions(conditionList); + targetList.add(target1); + + deliveryExpectation.setExpectationTargets(targetList); + + expectationList.add(deliveryExpectation); + + Expectation assuranceExceptation = new Expectation(); + assuranceExceptation.setExpectationType(ExpectationType.ASSURANCE); + ExpectationObject expectationObject2 = new ExpectationObject(); + expectationObject2.setObjectInstance(""); + assuranceExceptation.setExpectationObject(expectationObject2); + expectationList.add(assuranceExceptation); + intent.setIntentExpectations(expectationList); + + } + @Test + public void testDirectOperation(){ + // Mockito.doNothing().when(policyService).updateIntentConfigPolicy(any(), any(),any()); + IntentGoalBean intentGoalBean = new IntentGoalBean(intent,IntentGoalType.DELETE); + List<Intent> intentList = new ArrayList<>(); + intentList.add(intent); + + Mockito.when(intentService.getIntentByName(any())).thenReturn(intentList); + + cllAssuranceActuationModule.directOperation(intentGoalBean); + Assert.assertTrue(true); + } + @Test + public void testUpdateIntentOperationInfo(){ + // updateIntentOperationInfo(Intent originIntent, IntentGoalBean intentGoalBean){ + Intent originIntent = new Intent(); + originIntent.setIntentContexts(new ArrayList<>()); + originIntent.setIntentId("12345"); + cllAssuranceActuationModule.updateIntentOperationInfo(originIntent,new IntentGoalBean()); + verify(contextService, times(1)).updateContextList(originIntent.getIntentContexts(), originIntent.getIntentId()); + } + @Test + public void testDeleteIntentToDb(){ + Intent intent = new Intent(); + intent.setIntentId("1234"); + Mockito.when(intentService.getSubIntentList(any())).thenReturn(new ArrayList<>()); + cllAssuranceActuationModule.deleteIntentToDb(intent); + verify(intentService, times(1)).deleteIntent(any()); + + } +}
\ No newline at end of file diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java index 698dd40..2c04e7b 100644 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/clldeliveryIntentmgt/clldeliverymodule/CLLDeliveryActuationModuleTest.java @@ -16,17 +16,16 @@ */ package org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.clldeliverymodule; +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.adapters.so.SOService; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; -import org.onap.usecaseui.intentanalysis.bean.models.Expectation; -import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject; -import org.onap.usecaseui.intentanalysis.bean.models.Intent; -import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; +import org.onap.usecaseui.intentanalysis.bean.models.*; import org.onap.usecaseui.intentanalysis.service.ContextService; import org.onap.usecaseui.intentanalysis.service.ExpectationObjectService; import org.springframework.boot.test.context.SpringBootTest; @@ -47,7 +46,8 @@ public class CLLDeliveryActuationModuleTest { private ExpectationObjectService expectationObjectService; @Mock private ContextService contextService; - + @Mock + private SOService soService; Intent originalIntent = new Intent(); IntentGoalBean intentGoalBean = new IntentGoalBean(); @@ -81,4 +81,37 @@ public class CLLDeliveryActuationModuleTest { cllDeliveryActuationModulel.updateIntentOperationInfo(originalIntent,intentGoalBean); } + @Test + public void testGetInstanceId(){ + cllDeliveryActuationModulel.getInstanceId(); + Assert.assertTrue(true); + } + @Test + public void testDirectOperation (){ + intentGoalBean.setIntentGoalType(IntentGoalType.CREATE); + Intent intent = new Intent(); + List<Expectation> expectationList = new ArrayList<>(); + Expectation expectation = new Expectation(); + expectation.setExpectationId("1234"); + List<ExpectationTarget> targetList = new ArrayList<>(); + ExpectationTarget target = new ExpectationTarget(); + + List<Condition> conditionList = new ArrayList<>(); + Condition con = new Condition(); + con.setConditionName("source"); + conditionList.add(con); + target.setTargetConditions(conditionList); + targetList.add(target); + expectation.setExpectationTargets(targetList); + expectationList.add(expectation); + intent.setIntentExpectations(expectationList); + intentGoalBean.setIntent(intent); + + //Mockito.doNothing().when(soService).createIntentInstance(any()); + Mockito.when(expectationObjectService.getExpectationObject(any())).thenReturn(new ExpectationObject()); + Mockito.doNothing().when(expectationObjectService).updateExpectationObject(any(),any()); + cllDeliveryActuationModulel.fulfillIntent(intentGoalBean,null); + Assert.assertTrue(true); + } + }
\ No newline at end of file diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionServiceTest.java index c31aea1..cc5830a 100644 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionServiceTest.java +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionServiceTest.java @@ -22,6 +22,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType; import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType; @@ -32,6 +33,7 @@ import org.onap.usecaseui.intentanalysis.bean.models.Intent; import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -51,6 +53,8 @@ public class IntentDefinitionServiceTest { private IntentManagementFunction intentOwner; @Resource(name = "CLLBusinessIntentManagementFunction") private CLLBusinessIntentManagementFunction cllBusinessIntentManagementFunction; + @Mock + IntentContextService intentContextService; Intent intent = new Intent(); @Before diff --git a/intentanalysis/src/test/resources/intentdb-test-init.sql b/intentanalysis/src/test/resources/intentdb-test-init.sql index 8c8ab53..855d5dd 100644 --- a/intentanalysis/src/test/resources/intentdb-test-init.sql +++ b/intentanalysis/src/test/resources/intentdb-test-init.sql @@ -27,7 +27,8 @@ DROP TABLE IF EXISTS condition; create table if not exists intent ( intent_id varchar(255) primary key, - intent_name varchar(255) + intent_name varchar(255), + intent_generateType VARCHAR (225) ); create table if not exists expectation |