unit test customer table
This commit is contained in:
@@ -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
-1
@@ -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
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user