Skip to content

Commit

Permalink
Inactionware#99 Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minjing committed Mar 19, 2019
1 parent d260f3a commit 6470b6f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion uapi.config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
)

testCompile (
project(':uapi.service.apt'),
project(':uapi.service.apt')
)

compile (
Expand Down

0 comments on commit 6470b6f

Please sign in to comment.