Skip to content

Commit 6f21ed1

Browse files
author
helycopternicht
committed
Updated versions:
Gradle up to 6.4.1 Java up to 12 Kotlin up to 1.3.72
1 parent 9175e81 commit 6f21ed1

13 files changed

Lines changed: 301 additions & 15 deletions

File tree

.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ stages:
1212
variables:
1313
DOCKER_DRIVER: overlay2
1414

15+
1516
###########################
1617
# Tests
1718
###########################
1819
tests-unit:
1920
stage: test
20-
image: openjdk:8-jdk
21+
image: openjdk:12-jdk
2122
variables:
2223
POSTGRES_HOST: "postgres"
2324
POSTGRES_DB: "db"
@@ -48,7 +49,7 @@ tests-unit:
4849
###########################
4950
build-jar:
5051
stage: build
51-
image: openjdk:8-jdk
52+
image: openjdk:12-jdk
5253
before_script:
5354
- export GRADLE_USER_HOME=`pwd`/.gradle
5455
script:

build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
plugins {
22
id 'jacoco'
3-
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
4-
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.31'
5-
id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.31'
6-
id 'org.jetbrains.kotlin.kapt' version '1.3.31'
3+
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
4+
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.72'
5+
id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.72'
6+
id 'org.jetbrains.kotlin.kapt' version '1.3.72'
77
id 'org.springframework.boot' version '2.1.5.RELEASE'
88
}
99

1010
apply plugin: 'io.spring.dependency-management'
1111

1212
group = "io.openfuture"
1313
version = "0.0.1-SNAPSHOT"
14-
java.sourceCompatibility = JavaVersion.VERSION_1_8
14+
java.sourceCompatibility = JavaVersion.VERSION_12
1515

1616
repositories {
1717
mavenCentral()
1818
}
1919

