-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJxBrowserPluginFunctionalTest.kt
More file actions
219 lines (192 loc) · 7.16 KB
/
Copy pathJxBrowserPluginFunctionalTest.kt
File metadata and controls
219 lines (192 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Copyright 2023, TeamDev. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.teamdev.jxbrowser.gradle
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.io.TempDir
import java.io.File
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertFails
@DisplayName("JxBrowserPlugin should")
internal class JxBrowserPluginFunctionalTest {
private val jxBrowserVersion = System.getProperty("JXBROWSER_VERSION")
@TempDir
lateinit var testProjectDir: File
private lateinit var buildFile: File
private lateinit var libsFolder: File
@BeforeTest
fun setUp() {
val settingsFile = File(testProjectDir, "settings.gradle.kts")
settingsFile.writeText("rootProject.name = \"test-project\"")
buildFile = File(testProjectDir, "build.gradle.kts")
libsFolder = File(testProjectDir, "libs")
}
@Test
fun `built with the project`() {
buildFile.writeText(
"""
plugins {
java
id("com.teamdev.jxbrowser")
}
jxbrowser {
version = "$jxBrowserVersion"
}
dependencies {
implementation(jxbrowser.core)
implementation(jxbrowser.currentPlatform)
}
""".trimIndent(),
)
val result =
GradleRunner
.create()
.withProjectDir(testProjectDir)
.withPluginClasspath()
.withArguments("build")
.build()
result.outcome(":build") shouldBe SUCCESS
}
@Test
fun `download JxBrowser jars`() {
val taskName = "downloadJars"
val filesToCheck =
listOf(
"jxbrowser-$jxBrowserVersion.jar",
"jxbrowser-javafx-$jxBrowserVersion.jar",
"jxbrowser-swing-$jxBrowserVersion.jar",
"jxbrowser-swt-$jxBrowserVersion.jar",
"jxbrowser-win64-$jxBrowserVersion.jar",
"jxbrowser-win32-$jxBrowserVersion.jar",
"jxbrowser-linux64-$jxBrowserVersion.jar",
"jxbrowser-linux64-arm-$jxBrowserVersion.jar",
"jxbrowser-mac-$jxBrowserVersion.jar",
"jxbrowser-mac-arm-$jxBrowserVersion.jar",
"jxbrowser-kotlin-$jxBrowserVersion.jar",
"jxbrowser-compose-$jxBrowserVersion.jar",
"jxbrowser-win64-arm-$jxBrowserVersion.jar",
)
buildFile.writeText(
"""
plugins {
base
id("com.teamdev.jxbrowser")
}
jxbrowser {
version = "$jxBrowserVersion"
}
configurations {
create("toCopy")
}
dependencies {
"toCopy"(jxbrowser.core)
"toCopy"(jxbrowser.swt)
"toCopy"(jxbrowser.swing)
"toCopy"(jxbrowser.javafx)
"toCopy"(jxbrowser.mac)
"toCopy"(jxbrowser.macArm)
"toCopy"(jxbrowser.win32)
"toCopy"(jxbrowser.win64)
"toCopy"(jxbrowser.linux64)
"toCopy"(jxbrowser.linuxArm)
"toCopy"(jxbrowser.kotlin)
"toCopy"(jxbrowser.compose)
"toCopy"(jxbrowser.winArm)
}
tasks.register<Copy>("$taskName") {
from(configurations.getByName("toCopy"))
into("${libsFolder.toString().replace("\\", "/")}")
}
""".trimIndent(),
)
val result =
GradleRunner
.create()
.withProjectDir(testProjectDir)
.withPluginClasspath()
.withArguments(taskName)
.build()
result.outcome(":$taskName") shouldBe SUCCESS
libsFolder.files() shouldContainExactlyInAnyOrder filesToCheck
}
@Test
fun `fail to download unsupported artifacts`() {
val jxBrowserVersion = "7.40.0" // This version doesn't contain artifacts bellow.
val unsupportedArtifacts = listOf("kotlin", "compose", "winArm")
for (artifact in unsupportedArtifacts) {
buildFile.writeText(
"""
plugins {
java
id("com.teamdev.jxbrowser")
}
jxbrowser {
version = "$jxBrowserVersion"
}
dependencies {
implementation(jxbrowser.$artifact)
}
""".trimIndent(),
)
val failure =
assertFails {
GradleRunner
.create()
.withProjectDir(testProjectDir)
.withPluginClasspath()
.withArguments("build")
.build()
}
failure.message shouldContain "is not supported by JxBrowser"
}
}
@Test
fun `require JxBrowser version`() {
buildFile.writeText(
"""
plugins {
base
id("com.teamdev.jxbrowser")
}
jxbrowser {
includePreviewBuilds()
}
""".trimIndent(),
)
val failure =
assertFails {
GradleRunner
.create()
.withProjectDir(testProjectDir)
.withPluginClasspath()
.withArguments("check")
.build()
}
failure.message shouldContain "JxBrowser version is not specified"
}
private fun BuildResult.outcome(taskName: String) = this.task(taskName)!!.outcome
private fun File.files() = this.listFiles()!!.map { it.name }
}