Skip to content

Commit

Permalink
fix: support accessing query parameters for state handlebar extension
Browse files Browse the repository at this point in the history
- always call `toString` when accessing an option hash
- adding jar upload to build
  • Loading branch information
dirkbolte committed Apr 12, 2024
1 parent d960edb commit 8f4c882
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,24 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: build/reports/jacoco/
path: build/reports/jacoco/
archive:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
- name: Run the Gradle package task
uses: gradle/gradle-build-action@v2
with:
arguments: jar shadowjar
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: jars
path: |
build/libs/*.jar
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public StateHandlerbarHelper(ContextManager contextManager) {

@Override
public Object apply(Object o, Options options) {
String contextName = options.hash("context");
String property = options.hash("property");
String list = options.hash("list");
String defaultValue = options.hash("default");
String contextName = Optional.ofNullable(options.hash("context")).map(Object::toString).orElse(null);
String property = Optional.ofNullable(options.hash("property")).map(Object::toString).orElse(null);
String list = Optional.ofNullable(options.hash("list")).map(Object::toString).orElse(null);
String defaultValue = Optional.ofNullable(options.hash("default")).map(Object::toString).orElse(null);
if (StringUtils.isEmpty(contextName)) {
return handleError("'context' cannot be empty");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void postContext(String contextName, Map<String, Object> body) {
private void getContext(String contextName, Consumer<Map<String, Object>> assertion) {
Map<String, Object> result = given()
.accept(ContentType.JSON)
.get(assertDoesNotThrow(() -> new URI(String.format("%s/%s/%s", wm.getRuntimeInfo().getHttpBaseUrl(), "contexturl", contextName))))
.get(assertDoesNotThrow(() -> new URI(String.format("%s/%s/%s?contextName=%s", wm.getRuntimeInfo().getHttpBaseUrl(), "contexturl", contextName, contextName))))
.then()
.statusCode(HttpStatus.SC_OK)
.extract().body().as(mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class));
Expand Down Expand Up @@ -165,6 +165,7 @@ public void test_noExtensionUsage_ok() throws JsonProcessingException, URISyntax
public class ConfigurationErrors {

private final String contextName = "contextName";

@DisplayName("fails on missing context")
@Test
public void test_missingContext_fail() {
Expand Down Expand Up @@ -561,12 +562,43 @@ public void test_listSizeWithDefault() {
}
}

@DisplayName("with request query")
@Nested
public class RequestQuery {

private final String contextName = "aContextName";

@DisplayName("works for context")
@Test
void test_contextFromQuery() {
Map<String, Object> request = Map.of("contextValue", "aContextValue");
createContextStatePostStub(Map.of("contextValue", "{{jsonPath request.body '$.contextValue'}}"));
createContextGetStub(Map.of("contextValue", "{{state context=request.query.contextName property='contextValue'}}"));

postContext(contextName, request);
getContext(contextName, (result) -> assertThat(result).containsExactlyEntriesOf(request));
}

@DisplayName("works for property")
@Test
void test_contextFromProperty() {
Map<String, Object> request = Map.of("contextValue", "aContextValue");
createContextStatePostStub(Map.of(contextName, "{{jsonPath request.body '$.contextValue'}}"));
createContextGetStub(Map.of("contextValue", String.format("{{state context=request.query.contextName property='%s'}}", contextName)));

postContext(contextName, request);
getContext(contextName, (result) -> assertThat(result).containsExactlyEntriesOf(request));
}

}

@DisplayName("with existing property")
@Nested
public class ExistingProperty {

private final String contextName = "aContextName";


@DisplayName("returns property from previous request")
@Test
void test_returnsState() {
Expand Down

0 comments on commit 8f4c882

Please sign in to comment.