Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring tests: Move repeated @Sql annotations to class level #1119

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@
import com.yahoo.elide.spring.models.ArtifactGroup;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlMergeMode;

import javax.ws.rs.core.MediaType;

/**
* Example functional test.
*/
@SqlMergeMode(SqlMergeMode.MergeMode.MERGE)
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD,
statements = "INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);")
@Sql(executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD,
statements = "DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;")
public class ControllerTest extends IntegrationTest {
/**
* This test demonstrates an example test using the JSON-API DSL.
*/
@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
"INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);"
})
public void jsonApiGetTest() {
when()
.get("/json/group")
Expand All @@ -75,11 +77,6 @@ public void jsonApiGetTest() {
}

@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
"INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);"
})
public void jsonApiPatchTest() {
given()
.contentType(JsonApiController.JSON_API_CONTENT_TYPE)
Expand Down Expand Up @@ -124,11 +121,6 @@ public void jsonApiPatchTest() {
}

@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
"INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);"
})
public void jsonForbiddenApiPatchTest() {
given()
.contentType(JsonApiController.JSON_API_CONTENT_TYPE)
Expand All @@ -151,17 +143,14 @@ public void jsonForbiddenApiPatchTest() {
}

@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;"
})
public void jsonApiPostTest() {
given()
.contentType(JsonApiController.JSON_API_CONTENT_TYPE)
.body(
datum(
resource(
type("group"),
id("com.example.repository"),
id("com.example.repository2"),
attributes(
attr("commonName", "New group.")
)
Expand All @@ -174,7 +163,7 @@ public void jsonApiPostTest() {
.body(equalTo(datum(
resource(
type("group"),
id("com.example.repository"),
id("com.example.repository2"),
attributes(
attr("commonName", "New group."),
attr("deprecated", false),
Expand All @@ -189,11 +178,6 @@ public void jsonApiPostTest() {
}

@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
"INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);"
})
public void jsonApiDeleteTest() {
when()
.delete("/json/group/com.example.repository")
Expand All @@ -203,9 +187,6 @@ public void jsonApiDeleteTest() {

@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
"INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);",
"INSERT INTO ArtifactProduct (name, commonName, description, group_name) VALUES\n"
+ "\t\t('foo','foo Core','The guts of foo','com.example.repository');"
})
Expand All @@ -225,11 +206,6 @@ public void jsonApiDeleteRelationshipTest() {
* This test demonstrates an example test using the GraphQL DSL.
*/
@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
"INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);"
})
public void graphqlTest() {
given()
.contentType(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -275,9 +251,6 @@ public void swaggerDocumentTest() {
}

@Test
@Sql(statements = {
"DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;",
})
public void graphqlTestForbiddenCreate() {
ArtifactGroup group = new ArtifactGroup();
group.setDeprecated(true);
Expand Down