All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.gc.aafc.dina.testsupport.jsonapi.JsonAPIOperationBuilder Maven / Gradle / Ivy

The newest version!
package ca.gc.aafc.dina.testsupport.jsonapi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.http.HttpMethod;

/**
 * Helper builder to create CRNK Operation map.
 */
public final class JsonAPIOperationBuilder {

  private final List> operations = new ArrayList<>();

  private JsonAPIOperationBuilder() {
  }

  public static JsonAPIOperationBuilder newBuilder() {
    return new JsonAPIOperationBuilder();
  }

  /**
   * Add an operation to the current builder instance.
   * @param method
   * @param path
   * @param values usually comes from JsonAPITestHelper.toJsonAPIMap
   * @return
   */
  public JsonAPIOperationBuilder addOperation(HttpMethod method, String path, Map values) {
    Map operationsMap = Map.of(
      "op", method.name(),
      "path", path,
      // since toJsonAPIMap returns the value under "data" we remove it if present
      "value", values.getOrDefault("data", values)
    );

    operations.add(operationsMap);

    return this;
  }

  public List> buildOperation() {
    return Collections.unmodifiableList(operations);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy