Skip to content

Commit

Permalink
Allow empty watch or include projections in config gen
Browse files Browse the repository at this point in the history
  • Loading branch information
alechenninger committed Jun 3, 2016
1 parent 8d1c082 commit 11732d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.redhat.lightblue.client.Projection;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
* Defines notification hook configuration for a given entity using client-side constructs defined
* in lightblue-client library for building projection JSON.
Expand All @@ -24,8 +27,8 @@ static Builder forEntity(String entityName) {
final class Builder {
private final String entityName;

private Projection watchProjection = null;
private Projection includeProjection = null;
private Projection watchProjection = Projection.project();
private Projection includeProjection = Projection.project();
private boolean arrayOrderingSignificant = false;

private Builder(String entityName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.esbtools.lightbluenotificationhook;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -38,4 +39,28 @@ public void shouldWriteHookConfiguration() throws IllegalAccessException, IOExce
assertEquals("includedField", jsonConfig.get("includeProjection").get("field").textValue());
assertTrue(jsonConfig.get("arrayOrderingSignificant").booleanValue());
}

@Test
public void shouldWriteEmptyHookConfiguration() throws Exception {
Files.createDirectory(fileSystem.getPath("test/"));

main.writeHookConfigurationForClass(
HasEmptyHookConfiguration.class.getName(),
MainTest.class.getClassLoader(),
fileSystem.getPath("test/"));

Path expectedResult = fileSystem.getPath("test/testNotificationHookConfiguration.json");
JsonNode jsonConfig = mapper.readTree(Files.newBufferedReader(expectedResult));

assertEquals(0, jsonConfig.get("watchProjection").size());
assertEquals(0, jsonConfig.get("includeProjection").size());
assertFalse(jsonConfig.get("arrayOrderingSignificant").booleanValue());
}

static class HasEmptyHookConfiguration {
@GeneratesNotificationHookConfiguration
static EntityNotificationHookConfiguration emptyConfig = EntityNotificationHookConfiguration
.forEntity("test")
.build();
}
}

0 comments on commit 11732d5

Please sign in to comment.