Skip to content

Commit

Permalink
Using full enum type instead of String in Stream creation request.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers committed Jul 13, 2015
1 parent ec82b2f commit 7441478
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import org.graylog2.plugin.streams.Stream;
import org.graylog2.rest.resources.streams.rules.requests.CreateStreamRuleRequest;
import org.hibernate.validator.constraints.NotEmpty;

Expand All @@ -46,14 +47,14 @@ public abstract class CreateStreamRequest {

@JsonProperty
@Nullable
public abstract String matchingType();
public abstract Stream.MatchingType matchingType();

@JsonCreator
public static CreateStreamRequest create(@JsonProperty("title") @NotEmpty String title,
@JsonProperty("description") @Nullable String description,
@JsonProperty("rules") @Nullable List<CreateStreamRuleRequest> rules,
@JsonProperty("content_pack") @Nullable String contentPack,
@JsonProperty("matching_type") @Nullable String matchingType) {
@JsonProperty("matching_type") @Nullable Stream.MatchingType matchingType) {
return new AutoValue_CreateStreamRequest(title, description, rules, contentPack, matchingType);
}
}
Expand Up @@ -95,7 +95,7 @@ public Stream create(CreateStreamRequest cr, String userId) {
streamData.put(StreamImpl.FIELD_CREATOR_USER_ID, userId);
streamData.put(StreamImpl.FIELD_CREATED_AT, Tools.iso8601());
streamData.put(StreamImpl.FIELD_CONTENT_PACK, cr.contentPack());
streamData.put(StreamImpl.FIELD_MATCHING_TYPE, Stream.MatchingType.valueOfOrDefault(cr.matchingType()).toString());
streamData.put(StreamImpl.FIELD_MATCHING_TYPE, cr.matchingType().toString());

return create(streamData);
}
Expand Down
Expand Up @@ -213,12 +213,9 @@ public void creatingInvalidStreamShouldFail() throws Exception {
@Test
public void creatingInvalidMatchingStreamShouldFail() throws Exception {
final int beforeCount = streamCount();
final String streamTitle = "Another Test Stream";
final String description = "This is a test stream.";
final String matchingType = "OR";

final ValidatableResponse response = createStreamFromRequest(jsonResourceForMethod());
response.statusCode(400);
createStreamFromRequest(jsonResourceForMethod())
.statusCode(400);

final int afterCount = streamCount();
assertThat(afterCount).isEqualTo(beforeCount);
Expand Down

0 comments on commit 7441478

Please sign in to comment.