Skip to content

Commit

Permalink
Merge pull request #27 from FIAP-3SOAT-G15/fix-bugs
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
wellyfrs authored Aug 8, 2024
2 parents b0f0021 + 7c111d1 commit 75818e2
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 45 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ services:
DB_NAME: orders
DB_USERNAME: selforder
DB_PASSWORD: self@Order123!
ADMIN_ACCESS_TOKEN: token
STOCK_SERVICE_URL: http://localhost:8081
PAYMENTS_SERVICE_URL: http://localhost:8082
ports:
Expand Down
26 changes: 21 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.4</version>
<version>3.2.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.fiap</groupId>
Expand All @@ -19,8 +19,9 @@
<kotlin.compiler.jvmTarget>17</kotlin.compiler.jvmTarget>

<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
<awsspringcloud.version>3.2.0-M1</awsspringcloud.version>
<testcontainers.version>1.19.1</testcontainers.version>

<skipITs>true</skipITs>
<skipOpenAPIGen>true</skipOpenAPIGen>

Expand All @@ -43,16 +44,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.awspring.cloud/spring-cloud-aws-starter-sns -->
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-sns</artifactId>
<version>3.2.0-M1</version>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-sqs</artifactId>
<version>3.2.0-M1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
Expand Down Expand Up @@ -102,6 +104,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -149,8 +156,16 @@
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dependencies</artifactId>
<version>${awsspringcloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
Expand All @@ -160,6 +175,7 @@
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>orders</finalName>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MessagingConfig {

@Bean("PaymentSender")
fun createPaymentSender(snsTemplate: SnsTemplate,
@Value("\${topic.request-payment}") topicArn: String,
@Value("\${sns.topics.request-payment}") topicArn: String,
objectMapper: ObjectMapper) : PaymentSender {
return PaymentSenderImpl(snsTemplate, topicArn, objectMapper)
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/fiap/order/config/JWTSecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fiap.order.config

import io.swagger.v3.oas.annotations.enums.SecuritySchemeType
import io.swagger.v3.oas.annotations.security.SecurityScheme
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
Expand All @@ -19,6 +20,11 @@ import org.springframework.security.web.SecurityFilterChain
bearerFormat = "JWT",
scheme = "bearer"
)
@ConditionalOnProperty(
value = ["security.enable"],
havingValue = "true",
matchIfMissing = true
)
class JWTSecurityConfig {
@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class OrderConsumer(

private val log = LoggerFactory.getLogger(javaClass)


@SqsListener("\${sqs.queues.request-payment-response}")
fun onMessage(message: PaymentEvent, @Headers headers: MessageHeaders) {
log.info("Event from payment response received $message")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"properties": [
{
"name": "admin.access-token",
"type": "java.lang.String",
"description": "Description for admin-access-token."
},
{
"name": "payment-provider.mock",
"type": "java.lang.String",
Expand Down Expand Up @@ -34,6 +29,21 @@
"name": "mercadopago.integration.webhookBaseUrl",
"type": "java.lang.String",
"description": "Description for mercadopago.integration.webhookBaseUrl."
},
{
"name": "sqs.queues.request-payment-response",
"type": "java.lang.String",
"description": "Description for sqs.queues.request-payment-response."
},
{
"name": "sns.topics.request-payment",
"type": "java.lang.String",
"description": "Description for sns.topics.request-payment."
},
{
"name": "security.enable",
"type": "java.lang.String",
"description": "Description for security.enable."
}
]
}
10 changes: 10 additions & 0 deletions src/main/resources/application-live.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
security:
enable: true

spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: ${COGNITO_ISSUER_URI}
jwk-set-uri: ${COGNITO_JWK_SET_URI}
15 changes: 15 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
cloud:
aws:
endpoint: http://localhost:4566
credentials:
access-key: localstack
secret-key: localstack
region:
static: ${AWS_REGION}

clients:
stock-api:
url: http://stock.stock
payments-api:
url: http://payments.payments
7 changes: 5 additions & 2 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
admin:
access-token: token
clients:
stock-api:
url: http://stock.stock
payments-api:
url: http://payments.payments
30 changes: 8 additions & 22 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
spring:
cloud:
aws:
endpoint: http://localhost:4566
credentials:
access-key: localstack
secret-key: localstack
region:
static: ${AWS_REGION}
application:
name: orders-api
datasource:
Expand All @@ -25,26 +17,20 @@ spring:
non_contextual_creation: true
ddl-auto: validate
globally_quoted_identifiers: true
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://cognito-idp.us-east-1.amazonaws.com/us-east-1_ygM5FRn7D
jwk-set-uri: https://cognito-idp.us-east-1.amazonaws.com/us-east-1_ygM5FRn7D/.well-known/jwks.json

admin:
access-token: ${ADMIN_ACCESS_TOKEN}

clients:
stock-api:
url: ${STOCK_SERVICE_URL}
payments-api:
url: ${PAYMENTS_SERVICE_URL}


topic:
request-payment: arn:aws:sns:us-east-2:000000000000:request-payment_topic

sqs:
queues:
request-payment-response: payment-response_queue
request-payment-response: payment-response_queue

sns:
topics:
request-payment: request-payment_topic

security:
enable: false
23 changes: 19 additions & 4 deletions src/test/kotlin/com/fiap/order/TestAnnotations.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.fiap.order

import com.fiap.order.it.LocalStackContainerInitializer
import com.fiap.order.it.PostgreSQLContainerInitializer
import com.fiap.order.it.LocalStackTestConfig
import org.junit.jupiter.api.Tag
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.cloud.openfeign.FeignAutoConfiguration
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.ContextConfiguration

Expand All @@ -10,7 +15,17 @@ import org.springframework.test.context.ContextConfiguration
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class IntegrationTest

@ContextConfiguration(initializers = [PostgreSQLContainerInitializer::class])
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(
initializers = [
PostgreSQLContainerInitializer::class,
LocalStackContainerInitializer::class
],
classes = [
LocalStackTestConfig::class,
FeignAutoConfiguration::class,
ServletWebServerFactoryAutoConfiguration::class,
]
)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE)
annotation class WithPostgreSQL
annotation class WithAllDependencies
13 changes: 13 additions & 0 deletions src/test/kotlin/com/fiap/order/it/BasicIntegrationTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fiap.order.it

import com.fiap.order.IntegrationTest
import com.fiap.order.WithAllDependencies
import org.junit.jupiter.api.Test

@IntegrationTest
@WithAllDependencies
class BasicIntegrationTest {

@Test
fun contextLoads() { }
}
Loading

0 comments on commit 75818e2

Please sign in to comment.