Skip to content

Commit

Permalink
Move repeated @SQL annotations to class level (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 authored and aklish committed Dec 22, 2019
1 parent 279c86b commit fa5da76
Showing 1 changed file with 9 additions and 36 deletions.
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

0 comments on commit fa5da76

Please sign in to comment.