private boolean includeParametersInUri(OperationRequest request) { return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED .isCompatibleWith(request.getHeaders().getContentType())); }
private boolean includeParametersInUri(OperationRequest request) { return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED .isCompatibleWith(request.getHeaders().getContentType())); }
private boolean includeParametersInUri(OperationRequest request) { return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED .isCompatibleWith(request.getHeaders().getContentType())); }
@Override public OperationRequest preprocess(OperationRequest request) { byte[] modifiedContent = this.contentModifier.modifyContent(request.getContent(), request.getHeaders().getContentType()); return this.requestFactory.createFrom(request, modifiedContent); }
private boolean includeParametersAsFormOptions(OperationRequest request) { return request.getMethod() != HttpMethod.GET && (request.getContent().length == 0 || !MediaType.APPLICATION_FORM_URLENCODED .isCompatibleWith(request.getHeaders().getContentType())); }
@Test public void requestContentUriAnchorIsPreserved() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345#foo' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost#foo' should be used"); }
@Test public void modifyRequestContent() { OperationRequest request = this.requestFactory.create( URI.create("http://localhost"), HttpMethod.GET, "content".getBytes(), new HttpHeaders(), new Parameters(), Collections.<OperationRequestPart>emptyList()); OperationRequest preprocessed = this.preprocessor.preprocess(request); assertThat(preprocessed.getContent()).isEqualTo("modified".getBytes()); }
@Test public void requestContentUriHostCanBeModified() { this.preprocessor.host("api.example.com"); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://api.example.com:12345' should be used"); }
@Test public void requestContentUriQueryIsPreserved() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345?foo=bar' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost?foo=bar' should be used"); }
@Test public void requestContentUriAnchorIsPreserved() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345#foo' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost#foo' should be used"); }
@Test public void requestContentUriPortCanBeModified() { this.preprocessor.port(23456); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost:23456' should be used"); }
@Test public void requestContentUriSchemeCanBeModified() { this.preprocessor.scheme("https"); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'https://localhost:12345' should be used"); }
@Test public void requestContentUriHostCanBeModified() { this.preprocessor.host("api.example.com"); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://api.example.com:12345' should be used"); }
@Test public void requestContentUriPortCanBeRemoved() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost' should be used"); }
@Test public void requestContentUriSchemeCanBeModified() { this.preprocessor.scheme("https"); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'https://localhost:12345' should be used"); }
@Test public void multipleRequestContentUrisCanBeModified() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "Use 'http://localhost:12345' or 'https://localhost:23456' to access the service")); assertThat(new String(processed.getContent())).isEqualTo( "Use 'http://localhost' or 'https://localhost' to access the service"); }
@Test public void requestContentUriPortCanBeRemoved() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost' should be used"); }
@Test public void multipleRequestContentUrisCanBeModified() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "Use 'http://localhost:12345' or 'https://localhost:23456' to access the service")); assertThat(new String(processed.getContent())).isEqualTo( "Use 'http://localhost' or 'https://localhost' to access the service"); }
@Test public void requestContentUriPathIsPreserved() { this.preprocessor.removePort(); OperationRequest processed = this.preprocessor .preprocess(createRequestWithContent( "The uri 'http://localhost:12345/foo/bar' should be used")); assertThat(new String(processed.getContent())) .isEqualTo("The uri 'http://localhost/foo/bar' should be used"); }
@Test public void byteArrayInputStreamBody() { RequestSpecification requestSpec = RestAssured.given() .body(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 })) .port(tomcat.getPort()); requestSpec.post(); OperationRequest request = this.factory .convert((FilterableRequestSpecification) requestSpec); assertThat(request.getContent()).isEqualTo(new byte[] { 1, 2, 3, 4 }); }