тестирование api rest "service", с kotlin, junit5 и H2 - PullRequest
0 голосов
/ 25 апреля 2019

Я тестирую свой api rest и сейчас пытаюсь написать тесты для SERVICE.Но все тесты не пройдены.

Вот мой класс.

@DataJpaTest
@ExtendWith(SpringExtension::class)
@TestPropertySource(locations = ["classpath:application-test.properties"])
internal class ProductServiceTest {

    @Autowired
    val repository: ProductRepository? = null
    @Autowired
    val repositoryT: TaxRepository? = null

    var t: Tax? = null
    var p: Product? = null

    @BeforeEach
    fun instantiated() {
        var t = Tax(1L, 123, null)
        val p = Product(1L, 1L, true, "Test", BigDecimal(100.50), BigDecimal(200.20),
                UnitMeasurementEnum.UNIT, t)
        t!!.product = p
        repositoryT?.save(t)
        repository?.save(p)
    }

    @Test
    @Transactional
    fun find() {
        Assertions.assertEquals("Test", repository?.find(p!!.id)!!.name)
        Assertions.assertEquals(123, repository?.find(t!!.id)!!.tax.icms)
    }

Ошибка:

org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.projetogaia.products.entity.Product with id 1; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.projetogaia.products.entity.Product with id 1

Что я отпускаю?Может ли кто-нибудь помочь, пожалуйста?

Спасибо.

...