Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I3a0da8995a0bff989f9536392f106e4ddc7b316a Closes-Bug: #1786237
- Loading branch information
1 parent
75c0763
commit 395fa7a
Showing
21 changed files
with
238 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#maven.buildNumber.plugin properties file | ||
#Fri Aug 03 14:36:20 CEST 2018 | ||
buildNumber=1656 | ||
#Mon Aug 13 14:44:21 CEST 2018 | ||
buildNumber=1732 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...tests/src/test/groovy/net/juniper/contrail/vro/tests/actions/IsNotReferencedBySpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...ontrail-tests/src/test/groovy/net/juniper/contrail/vro/tests/dsl/ValidationAndSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package net.juniper.contrail.vro.tests.dsl | ||
|
||
import net.juniper.contrail.vro.tests.ScriptTestEngine | ||
import net.juniper.contrail.vro.tests.actions.ValidationAsserts | ||
import net.juniper.contrail.vro.workflows.dsl.AlwaysValid | ||
import net.juniper.contrail.vro.workflows.dsl.AlwaysInvalid | ||
import net.juniper.contrail.vro.workflows.dsl.ValidationConditionKt | ||
import spock.lang.Specification | ||
|
||
class ValidationConjunctionSpec extends Specification implements ValidationAsserts{ | ||
def errorMessage = "Error message" | ||
def anotherErrorMessage = "Another error message" | ||
def scriptTestEngine = new ScriptTestEngine() | ||
|
||
def "error message and null results in error message"() { | ||
given: "arguments" | ||
def firstArgument = new AlwaysInvalid(errorMessage) | ||
def secondArgument = new AlwaysValid() | ||
when: "conditions are evaluated" | ||
def complexCondition = ValidationConditionKt.and(firstArgument, secondArgument) | ||
def result = scriptTestEngine.evalCondition(complexCondition.stringCondition) | ||
then: "validation is unsuccessful with error message" | ||
validationFailureWith(result, errorMessage) | ||
} | ||
|
||
def "null and error message results in error message"() { | ||
given: "arguments" | ||
def firstArgument = new AlwaysValid() | ||
def secondArgument = new AlwaysInvalid(errorMessage) | ||
when: "conditions are evaluated" | ||
def complexCondition = ValidationConditionKt.and(firstArgument, secondArgument) | ||
def result = scriptTestEngine.evalCondition(complexCondition.stringCondition) | ||
then: "validation is unsuccessful with error message" | ||
validationFailureWith(result, errorMessage) | ||
} | ||
|
||
def "error message and another error message results in first error message"() { | ||
given: "arguments" | ||
def firstArgument = new AlwaysInvalid(errorMessage) | ||
def secondArgument = new AlwaysInvalid(anotherErrorMessage) | ||
when: "conditions are evaluated" | ||
def complexCondition = ValidationConditionKt.and(firstArgument, secondArgument) | ||
def result = scriptTestEngine.evalCondition(complexCondition.stringCondition) | ||
then: "validation is unsuccessful with first error message" | ||
validationFailureWith(result, errorMessage) | ||
} | ||
|
||
def "successful validation and successful validation results in successful validation"() { | ||
given: "arguments" | ||
def firstArgument = new AlwaysValid() | ||
def secondArgument = new AlwaysValid() | ||
when: "conditions are evaluated" | ||
def complexCondition = ValidationConditionKt.and(firstArgument, secondArgument) | ||
def result = scriptTestEngine.evalCondition(complexCondition.stringCondition) | ||
then: "validation is successful" | ||
validationSuccess(result) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...orkflow-dsl/src/main/kotlin/net/juniper/contrail/vro/workflows/dsl/ValidationCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.juniper.contrail.vro.workflows.dsl | ||
|
||
sealed class ValidationCondition { | ||
abstract val stringCondition: String | ||
} | ||
|
||
object AlwaysValid : ValidationCondition() { | ||
override val stringCondition = "null" | ||
} | ||
|
||
class AlwaysInvalid(errorMesssage: String) : ValidationCondition() { | ||
override val stringCondition: String = "\"$errorMesssage\"" | ||
} | ||
|
||
private class ValidationFromAction(actionCallBuilder: ActionCallBuilder) : ValidationCondition() { | ||
override val stringCondition = actionCallBuilder.create().ognl | ||
} | ||
|
||
private class ValidationConditionConjunction(vararg conditions: ValidationCondition) : ValidationCondition() { | ||
// Successful validation returns null which is a falsy value in ognl | ||
// Unsuccessful validation returns string which is a truthy value in ognl | ||
// && operator finishes evaluating on first falsy value and won't evaluate following validations | ||
// || on the other hand stops at first truthy value(which is an error) and returns it | ||
// Because we want all the conditions to be met, we use || operator | ||
override val stringCondition: String = conditions.joinToString(" || ") { "(${it.stringCondition})" } | ||
} | ||
|
||
infix fun ValidationCondition.and(other: ValidationCondition): ValidationCondition = when { | ||
this == AlwaysValid -> other | ||
other == AlwaysValid -> this | ||
else -> ValidationConditionConjunction(this, other) | ||
} | ||
|
||
fun ActionCallBuilder.asValidationCondition(): ValidationCondition { | ||
return ValidationFromAction(this) | ||
} |
13 changes: 13 additions & 0 deletions
13
o11nplugin-contrail-workflows/src/main/js/actions/isNotReferencedBy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
if (child === null) { | ||
return null | ||
} | ||
|
||
methodName = "isReferencedBy" + parent.getObjectClassName() | ||
toInvoke = "child." + methodName + "(parent)"; | ||
|
||
if (eval(toInvoke)) { | ||
return "Already referenced" | ||
} | ||
|
||
return null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.