From 54e7ca4ddf183cd15bd7afff0c53b1970698432b Mon Sep 17 00:00:00 2001 From: zhangfan345 Date: Thu, 1 Sep 2022 11:24:47 +0800 Subject: Add UT to intent service Issue-ID: USECASEUI-716 Signed-off-by: zhangfan345 Change-Id: I45b7faf76bf899510d11939021fd1d788c95a4bf --- .../intentanalysis/mapper/IntentMapper.java | 2 +- .../intentanalysis/mapper/StateMapper.java | 43 -------- .../intentanalysis/service/StateService.java | 37 ------- .../service/impl/IntentServiceImpl.java | 6 +- .../service/impl/StateServiceImpl.java | 122 --------------------- .../main/resources/mybatis/sql/IntentMapper.xml | 2 +- .../src/main/resources/mybatis/sql/StateMapper.xml | 53 --------- 7 files changed, 7 insertions(+), 258 deletions(-) delete mode 100644 intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java delete mode 100644 intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java delete mode 100644 intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java delete mode 100644 intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml (limited to 'intentanalysis/src/main') diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java index cc253ab..1178b6d 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentMapper.java @@ -37,5 +37,5 @@ public interface IntentMapper { int deleteIntent(@Param(value = "intentId") String intentId); - List getIntentByName(@Param(value = "name") String name); + List getIntentByName(@Param(value = "intentName") String name); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java deleted file mode 100644 index 10538c4..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/StateMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * 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.mapper; - - -import java.util.List; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.onap.usecaseui.intentanalysis.bean.models.Expectation; -import org.onap.usecaseui.intentanalysis.bean.models.State; - - -@Mapper - -public interface StateMapper { - - int insertStateList(@Param(value = "stateList") List state, - @Param(value = "expectationId") String expectationId); - - List selectStateByExpectation(@Param(value = "expectationId") String expectationId); - - int deleteStateByExpectationId(@Param(value = "expectationId") String expectationId); - - int updateState(@Param(value = "state") State state); - - int insertState(@Param(value = "state") State state, @Param(value = "expectationId") String expectationId); - - int deleteStateById(@Param(value = "stateId") String stateId); -} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java deleted file mode 100644 index d2d66c7..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/StateService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * 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.service; - - -import java.util.List; -import org.onap.usecaseui.intentanalysis.bean.models.State; - - -public interface StateService { - - void createStateList(List stateList, String expectationId); - - void deleteStateListByExpectationId(String expectationId); - - void updateStateListByExpectationId(List stateList, String expectationId); - - List getStateListByExpectationId(String expectationId); - - void createState(State state, String expectationId); - - void deleteStateById(String stateId); -} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java index 952b6dd..bb1759c 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/IntentServiceImpl.java @@ -87,7 +87,9 @@ public class IntentServiceImpl implements IntentService { public Intent getIntent(String intentId) { Intent intent = intentMapper.selectIntent(intentId); if (intent != null) { - intent.setIntentExpectations(expectationService.getIntentExpectationList(intent.getIntentId())); + intent.setIntentExpectations(expectationService.getIntentExpectationList(intentId)); + intent.setIntentContexts(contextService.getContextList(intentId)); + intent.setIntentFulfilmentInfo(fulfilmentInfoService.getFulfilmentInfo(intentId)); } else { log.info(String.format("Intent is null, intentId = %s", intentId)); } @@ -140,6 +142,8 @@ public class IntentServiceImpl implements IntentService { if (!CollectionUtils.isEmpty(intentList)) { for (Intent intent : intentList) { intent.setIntentExpectations(expectationService.getIntentExpectationList(intent.getIntentId())); + intent.setIntentContexts(contextService.getContextList(intent.getIntentId())); + intent.setIntentFulfilmentInfo(fulfilmentInfoService.getFulfilmentInfo(intent.getIntentId())); } } else { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java deleted file mode 100644 index b9c7b95..0000000 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/service/impl/StateServiceImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2022 Huawei Technologies Co., Ltd. - * - * 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.service.impl; - - -import lombok.extern.slf4j.Slf4j; -import org.onap.usecaseui.intentanalysis.bean.models.State; -import org.onap.usecaseui.intentanalysis.common.ResponseConsts; -import org.onap.usecaseui.intentanalysis.exception.DataBaseException; -import org.onap.usecaseui.intentanalysis.mapper.StateMapper; -import org.onap.usecaseui.intentanalysis.service.StateService; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - - -@Service -@Slf4j -public class StateServiceImpl implements StateService { - - @Autowired - private StateMapper stateMapper; - - @Autowired - private StateService stateService; - - @Override - public void createStateList(List stateList, String expectationId) { - int res = stateMapper.insertStateList(stateList, expectationId); - if (res < 1) { - String msg = "Create state to database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); - } - } - - @Override - public List getStateListByExpectationId(String expectationId) { - List stateList = stateMapper.selectStateByExpectation(expectationId); - if (stateList == null) { - String msg = String.format("State: Expectation id %s doesn't exist in database.", expectationId); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - return stateList; - } - - @Override - public void deleteStateListByExpectationId(String expectationId) { - if (stateMapper.deleteStateByExpectationId(expectationId) < 1) { - String msg = "Delete state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); - } - } - - @Override - public void updateStateListByExpectationId(List stateList, String expectationId) { - List stateDBList = stateMapper.selectStateByExpectation(expectationId); - if (stateDBList == null) { - String msg = String.format("Expectation id %s doesn't exist in database.", expectationId); - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY); - } - List stateDBIdList = new ArrayList<>(); - for (State stateDB : stateDBList) { - stateDBIdList.add(stateDB.getStateId()); - } - for (State state : stateList) { - if (stateDBIdList.contains(state.getStateId())) { - int res = stateMapper.updateState(state); - if (res < 1) { - String msg = "Update state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_UPDATE_DATA_FAIL); - } - stateDBIdList.remove(state.getStateId()); - } else { - stateService.createState(state, expectationId); - } - } - for (String stateDBId : stateDBIdList) { - stateService.deleteStateById(stateDBId); - } - log.info("States are successfully updated."); - } - - @Override - public void createState(State state, String expectationId) { - if (stateMapper.insertState(state, expectationId) < 1) { - String msg = "Create state to database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_INSERT_DATA_FAIL); - } - } - - @Override - public void deleteStateById(String stateId) { - if (stateMapper.deleteStateById(stateId) < 1) { - String msg = "Delete state in database failed."; - log.error(msg); - throw new DataBaseException(msg, ResponseConsts.RET_DELETE_DATA_FAIL); - } - } -} \ No newline at end of file diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml index c5d3b3d..57c8952 100644 --- a/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml +++ b/intentanalysis/src/main/resources/mybatis/sql/IntentMapper.xml @@ -34,7 +34,7 @@ \ No newline at end of file diff --git a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml deleted file mode 100644 index d103015..0000000 --- a/intentanalysis/src/main/resources/mybatis/sql/StateMapper.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - insert into state(state_id, state_name, expectation_id, is_satisfied, condition) - values - - (#{item.stateId}, #{item.stateName}, #{expectationId}, #{item.isSatisfied}, #{item.condition}) - - - - - - delete - from state - where expectation_id = #{expectationId} - - - - - insert into state(state_id, state_name, expectation_id, is_satisfied, condition) - values (#{state.stateId}, #{state.stateName}, #{expectationId}, #{state.isSatisfied}, #{state.condition}) - - - - - update state - - state_name = #{stateName}, - is_satisfied = #{isSatisfied}, - condition = #{condition}, - - where state_id = #{stateId} - - - - delete - from state - where state_id = #{stateId} - - - \ No newline at end of file -- cgit 1.2.3-korg