Skip to content

Commit

Permalink
Including null attributes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jan 27, 2018
1 parent 92ced8a commit 632b937
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Generic Webhook Plugin Changelog
Changelog of Generic Webhook Plugin.
## Unreleased
### GitHub [#31](https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/31) Wanna get all request body that payload body including null value

**Including null attributes #31**


[6829688da6c3d17](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/6829688da6c3d17) Tomas Bjerre *2018-01-27 13:07:46*


### No issue

**Removing newlines from assert in test**


[92ced8a3dc25a34](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/92ced8a3dc25a34) Tomas Bjerre *2018-01-03 12:33:36*


## 1.22 (2018-01-03 12:22:47)
### GitHub [#30](https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/30) Request: Supporting of JSON header without flattening

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import com.google.gson.GsonBuilder;

public class JsonFlattener {
private static Gson GSON = new GsonBuilder().create();
private static Gson GSON =
new GsonBuilder() //
.serializeNulls() //
.create();

public JsonFlattener() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ public void testJSONPathGetSeveralMixedListItems() throws Exception {
"[{\"name\":\"Administrator\"},{\"username\":\"root\"},\"a simple string\",33333,{\"a number\":\"a value\"},\"another simple string\",66666,{\"another number\":\"another value\"}]");
}

@Test
public void testJSONPathGetNullValues() throws Exception {
final Map<String, String> variables =
getJsonPathVariablesFromContent("$", "{\"a\": null,\"b\": \"value\"}");

assertThat(variables.get("variableName")) //
.isEqualTo("{\"a\":null,\"b\":\"value\"}");
}

@Test
public void testJSONPathGetAllVariable() throws Exception {
final String resourceName = "gitlab-mergerequest-comment.json";
Expand Down Expand Up @@ -344,6 +353,11 @@ private Map<String, String> getJsonPathVariables(
final String resourceName, final String jsonPath) {
final String postContent = getContent(resourceName);

return getJsonPathVariablesFromContent(jsonPath, postContent);
}

private Map<String, String> getJsonPathVariablesFromContent(
final String jsonPath, final String postContent) {
final String regexpFilter = "";
final List<GenericVariable> genericVariables =
newArrayList( //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void testXPathTwoListListItemsFirstBook() throws Exception {

assertThat(variables.get("book").replaceAll("\\r|\\n|\\s", "")) //
.isEqualTo(
"<book><page><number>1</number><content>content1</content></page><page><number>2</number><content>content2</content></page></book>");
"<book><page><number>1</number><content>content1</content></page><page><number>2</number><content>content2</content></page></book>");
}

@Test
Expand Down Expand Up @@ -298,7 +298,7 @@ public void testXPathRootElement() throws Exception {

assertThat(variables.get("book").replaceAll("\\r|\\n|\\s", "")) //
.isEqualTo(
"<bookstore><book><page><number>1</number><content>content1</content></page><page><number>2</number><content>content2</content></page></book><book><page><number>21</number><content>content21</content></page></book></bookstore>");
"<bookstore><book><page><number>1</number><content>content1</content></page><page><number>2</number><content>content2</content></page></book><book><page><number>21</number><content>content21</content></page></book></bookstore>");
}

@Test
Expand Down

0 comments on commit 632b937

Please sign in to comment.