Merge branch 'master' into update-links
This commit is contained in:
@@ -7,7 +7,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock)
|
||||
- [Using WireMock Scenarios](http://www.baeldung.com/using-wiremock-scenarios)
|
||||
- [Using WireMock Scenarios](https://www.baeldung.com/wiremock-scenarios)
|
||||
- [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing)
|
||||
- [Testing a REST API with JBehave](http://www.baeldung.com/jbehave-rest-testing)
|
||||
- [REST API Testing with Karate](http://www.baeldung.com/karate-rest-api-testing)
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package org.baeldung.rest;
|
||||
|
||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GithubBasicLiveTest {
|
||||
|
||||
// simple request - response
|
||||
|
||||
@Test
|
||||
public void givenUserDoesNotExists_whenUserInfoIsRetrieved_then404IsReceived() throws ClientProtocolException, IOException {
|
||||
// Given
|
||||
final String name = randomAlphabetic(8);
|
||||
final HttpUriRequest request = new HttpGet("https://api.github.com/users/" + name);
|
||||
|
||||
// When
|
||||
final HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request);
|
||||
|
||||
// Then
|
||||
assertThat(httpResponse.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_NOT_FOUND));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequestWithNoAcceptHeader_whenRequestIsExecuted_thenDefaultResponseContentTypeIsJson() throws ClientProtocolException, IOException {
|
||||
// Given
|
||||
final String jsonMimeType = "application/json";
|
||||
final HttpUriRequest request = new HttpGet("https://api.github.com/users/eugenp");
|
||||
|
||||
// When
|
||||
final HttpResponse response = HttpClientBuilder.create().build().execute(request);
|
||||
|
||||
// Then
|
||||
final String mimeType = ContentType.getOrDefault(response.getEntity()).getMimeType();
|
||||
assertEquals(jsonMimeType, mimeType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUserExists_whenUserInformationIsRetrieved_thenRetrievedResourceIsCorrect() throws ClientProtocolException, IOException {
|
||||
// Given
|
||||
final HttpUriRequest request = new HttpGet("https://api.github.com/users/eugenp");
|
||||
|
||||
// When
|
||||
final HttpResponse response = HttpClientBuilder.create().build().execute(request);
|
||||
|
||||
// Then
|
||||
final GitHubUser resource = RetrieveUtil.retrieveResourceFromResponse(response, GitHubUser.class);
|
||||
assertThat("eugenp", Matchers.is(resource.getLogin()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user