Giter VIP home page Giter VIP logo

Comments (16)

BrainStone avatar BrainStone commented on June 3, 2024 1

Ok. Will give that a shot.
Thanks very much!

from hoverfly-java.

BrainStone avatar BrainStone commented on June 3, 2024 1

That worked great!

Looking forward to having that being done automatically.

For people that might stumble across this in the future, here is my code:

public class TestApi {
  private static final String simulationFile = "simulation.json";

  @ClassRule
  public static final HoverflyRule hoverflyRule =
      HoverflyRule.inSimulationMode(
          SimulationSource.defaultPath(simulationFile),
          HoverflyConfig.localConfigs()
              .addCommands(
                  "-response-body-files-path",
                  getPathOfResource(simulationFile).getParent().toAbsolutePath().toString()));

  private static URL findResourceOnClasspath(String resourceName) {
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    return Optional.ofNullable(classLoader.getResource(resourceName))
        .orElseThrow(
            () -> new IllegalArgumentException("Resource not found with name: " + resourceName));
  }

  @SneakyThrows(URISyntaxException.class)
  private static Path getPathOfResource(String resource) {
    return Paths.get(
        findResourceOnClasspath(HoverflyConstants.DEFAULT_HOVERFLY_RESOURCE_DIR + '/' + resource)
            .toURI());
  }
}

(@SneakyThrows is from lombok. If you don't have that, just catch the exception and rethrow it wrapped in a RuntimeException)

from hoverfly-java.

BrainStone avatar BrainStone commented on June 3, 2024

Issue still present on 0.14.0

from hoverfly-java.

tommysitu avatar tommysitu commented on June 3, 2024

👀

from hoverfly-java.

tommysitu avatar tommysitu commented on June 3, 2024

@BrainStone we haven't supported the bodyFile feature in hoverfly-java properly yet. In hoverfly, there is a flag you can set the relative file path of a body file:

  -response-body-files-path string
    	When a response contains a relative bodyFile, it will be resolved against this path (default is CWD)

will try to add the support to this in the next release

from hoverfly-java.

BrainStone avatar BrainStone commented on June 3, 2024

Awesome. When could I expect that to be done?

And excuse the question but is there a way to specify the flag when doing unit tests?

from hoverfly-java.

tommysitu avatar tommysitu commented on June 3, 2024

There are two workarounds actually:

  1. you can copy hoverfly binary to your test resource folder, and set its location with this config:
localConfigs().binaryLocation("/absolute/path/to/hoverfly/directory")
  1. or you can pass hoverfly flag using this config
localConfigs().addCommands("-response-body-files-path", "/absolute/path/to/your/test/resource/folder")

from hoverfly-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.