Skip to content

Commit

Permalink
Fixes #277 JSONPath validator array length
Browse files Browse the repository at this point in the history
- Use List instead of Set to not ignore duplicate entries
- Add unit and integration tests for this scenario
  • Loading branch information
Christian Guggenmos committed Aug 4, 2017
1 parent a7f99a4 commit d8722a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
Expand Up @@ -22,11 +22,16 @@
import com.consol.citrus.validation.matcher.ValidationMatcher;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.springframework.util.*;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -173,14 +178,14 @@ private Matcher getMatcher(String matcherName, String[] matcherParameter) {
* @param value
* @return
*/
private Set<String> getCollection(String value) {
private List<String> getCollection(String value) {
String arrayString = value;

if (arrayString.startsWith("[") && arrayString.endsWith("]")) {
arrayString = arrayString.substring(1, arrayString.length()-1);
}

return StringUtils.commaDelimitedListToSet(arrayString);
return Arrays.asList(StringUtils.commaDelimitedListToStringArray(arrayString));
}

/**
Expand Down
Expand Up @@ -68,7 +68,9 @@ public Object[][] testData() {
new Object[]{"foo", "9", Collections.singletonList("lessThanOrEqualTo(9)")},
new Object[]{"foo", "", Arrays.asList("1", "lessThanOrEqualTo(9)")},
new Object[]{"foo", "", Arrays.asList("9", "lessThanOrEqualTo(9)")},
new Object[]{"foo", "[value1,value2,value3,value4,value5]", Collections.singletonList("hasSize(5)") }
new Object[]{"foo", "[value1,value2,value3,value4,value5]", Collections.singletonList("hasSize(5)") },
new Object[]{"foo", "[\"unique_value\",\"different_unique_value\"]", Collections.singletonList("hasSize(2)") },
new Object[]{"foo", "[\"duplicate_value\",\"duplicate_value\"]", Collections.singletonList("hasSize(2)") }
};
}

Expand Down Expand Up @@ -113,4 +115,4 @@ public Object[][] testDataFailed() {
new Object[]{"foo", "[value1,value2]", Collections.singletonList("hasSize(5)") }
};
}
}
}
Expand Up @@ -22,14 +22,23 @@
<http:send-request client="httpClient">
<http:POST>
<http:body>
<http:data>
{
"type" : "read",
"mbean" : "java.lang:type=Memory",
"attribute" : "HeapMemoryUsage",
"path" : "used",
"lastModified": null
}
<http:data>{
"type": "read",
"mbean": "java.lang:type=Memory",
"attribute": "HeapMemoryUsage",
"path": "used",
"lastModified": null,
"test_array": [
{
"key_with_identical_values": "identical_value",
"key_with_unique_values": "unique_value"
},
{
"key_with_identical_values": "identical_value",
"key_with_unique_values": "different_unique_value"
}
]
}
</http:data>
</http:body>
</http:POST>
Expand All @@ -45,6 +54,8 @@
<http:json-path expression="$..attribute" value="HeapMemoryUsage"/>
<http:json-path expression="$.path" value="@equalsIgnoreCase('USED')@"/>
<http:json-path expression="$.lastModified" value="@assertThat(nullValue())@"/>
<http:json-path expression="$..key_with_identical_values" value="@assertThat(hasSize(2))@"/>
<http:json-path expression="$..key_with_unique_values" value="@assertThat(hasSize(2))@"/>
</http:validate>
</http:body>
</http:POST>
Expand Down Expand Up @@ -108,4 +119,4 @@

</actions>
</testcase>
</spring:beans>
</spring:beans>

0 comments on commit d8722a6

Please sign in to comment.