Skip to content

Commit bb129ce

Browse files
author
Jony Santos
committed
initial commit
1 parent 20bf869 commit bb129ce

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
<artifactId>spring-boot-starter-test</artifactId>
6262
<scope>test</scope>
6363
</dependency>
64+
<dependency>
65+
<groupId>org.assertj</groupId>
66+
<artifactId>assertj-core</artifactId>
67+
</dependency>
6468
</dependencies>
6569

6670
<build>
Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,77 @@
11
package br.com.jonyfs.springbootkotlinapi
22

3+
import br.com.jonyfs.springbootkotlinapi.privilege.PrivilegeRepository
4+
import br.com.jonyfs.springbootkotlinapi.role.RoleRepository
5+
import br.com.jonyfs.springbootkotlinapi.user.User
6+
import br.com.jonyfs.springbootkotlinapi.user.UserRepository
7+
import org.assertj.core.api.Assertions.assertThat
38
import org.junit.Test
49
import org.junit.runner.RunWith
10+
import org.springframework.beans.factory.annotation.Autowired
511
import org.springframework.boot.test.context.SpringBootTest
12+
import org.springframework.boot.test.json.JacksonTester
13+
import org.springframework.boot.test.web.client.TestRestTemplate
14+
import org.springframework.context.ApplicationContext
15+
import org.springframework.http.ResponseEntity
616
import org.springframework.test.context.junit4.SpringRunner
17+
import javax.annotation.Resource
18+
719

820
@RunWith(SpringRunner::class)
9-
@SpringBootTest
21+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
1022
class SpringBootKotlinApiApplicationTests {
1123

24+
@Autowired
25+
lateinit var restTemplate: TestRestTemplate
26+
27+
@Resource
28+
private val applicationContext: ApplicationContext? = null
29+
30+
@Resource
31+
lateinit var userRepository: UserRepository
32+
33+
@Resource
34+
lateinit var roleRepository: RoleRepository
35+
36+
@Resource
37+
lateinit var privilegeRepository: PrivilegeRepository
38+
39+
@Autowired
40+
private val json: JacksonTester<User>? = null
41+
42+
43+
@Test
44+
fun testIfContextLoads() {
45+
assertThat(applicationContext).isNotNull()
46+
}
47+
1248
@Test
13-
fun contextLoads() {
49+
fun testIfApiLoads() {
50+
51+
var user = User()
52+
user.firstName = "John"
53+
user.lastName = "Anderson"
54+
user.email = "john.anderson@test.com"
55+
user.password = "XPTO"
56+
57+
58+
user = userRepository.save(user)
59+
60+
assertThat(user).isNotNull()
61+
assertThat(user.id).isNotNull()
62+
assertThat(user.firstName).isNotNull()
63+
64+
var response: ResponseEntity<User> = restTemplate.getForEntity("/users/" + user.id, User::class.java)
65+
66+
assertThat(response).isNotNull()
67+
68+
var savedUser = response.body
69+
70+
assertThat(savedUser).isNotNull()
71+
//assertThat(savedUser.id).isNotNull()
72+
assertThat(savedUser.firstName).isNotNull()
73+
74+
1475
}
1576

1677
}

0 commit comments

Comments
 (0)