Skip to content

Commit

Permalink
feat: support for DSL-like configuration specification
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkbolte committed Mar 29, 2024
1 parent ce9ff80 commit cc706e3
Show file tree
Hide file tree
Showing 18 changed files with 695 additions and 150 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ The state is recorded in `serveEventListeners` of a stub. The following function
- to delete a selective property, set it to `null` (as string).
- `list` : stores a state in a list. Can be used to prepend/append new states to an existing list. List elements cannot be modified (only read/deleted).

`state` and `list` can be used in the same `ServeEventListener` (would count as ONE updates). Adding multiple `recordState` `ServeEventListener` is supported.
`state` and `list` can be used in the same `ServeEventListener` (would count as ONE update). Adding multiple `recordState` `ServeEventListener` is supported.

The following parameters have to be provided:

Expand Down
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id 'jacoco'
id 'com.diffplug.spotless' version '6.25.0'
id 'org.wiremock.tools.gradle.wiremock-extension-convention' version '0.1.2'
id 'org.jetbrains.kotlin.jvm' version '1.9.22'
}

group 'org.wiremock.extensions'
Expand All @@ -17,8 +18,15 @@ project.ext {
]
}


sourceSets {
test.java.srcDirs += 'src/test/java'
test.kotlin.srcDirs += 'src/test/kotlin'
}

dependencies {
implementation("com.github.ben-manes.caffeine:caffeine:${versions.caffeine}")
implementation("org.wiremock:wiremock:3.3.3")
implementation("com.github.jknack:handlebars-helpers:${versions.handlebars}") {
exclude group: 'org.mozilla', module: 'rhino'
}
Expand All @@ -32,6 +40,15 @@ shadowJar {
test {
finalizedBy jacocoTestReport
}

kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(11)
implementation = JvmImplementation.J9
}
}


jacocoTestReport {
dependsOn test
reports {
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
*/
public class DeleteStateEventListener implements ServeEventListener, StateExtensionMixin {

public final static String NAME = "deleteState";

private final TemplateEngine templateEngine;
private final ContextManager contextManager;

Expand All @@ -58,7 +60,7 @@ public DeleteStateEventListener(ContextManager contextManager, TemplateEngine te

@Override
public String getName() {
return "deleteState";
return NAME;
}

@Override
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/wiremock/extensions/state/extensions/Dsl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.wiremock.extensions.state.extensions;


import org.jetbrains.annotations.NotNull;
import org.wiremock.extensions.state.extensions.builder.DeleteStateEventListenerBuilder;
import org.wiremock.extensions.state.extensions.builder.DeleteStateEventListenerBuilder.MultiContextBuilder;
import org.wiremock.extensions.state.extensions.builder.DeleteStateEventListenerBuilder.SingleContextBuilder;
import org.wiremock.extensions.state.extensions.builder.RecordStateEventListenerBuilder;
import org.wiremock.extensions.state.extensions.builder.StateRequestMatcherBuilder;
import org.wiremock.extensions.state.extensions.builder.StateRequestMatcherBuilder.HasContextBuilder;
import org.wiremock.extensions.state.extensions.builder.StateRequestMatcherBuilder.HasNotContextBuilder;

import java.util.Arrays;
import java.util.Collection;

public class Dsl {

public static @NotNull RecordStateEventListenerBuilder recordContext(@NotNull String context) {
return RecordStateEventListenerBuilder.context(context);
}

public static @NotNull SingleContextBuilder deleteContext(@NotNull String context) {
return DeleteStateEventListenerBuilder.context(context);
}

public static @NotNull MultiContextBuilder deleteContexts(@NotNull String... contexts) {
return DeleteStateEventListenerBuilder.contexts(Arrays.asList(contexts));
}

public static @NotNull MultiContextBuilder deleteContexts(@NotNull Collection<String> contexts) {
return DeleteStateEventListenerBuilder.contexts(contexts);
}

public static @NotNull MultiContextBuilder deleteContextsMatching(@NotNull String contextMatching) {
return DeleteStateEventListenerBuilder.contextsMatching(contextMatching);
}

public static @NotNull HasContextBuilder hasContext(@NotNull String context) {
return StateRequestMatcherBuilder.hasContext(context);
}

public static @NotNull HasNotContextBuilder hasNotContext(@NotNull String context) {
return StateRequestMatcherBuilder.hasNotContext(context);
}
}
Loading

0 comments on commit cc706e3

Please sign in to comment.