This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
File Path Specifications
Wade Pearce edited this page Jan 15, 2015
·
2 revisions
If your RAML specification exists on the file path you can create a specification instance by constructing a FilePathSpecification
.
RamlSpecification specification = new FilePathSpecification("my-service", "target/specifications/other-service/apispecs.yml");
public class MySpecificationTest {
@Rule
public MockServerRule server = new MockServerRule(5000, this);
private final static RamlSpecification SPECIFICATION = new FilePathSpecification("my-service", "target/specifications/other-service/apispecs.yml");
@BeforeClass
public static void setUpClass() {
SPECIFICATION.initialize();
}
@Test
public void shouldInteractWithServiceCorrectly() {
MockServiceClient client = new MockServiceClient("localhost", 5000);
client.when(
request()
.withPath("/hello/world")
.withMethod("GET")
.withHeaders(
new Header(HttpHeaders.ACCEPT, "text/plain"),
new Header(HttpHeaders.AUTHORIZATION, "Basic TOKEN1234")
)
).respond(
response()
.withStatusCode(200)
.withHeaders(
new Header(HttpHeaders.CONTENT_TYPE, "text/plain"
)
.withBody("Hello World!")
);
Client testClient = Client.create(new DefaultClientConfig());
ClientResponse response = testClient.resource("http://localhost:5000/hello/world").get(ClientResponse.class);
try {
assertThat(response.getStatus(), is(200));
assertThat(response.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE), is("text/plain"));
assertThat(response.getEntity(String.class), is("Hello world!"));
} finally {
response.close();
}
}
RamlSpecification.Result specificationResult = SPECIFICATION.obeyedBy(client);
assertTrue(specificationResult.getFormattedErrorMessage(), specificationResult.isValid());
}
- Home
- [RAML Specifications](RAML Specifications)
- [Class Path Specification](Class Path Specifications)
- [File Path Specification](File Path Specifications)
- [Remote Specification](Remote Path Specifications)
-
Handlers
- [Zip Archive](Zip Archive Handler)
- [RAML File](RAML File Handler)
- [Custom](Custom Resource Handler)
-
Handlers
- [Custom Specification](Custom Specification)
- [JUnit Test Rule](JUnit Test Rule)