瀏覽代碼

Align Data Java Config Sample to Match Other Samples

Josh Cummings 1 月之前
父節點
當前提交
a1286f2837
共有 2 個文件被更改,包括 47 次插入13 次删除
  1. 6 13
      servlet/java-configuration/data/build.gradle
  2. 41 0
      servlet/java-configuration/data/gradle/gretty.gradle

+ 6 - 13
servlet/java-configuration/data/build.gradle

@@ -1,36 +1,29 @@
 plugins {
 	id "java"
 	id "nebula.integtest" version "8.2.0"
-	alias(libs.plugins.io.spring.dependency.management)
-	alias(libs.plugins.org.springframework.boot) apply(false)
+	id "org.gretty" version "4.0.3"
+	id "war"
 }
 
+apply from: "gradle/gretty.gradle"
+
 repositories {
 	mavenCentral()
 	maven { url "https://repo.spring.io/milestone" }
 	maven { url "https://repo.spring.io/snapshot" }
 }
 
-dependencyManagement {
-	imports {
-		mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
-	}
-}
-
 dependencies {
 	implementation platform(libs.org.springframework.spring.framework.bom)
 	implementation platform(libs.org.springframework.security.spring.security.bom)
 	implementation platform(libs.org.springframework.data.spring.data.bom)
-	implementation "org.springframework.boot:spring-boot-starter-validation"
 	implementation platform("org.junit:junit-bom:5.10.5")
 
 	implementation "org.springframework.security:spring-security-config"
 	implementation "org.springframework.security:spring-security-data"
 	implementation "org.springframework.security:spring-security-web"
-	implementation 'jakarta.validation:jakarta.validation-api'
-	implementation 'jakarta.persistence:jakarta.persistence-api'
-	implementation 'org.hibernate.orm:hibernate-core'
-	implementation 'org.hibernate.validator:hibernate-validator'
+	implementation 'org.hibernate.orm:hibernate-core:6.6.21.Final'
+	implementation 'org.hibernate.validator:hibernate-validator:8.0.2.Final'
 	implementation 'org.hsqldb:hsqldb:2.7.3'
 	implementation 'org.springframework.data:spring-data-jpa'
 

+ 41 - 0
servlet/java-configuration/data/gradle/gretty.gradle

@@ -0,0 +1,41 @@
+gretty {
+	servletContainer = "tomcat10"
+	contextPath = "/"
+	fileLogEnabled = false
+	integrationTestTask = 'integrationTest'
+}
+
+Task prepareAppServerForIntegrationTests = project.tasks.create('prepareAppServerForIntegrationTests') {
+	group = 'Verification'
+	description = 'Prepares the app server for integration tests'
+	doFirst {
+		project.gretty {
+			httpPort = -1
+		}
+	}
+}
+
+project.tasks.matching { it.name == "appBeforeIntegrationTest" }.all { task ->
+	task.dependsOn prepareAppServerForIntegrationTests
+}
+
+project.tasks.matching { it.name == "integrationTest" }.all {
+	task -> task.doFirst {
+		def gretty = project.gretty
+		String host = project.gretty.host ?: 'localhost'
+		boolean isHttps = gretty.httpsEnabled
+		Integer httpPort = integrationTest.systemProperties['gretty.httpPort']
+		Integer httpsPort = integrationTest.systemProperties['gretty.httpsPort']
+		int port = isHttps ? httpsPort : httpPort
+		String contextPath = project.gretty.contextPath
+		String httpBaseUrl = "http://${host}:${httpPort}${contextPath}"
+		String httpsBaseUrl = "https://${host}:${httpsPort}${contextPath}"
+		String baseUrl = isHttps ? httpsBaseUrl : httpBaseUrl
+		integrationTest.systemProperty 'app.port', port
+		integrationTest.systemProperty 'app.httpPort', httpPort
+		integrationTest.systemProperty 'app.httpsPort', httpsPort
+		integrationTest.systemProperty 'app.baseURI', baseUrl
+		integrationTest.systemProperty 'app.httpBaseURI', httpBaseUrl
+		integrationTest.systemProperty 'app.httpsBaseURI', httpsBaseUrl
+	}
+}