Skip to content

Commit c3e5439

Browse files
EFRS-1286: Fixed tests
1 parent ac79bcd commit c3e5439

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

java/admin/src/main/resources/db/changelog/db.changelog-0.2.4.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ databaseChangeLog:
33
id: expand-oauth_access_token-and-oauth_refresh_token-with-expiration-column
44
author: Volodymyr Bushko
55
changes:
6-
# add an expiration column
6+
# add an expiration column to the oauth_access_token & oauth_refresh_token tables
77
- addColumn:
88
tableName: oauth_access_token
99
columns:
@@ -16,15 +16,15 @@ databaseChangeLog:
1616
- column:
1717
name: expiration
1818
type: timestamp
19-
# set an oauth token expiration to avoid conflicts
19+
# set the expiration columns in order to avoid conflicts
2020
- customChange: {
2121
"class": "com.exadel.frs.commonservice.system.liquibase.customchange.SetOAuthTokenExpirationCustomChange",
2222
"clientId": "${common-client.client-id}",
2323
"accessTokenValidity": "${common-client.access-token-validity}",
2424
"refreshTokenValidity": "${common-client.refresh-token-validity}",
2525
"authorizedGrantTypes": "${common-client.authorized-grant-types}"
2626
}
27-
# add a non-null constraint to the expiration column
27+
# add a not-null constraint to the expiration columns
2828
- addNotNullConstraint:
2929
tableName: oauth_access_token
3030
columnName: expiration

java/api/src/test/java/com/exadel/frs/core/trainservice/EmbeddedPostgreSQLTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.exadel.frs.core.trainservice.config.IntegrationTest;
44
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
5+
import javax.annotation.PostConstruct;
6+
import javax.sql.DataSource;
57
import liquibase.Contexts;
68
import liquibase.LabelExpression;
79
import liquibase.Liquibase;
@@ -10,12 +12,10 @@
1012
import liquibase.integration.spring.SpringResourceAccessor;
1113
import org.junit.jupiter.api.extension.ExtendWith;
1214
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.core.env.Environment;
1316
import org.springframework.core.io.ResourceLoader;
1417
import org.springframework.test.context.junit.jupiter.SpringExtension;
1518

16-
import javax.annotation.PostConstruct;
17-
import javax.sql.DataSource;
18-
1919
@IntegrationTest
2020
@ExtendWith(SpringExtension.class)
2121
@AutoConfigureEmbeddedDatabase(beanName = "dsPg")
@@ -27,6 +27,9 @@ public class EmbeddedPostgreSQLTest {
2727
@Autowired
2828
ResourceLoader resourceLoader;
2929

30+
@Autowired
31+
private Environment env;
32+
3033
@PostConstruct
3134
public void initDatabase() {
3235
try {
@@ -35,10 +38,23 @@ public void initDatabase() {
3538
new SpringResourceAccessor(resourceLoader),
3639
DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()))
3740
);
41+
setLiquibaseChangeLogParams(liquibase);
3842
liquibase.update(new Contexts(), new LabelExpression());
3943
} catch (Exception e) {
4044
//manage exception
4145
e.printStackTrace();
4246
}
4347
}
48+
49+
private void setLiquibaseChangeLogParams(final Liquibase liquibase) {
50+
String clientId = env.getProperty("spring.liquibase.parameters.common-client.client-id", "CommonClientId");
51+
String accessTokenValidity = env.getProperty("spring.liquibase.parameters.common-client.access-token-validity", "2400");
52+
String refreshTokenValidity = env.getProperty("spring.liquibase.parameters.common-client.refresh-token-validity", "1209600");
53+
String authorizedGrantTypes = env.getProperty("spring.liquibase.parameters.common-client.authorized-grant-types", "password,refresh_token");
54+
55+
liquibase.setChangeLogParameter("common-client.client-id", clientId);
56+
liquibase.setChangeLogParameter("common-client.access-token-validity", accessTokenValidity);
57+
liquibase.setChangeLogParameter("common-client.refresh-token-validity", refreshTokenValidity);
58+
liquibase.setChangeLogParameter("common-client.authorized-grant-types", authorizedGrantTypes);
59+
}
4460
}

java/api/src/test/resources/application.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ spring:
55
enabled: false
66
liquibase:
77
enabled: false
8+
parameters:
9+
common-client:
10+
client-id: CommonClientId
11+
access-token-validity: 2400
12+
refresh-token-validity: 1209600
13+
authorized-grant-types: password,refresh_token
814
datasource-pg:
915
driver-class-name: org.postgresql.Driver
1016
url: ${POSTGRES_URL:jdbc:postgresql://localhost:5432/frs_test}

java/api/src/test/resources/db/changelog/db.changelog-0.2.4.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ databaseChangeLog:
33
id: expand-oauth_access_token-and-oauth_refresh_token-with-expiration-column
44
author: Volodymyr Bushko
55
changes:
6-
# add an expiration column
6+
# add an expiration column to the oauth_access_token & oauth_refresh_token tables
77
- addColumn:
88
tableName: oauth_access_token
99
columns:
@@ -16,15 +16,15 @@ databaseChangeLog:
1616
- column:
1717
name: expiration
1818
type: timestamp
19-
# set an oauth token expiration to avoid conflicts
19+
# set the expiration columns in order to avoid conflicts
2020
- customChange: {
2121
"class": "com.exadel.frs.commonservice.system.liquibase.customchange.SetOAuthTokenExpirationCustomChange",
22-
"clientId": "CommonClientId",
23-
"accessTokenValidity": "2400",
24-
"refreshTokenValidity": "1209600",
25-
"authorizedGrantTypes": "password,refresh_token"
22+
"clientId": "${common-client.client-id}",
23+
"accessTokenValidity": "${common-client.access-token-validity}",
24+
"refreshTokenValidity": "${common-client.refresh-token-validity}",
25+
"authorizedGrantTypes": "${common-client.authorized-grant-types}"
2626
}
27-
# add a non-null constraint to the expiration column
27+
# add a not-null constraint to the expiration columns
2828
- addNotNullConstraint:
2929
tableName: oauth_access_token
3030
columnName: expiration

0 commit comments

Comments
 (0)