Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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());
    }
}
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #testing #web #layer #authentication #spring
ADD COMMENT
Topic
Name
5+3 =