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

View File

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

View File

@ -5,6 +5,8 @@ import com.aitrainer.api.repository.CustomerRepository
import com.aitrainer.api.model.Customer import com.aitrainer.api.model.Customer
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import kotlin.test.fail import kotlin.test.fail
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +16,14 @@ class CustomerTests {
@Autowired @Autowired
lateinit private var customerRepository: CustomerRepository lateinit private var customerRepository: CustomerRepository
private val customerId: Long = 4 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 @Test
fun testInsert() { fun testInsert() {
@ -21,9 +31,30 @@ class CustomerTests {
val savedCustomer: Customer = customerRepository.save(newCustomer) val savedCustomer: Customer = customerRepository.save(newCustomer)
assertEquals(savedCustomer.age, 48) assertEquals(savedCustomer.age, 48)
this.inserted_id = savedCustomer.customer_id;
val customer: Customer = customerRepository.findById( savedCustomer.customer_id ).orElse(null); val customer: Customer = customerRepository.findById( savedCustomer.customer_id ).orElse(null);
assertEquals( customer.firstname, "Tibor") 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);
}
} }