From 19bab82565653c30fa6d65ecdea875f99fcc6da2 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 29 Nov 2023 09:17:23 +0800 Subject: [PATCH] Do not erase database on deployment (#104) * Do not erase database on deployment * Enhance tests --- .../template/application/BinderFactory.java | 2 +- .../application/AbstractITSpec.groovy | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java b/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java index b85e9495..1263833e 100644 --- a/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java +++ b/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java @@ -211,7 +211,7 @@ private static Properties getDefaultDbConfigs() { final Properties dbProperties = new Properties(); dbProperties.put("hibernate.show_sql", "true"); - dbProperties.put("hibernate.hbm2ddl.auto", "create"); + dbProperties.put("hibernate.hbm2ddl.auto", "update"); dbProperties.put("hibernate.dialect", JPA_DATASTORE_CONFIG.dbDialect()); dbProperties.put("hibernate.current_session_context_class", "thread"); dbProperties.put("hibernate.jdbc.use_scrollable_resultset", "true"); diff --git a/src/test/groovy/com/qubitpi/ws/jersey/template/application/AbstractITSpec.groovy b/src/test/groovy/com/qubitpi/ws/jersey/template/application/AbstractITSpec.groovy index 74c3e3fd..f7c86e4d 100644 --- a/src/test/groovy/com/qubitpi/ws/jersey/template/application/AbstractITSpec.groovy +++ b/src/test/groovy/com/qubitpi/ws/jersey/template/application/AbstractITSpec.groovy @@ -38,6 +38,7 @@ import com.qubitpi.ws.jersey.template.models.Book import org.apache.http.HttpStatus +import groovy.json.JsonBuilder import io.restassured.RestAssured import io.restassured.response.Response import jakarta.validation.constraints.NotNull @@ -429,9 +430,11 @@ abstract class AbstractITSpec extends Specification { def "GraphQL API can sort and paginate (effectively fetching 1 record with some min/max attribute)"() { given: "3 entities are inserted into the database" - createBook(new Book(id: 1, title: "Pride & Prejudice")) - createBook(new Book(id: 2, title: "Effective Java")) - createBook(new Book(id: 3, title: "Critiques of Pure Reason")) + createBook(new Book(title: "Pride & Prejudice")) + createBook(new Book(title: "Effective Java")) + final String maxBookId = createBook(new Book(title: "Critiques of Pure Reason")) + .jsonPath() + .get("data.book.edges[0].node.id") expect: "sorting by ID in descending order and paginating to get the firsts result returns Kant's work" RestAssured @@ -461,23 +464,25 @@ abstract class AbstractITSpec extends Specification { ) .when().post().then() .statusCode(200) - .body("", equalTo( - data: [ - book: [ - edges:[[ - node: [ - id: "3", - title:"Critiques of Pure Reason" + .body(equalTo( + new JsonBuilder( + data: [ + book: [ + edges:[[ + node: [ + id: "${maxBookId}", + title:"Critiques of Pure Reason" + ] + ]], + pageInfo: [ + totalRecords: 3, + startCursor: "0", + endCursor: "1", + hasNextPage:true ] - ]], - pageInfo: [ - totalRecords: 3, - startCursor: "0", - endCursor: "1", - hasNextPage:true ] ] - ] as HashMap + ).toString() )) }