2020
ext {
21-
kotlinVersion = '1.3.31'
21+
kotlinVersion = '1.3.72'
2222
springBootVersion = '2.1.5.RELEASE'
2323
swaggerVersion = '2.9.2'
2424
feignVersion = '2.1.3.RELEASE'
@@ -62,13 +62,13 @@ dependencies {
6262
compileKotlin {
6363
kotlinOptions {
6464
freeCompilerArgs = ['-Xjsr305=strict']
65-
jvmTarget = '1.8'
65+
jvmTarget = '12'
6666
}
6767
}
6868
compileTestKotlin {
6969
kotlinOptions {
7070
freeCompilerArgs = ['-Xjsr305=strict']
71-
jvmTarget = '1.8'
71+
jvmTarget = '12'
7272
}
7373
}
7474

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip

src/main/kotlin/io/openfuture/state/Application.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ class Application
1111
fun main(args: Array<String>) {
1212
runApplication<Application>(*args)
1313
}
14+

src/main/kotlin/io/openfuture/state/controller/domain/request/CreateAccountRequest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.openfuture.state.controller.domain.request
22

33
import org.apache.commons.validator.routines.UrlValidator
4+
import javax.validation.Valid
45
import javax.validation.constraints.AssertTrue
56

67
data class CreateAccountRequest(
78
val webHook: String,
9+
@field:Valid
810
val integrations: Set<CreateIntegrationRequest>
911
) {
1012

src/main/kotlin/io/openfuture/state/entity/Account.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import javax.persistence.*
55

66
@Entity
77
@Table(name = "accounts")
8-
class Account(
8+
data class Account(
99

1010
@Column(name = "web_hook", nullable = false)
1111
var webHook: String,
@@ -21,4 +21,4 @@ class Account(
2121
)
2222
var wallets: MutableSet<Wallet> = mutableSetOf()
2323

24-
) : BaseModel()
24+
) : BaseModel()

src/main/kotlin/io/openfuture/state/entity/OpenScaffold.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import javax.persistence.Table
77

88
@Entity
99
@Table(name = "open_scaffolds")
10-
class OpenScaffold(
10+
data class OpenScaffold(
1111

1212
@Column(name = "recipient_address", nullable = false, unique = true)
1313
var recipientAddress: String,

src/test/kotlin/io/openfuture/state/controller/AccountControllerTest.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.openfuture.state.controller
22

33
import io.openfuture.state.entity.Account
4+
import io.openfuture.state.exception.NotFoundException
45
import io.openfuture.state.service.AccountService
56
import io.openfuture.state.service.WalletService
67
import io.openfuture.state.util.any
@@ -38,6 +39,27 @@ class AccountControllerTest : BaseControllerTest() {
3839
.andExpect(status().isOk)
3940
}
4041

42+
@Test
43+
fun create_WhenAccountRequestAddressIsEmpty_ShouldReturnUnprocessableEntityStatus() {
44+
val requestBody = """
45+
{
46+
"webHook": "",
47+
"integrations": [
48+
{
49+
"address": "",
50+
"blockchainId": 1
51+
52+
}
53+
]
54+
}
55+
""".trimIndent()
56+
57+
mockMvc.perform(post("/api/accounts")
58+
.contentType(MediaType.APPLICATION_JSON)
59+
.content(requestBody))
60+
.andExpect(status().isBadRequest)
61+
}
62+
4163
@Test
4264
fun getAccountByIdTest() {
4365
val account = createDummyAccount().apply { id = 1 }
@@ -48,6 +70,15 @@ class AccountControllerTest : BaseControllerTest() {
4870
.andExpect(status().isOk)
4971
}
5072

73+
@Test
74+
fun get_WhenAccountIsNotPresented_ShouldReturnNotFoundStatus() {
75+
76+
given(accountService.get(any(Long::class.java))).willThrow(NotFoundException("Account with id 1 not found"))
77+
78+
mockMvc.perform(get("/api/accounts/1"))
79+
.andExpect(status().isNotFound)
80+
}
81+
5182
@Test
5283
fun updateAccountWebHookTest() {
5384
val requestBody = readResource("updateAccountWebHookRequest.json", javaClass)
@@ -62,6 +93,21 @@ class AccountControllerTest : BaseControllerTest() {
6293
.andExpect(status().isOk)
6394
}
6495

96+
@Test
97+
fun update_WithInvalidUpdateRequest_ShouldReturnBadRequestStatus() {
98+
val requestBody = """
99+
{
100+
"id": 1,
101+
"webHook": ""
102+
}
103+
""".trimIndent()
104+
105+
mockMvc.perform(put("/api/accounts")
106+
.contentType(MediaType.APPLICATION_JSON)
107+
.content(requestBody))
108+
.andExpect(status().isBadRequest)
109+
}
110+
65111
@Test
66112
fun deleteAccountTest() {
67113
val accountId = 1L
@@ -73,4 +119,12 @@ class AccountControllerTest : BaseControllerTest() {
73119
.andExpect(status().isOk)
74120
}
75121

122+
@Test
123+
fun delete_WhenAccountIsNotPresented_ShouldReturn_NotFoundStatus() {
124+
given(accountService.delete(1L)).willThrow(NotFoundException("Account with id 1 not found"))
125+
126+
mockMvc.perform(delete("/api/accounts/1"))
127+
.andExpect(status().isNotFound)
128+
}
129+
76130
}

src/test/kotlin/io/openfuture/state/controller/BlockchainControllerTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.openfuture.state.controller
22

3+
import io.openfuture.state.exception.NotFoundException
34
import io.openfuture.state.service.BlockchainService
45
import io.openfuture.state.util.createDummyBlockchain
56
import org.junit.Test
@@ -36,4 +37,12 @@ class BlockchainControllerTest : BaseControllerTest() {
3637
.andExpect(MockMvcResultMatchers.status().isOk)
3738
}
3839

40+
@Test
41+
fun get_WhenBlockchainIsNotPresent_ShouldReturnNotFoundStatusCode() {
42+
given(blockchainService.get(1L)).willThrow(NotFoundException("Blockchain with id 1 not found"))
43+
44+
mockMvc.perform(MockMvcRequestBuilders.get("/api/blockchains/1"))
45+
.andExpect(MockMvcResultMatchers.status().isNotFound)
46+
}
47+
3948
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.openfuture.state.controller
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import io.openfuture.state.controller.domain.request.SaveOpenScaffoldRequest
5+
import io.openfuture.state.entity.OpenScaffold
6+
import io.openfuture.state.service.DefaultOpenScaffoldService
7+
import org.junit.Test
8+
import org.mockito.BDDMockito.given
9+
import org.springframework.beans.factory.annotation.Autowired
10+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
11+
import org.springframework.boot.test.mock.mockito.MockBean
12+
import org.springframework.http.MediaType
13+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
14+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
15+
16+
@WebMvcTest(OpenScaffoldController::class)
17+
class OpenScaffoldControllerTest : BaseControllerTest() {
18+
19+
@MockBean
20+
private lateinit var openScaffoldService: DefaultOpenScaffoldService
21+
@Autowired
22+
private lateinit var objectMapper: ObjectMapper
23+
24+
@Test
25+
fun save_WhenRequestIsValid_ShouldReturnIsOkStatusCode() {
26+
val request = SaveOpenScaffoldRequest(
27+
address = "Address",
28+
webHook = "https://url.com"
29+
)
30+
val expected = OpenScaffold("Address", "https://url.com")
31+
.apply { id = 1L }
32+
33+
given(openScaffoldService.save(request)).willReturn(expected)
34+
35+
mockMvc.perform(post("/api/open-scaffolds")
36+
.contentType(MediaType.APPLICATION_JSON)
37+
.content(objectMapper.writeValueAsString(request)))
38+
.andExpect(status().isOk)
39+
}
40+
41+
@Test
42+
fun save_WhenRequestAddressIsEmpty_ShouldReturnBadRequestStatus() {
43+
val request = """
44+
{
45+
"address": "",
46+
"webHook": "https://url.com"
47+
}
48+
""".trimIndent()
49+
50+
mockMvc.perform(post("/api/open-scaffolds")
51+
.contentType(MediaType.APPLICATION_JSON)
52+
.content(request))
53+
.andExpect(status().isBadRequest)
54+
}
55+
56+
@Test
57+
fun save_WhenRequestWebHookIsEmpty_ShouldReturnBadRequestStatus() {
58+
val request = """
59+
{
60+
"address": "some_address",
61+
"webHook": ""
62+
}
63+
""".trimIndent()
64+
65+
mockMvc.perform(post("/api/open-scaffolds")
66+
.contentType(MediaType.APPLICATION_JSON)
67+
.content(request))
68+
.andExpect(status().isBadRequest)
69+
}
70+
71+
}

0 commit comments

Comments
 (0)