diff options
author | Keguang He <hekeguang@chinamobile.com> | 2022-09-01 07:44:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-09-01 07:44:55 +0000 |
commit | d004c121a83dfea3654d9ac47bd558e2237b7e6f (patch) | |
tree | 103640f096a16e868037470977bf77d4260258d8 /intentanalysis/src/test/java | |
parent | 63492d1459f46c889ba93641ec51ab8928cc0127 (diff) | |
parent | 54e7ca4ddf183cd15bd7afff0c53b1970698432b (diff) |
Merge "Add UT to intent service"
Diffstat (limited to 'intentanalysis/src/test/java')
-rw-r--r-- | intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java | 121 |
1 files changed, 118 insertions, 3 deletions
diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java index 3a692c0..6dc1062 100644 --- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java @@ -15,11 +15,21 @@ package org.onap.usecaseui.intentanalysis.test.service; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.usecaseui.intentanalysis.bean.enums.*; import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.Condition; +import org.onap.usecaseui.intentanalysis.bean.models.FulfilmentInfo; +import org.onap.usecaseui.intentanalysis.bean.models.Context; +import org.onap.usecaseui.intentanalysis.bean.models.Expectation; +import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget; +import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject; import org.onap.usecaseui.intentanalysis.service.IntentService; import org.onap.usecaseui.intentanalysis.test.IntentAnalysisApplicationTests; import org.onap.usecaseui.intentanalysis.util.SpringContextUtil; @@ -36,6 +46,12 @@ public class IntentServiceTest extends AbstractJUnit4SpringContextTests { private static final Logger LOGGER = LoggerFactory.getLogger(IntentServiceTest.class); + private static final String TEST_INTENT_ID_1 = "intentId1"; + + private static final String TEST_INTENT_ID_2 = "intentId2"; + + private static final String TEST_INTENT_NAME = "CLL Business intent"; + @Autowired private IntentService intentService; @@ -47,10 +63,109 @@ public class IntentServiceTest extends AbstractJUnit4SpringContextTests { @Test public void testCreateIntentSuccess() throws IOException { Intent intent = new Intent(); - intent.setIntentId("testUUID"); + Expectation expectation1 = new Expectation(); + ExpectationTarget target1 = new ExpectationTarget(); + ExpectationObject object1 = new ExpectationObject(); + Context intentContext = new Context(); + FulfilmentInfo intentFulfilmentInfo = new FulfilmentInfo(); + Condition targetCondition1 = new Condition(); + targetCondition1.setConditionId("conditionId"); + targetCondition1.setConditionName("conditionName"); + targetCondition1.setOperator(OperatorType.valueOf("EQUALTO")); + targetCondition1.setConditionValue("conditionValue"); + List<Condition> targetConditionList = new ArrayList<>(); + targetConditionList.add(targetCondition1); + target1.setTargetId("targetId"); + target1.setTargetName("targetName"); + target1.setTargetConditions(targetConditionList); + List<ExpectationTarget> expectationTargetList = new ArrayList<>(); + expectationTargetList.add(target1); + object1.setObjectType(ObjectType.valueOf("OBJECT1")); + object1.setObjectInstance("objectInstance"); + expectation1.setExpectationId("expectationId"); + expectation1.setExpectationName("expectationName"); + expectation1.setExpectationType(ExpectationType.valueOf("DELIVERY")); + expectation1.setExpectationObject(object1); + expectation1.setExpectationTargets(expectationTargetList); + List<Expectation> expectationList = new ArrayList<>(); + expectationList.add(expectation1); + intentContext.setContextId("intentContextId"); + intentContext.setContextName("intentContextName"); + List<Context> intentContextList = new ArrayList<>(); + intentContextList.add(intentContext); + intentFulfilmentInfo.setFulfilmentStatus(FulfilmentStatus.valueOf("NOT_FULFILLED")); + intentFulfilmentInfo.setNotFulfilledReason("NotFulfilledReason"); + intentFulfilmentInfo.setNotFulfilledState(NotFulfilledState.valueOf("COMPLIANT")); + intent.setIntentId("testIntentId"); intent.setIntentName("testIntentName"); - //ToDo - //Intent intentTmp = intentService.createIntent(intent); + intent.setIntentContexts(intentContextList); + intent.setIntentExpectations(expectationList); + intent.setIntentFulfilmentInfo(intentFulfilmentInfo); + + Intent intentTmp = intentService.createIntent(intent); + Assert.assertNotNull(intentTmp); + } + + @Test + public void testGetIntentListSuccess() { + List<Intent> intentList = intentService.getIntentList(); + Assert.assertNotNull(intentList); + } + + @Test + public void testGetIntentSuccess() { + Intent intent = intentService.getIntent(TEST_INTENT_ID_1); Assert.assertNotNull(intent); } + + @Test + public void testGetIntentByNameSuccess() { + List<Intent> intentList = intentService.getIntentByName(TEST_INTENT_NAME); + Assert.assertNotNull(intentList); + + } + + @Test + public void testUpdateIntentSuccess() { + Intent intent = intentService.getIntent(TEST_INTENT_ID_1); + intent.setIntentName("new intent name"); + List<Context> contextList = intent.getIntentContexts(); + Context intentContext = contextList.get(0); + intentContext.setContextName("new context name"); + contextList.set(0, intentContext); + intent.setIntentContexts(contextList); + FulfilmentInfo intentFulfilmentInfo = intent.getIntentFulfilmentInfo(); + intentFulfilmentInfo.setNotFulfilledReason("new reason"); + intent.setIntentFulfilmentInfo(intentFulfilmentInfo); + List<Expectation> expectationList = intent.getIntentExpectations(); + Expectation expectation = expectationList.get(0); + expectation.setExpectationName("new expectation name"); + ExpectationObject expectationObject = expectation.getExpectationObject(); + expectationObject.setObjectInstance("new object instance"); + expectation.setExpectationObject(expectationObject); + List<ExpectationTarget> expectationTargetList = expectation.getExpectationTargets(); + ExpectationTarget expectationTarget = expectationTargetList.get(0); + expectationTarget.setTargetName("new target name"); + List<Condition> targetConditionList = expectationTarget.getTargetConditions(); + Condition targetCondition = targetConditionList.get(0); + targetCondition.setConditionName("new conditon name"); + targetConditionList.set(0, targetCondition); + expectationTarget.setTargetConditions(targetConditionList); + expectationTargetList.remove(2); + expectationTargetList.set(0, expectationTarget); + expectation.setExpectationTargets(expectationTargetList); + expectationList.set(0, expectation); + intent.setIntentExpectations(expectationList); + + Intent updatedIntent = intentService.updateIntent(intent); + Assert.assertEquals("new intent name", updatedIntent.getIntentName()); + + } + + @Test + public void testDeleteIntentSuccess() { + intentService.deleteIntent(TEST_INTENT_ID_2); + Intent intent = intentService.getIntent(TEST_INTENT_ID_2); + Assert.assertNull(intent); + } } |