Last active
November 18, 2016 19:14
-
-
Save geapi/31c75d845bc309011be9abea3f13602a to your computer and use it in GitHub Desktop.
example of using basic auth in RestTemplate call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tips.cloudnative.todotest; | |
// imports | |
import static tips.cloudnative.testauthentication.TestAuthentication.basicAuthHeaders; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
public class TodoTest { | |
@Test | |
public void testListTodos() { | |
RestTemplate restTemplate = new RestTemplate(); | |
HttpEntity<String> requestEntity = new HttpEntity<>(basicAuthHeaders()); | |
ResponseEntity<List<Todo>> response = restTemplate.exchange( | |
"http://localhost:" + port + "/todos", | |
HttpMethod.GET, | |
requestEntity, | |
Todo); | |
Todo returnedTodo = response.getBody(); | |
assertThat(returnedTodo).isEqualTo(new Todo(1L, "renew New York Times subscription", false))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment