Tabnine Logo
Fixture
Code IndexAdd Tabnine to your IDE (free)

How to use
Fixture
in
com.orhanobut.mockwebserverplus

Best Java code snippets using com.orhanobut.mockwebserverplus.Fixture (Showing top 8 results out of 315)

origin: orhanobut/mockwebserverplus

/**
 * Parse the given filename and returns the Fixture object.
 *
 * @param fileName filename should not contain extension or relative path. ie: login
 */
public static Fixture parseFrom(String fileName) {
 return parseFrom(fileName, new YamlParser());
}
origin: orhanobut/mockwebserverplus

/**
 * Parse the given filename and returns the Fixture object.
 *
 * @param fileName filename should not contain extension or relative path. ie: login
 * @param parser   parser is required for parsing operation, it should not be null
 */
public static Fixture parseFrom(String fileName, Parser parser) {
 if (fileName == null) {
  throw new NullPointerException("File name should not be null");
 }
 String path = "fixtures/" + fileName + ".yaml";
 InputStream inputStream = openPathAsStream(path);
 Fixture result = parser.parse(inputStream);
 if (result.body != null && !result.body.startsWith("{")) {
  String bodyPath = "fixtures/" + result.body;
  try {
   result.body = readPathIntoString(bodyPath);
  } catch (IOException e) {
   throw new IllegalStateException("Error reading body: " + bodyPath, e);
  }
 }
 return result;
}
origin: orhanobut/mockwebserverplus

/**
 * Given paths will be parsed to fixtures and added to the queue. Can be multiple
 */
public List<MockResponse> enqueue(String... paths) {
 if (paths == null) {
  return null;
 }
 List<MockResponse> mockResponseList = new ArrayList<>();
 for (String path : paths) {
  Fixture fixture = Fixture.parseFrom(path, parser);
  MockResponse mockResponse = fixture.toMockResponse();
  mockWebServer.enqueue(mockResponse);
  mockResponseList.add(mockResponse);
 }
 return mockResponseList;
}
origin: orhanobut/mockwebserverplus

private static String readPathIntoString(String path) throws IOException {
 InputStream inputStream = openPathAsStream(path);
 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
 StringBuilder out = new StringBuilder();
 int read;
 while ((read = reader.read()) != -1) {
  out.append((char) read);
 }
 reader.close();
 return out.toString();
}
origin: orhanobut/mockwebserverplus

@Test public void parseWithoutParser() {
 Fixture fixture = Fixture.parseFrom(Fixtures.SIMPLE_WITH_DELAY);
 assertThat(fixture.statusCode).isEqualTo(200);
 assertThat(fixture.delay).isEqualTo(300);
 assertThat(fixture.body).isEqualTo("{result:{}}");
 assertThat(fixture.headers).containsExactly("Auth:auth", "key:value");
}
origin: orhanobut/mockwebserverplus

@Test public void parseFixtureFromYaml() {
 Fixture fixture = Fixture.parseFrom(Fixtures.SIMPLE_WITH_DELAY, parser);
 assertThat(fixture.statusCode).isEqualTo(200);
 assertThat(fixture.delay).isEqualTo(300);
 assertThat(fixture.body).isEqualTo("{result:{}}");
 assertThat(fixture.headers).containsExactly("Auth:auth", "key:value");
}
origin: orhanobut/mockwebserverplus

@Test public void invalidPathThrowsExceptionOnParse() {
 try {
  Fixture.parseFrom("invalid_path", parser);
  fail("should fail");
 } catch (Exception e) {
  assertThat(e).hasMessage("Invalid path: fixtures/invalid_path.yaml");
 }
 try {
  Fixture.parseFrom(null, parser);
  fail("should fail");
 } catch (Exception e) {
  assertThat(e).hasMessage("File name should not be null");
 }
}
origin: orhanobut/mockwebserverplus

 @Test public void parseFixtureWithBodyReference() {
  Fixture fixture = Fixture.parseFrom(Fixtures.SIMPLE_BODY_FILE, parser);

  assertThat(fixture.statusCode).isEqualTo(200);
  assertThat(fixture.delay).isEqualTo(0);
  assertThat(fixture.body).isEqualTo("{\n" +
    "  \"array\": [\n" +
    "    1,\n" +
    "    2,\n" +
    "    3\n" +
    "  ],\n" +
    "  \"boolean\": true,\n" +
    "  \"null\": null,\n" +
    "  \"number\": 123,\n" +
    "  \"object\": {\n" +
    "    \"a\": \"b\",\n" +
    "    \"c\": \"d\",\n" +
    "    \"e\": \"f\"\n" +
    "  },\n" +
    "  \"string\": \"Hello World\"\n" +
    "}");
  assertThat(fixture.headers).containsExactly("Auth:auth", "key:value");
 }
}
com.orhanobut.mockwebserverplusFixture

Javadoc

A value container that holds all information about the fixture file.

Most used methods

  • parseFrom
    Parse the given filename and returns the Fixture object.
  • openPathAsStream
  • readPathIntoString
  • toMockResponse

Popular in Java

  • Updating database using SQL prepared statement
  • getResourceAsStream (ClassLoader)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now