Skip to content

Commit

Permalink
refs #139: run database down scenarios in a separated file
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciogeneroso committed Nov 3, 2023
1 parent c868cdd commit e73551b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.zonky.test.db.postgres.embedded.EmbeddedPostgres
import org.postgresql.util.PSQLException
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.sql.DriverManager
import java.sql.SQLException
import java.sql.Timestamp
import java.util.*
Expand All @@ -21,6 +22,9 @@ class PostgresDao(
embeddedPostgres.postgresDatabase.connection
} catch (ex: PSQLException) {
embeddedPostgres = EmbeddedPostgres.builder().setPort(5432).start()
while(DriverManager.getConnection(embeddedPostgres.getJdbcUrl("postgres", "postgres")) == null) {
Thread.sleep(1000)
}
}
createTables()
}
Expand Down
9 changes: 0 additions & 9 deletions sales-catalog-ft/src/test/resources/features/actuator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ Feature: Checking Service Discovery actuator endpoints return expected outputs
| ping |
| refreshScope |

Scenario: When database is down, returns 503 response status
Given a private endpoint PRIVATE_HEALTH_CHECK is prepared
And database is down
When the request is sent
Then the response status code should be 503
And the health response body of the message should have the status "DOWN"
And health components should contain the status DOWN:
| db |

Scenario: When application is running, display metric content
Given a private endpoint PRIVATE_METRICS is prepared
When the request is sent
Expand Down
34 changes: 34 additions & 0 deletions sales-catalog-ft/src/test/resources/features/database.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Feature: Scenarios for database down

Background:
And database is down

# Actuator
Scenario: When database is down, returns 503 response status
Given a private endpoint PRIVATE_HEALTH_CHECK is prepared
When the request is sent
Then the response status code should be 503
And the health response body of the message should have the status "DOWN"
And health components should contain the status DOWN:
| db |

# Get products
Scenario: When call to retrieve products and database is down should return 500
Given an endpoint PRODUCT_GET is prepared
When the request is sent
Then the response status code should be 500
And the response error detail should be Database exception

Scenario: When call to retrieve product by id gets a database down should return 500
Given an endpoint PRODUCT_GET is prepared with path parameter d6b76b42-7a45-11ee-b962-0242ac120002
When the request is sent
Then the response status code should be 500
And the response error detail should be Database exception

# Create products
Scenario: When a sales user calls to register a new product and database is down should return internal server error
Given an endpoint PRODUCT_POST is prepared
And use a JWT token for user sales with role api-sales
When the request is sent
Then the response status code should be 500
And the response error detail should be Database exception
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,4 @@ Feature: Product controller scenarios for creating a new product
| DESCRIPTION_MISSING |
| PRICE_MAX_DIGITS_ALLOWED |
| PRICE_DECIMAL_MAX_DIGITS_ALLOWED |
| QUANTITY_POSITIVE |

# Internal Server Error
Scenario: When a sales user calls to register a new product and database is down should return internal server error
Given an endpoint PRODUCT_POST is prepared
And use a JWT token for user sales with role api-sales
And database is down
When the request is sent
Then the response status code should be 500
And the response error detail should be Database exception
| QUANTITY_POSITIVE |
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,4 @@ Feature: Product controller scenarios for retrieving products
Then the response status code should be 200
And product response object has:
| version | name | description | price | quantity | isReserved | isSold |
| v1 | Product name | Product description | 10.00 | 50 | false | false |

# Internal Server Error
Scenario: When call to retrieve products and database is down should return 500
Given an endpoint PRODUCT_GET is prepared
And database is down
When the request is sent
Then the response status code should be 500
And the response error detail should be Database exception

Scenario: When call to retrieve product by id gets a database down should return 500
Given an endpoint PRODUCT_GET is prepared with path parameter d6b76b42-7a45-11ee-b962-0242ac120002
And database is down
When the request is sent
Then the response status code should be 500
And the response error detail should be Database exception
| v1 | Product name | Product description | 10.00 | 50 | false | false |

0 comments on commit e73551b

Please sign in to comment.