CustomerTest finish

This commit is contained in:
Bossanyi Tibor 2020-05-06 19:00:25 +02:00
parent e4c5e8bd18
commit c47147ce5c
2 changed files with 37 additions and 6 deletions
src
main/kotlin/com/aitrainer/api/model
test/kotlin/com/aitrainer/api/test

View File

@ -10,11 +10,11 @@ import javax.validation.constraints.NotBlank
data class Customer (
@get: NotBlank
val name: String = "",
val firstname: String = "",
val email: String = "",
val age: Int = 0,
val sex: String = "m",
var name: String = "",
var firstname: String = "",
var email: String = "",
var age: Int = 0,
var sex: String = "m",
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val customer_id: Long = 0

View File

@ -5,6 +5,8 @@ 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.assertNotEquals
import kotlin.test.assertNotNull
import kotlin.test.fail
import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +16,14 @@ class CustomerTests {
@Autowired
lateinit private var customerRepository: CustomerRepository
private val customerId: Long = 4
private var inserted_id: Long? = null
@Test
fun testGet() {
val id: Long = 7;
val customer: Customer = customerRepository.findById( id ).orElse(null);
assertEquals( customer.name, "Átlag 18 éves fiú")
}
@Test
fun testInsert() {
@ -21,9 +31,30 @@ class CustomerTests {
val savedCustomer: Customer = customerRepository.save(newCustomer)
assertEquals(savedCustomer.age, 48)
this.inserted_id = savedCustomer.customer_id;
val customer: Customer = customerRepository.findById( savedCustomer.customer_id ).orElse(null);
assertEquals( customer.firstname, "Tibor")
//assertEquals( customer?.name, "Boss")
this.testUpdate(savedCustomer.customer_id);
}
fun testUpdate( customerId: Long ) {
var id: Long? = customerId;
assertNotNull(id)
var updatedCustomer: Customer = customerRepository.findById( id ).orElse(null);
assertNotNull(updatedCustomer)
updatedCustomer.firstname ="Tiborka"
val customer: Customer = customerRepository.save( updatedCustomer );
assertEquals( customer.firstname, "Tiborka")
customerRepository.delete(updatedCustomer);
val customerDeleted: Customer? = customerRepository.findById( id );
assertNull(customer);
}
}