-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into feat/#483
- Loading branch information
Showing
13 changed files
with
325 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
backend/src/test/java/com/festago/acceptance/CucumberClient.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,39 @@ | ||
package com.festago.acceptance; | ||
|
||
import io.cucumber.spring.ScenarioScope; | ||
import io.restassured.response.Response; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ScenarioScope | ||
public class CucumberClient { | ||
|
||
private Map<String, Object> dataStorage = new HashMap<>(); | ||
private Response response; | ||
private String token; | ||
|
||
public CucumberClient() { | ||
} | ||
|
||
public void addData(String key, Object value) { | ||
dataStorage.put(key, value); | ||
} | ||
|
||
public void addAuthToken(String token) { | ||
this.token = token; | ||
} | ||
|
||
public Object getData(String key) { | ||
return dataStorage.get(key); | ||
} | ||
|
||
public Response getResponse() { | ||
return response; | ||
} | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/test/java/com/festago/acceptance/CucumberSpringConfiguration.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,26 @@ | ||
package com.festago.acceptance; | ||
|
||
import io.cucumber.java.Before; | ||
import io.cucumber.spring.CucumberContextConfiguration; | ||
import io.restassured.RestAssured; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
|
||
@CucumberContextConfiguration | ||
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) | ||
public class CucumberSpringConfiguration { | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@Autowired | ||
private DataInitializer dataInitializer; | ||
|
||
@Before | ||
public void before() { | ||
dataInitializer.execute(); | ||
RestAssured.port = port; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
backend/src/test/java/com/festago/acceptance/DataInitializer.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,83 @@ | ||
package com.festago.acceptance; | ||
|
||
import java.sql.DatabaseMetaData; | ||
import java.sql.ResultSet; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import javax.sql.DataSource; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@Profile("test") | ||
public class DataInitializer implements InitializingBean { | ||
|
||
@Autowired | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
private List<String> tableNames; | ||
|
||
private Set<String> metaTableNames = Set.of( | ||
"sys_config", | ||
"flyway_schema_history", | ||
"CONSTANTS", | ||
"ENUM_VALUES", | ||
"INDEXES", | ||
"INDEX_COLUMNS", | ||
"INFORMATION_SCHEMA_CATALOG_NAME", | ||
"IN_DOUBT", | ||
"LOCKS", | ||
"QUERY_STATISTICS", | ||
"RIGHTS", | ||
"ROLES", | ||
"SESSIONS", | ||
"SESSION_STATE", | ||
"SETTINGS", | ||
"SYNONYMS", | ||
"USERS" | ||
); | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
tableNames = new ArrayList<>(); | ||
try { | ||
DatabaseMetaData metaData = dataSource.getConnection().getMetaData(); | ||
ResultSet tables = metaData.getTables(null, null, null, new String[]{"TABLE"}); | ||
while (tables.next()) { | ||
String tableName = tables.getString("TABLE_NAME"); | ||
if (metaTableNames.contains(tableName)) { | ||
continue; | ||
} | ||
tableNames.add(tableName); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void execute() { | ||
truncateAllTables(); | ||
} | ||
|
||
private void truncateAllTables() { | ||
jdbcTemplate.execute("SET foreign_key_checks = 0;"); | ||
tableNames.forEach( | ||
tableName -> executeQueryWithTable(tableName) | ||
); | ||
jdbcTemplate.execute("SET foreign_key_checks = 1;"); | ||
} | ||
|
||
private void executeQueryWithTable(String tableName) { | ||
jdbcTemplate.execute("TRUNCATE TABLE " + tableName); | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
backend/src/test/java/com/festago/acceptance/EntryPoint.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,16 @@ | ||
package com.festago.acceptance; | ||
|
||
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; | ||
|
||
import org.junit.platform.suite.api.ConfigurationParameter; | ||
import org.junit.platform.suite.api.IncludeEngines; | ||
import org.junit.platform.suite.api.SelectClasspathResource; | ||
import org.junit.platform.suite.api.Suite; | ||
|
||
@Suite | ||
@IncludeEngines("cucumber") | ||
@SelectClasspathResource("features") | ||
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.festago.acceptance") | ||
public class EntryPoint { | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
backend/src/test/java/com/festago/acceptance/steps/ExampleStep.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,98 @@ | ||
package com.festago.acceptance.steps; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.festago.acceptance.CucumberClient; | ||
import com.festago.auth.dto.AdminLoginRequest; | ||
import com.festago.auth.dto.RootAdminInitializeRequest; | ||
import com.festago.festival.dto.FestivalCreateRequest; | ||
import com.festago.festival.dto.FestivalDetailResponse; | ||
import com.festago.festival.dto.FestivalResponse; | ||
import com.festago.festival.dto.FestivalsResponse; | ||
import com.festago.school.dto.SchoolCreateRequest; | ||
import com.festago.school.dto.SchoolResponse; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.Then; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import java.time.LocalDate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class ExampleStep { | ||
|
||
@Autowired | ||
CucumberClient cucumberClient; | ||
|
||
@Given("๋ก๊ทธ์ธ์ ํ ์ํ์์") | ||
public void login() { | ||
String password = "password"; | ||
RestAssured.given() | ||
.contentType(ContentType.JSON) | ||
.body(new RootAdminInitializeRequest(password)) | ||
.post("admin/initialize") | ||
.then() | ||
.statusCode(200); | ||
|
||
ExtractableResponse<Response> response = RestAssured.given() | ||
.contentType(ContentType.JSON) | ||
.body(new AdminLoginRequest("admin", password)) | ||
.post("admin/login") | ||
.then() | ||
.extract(); | ||
|
||
cucumberClient.addAuthToken(response.cookie("token")); | ||
} | ||
|
||
@Given("์ถ์ ๋ฅผ ์์ฑํ๊ณ ") | ||
public void given() { | ||
SchoolResponse schoolResponse = (SchoolResponse) cucumberClient.getData("schoolResponse"); | ||
FestivalCreateRequest request = new FestivalCreateRequest("ํธ์ฐ ์ถ์ ", LocalDate.now(), | ||
LocalDate.now().plusDays(1), "thumnail", schoolResponse.id()); | ||
FestivalResponse response = RestAssured.given() | ||
.contentType(ContentType.JSON) | ||
.cookie("token", cucumberClient.getToken()) | ||
.body(request) | ||
.post("admin/festivals") | ||
.then() | ||
.extract() | ||
.body() | ||
.as(FestivalResponse.class); | ||
cucumberClient.addData("festivalData", response); | ||
} | ||
|
||
@Given("{string}๋ฅผ ์์ฑํ๊ณ ") | ||
public void makeSchool(String schoolName) { | ||
SchoolCreateRequest request = new SchoolCreateRequest(schoolName, "domain.com"); | ||
SchoolResponse response = RestAssured.given() | ||
.contentType(ContentType.JSON) | ||
.cookie("token", cucumberClient.getToken()) | ||
.body(request) | ||
.post("admin/schools") | ||
.then() | ||
.extract() | ||
.body() | ||
.as(SchoolResponse.class); | ||
cucumberClient.addData("schoolResponse", response); | ||
} | ||
|
||
@Then("์ถ์ ๊ฐ ์๋ค") | ||
public void then() { | ||
FestivalDetailResponse response = (FestivalDetailResponse) cucumberClient.getData("searchResult"); | ||
assertThat(response.name()).isEqualTo("ํธ์ฐ ์ถ์ "); | ||
} | ||
|
||
@Then("์ ์๋๋ฆฌ์ค์์ ์์ฑ๋ ๋ฐ์ดํฐ๋ ์์ด์ง๋ค") | ||
public void exist() { | ||
FestivalsResponse as = RestAssured.given() | ||
.when() | ||
.get("/festivals") | ||
.then() | ||
.extract() | ||
.as(FestivalsResponse.class); | ||
|
||
assertThat(as.festivals().size()).isEqualTo(0); | ||
} | ||
|
||
} |
Oops, something went wrong.