-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...end/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
package com.now.naaga.temporaryplace.presentation; | ||
|
||
import com.now.naaga.temporaryplace.application.TemporaryPlaceService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/temporary-places") | ||
@RestController | ||
public class TemporaryPlaceController { | ||
|
||
private final TemporaryPlaceService temporaryPlaceService; | ||
|
||
public TemporaryPlaceController(final TemporaryPlaceService temporaryPlaceService) { | ||
this.temporaryPlaceService = temporaryPlaceService; | ||
} | ||
|
||
@DeleteMapping("/{temporaryPlaceId}") | ||
public ResponseEntity<Void> deleteTemporaryPlace(@PathVariable final Long temporaryPlaceId) { | ||
temporaryPlaceService.deleteById(temporaryPlaceId); | ||
return ResponseEntity | ||
.status(HttpStatus.NO_CONTENT) | ||
.build(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.now.naaga.temporaryplace.presentation; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.now.naaga.common.CommonControllerTest; | ||
import com.now.naaga.common.builder.TemporaryPlaceBuilder; | ||
import com.now.naaga.temporaryplace.domain.TemporaryPlace; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
@ActiveProfiles("test") | ||
class TemporaryPlaceControllerTest extends CommonControllerTest { | ||
|
||
@Autowired | ||
private TemporaryPlaceBuilder temporaryPlaceBuilder; | ||
|
||
@Value("${manager.id}") | ||
private String id; | ||
|
||
@Value("${manager.password}") | ||
private String password; | ||
|
||
@BeforeEach | ||
protected void setUp() { | ||
super.setUp(); | ||
} | ||
|
||
@Test | ||
void ID를_통한_삭제_요청이_성공하면_204_응답코드를_반환한다() { | ||
// given | ||
final TemporaryPlace temporaryPlace = temporaryPlaceBuilder.init() | ||
.build(); | ||
|
||
// when | ||
final ExtractableResponse<Response> extract = RestAssured.given() | ||
.log().all() | ||
.auth().preemptive().basic(id, password) | ||
.when() | ||
.delete("/temporary-places/{temporaryPlaceId}", temporaryPlace.getId()) | ||
.then() | ||
.log().all() | ||
.extract(); | ||
|
||
// then | ||
final int statusCode = extract.statusCode(); | ||
assertThat(statusCode).isEqualTo(HttpStatus.NO_CONTENT.value()); | ||
} | ||
} |