/
IsNotReferencedBySpec.groovy
42 lines (36 loc) · 1.79 KB
/
IsNotReferencedBySpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package net.juniper.contrail.vro.tests.actions
import net.juniper.contrail.vro.gen.NetworkPolicy_Wrapper
import net.juniper.contrail.vro.tests.workflows.WorkflowSpec
import static net.juniper.contrail.vro.config.Actions.isNotReferencedBy
class IsNotReferencedBySpec extends WorkflowSpec implements ValidationAsserts{
def isNotReferencedByAction = actionFromScript(isNotReferencedBy)
def errorMessage = "Already referenced"
def "null child results in success validation"() {
given: "child is set to null"
def parent = null
def child = null
when: "executing validation script"
def result = engine.invokeFunction(isNotReferencedByAction, child, parent)
then: "it succeeds"
validationSuccess(result)
}
def "child which is not already referenced by parent results in success validation"() {
given: "parent is set to some virtual network and child is set to some policy"
def parent = dependencies.someVirtualNetwork()
def child = dependencies.someNetworkPolicy()
when: "executing validation script"
def result = engine.invokeFunction(isNotReferencedByAction, child, parent)
then: "it succeeds"
validationSuccess(result)
}
def "child which is already referenced by parent results in failure validation with message"() {
given: "parent is set to some virtual network and child is set to some policy"
def parent = dependencies.someVirtualNetwork()
def child = Mock(NetworkPolicy_Wrapper)
child.isReferencedByVirtualNetwork(parent) >> true
when: "executing validation script"
def result = engine.invokeFunction(isNotReferencedByAction, child, parent)
then: "it fails with message"
validationFailureWith(result, errorMessage)
}
}