Skip to content

Commit

Permalink
Add BDD
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyfrs committed May 21, 2024
1 parent 6490c59 commit bdbc0f6
Show file tree
Hide file tree
Showing 27 changed files with 376 additions and 101 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Microsserviço de estoque

### BDD

Este microsserviço contém testes de integração implementados com Cucumber.

### Análise estática

Projeto no SonarCloud: [https://sonarcloud.io/project/overview?id=FIAP-3SOAT-G15_stock-api](https://sonarcloud.io/project/overview?id=FIAP-3SOAT-G15_stock-api)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=FIAP-3SOAT-G15_stock-api&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=FIAP-3SOAT-G15_stock-api)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=FIAP-3SOAT-G15_stock-api&metric=coverage)](https://sonarcloud.io/summary/new_code?id=FIAP-3SOAT-G15_stock-api)

Expand Down
63 changes: 57 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<kotlin.compiler.jvmTarget>17</kotlin.compiler.jvmTarget>
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
<testcontainers.version>1.19.1</testcontainers.version>
<skipUnitTests>false</skipUnitTests>
<skipITs>true</skipITs>
<skipOpenAPIGen>true</skipOpenAPIGen>
<sonar.organization>fiap-3soat-g15</sonar.organization>
Expand Down Expand Up @@ -92,6 +93,36 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -143,6 +174,20 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.15.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down Expand Up @@ -337,26 +382,32 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<excludedGroups>IntegrationTest</excludedGroups>
<skipTests>${skipUnitTests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<includes>
<include>**/*</include>
</includes>
<groups>IntegrationTest</groups>
<skipITs>${skipITs}</skipITs>
<properties>
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skipITs}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ interface ComponentGateway {
fun update(component: Component): Component

fun delete(component: Component): Component

fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ interface ProductGateway {
fun update(product: Product): Product

fun delete(productNumber: Long): Product

fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class ComponentGatewayImpl(
return component
}

override fun deleteAll() {
componentJpaRepository.deleteAll()
}

private fun persist(component: Component): Component =
component
.let(mapper::toEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ class ProductGatewayImpl(
)
}

override fun deleteAll() {
productJpaRepository.deleteAll()
}

private fun persist(product: Product): Product =
product
.let(mapper::toEntity)
Expand Down
36 changes: 0 additions & 36 deletions src/test/kotlin/IntegrationTestFixtures.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import org.junit.jupiter.api.Tag
package com.fiap.stock.application

import com.fiap.stock.application.it.PostgreSQLContainerInitializer
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.ContextConfiguration

@Tag("IntegrationTest")
@ActiveProfiles("test")
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class IntegrationTest

@ContextConfiguration(initializers = [PostgreSQLContainerInitializer::class])
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.fiap.stock.application

import com.fiap.stock.application.domain.entities.Component
import com.fiap.stock.application.domain.entities.Product
import com.fiap.stock.application.domain.entities.Stock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fiap.stock.application.driver.web.request.ComponentRequest
import com.fiap.stock.application.usecases.CreateComponentUseCase
import com.fiap.stock.application.usecases.LoadComponentUseCase
import com.fiap.stock.application.usecases.SearchComponentUseCase
import createComponent
import com.fiap.stock.application.createComponent
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -101,4 +101,4 @@ class ComponentControllerTest {



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.fiap.stock.application.adapter.controller
import com.fiap.stock.application.domain.valueobjects.ProductCategory
import com.fiap.stock.application.usecases.LoadProductUseCase
import com.fiap.stock.application.usecases.SearchProductUseCase
import createProduct
import com.fiap.stock.application.createProduct
import io.mockk.every
import io.mockk.mockk
import io.mockk.unmockkAll
Expand Down Expand Up @@ -106,4 +106,4 @@ class MenuControllerTest {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.fiap.stock.application.usecases.AdjustStockUseCase
import com.fiap.stock.application.usecases.AssembleProductsUseCase
import com.fiap.stock.application.usecases.LoadProductUseCase
import com.fiap.stock.application.usecases.SearchProductUseCase
import createProduct
import createProductRequest
import com.fiap.stock.application.createProduct
import com.fiap.stock.application.it.createProductRequest
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fiap.stock.application.adapter.gateway.impl.ComponentGatewayImpl
import com.fiap.stock.application.domain.errors.SelfOrderManagementException
import com.fiap.stock.application.driver.database.persistence.jpa.ComponentJpaRepository
import com.fiap.stock.application.driver.database.persistence.mapper.ComponentMapper
import createComponent
import com.fiap.stock.application.createComponent
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -106,17 +106,6 @@ class ComponentGatewayTest {

assertThat(result).isNotNull()
}

@Test
fun `deleteAll should return nothing`() {

every { componentJpaRepository.deleteAll() } returns Unit

gateway.deleteAll()
}



}

@Nested
Expand Down Expand Up @@ -170,4 +159,4 @@ class ComponentGatewayTest {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fiap.stock.application.domain.errors.SelfOrderManagementException
import com.fiap.stock.application.domain.valueobjects.ProductCategory
import com.fiap.stock.application.driver.database.persistence.jpa.ProductJpaRepository
import com.fiap.stock.application.driver.database.persistence.mapper.ProductMapper
import createProduct
import com.fiap.stock.application.createProduct
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -118,15 +118,6 @@ class ProductGatewayTest {

assertThat(response).isNotNull()
}

@Test
fun `deleteAll should return nothing`() {

every { productJpaRepository.deleteAll() } returns Unit

gateway.deleteAll()
}

}

@Nested
Expand Down Expand Up @@ -191,4 +182,4 @@ class ProductGatewayTest {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fiap.stock.application.adapter.gateway.impl.StockGatewayImpl
import com.fiap.stock.application.domain.errors.SelfOrderManagementException
import com.fiap.stock.application.driver.database.persistence.jpa.StockJpaRepository
import com.fiap.stock.application.driver.database.persistence.mapper.StockMapper
import createStock
import com.fiap.stock.application.createStock
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -106,4 +106,4 @@ class StockGatewayTest {
}


}
}
32 changes: 32 additions & 0 deletions src/test/kotlin/com/fiap/stock/application/it/CommonSteps.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fiap.stock.application.it

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()
)
}
}
Loading

0 comments on commit bdbc0f6

Please sign in to comment.