diff --git a/uapi.behavior/src/main/java/uapi/behavior/BehaviorExecutingEvent.java b/uapi.behavior/src/main/java/uapi/behavior/BehaviorExecutingEvent.java index 24ee6d1..0a87c66 100644 --- a/uapi.behavior/src/main/java/uapi/behavior/BehaviorExecutingEvent.java +++ b/uapi.behavior/src/main/java/uapi/behavior/BehaviorExecutingEvent.java @@ -7,8 +7,6 @@ */ public class BehaviorExecutingEvent extends BehaviorTraceEvent { - private static final String KEY_ACTION_ID = "ActionId"; - public BehaviorExecutingEvent( final String sourceName, final ExecutionIdentify executionId, @@ -21,13 +19,9 @@ public BehaviorExecutingEvent( ArgumentChecker.required(executionId, "executionId"); set(KEY_EXECUTION_ID, executionId); set(KEY_BEHAVIOR_INPUTS, behaviorInputs); - set(KEY_ACTION_ID, actionId); + set(KEY_CURRENT_ACTION_ID, actionId); set(KEY_CURRENT_INPUTS, actionInputs); set(KEY_CURRENT_OUTPUTS, actionOutputs); set(KEY_SOURCE_NAME, sourceName); } - - public ActionIdentify executingActionId() { - return (ActionIdentify) get(KEY_ACTION_ID); - } } diff --git a/uapi.behavior/src/main/java/uapi/behavior/BehaviorTraceEvent.java b/uapi.behavior/src/main/java/uapi/behavior/BehaviorTraceEvent.java index 7e78091..2c7d64d 100644 --- a/uapi.behavior/src/main/java/uapi/behavior/BehaviorTraceEvent.java +++ b/uapi.behavior/src/main/java/uapi/behavior/BehaviorTraceEvent.java @@ -5,13 +5,14 @@ */ public abstract class BehaviorTraceEvent extends BehaviorEvent { - public static final String TOPIC = "BehaviorTrace"; - public static final String KEY_EXECUTION_ID = "ExecutionId"; - public static final String KEY_BEHAVIOR_INPUTS = "BehaviorInputs"; - public static final String KEY_CURRENT_ACTION_ID = "CurrentActionId"; - public static final String KEY_CURRENT_INPUTS = "CurrentInputs"; - public static final String KEY_CURRENT_OUTPUTS = "CurrentOutputs"; - public static final String KEY_EX = "Exception"; + public static final String TOPIC = "BehaviorTrace"; + + protected static final String KEY_EXECUTION_ID = "ExecutionId"; + protected static final String KEY_BEHAVIOR_INPUTS = "BehaviorInputs"; + protected static final String KEY_CURRENT_ACTION_ID = "CurrentActionId"; + protected static final String KEY_CURRENT_INPUTS = "CurrentInputs"; + protected static final String KEY_CURRENT_OUTPUTS = "CurrentOutputs"; + protected static final String KEY_EX = "Exception"; public BehaviorTraceEvent(String sourceName) { super(TOPIC, sourceName); diff --git a/uapi.behavior/src/test/groovy/uapi/behavior/ActionIdentifyTest.groovy b/uapi.behavior/src/test/groovy/uapi/behavior/ActionIdentifyTest.groovy index 8094e9d..ee4255f 100644 --- a/uapi.behavior/src/test/groovy/uapi/behavior/ActionIdentifyTest.groovy +++ b/uapi.behavior/src/test/groovy/uapi/behavior/ActionIdentifyTest.groovy @@ -9,16 +9,12 @@ package uapi.behavior -import spock.lang.Ignore import spock.lang.Specification import uapi.InvalidArgumentException -import uapi.behavior.ActionIdentify -import uapi.behavior.ActionType /** * Unit test for ActionIdentify */ -@Ignore class ActionIdentifyTest extends Specification { def 'Test create instance'() { diff --git a/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorExecutingEventTest.groovy b/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorExecutingEventTest.groovy index 706cb9d..0486fd7 100644 --- a/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorExecutingEventTest.groovy +++ b/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorExecutingEventTest.groovy @@ -9,31 +9,29 @@ package uapi.behavior -import spock.lang.Ignore import spock.lang.Specification /** * Unit test for BehaviorExecutingEvent */ -@Ignore class BehaviorExecutingEventTest extends Specification { def 'Test create instance'() { when: def execId = new ExecutionIdentify(behaviorName, ActionType.BEHAVIOR, sequence) - def event = new BehaviorExecutingEvent(execId, oriData, data, actionId, 'respName') + def event = new BehaviorExecutingEvent(srcName, execId, actionId, inputs, outputs, bInputs) then: noExceptionThrown() event.topic() == BehaviorTraceEvent.TOPIC event.executionId() == execId - event.actionId() == actionId + event.currentActionId() == actionId event.behaviorName() == behaviorName - event.data() == data - event.originalData() == oriData + event.currentOutputs() == outputs + event.behaviorInputs() == bInputs where: - behaviorName | sequence | oriData | data | actionId - 'BName' | 1 | '2' | '3' | ActionIdentify.parse('1@ACTION') + srcName | behaviorName | sequence | inputs | outputs | actionId | bInputs + 'srcName' | 'BName' | 1 | ['2'] as String[] | [] as ActionOutput[] | ActionIdentify.parse('1@ACTION') | ['2'] as String[] } } diff --git a/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorFinishedEventTest.groovy b/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorFinishedEventTest.groovy index feb074e..a9831f1 100644 --- a/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorFinishedEventTest.groovy +++ b/uapi.behavior/src/test/groovy/uapi/behavior/BehaviorFinishedEventTest.groovy @@ -9,30 +9,28 @@ package uapi.behavior -import spock.lang.Ignore import spock.lang.Specification /** * Unit test for BehaviorFinishedEvent */ -@Ignore class BehaviorFinishedEventTest extends Specification { def 'Test create instance'() { when: def exeId = new ExecutionIdentify(behaviorName, ActionType.BEHAVIOR, sequence) - def instance = new BehaviorFinishedEvent(exeId, oriData, data, 'respName') + def instance = new BehaviorFinishedEvent(srcName, exeId, inputs, outputs, null) then: noExceptionThrown() instance.topic() == BehaviorTraceEvent.TOPIC instance.executionId() == exeId instance.behaviorName() == behaviorName - instance.originalData() == oriData - instance.data() == data + instance.behaviorInputs() == inputs + instance.behaviorOutputs() == outputs where: - behaviorName | sequence | oriData | data - 'BName' | 2 | 'abc' | 'cba' + srcName | behaviorName | sequence | inputs | outputs + 'src' | 'BName' | 2 | ['abc'] as String[] | [] as ActionOutput[] } } diff --git a/uapi.behavior/src/test/groovy/uapi/behavior/internal/ActionHolderTest.groovy b/uapi.behavior/src/test/groovy/uapi/behavior/internal/ActionHolderTest.groovy index 366eec3..e087932 100644 --- a/uapi.behavior/src/test/groovy/uapi/behavior/internal/ActionHolderTest.groovy +++ b/uapi.behavior/src/test/groovy/uapi/behavior/internal/ActionHolderTest.groovy @@ -15,6 +15,7 @@ import uapi.GeneralException import uapi.InvalidArgumentException import uapi.behavior.ActionIdentify import uapi.behavior.ActionInputMeta +import uapi.behavior.ActionOutputMeta import uapi.behavior.ActionType import uapi.behavior.BehaviorException import uapi.behavior.IAction @@ -32,10 +33,10 @@ class ActionHolderTest extends Specification { when: def action = Mock(IAction) { getId() >> Mock(ActionIdentify) - inputType() >> String.class - outputType() >> String.class + inputMetas() >> ([new ActionInputMeta(String.class)] as ActionInputMeta[]) + outputMetas() >> ([new ActionOutputMeta(String.class)] as ActionOutputMeta[]) } - def actionHolder = new ActionHolder(action) + def actionHolder = new ActionHolder(action, 'label', null, Mock(Behavior), null, 'input') then: noExceptionThrown() @@ -47,10 +48,11 @@ class ActionHolderTest extends Specification { when: def action = Mock(IAction) { getId() >> Mock(ActionIdentify) - inputType() >> String.class - outputType() >> String.class + inputMetas() >> ([new ActionInputMeta(String.class)] as ActionInputMeta[]) + outputMetas() >> ([new ActionOutputMeta(String.class)] as ActionOutputMeta[]) } - def actionHolder = new ActionHolder(action, Mock(Functionals.Evaluator)) + def actionHolder = new ActionHolder( + action, 'label', null, Mock(Behavior), Mock(Functionals.Evaluator), 'input') then: noExceptionThrown() @@ -59,34 +61,46 @@ class ActionHolderTest extends Specification { } def 'Test set next action by unmatched input type'() { + given: + def action = Mock(IAction) { + getId() >> Mock(ActionIdentify) + inputMetas() >> new ActionInputMeta[0] + outputMetas() >> new ActionOutputMeta[0] + } + + def action2 = Mock(IAction) { + getId() >> Mock(ActionIdentify) + inputMetas() >> ([new ActionInputMeta(String.class)] as ActionInputMeta[]) + outputMetas() >> new ActionOutputMeta[0] + } + when: - def instance = new ActionHolder(new TestAction1()) - instance.next(new ActionHolder(new TestAction2())) + def instance = new ActionHolder(action, 'label', Mock(Behavior)) + instance.next(new ActionHolder(action2, 'label', Mock(Behavior))) then: -// thrown(BehaviorException) - noExceptionThrown() - instance.hasNext() + thrown(BehaviorException) + ! instance.hasNext() } def 'Test set next action'() { + given: + def action = Mock(IAction) { + getId() >> Mock(ActionIdentify) + inputMetas() >> new ActionInputMeta[0] + outputMetas() >> new ActionOutputMeta[0] + } + when: - def instance = new ActionHolder(new TestAction1()) - instance.next(new ActionHolder(new TestAction3())) + def instance = new ActionHolder(action, 'label', Mock(Behavior)) + instance.next(new ActionHolder(action, 'label', Mock(Behavior))) then: noExceptionThrown() instance.hasNext() } -// def 'Test find next action but no next action'() { -// when: -// def instance = new ActionHolder(new TestAction1()) -// instance.findNext(new Object()) -// -// then: -// thrown(GeneralException) -// } + /// Not verified below def 'Test find next action with one next action'() { when: diff --git a/uapi.config/build.gradle b/uapi.config/build.gradle index 5351047..16866a7 100644 --- a/uapi.config/build.gradle +++ b/uapi.config/build.gradle @@ -21,7 +21,7 @@ dependencies { ) testCompile ( - project(':uapi.service.apt'), + project(':uapi.service.apt') ) compile (