@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@SpringBootTest
@AutoConfigureWebTestClient
class BeerEndpointTest {
@Autowired
WebTestClient webTestClient;
@Test
void testPatchIdNotFound() {
webTestClient
.mutateWith(mockOAuth2Login())
.patch()
.uri(BeerRouterConfig.BEER_PATH_ID, 999)
.body(Mono.just(BeerServiceImplTest.getTestBeer()), BeerDTO.class)
.exchange()
.expectStatus().isNotFound();
}
@Test
void testPatchIdFound() {
BeerDTO beerDTO = getSavedTestBeer();
webTestClient
.mutateWith(mockOAuth2Login())
.patch()
.uri(BeerRouterConfig.BEER_PATH_ID, beerDTO.getId())
.body(Mono.just(beerDTO), BeerDTO.class)
.exchange()
.expectStatus().isNoContent();
}
@Test
void testDeleteNotFound() {
webTestClient
.mutateWith(mockOAuth2Login())
.delete()
.uri(BeerRouterConfig.BEER_PATH_ID, 999)
.exchange()
.expectStatus().isNotFound();
}
@Test
@Order(999)
void testDeleteBeer() {
BeerDTO beerDTO = getSavedTestBeer();
webTestClient
.mutateWith(mockOAuth2Login())
.delete()
.uri(BeerRouterConfig.BEER_PATH_ID, beerDTO.getId())
.exchange()
.expectStatus()
.isNoContent();
}
@Test
@Order(4)
void testUpdateBeerBadRequest() {
BeerDTO testBeer = getSavedTestBeer();
testBeer.setBeerStyle("");
webTestClient
.mutateWith(mockOAuth2Login())
.put()
.uri(BeerRouterConfig.BEER_PATH_ID, testBeer)
.body(Mono.just(testBeer), BeerDTO.class)
.exchange()
.expectStatus().isBadRequest();
}
@Test
void testUpdateBeerNotFound() {
webTestClient
.mutateWith(mockOAuth2Login())
.put()
.uri(BeerRouterConfig.BEER_PATH_ID, 999)
.body(Mono.just(BeerServiceImplTest.getTestBeer()), BeerDTO.class)
.exchange()
.expectStatus().isNotFound();
}
@Test
@Order(3)
void testUpdateBeer() {
BeerDTO beerDTO = getSavedTestBeer();
beerDTO.setBeerName("New");
webTestClient
.mutateWith(mockOAuth2Login())
.put()
.uri(BeerRouterConfig.BEER_PATH_ID, beerDTO.getId())
.body(Mono.just(beerDTO), BeerDTO.class)
.exchange()
.expectStatus().isNoContent();
}
@Test
void testCreateBeerBadData() {
Beer testBeer = BeerServiceImplTest.getTestBeer();
testBeer.setBeerName("");
webTestClient
.mutateWith(mockOAuth2Login())
.post().uri(BeerRouterConfig.BEER_PATH)
.body(Mono.just(testBeer), BeerDTO.class)
.header("Content-Type", "application/json")
.exchange()
.expectStatus().isBadRequest();
}
@Test
void testCreateBeer() {
BeerDTO testDto = getSavedTestBeer();
webTestClient
.mutateWith(mockOAuth2Login())
.post().uri(BeerRouterConfig.BEER_PATH)
.body(Mono.just(testDto), BeerDTO.class)
.header("Content-Type", "application/json")
.exchange()
.expectStatus().isCreated()
.expectHeader().exists("location");
}
@Test
void testGetByIdNotFound() {
webTestClient
.mutateWith(mockOAuth2Login())
.get().uri(BeerRouterConfig.BEER_PATH_ID, 999)
.exchange()
.expectStatus().isNotFound();
}
@Test
@Order(1)
void testGetById() {
BeerDTO beerDTO = getSavedTestBeer();
webTestClient
.mutateWith(mockOAuth2Login())
.get().uri(BeerRouterConfig.BEER_PATH_ID, beerDTO.getId())
.exchange()
.expectStatus().isOk()
.expectHeader().valueEquals("Content-type", "application/json")
.expectBody(BeerDTO.class);
}
}