Answers for "spring boot gradle project with integration test mockmvc and mock bean example"

0

testing the web layer without authentication spring

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SecuredControllerRestTemplateIntegrationTest {
 
    @Autowired
    private TestRestTemplate template;
 
    // ... other methods
 
    @Test
    public void givenAuthRequestOnPrivateService_shouldSucceedWith200() throws Exception {
        ResponseEntity<String> result = template.withBasicAuth("spring", "secret")
          .getForEntity("/private/hello", String.class);
        assertEquals(HttpStatus.OK, result.getStatusCode());
    }
}
Posted by: Guest on May-22-2020

Code answers related to "spring boot gradle project with integration test mockmvc and mock bean example"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language