Skip to content

Commit

Permalink
#150 Refactored Kubernetes expect command result
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Jan 20, 2017
1 parent b02840f commit 570e21d
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public class KubernetesExecuteAction extends AbstractTestAction {
/** Kubernetes command to execute */
private KubernetesCommand command;

/** Expected command result for validation */
/** Control command result for validation */
private String commandResult;

/** Expected path expressions in command result */
/** Control path expressions in command result */
private Map<String, Object> commandResultExpressions;

@Autowired
Expand Down Expand Up @@ -127,7 +127,7 @@ private void validateCommandResult(KubernetesCommand command, TestContext contex
}

if (command.getResultCallback() != null && result != null) {
command.getResultCallback().doWithCommandResult(result, context);
command.getResultCallback().validateCommandResult(result, context);
}
}

Expand Down Expand Up @@ -167,24 +167,24 @@ public KubernetesExecuteAction setKubernetesClient(KubernetesClient kubernetesCl
}

/**
* Gets the expected command result data.
* Gets the expected control command result data.
* @return
*/
public String getCommandResult() {
return commandResult;
}

/**
* Sets the expected command result data.
* @param expectedCommandResult
* Sets the expected control command result data.
* @param controlCommandResult
*/
public KubernetesExecuteAction setCommandResult(String expectedCommandResult) {
this.commandResult = expectedCommandResult;
public KubernetesExecuteAction setCommandResult(String controlCommandResult) {
this.commandResult = controlCommandResult;
return this;
}

/**
* Gets the expected command result expressions such as JsonPath expressions.
* Gets the expected control command result expressions such as JsonPath expressions.
* @return
*/
public Map<String, Object> getCommandResultExpressions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Message receive(String selector, TestContext context, long timeout) {
}

if (command.getResultCallback() != null) {
command.getResultCallback().doWithCommandResult(command.getCommandResult(), context);
command.getResultCallback().validateCommandResult(command.getCommandResult(), context);
}

return getEndpointConfiguration().getMessageConverter().convertInbound(command, getEndpointConfiguration(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
public interface CommandResultCallback<R extends KubernetesResource> {

/**
* Callback method called with command result.
* Callback method called with command result for validation.
* @param result
* @param context
*/
void doWithCommandResult(CommandResult<R> result, TestContext context);
void validateCommandResult(CommandResult<R> result, TestContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
}
}

Element expectCmdResult = DomUtils.getChildElementByTagName(element, "expect");
if (expectCmdResult != null) {
Element resultElement = DomUtils.getChildElementByTagName(expectCmdResult, "result");
Element controlCmdResult = DomUtils.getChildElementByTagName(element, "validate");
if (controlCmdResult != null) {
Element resultElement = DomUtils.getChildElementByTagName(controlCmdResult, "result");
if (resultElement != null) {
beanDefinition.addPropertyValue("commandResult", DomUtils.getTextValue(resultElement));
}

Map<String, Object> pathExpressions = new HashMap<>();
List<?> pathElements = DomUtils.getChildElementsByTagName(expectCmdResult, "element");
List<?> pathElements = DomUtils.getChildElementsByTagName(controlCmdResult, "element");
for (Iterator<?> iter = pathElements.iterator(); iter.hasNext();) {
Element messageValue = (Element) iter.next();
pathExpressions.put(messageValue.getAttribute("path"), messageValue.getAttribute("value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<k8s:info client="myK8sClient"/>

<k8s:list-pods>
<k8s:expect>
<k8s:validate>
<k8s:result>{}</k8s:result>
<k8s:element path="$.apiVersion" value="v1"/>
<k8s:element path="$..name.toString()" value="[a,b,c,d]"/>
</k8s:expect>
</k8s:validate>
</k8s:list-pods>

<k8s:list-events/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@

<repeat-onerror-until-true condition="@assertThat('greaterThan(9)')@" auto-sleep="1000">
<k8s:list-pods label="${podLabel}">
<k8s:expect>
<k8s:validate>
<k8s:element path="$.result.items.size()" value="1"/>
<k8s:element path="$..status.phase" value="Running"/>
</k8s:expect>
</k8s:validate>
</k8s:list-pods>
</repeat-onerror-until-true>

Expand All @@ -62,9 +62,9 @@
</echo>

<k8s:list-services label="${serviceLabel}">
<k8s:expect>
<k8s:validate>
<k8s:element path="$.result.items.size()" value="1"/>
</k8s:expect>
</k8s:validate>
</k8s:list-services>

</actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</echo>

<k8s:info>
<k8s:expect>
<k8s:validate>
<k8s:result>{
"result": {
"clientVersion": "1.4.27",
Expand All @@ -44,15 +44,15 @@
"namespace": "${namespace}"
}
}</k8s:result>
</k8s:expect>
</k8s:validate>
</k8s:info>

<echo>
<message>List all pods</message>
</echo>

<k8s:list-pods>
<k8s:expect>
<k8s:validate>
<k8s:result>{
"result": {
"apiVersion":"${apiVersion}",
Expand Down Expand Up @@ -97,15 +97,15 @@
<k8s:element path="$.result.items.size()" value="1"/>
<k8s:element path="$..status.phase" value="Running"/>
<k8s:element path="$..metadata.name" value="@variable('podName')@"/>
</k8s:expect>
</k8s:validate>
</k8s:list-pods>

<echo>
<message>List all services</message>
</echo>

<k8s:list-services>
<k8s:expect>
<k8s:validate>
<k8s:result>{
"result": {
"apiVersion":"${apiVersion}",
Expand All @@ -115,15 +115,15 @@
}
}</k8s:result>
<k8s:element path="$.result.items.size()" value="2"/>
</k8s:expect>
</k8s:validate>
</k8s:list-services>

<echo>
<message>Get hello-minikube service by name</message>
</echo>

<k8s:get-service name="hello-minikube">
<k8s:expect>
<k8s:validate>
<k8s:result>{
"result": {
"apiVersion":"${apiVersion}",
Expand Down Expand Up @@ -161,7 +161,7 @@
"status":"@ignore@"
}
}</k8s:result>
</k8s:expect>
</k8s:validate>
</k8s:get-service>

<echo>
Expand Down Expand Up @@ -189,7 +189,7 @@
</echo>

<k8s:list-endpoints>
<k8s:expect>
<k8s:validate>
<k8s:result>{
"result": {
"apiVersion":"${apiVersion}",
Expand All @@ -199,7 +199,7 @@
}
}</k8s:result>
<k8s:element path="$.result.items.size()" value="2"/>
</k8s:expect>
</k8s:validate>
</k8s:list-endpoints>
<k8s:list-events/>

Expand All @@ -208,7 +208,7 @@
</echo>

<k8s:get-pod name="${podName}">
<k8s:expect>
<k8s:validate>
<k8s:result>{
"result": {
"apiVersion":"${apiVersion}",
Expand Down Expand Up @@ -259,7 +259,7 @@
}
}</k8s:result>
<k8s:element path="$..status.phase" value="Running"/>
</k8s:expect>
</k8s:validate>
</k8s:get-pod>

</actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
</xs:complexType>
Expand Down Expand Up @@ -85,7 +85,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="name" type="xs:string"/>
Expand All @@ -101,7 +101,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -116,7 +116,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand Down Expand Up @@ -171,7 +171,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="name" type="xs:string"/>
Expand All @@ -187,7 +187,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -202,7 +202,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -218,7 +218,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -233,7 +233,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -249,7 +249,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -264,7 +264,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -278,7 +278,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -293,7 +293,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -307,7 +307,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
Expand All @@ -322,14 +322,14 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="description" minOccurs="0"/>
<xs:element name="expect" type="ExpectCmdResultType" minOccurs="0"/>
<xs:element name="validate" type="ValidateCommandResultType" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="client" type="xs:string"/>
<xs:attribute name="label" type="xs:string"/>
</xs:complexType>
</xs:element>

<xs:complexType name="ExpectCmdResultType">
<xs:complexType name="ValidateCommandResultType">
<xs:annotation>
<xs:documentation>Expects and validates a command result</xs:documentation>
</xs:annotation>
Expand Down
Loading

0 comments on commit 570e21d

Please sign in to comment.