Skip to content

Commit

Permalink
remove default input/output from header constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jam01 committed Dec 2, 2020
1 parent 1e71543 commit 4e4e685
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/main/java/com/datasonnet/header/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,14 @@ public class Header {
public Header(String version,
boolean preserveOrder,
Map<String, Collection<MediaType>> namedInputs,
Map<String, MediaType> defaultInputs,
List<MediaType> outputs,
MediaType defaultOutput,
Iterable<MediaType> allInputs,
Iterable<MediaType> dataFormats) {
String[] versions = version.split("\\.",2); //[0] = major [1] = minor + remainder if exists
this.versionMajor = versions[0];
this.versionMinor = versions[1];
this.preserveOrder = preserveOrder;
this.defaultInputs = new HashMap<>(defaultInputs);
this.defaultInputs = new HashMap<>();
this.namedInputs = new HashMap<>();

for (Map.Entry<String, Collection<MediaType>> entry : namedInputs.entrySet()) {
Expand All @@ -91,12 +89,12 @@ public Header(String version,
}

this.outputs = indexMediaTypes(outputs);
if (defaultOutput == null && outputs.size() > 0) {
if (outputs.size() > 0) {
List<MediaType> sorted = new ArrayList<>(outputs);
MediaType.sortByQualityValue(sorted);
this.defaultOutput = sorted.get(0);
} else {
this.defaultOutput = defaultOutput;
this.defaultOutput = MediaTypes.ANY;
}

this.allInputs = indexMediaTypes(allInputs);
Expand All @@ -116,7 +114,7 @@ private Integer calculateIndex(MediaType mediaType) {
}

private static final Header EMPTY =
new Header(LATEST_RELEASE_VERSION, true, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), MediaTypes.ANY, Collections.emptyList(), Collections.emptyList());
new Header(LATEST_RELEASE_VERSION, true, Collections.emptyMap(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());

public static Header parseHeader(String script) throws HeaderParseException {
if (!script.trim().startsWith(DATASONNET_HEADER)) {
Expand Down Expand Up @@ -220,9 +218,7 @@ public JPropPathSplitter pathSplitter() {
return new Header("1.0",
getBoolean(propsMap,DATASONNET_PRESERVE_ORDER, true),
inputs,
Collections.emptyMap(),
output,
null,
allInputs,
dataFormat);
} catch (IOException|IllegalArgumentException exc) {
Expand Down Expand Up @@ -312,7 +308,7 @@ private static Header parseHeader20(String headerSection, String version) throws
}
}

return new Header(version, preserve, Collections.unmodifiableMap(inputs), Collections.emptyMap(), outputs, null, allInputs, dataformat);
return new Header(version, preserve, Collections.unmodifiableMap(inputs), outputs, allInputs, dataformat);
}

@NotNull
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/datasonnet/HeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void testUnterminatedHeaderFailsNicely() {
}

@Test
public void test_default_output() throws HeaderParseException {
public void testDefaultOutput() throws HeaderParseException {
Header header1 = Header.parseHeader("/** DataSonnet\n" +
"version=2.0\n" +
"output application/x-java-object;q=0.9\n" +
Expand All @@ -156,11 +156,11 @@ public void test_default_output() throws HeaderParseException {
}

@Test
public void test_default_input() throws HeaderParseException {
public void testDefaultInput() throws HeaderParseException {
Header header1 = Header.parseHeader("/** DataSonnet\n" +
"version=2.0\n" +
"input payload application/json;q=0.9\n" +
"input payload application/x-java-object;q=1.0\n" +
"input payload application/json;q=0.9\n" +
"*/");

assertTrue(header1.getDefaultPayload().isPresent());
Expand Down

0 comments on commit 4e4e685

Please sign in to comment.