Skip to content

Commit

Permalink
Merge pull request #143 from jenkinsci/eventScopeDeserialization
Browse files Browse the repository at this point in the history
JENKINS-40155: Fix event's scope deserialization
  • Loading branch information
olivierdagenais committed Dec 31, 2016
2 parents aa7b022 + 35ad535 commit b82787a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
@@ -1,5 +1,11 @@
package hudson.plugins.tfs.model.servicehooks;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

public enum EventScope {
/**
* No input scope specified.
Expand Down Expand Up @@ -30,4 +36,28 @@ public enum EventScope {
* Deployment scope.
*/
Deployment,

;

private static final Map<String, EventScope> CASE_INSENSITIVE_LOOKUP;

static {
final Map<String, EventScope> map = new TreeMap<String, EventScope>(String.CASE_INSENSITIVE_ORDER);
for (final EventScope value : EventScope.values()) {
map.put(value.name(), value);
}
CASE_INSENSITIVE_LOOKUP = Collections.unmodifiableMap(map);
}

@SuppressWarnings("unused" /* Invoked by Jackson via @JsonCreator */)
@JsonCreator
public static EventScope caseInsensitiveValueOf(final String name) {
if (name == null) {
throw new NullPointerException("Name is null");
}
if (!CASE_INSENSITIVE_LOOKUP.containsKey(name)) {
throw new IllegalArgumentException("No enum constant " + name);
}
return CASE_INSENSITIVE_LOOKUP.get(name);
}
}
Expand Up @@ -2,6 +2,7 @@
"id": "6872ee8c-b333-4eff-bfb9-0d5274943566",
"eventType": "git.pullrequest.merged",
"publisherId": "tfs",
"scope": "all",
"message": {
"text": "Jamal Hartnett has created a pull request merge commit",
"html": "Jamal Hartnett has created a pull request merge commit",
Expand Down
Expand Up @@ -2,6 +2,7 @@
"id": "03c164c2-8912-4d5e-8009-3707d5f83734",
"eventType": "git.push",
"publisherId": "tfs",
"scope": "all",
"message": {
"text": "Jamal Hartnett pushed updates to branch master of repository Fabrikam-Fiber-Git.",
"html": "Jamal Hartnett pushed updates to branch master of repository Fabrikam-Fiber-Git.",
Expand Down
@@ -0,0 +1,21 @@
package hudson.plugins.tfs.model.servicehooks;

import hudson.plugins.tfs.util.EndpointHelper;
import org.junit.Assert;
import org.junit.Test;

/**
* A class to test {@link EventScope}.
*/
public class EventScopeTest {

@Test
public void deserialize_enumCasing() throws Exception {
final String input = "{\"scope\": \"all\"}";

final Event actual = EndpointHelper.MAPPER.readValue(input, Event.class);

Assert.assertEquals(EventScope.All, actual.getScope());
}

}
Expand Up @@ -2,6 +2,7 @@
"id": "03c164c2-8912-4d5e-8009-3707d5f83734",
"eventType": "git.push",
"publisherId": "tfs",
"scope": "all",
"message": {
"text": "Jamal Hartnett pushed updates to branch master of repository Fabrikam-Fiber-Git.",
"html": "Jamal Hartnett pushed updates to branch master of repository Fabrikam-Fiber-Git.",
Expand Down

0 comments on commit b82787a

Please sign in to comment.