unit test customer table
This commit is contained in:
parent
3dfef8add8
commit
fa4efd699d
@ -9,7 +9,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
version = "0.0.2"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
@ -26,7 +26,9 @@ dependencies {
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
|
||||
}
|
||||
testCompile("org.junit.jupiter:junit-jupiter-api")
|
||||
testCompile("junit:junit:4.13")
|
||||
testCompile("org.jetbrains.kotlin:kotlin-test-junit5:1.3.72")
|
||||
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
aitrainer server API v0.1.1
|
||||
aitrainer server API v0.0.2
|
||||
|
||||
connects the MYSQL Database
|
||||
provide a RESTful API to the mobile app
|
@ -17,7 +17,7 @@ class CustomerController ( private val customerRepository: CustomerRepository )
|
||||
customerRepository.findAll()
|
||||
|
||||
@PostMapping("/customers")
|
||||
fun createNewArticle(@Valid @RequestBody customer: Customer): Customer =
|
||||
fun createNewCustomer(@Valid @RequestBody customer: Customer): Customer =
|
||||
customerRepository.save(customer)
|
||||
|
||||
@GetMapping("/customers/{id}")
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.aitrainer.api.model
|
||||
|
||||
import com.aitrainer.api.enums.SexEnum
|
||||
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
@ -11,13 +9,13 @@ import javax.validation.constraints.NotBlank
|
||||
@Entity
|
||||
data class Customer (
|
||||
@get: NotBlank
|
||||
val name: String = "",
|
||||
|
||||
val firstname: String,
|
||||
val email: String,
|
||||
val age: Int,
|
||||
val sex: String,
|
||||
val name: String = "",
|
||||
val firstname: String = "",
|
||||
val email: String = "",
|
||||
val age: Int = 0,
|
||||
val sex: String = "m",
|
||||
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val customer_id: Long? = null
|
||||
val customer_id: Long = 0
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.aitrainer.api
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
29
src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt
Normal file
29
src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt
Normal file
@ -0,0 +1,29 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import com.aitrainer.api.repository.CustomerRepository
|
||||
import com.aitrainer.api.model.Customer
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.fail
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@SpringBootTest
|
||||
class CustomerTests {
|
||||
|
||||
@Autowired
|
||||
lateinit private var customerRepository: CustomerRepository
|
||||
private val customerId: Long = 4
|
||||
|
||||
@Test
|
||||
fun testInsert() {
|
||||
val newCustomer = Customer("Bossanyi", "Tibor", "", 48, "m");
|
||||
val savedCustomer: Customer = customerRepository.save(newCustomer)
|
||||
assertEquals(savedCustomer?.age, 48)
|
||||
|
||||
val customer: Customer? = customerRepository.findById( savedCustomer?.customer_id ).orElse(null);
|
||||
assertEquals( customer?.firstname, "Tibor")
|
||||
//assertEquals( customer?.name, "Boss")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user