Skip to content

Commit 9bfcf15

Browse files
authored
Merge pull request #3 from javieraviles/feature/adding-flyway
Adding flyway
2 parents 596ae39 + 6e61d80 commit 9bfcf15

File tree

7 files changed

+72
-82
lines changed

7 files changed

+72
-82
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Even though the dashboard will always represent the quality status of master, is
8080
- Make sure the technial debt in Sonar is the same or better when your code is merged.
8181

8282
## Database
83-
Locally, just for development purposes, an H2 database will be used. Once deployed, the application will use a *PostgreSQL* in Heroku. Connection details will get overriden as environment variables replaced in the `Dockerfile` CMD.
83+
For testing purposes an H2 database will be used (notice the %test prefix in `application properties` that only apply to mvn test). Once deployed, the application will use a *PostgreSQL* in Heroku. Connection details will get overriden as environment variables will replace some `application properties` (notice the ${PORT:8080} annotation, this will get a default value of `8080` unless a `PORT` environment variables is set, in which case its value will override the `8080`).
8484

8585
## Api docs
8686
Both [OpenAPI](https://quarkus-github-flow.herokuapp.com/openapi) and [Swagger-UI](https://quarkus-github-flow.herokuapp.com/swagger-ui) are available.
@@ -114,10 +114,3 @@ Or, if you don't have GraalVM installed, you can run the native executable build
114114
You can then execute your native executable with: `./target/quarkus-github-flow-1.0.0-SNAPSHOT-runner`
115115

116116
If you want to learn more about building native executables, please consult https://quarkus.io/guides/building-native-image.
117-
118-
119-
120-
## TODO / WHY NATIVE IMAGE
121-
122-
## TODO / HEROKU
123-

integrationtests/quarkus-github-flow.postman_collection.json

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
11
{
22
"info": {
3-
"_postman_id": "4a5ee180-a2f0-4973-8078-e76a6132ab40",
3+
"_postman_id": "5bcc2efa-836e-46a0-a515-9c28d2a07cb2",
44
"name": "quarkus-github-flow",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
77
"item": [
88
{
9-
"name": "Developers endpoint contain expected object",
9+
"name": "Create a new developer",
1010
"event": [
1111
{
1212
"listen": "test",
1313
"script": {
14-
"id": "625d8279-05a6-48e8-8856-11ce19d66f77",
14+
"id": "d3ed8cea-2dd9-41b9-8a79-5e8833936f11",
1515
"exec": [
1616
"pm.test(\"Status code is 200\", function () {\r",
1717
" pm.response.to.have.status(200);\r",
1818
"});\r",
1919
"\r",
20-
"var devJavi = { id:1, name: \"Javier Aviles\", email: \"avileslopez.javier@gmail.com\" };\r",
20+
"var jsonData = pm.response.json();\r",
2121
"\r",
22-
"pm.test(\"Check if developers array includes Javier Aviles\", function () {\r",
23-
" pm.expect(pm.response.json()).to.be.an('array').that.deep.includes.members([devJavi]);\r",
24-
"});"
22+
"pm.environment.set(\"devId\", jsonData.id);"
2523
],
2624
"type": "text/javascript"
2725
}
2826
}
2927
],
3028
"request": {
31-
"method": "GET",
29+
"method": "POST",
3230
"header": [],
31+
"body": {
32+
"mode": "raw",
33+
"raw": "{\n\t\"name\":\"Javier Aviles\",\n\t\"email\":\"avileslopez.javier@gmail.com\"\n}",
34+
"options": {
35+
"raw": {
36+
"language": "json"
37+
}
38+
}
39+
},
3340
"url": {
3441
"raw": "{{baseUrl}}developers",
3542
"host": [
@@ -40,20 +47,20 @@
4047
"response": []
4148
},
4249
{
43-
"name": "Developers search endpoint works as expected",
50+
"name": "Developers endpoint contain new Developer",
4451
"event": [
4552
{
4653
"listen": "test",
4754
"script": {
48-
"id": "a686ca82-1e32-44f6-afe9-1b8f24857ad5",
55+
"id": "1119c6f3-02e6-4c26-accc-5466d66d4727",
4956
"exec": [
5057
"pm.test(\"Status code is 200\", function () {\r",
5158
" pm.response.to.have.status(200);\r",
5259
"});\r",
5360
"\r",
54-
"var devJavi = { id:1, name: \"Javier Aviles\", email: \"avileslopez.javier@gmail.com\" };\r",
61+
"var devJavi = { id:pm.environment.get(\"devId\"), name: \"Javier Aviles\", email: \"avileslopez.javier@gmail.com\" };\r",
5562
"\r",
56-
"pm.test(\"Check if developers array includes Javier Aviles\", function () {\r",
63+
"pm.test(\"Check if developers collection includes Javier Aviles\", function () {\r",
5764
" pm.expect(pm.response.json()).to.be.an('array').that.deep.includes.members([devJavi]);\r",
5865
"});"
5966
],
@@ -64,47 +71,6 @@
6471
"request": {
6572
"method": "GET",
6673
"header": [],
67-
"url": {
68-
"raw": "{{baseUrl}}developers/search/Avile",
69-
"host": [
70-
"{{baseUrl}}developers"
71-
],
72-
"path": [
73-
"search",
74-
"Avile"
75-
]
76-
}
77-
},
78-
"response": []
79-
},
80-
{
81-
"name": "Create a new developer",
82-
"event": [
83-
{
84-
"listen": "test",
85-
"script": {
86-
"id": "e2c27a4d-bcdb-4b53-96c0-e0d6640292c5",
87-
"exec": [
88-
"pm.test(\"Status code is 204\", function () {\r",
89-
" pm.response.to.have.status(204);\r",
90-
"});"
91-
],
92-
"type": "text/javascript"
93-
}
94-
}
95-
],
96-
"request": {
97-
"method": "POST",
98-
"header": [],
99-
"body": {
100-
"mode": "raw",
101-
"raw": "{\n\t\"name\":\"James Gosling\",\n\t\"email\":\"james.gosling@java.net\"\n}",
102-
"options": {
103-
"raw": {
104-
"language": "json"
105-
}
106-
}
107-
},
10874
"url": {
10975
"raw": "{{baseUrl}}developers",
11076
"host": [
@@ -115,21 +81,21 @@
11581
"response": []
11682
},
11783
{
118-
"name": "Developers endpoint contain new developer",
84+
"name": "Developers search endpoint find new developer",
11985
"event": [
12086
{
12187
"listen": "test",
12288
"script": {
123-
"id": "cc57a782-bb5b-4232-be6a-a847f9d37bb3",
89+
"id": "25af1768-b6ef-4f81-ba5c-8caba48f71d2",
12490
"exec": [
12591
"pm.test(\"Status code is 200\", function () {\r",
12692
" pm.response.to.have.status(200);\r",
12793
"});\r",
12894
"\r",
129-
"var devJames = { id:3, name: \"James Gosling\", email: \"james.gosling@java.net\" };\r",
95+
"var devJavi = { id:pm.environment.get(\"devId\"), name: \"Javier Aviles\", email: \"avileslopez.javier@gmail.com\" };\r",
13096
"\r",
131-
"pm.test(\"Check if developers array includes James Gosling\", function () {\r",
132-
" pm.expect(pm.response.json()).to.be.an('array').that.deep.includes.members([devJames]);\r",
97+
"pm.test(\"Check if search can find Javier Aviles\", function () {\r",
98+
" pm.expect(pm.response.json()).to.be.an('array').that.deep.includes.members([devJavi]);\r",
13399
"});"
134100
],
135101
"type": "text/javascript"
@@ -140,9 +106,13 @@
140106
"method": "GET",
141107
"header": [],
142108
"url": {
143-
"raw": "{{baseUrl}}developers",
109+
"raw": "{{baseUrl}}developers/search/Avile",
144110
"host": [
145111
"{{baseUrl}}developers"
112+
],
113+
"path": [
114+
"search",
115+
"Avile"
146116
]
147117
}
148118
},
@@ -154,7 +124,7 @@
154124
{
155125
"listen": "test",
156126
"script": {
157-
"id": "a16da8ce-b8dd-400b-a9bc-ee29b63bdd50",
127+
"id": "f55d548e-d31d-4ecb-b683-3ea1e163638b",
158128
"exec": [
159129
"pm.test(\"Status code is 204\", function () {\r",
160130
" pm.response.to.have.status(204);\r",
@@ -168,33 +138,33 @@
168138
"method": "DELETE",
169139
"header": [],
170140
"url": {
171-
"raw": "{{baseUrl}}developers/3",
141+
"raw": "{{baseUrl}}developers/{{devId}}",
172142
"host": [
173143
"{{baseUrl}}developers"
174144
],
175145
"path": [
176-
"3"
146+
"{{devId}}"
177147
]
178148
}
179149
},
180150
"response": []
181151
},
182152
{
183-
"name": "Developer should not be there anymore",
153+
"name": "Developers search endpoint cant find developer anymore",
184154
"event": [
185155
{
186156
"listen": "test",
187157
"script": {
188-
"id": "6107c6e5-e9e6-43d4-8993-0691c29ed375",
158+
"id": "c43cba2a-aefe-438c-a809-2709629a7434",
189159
"exec": [
190160
"pm.test(\"Status code is 200\", function () {\r",
191161
" pm.response.to.have.status(200);\r",
192162
"});\r",
193163
"\r",
194-
"var devJames = { id:3, name: \"James Gosling\", email: \"james.gosling@java.net\" };\r",
164+
"var devJavi = { id:pm.environment.get(\"devId\"), name: \"Javier Aviles\", email: \"avileslopez.javier@gmail.com\" };\r",
195165
"\r",
196-
"pm.test(\"Check if developers array does not include James Gosling anymore\", function () {\r",
197-
" pm.expect(pm.response.json()).to.be.an('array').that.deep.not.includes.members([devJames]);\r",
166+
"pm.test(\"Developer Javier Aviles cant be found anymore\", function () {\r",
167+
" pm.expect(pm.response.json()).to.be.an('array').that.deep.not.includes.members([devJavi]);\r",
198168
"});"
199169
],
200170
"type": "text/javascript"
@@ -205,9 +175,13 @@
205175
"method": "GET",
206176
"header": [],
207177
"url": {
208-
"raw": "{{baseUrl}}developers",
178+
"raw": "{{baseUrl}}developers/search/Avile",
209179
"host": [
210180
"{{baseUrl}}developers"
181+
],
182+
"path": [
183+
"search",
184+
"Avile"
211185
]
212186
}
213187
},

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.javieraviles</groupId>
66
<artifactId>quarkus-github-flow</artifactId>
7-
<version>0.0.2-SNAPSHOT</version>
7+
<version>0.1.0-SNAPSHOT</version>
88
<properties>
99
<compiler-plugin.version>3.8.1</compiler-plugin.version>
1010
<maven.compiler.parameters>true</maven.compiler.parameters>
@@ -68,6 +68,10 @@
6868
<groupId>io.quarkus</groupId>
6969
<artifactId>quarkus-jdbc-postgresql</artifactId>
7070
</dependency>
71+
<dependency>
72+
<groupId>io.quarkus</groupId>
73+
<artifactId>quarkus-flyway</artifactId>
74+
</dependency>
7175
</dependencies>
7276
<build>
7377
<plugins>

src/main/java/com/javieraviles/DeveloperResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public List<Developer> searchDeveloper(@PathParam("word") String word) {
3434

3535
@POST
3636
@Transactional
37-
public void createDeveloper(@RequestBody Developer newDeveloper) {
37+
public Developer createDeveloper(@RequestBody Developer newDeveloper) {
3838
Developer.persist(newDeveloper);
39+
return newDeveloper;
3940
}
4041

4142
@DELETE

src/main/resources/application.properties

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ quarkus.http.port=${PORT:8080}
22

33
# set DB - only mandatory part
44
quarkus.datasource.driver=org.postgresql.Driver
5-
quarkus.datasource.url=${JDBC_DATABASE_URL:jdbc:postgresql://localhost/db}
5+
quarkus.datasource.url=${JDBC_DATABASE_URL:jdbc:postgresql://192.168.99.111:5432/db}
66
quarkus.datasource.username=${JDBC_DATABASE_USERNAME:user}
77
quarkus.datasource.password=${JDBC_DATABASE_PASSWORD:pass}
8+
9+
# Only for tests
810
%test.quarkus.datasource.url=jdbc:h2:tcp://localhost/mem:test
911
%test.quarkus.datasource.driver=org.h2.Driver
12+
%test.quarkus.hibernate-orm.database.generation=drop-and-create
13+
%test.quarkus.hibernate-orm.sql-load-script=import-developers.sql
1014

1115
# Hibernate details
12-
quarkus.hibernate-orm.log.sql=true
13-
quarkus.hibernate-orm.database.generation=drop-and-create
14-
quarkus.hibernate-orm.sql-load-script=import-developers.sql
16+
%dev.quarkus.hibernate-orm.log.sql=true
17+
18+
# Execute flyway on startup
19+
quarkus.flyway.migrate-at-start=true
20+
quarkus.flyway.schemas=public
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
CREATE SEQUENCE hibernate_sequence START 1;
3+
4+
CREATE TABLE developer (
5+
id int8 NOT NULL,
6+
email varchar(255) NULL,
7+
"name" varchar(255) NULL,
8+
CONSTRAINT developer_pkey PRIMARY KEY (id)
9+
);

src/test/java/com/javieraviles/DeveloperResourceTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import io.quarkus.test.h2.H2DatabaseTestResource;
1313
import io.quarkus.test.junit.QuarkusTest;
1414

15+
/*
16+
* Database is populated for tests form import-developers.sql
17+
*/
1518
@QuarkusTest
1619
@QuarkusTestResource(H2DatabaseTestResource.class)
1720
public class DeveloperResourceTest {

0 commit comments

Comments
 (0)