Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,21 @@ public Builder requestOptions(RequestOptions requestOptions) {
*/
public GetFeaturesRequest build() {
if (this.requestOptions != null) {
// If requestOptions is set, use the constructor that accepts it
// If requestOptions is set and metadataOptions is or is not set (using a default if not
// set).
Set<MetadataOption> options =
this.metadataOptions.isEmpty()
? RequestConstants.DEFAULT_METADATA_OPTIONS
: this.metadataOptions;
return new GetFeaturesRequest(
workspaceName, featureServiceName, getFeaturesRequestData, options, requestOptions);
} else if (this.metadataOptions.isEmpty()) {
// If requestOptions is not set and metadataOptions is empty, use the constructor that does
// not take metadataOptions.
return new GetFeaturesRequest(workspaceName, featureServiceName, getFeaturesRequestData);
} else {
// If requestOptions is not set and metadataOptions is not empty, use the constructor that
// takes metadataOptions.
return new GetFeaturesRequest(
workspaceName, featureServiceName, getFeaturesRequestData, metadataOptions);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/ai/tecton/client/request/RequestOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public RequestOptions() {
* @throws IllegalArgumentException if value is not Integer or Boolean
*/
public RequestOptions setOption(String key, Object value) {
if (value != null && !(value instanceof Integer) && !(value instanceof Boolean)) {
throw new IllegalArgumentException(
"Option value must be either Integer or Boolean, got: "
+ value.getClass().getSimpleName());
if (value == null) {
throw new IllegalArgumentException("Option value must not be null: " + key);
}
this.options.put(key, value);
return this;
Expand Down
57 changes: 3 additions & 54 deletions src/test/java/ai/tecton/client/request/RequestOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,6 @@ public void testRequestOptionsCreation() {
assertTrue(options.isEmpty());
}

@Test
public void testIntegerOptionSetting() {
RequestOptions options = new RequestOptions();
options.setOption("latency_budget_ms", 1000);

assertEquals(Integer.valueOf(1000), options.getIntegerOption("latency_budget_ms"));
assertEquals(Integer.valueOf(1000), options.getOption("latency_budget_ms"));
assertFalse(options.isEmpty());
assertEquals(1, options.getOptions().size());
}

@Test
public void testBooleanOptionSetting() {
RequestOptions options = new RequestOptions();
options.setOption("coerceNullCountsToZero", true);

assertEquals(Boolean.TRUE, options.getBooleanOption("coerceNullCountsToZero"));
assertEquals(Boolean.TRUE, options.getOption("coerceNullCountsToZero"));
assertFalse(options.isEmpty());
}

@Test
public void testMultipleBooleanOptions() {
RequestOptions options = new RequestOptions();
options.setOption("readFromCache", true);
options.setOption("writeFromCache", false);
options.setOption("ignoreExtraRequestContextFields", true);

assertEquals(Boolean.TRUE, options.getBooleanOption("readFromCache"));
assertEquals(Boolean.FALSE, options.getBooleanOption("writeFromCache"));
assertEquals(Boolean.TRUE, options.getBooleanOption("ignoreExtraRequestContextFields"));
assertEquals(3, options.getOptions().size());
}

@Test
public void testMixedIntegerAndBooleanOptions() {
RequestOptions options = new RequestOptions();
options.setOption("latency_budget_ms", 5000);
options.setOption("coerceNullCountsToZero", false);

assertEquals(Integer.valueOf(5000), options.getIntegerOption("latency_budget_ms"));
assertEquals(Boolean.FALSE, options.getBooleanOption("coerceNullCountsToZero"));
assertEquals(2, options.getOptions().size());
}

@Test(expected = IllegalArgumentException.class)
public void testInvalidValueTypeThrowsException() {
RequestOptions options = new RequestOptions();
options.setOption("invalid_option", "string_value");
}

@Test
public void testBuilder() {
RequestOptions options =
Expand All @@ -72,9 +21,9 @@ public void testBuilder() {
.option("writeFromCache", false)
.build();

assertEquals(Integer.valueOf(2000), options.getIntegerOption("latency_budget_ms"));
assertEquals(Boolean.TRUE, options.getBooleanOption("readFromCache"));
assertEquals(Boolean.FALSE, options.getBooleanOption("writeFromCache"));
assertEquals(2000, options.getOption("latency_budget_ms"));
assertEquals(true, options.getOption("readFromCache"));
assertEquals(false, options.getOption("writeFromCache"));
assertEquals(3, options.getOptions().size());
}

Expand Down