-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
368 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.fiap.stock.application | ||
|
||
import io.cucumber.java.Before | ||
import io.restassured.RestAssured | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.web.server.LocalServerPort | ||
import org.springframework.jdbc.core.JdbcTemplate | ||
|
||
class CommonSteps: IntegrationTest() { | ||
|
||
@Autowired | ||
lateinit var jdbcTemplate: JdbcTemplate | ||
|
||
@LocalServerPort | ||
private val port: Int? = null | ||
|
||
@Before | ||
fun setup() { | ||
RestAssured.baseURI = "http://localhost:$port" | ||
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails() | ||
} | ||
|
||
@Before("@database") | ||
fun setupDatabase() { | ||
jdbcTemplate.execute(""" | ||
TRUNCATE TABLE product RESTART IDENTITY CASCADE; | ||
TRUNCATE TABLE stock RESTART IDENTITY; | ||
TRUNCATE TABLE component RESTART IDENTITY CASCADE; | ||
""".trimIndent() | ||
) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/kotlin/com/fiap/stock/application/ComponentCreation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.fiap.stock.application | ||
|
||
import com.fiap.stock.application.adapter.gateway.ComponentGateway | ||
import com.fiap.stock.application.adapter.gateway.StockGateway | ||
import com.fiap.stock.application.domain.entities.Component | ||
import com.fiap.stock.application.domain.entities.Stock | ||
import com.fiap.stock.application.driver.web.request.ComponentRequest | ||
import io.cucumber.java.en.Given | ||
import io.cucumber.java.en.Then | ||
import io.cucumber.java.en.When | ||
import io.restassured.RestAssured.given | ||
import io.restassured.http.ContentType | ||
import io.restassured.response.Response | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.http.HttpStatus | ||
|
||
class ComponentCreation: IntegrationTest() { | ||
|
||
@Autowired | ||
lateinit var componentRepository: ComponentGateway | ||
|
||
@Autowired | ||
lateinit var stockRepository: StockGateway | ||
|
||
private lateinit var componentRequest: ComponentRequest | ||
private lateinit var response: Response | ||
|
||
@Given("valid data for product component") | ||
fun validDataForProductComponent() { | ||
componentRequest = createComponentRequest() | ||
} | ||
|
||
@When("request to create product component") | ||
fun requestToCreateProductComponent() { | ||
response = given() | ||
.contentType(ContentType.JSON) | ||
.body(componentRequest) | ||
.`when`() | ||
.post("/admin/components") | ||
} | ||
|
||
@Then("product component should be created") | ||
fun productComponentShouldBeCreated() { | ||
val persistedProduct = componentRepository.findAll()[0] | ||
|
||
assertThat(persistedProduct).isEqualTo(Component( | ||
number = 1, | ||
name = componentRequest.name, | ||
)) | ||
|
||
response.then() | ||
.statusCode(HttpStatus.OK.value()) | ||
.body( | ||
"number", equalTo(persistedProduct.number!!.toInt()), | ||
"name", equalTo(componentRequest.name), | ||
) | ||
|
||
val stock = stockRepository.findByComponentNumber(persistedProduct.number as Long) | ||
|
||
assertThat(stock).isEqualTo(Stock( | ||
componentNumber = persistedProduct.number as Long, | ||
quantity = componentRequest.initialQuantity, | ||
)) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/kotlin/com/fiap/stock/application/IntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.fiap.stock.application | ||
|
||
import io.cucumber.spring.CucumberContextConfiguration | ||
import org.junit.jupiter.api.Tag | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@CucumberContextConfiguration | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@WithPostgreSQL | ||
@Tag("IntegrationTest") | ||
class IntegrationTest |
32 changes: 32 additions & 0 deletions
32
src/test/kotlin/com/fiap/stock/application/IntegrationTestFixtures.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.fiap.stock.application | ||
|
||
import com.fiap.stock.application.domain.valueobjects.ProductCategory | ||
import com.fiap.stock.application.driver.web.request.ComponentRequest | ||
import com.fiap.stock.application.driver.web.request.ProductRequest | ||
import java.math.BigDecimal | ||
|
||
fun createComponentRequest( | ||
name: String = "Hamburger", | ||
initialQuantity: Long = 100L, | ||
) = ComponentRequest( | ||
name = name, | ||
initialQuantity = initialQuantity, | ||
) | ||
|
||
fun createProductRequest( | ||
name: String = "Big Mac", | ||
category: String = ProductCategory.MAIN.name, | ||
price: BigDecimal = BigDecimal("10.00"), | ||
description: String = "Dois hambúrgueres, alface, queijo, molho especial, cebola, picles, num pão com gergelim", | ||
minSub: Int = 3, | ||
maxSub: Int = 3, | ||
components: List<Long> = listOf(1, 2, 3, 4, 5, 6, 7), | ||
) = ProductRequest( | ||
name = name, | ||
category = category, | ||
price = price, | ||
description = description, | ||
minSub = minSub, | ||
maxSub = maxSub, | ||
components = components, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.