Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Implemented unit test & added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lmeinen committed Jun 25, 2021
1 parent d905fac commit 6b6c41e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ch.admin.bag.covidcertificate.backend.verifier.data;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

class AppTokenDataServiceTest extends BaseDataServiceTest {

@Autowired AppTokenDataService appTokenDataService;
@Autowired DataSource dataSource;

@Test
void getAppTokensTest() {
var appTokens = appTokenDataService.getAppTokens();
assertTrue(appTokens.isEmpty());
final var insert = new SimpleJdbcInsert(dataSource).withTableName("t_app_tokens");
final var params = new MapSqlParameterSource();
params.addValue("api_key", "4d1d5663-b4ef-46a5-85b6-3d1d376429da");
params.addValue("description", "local");
insert.execute(params);
appTokens = appTokenDataService.getAppTokens();
assertEquals(1, appTokens.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

package ch.admin.bag.covidcertificate.backend.verifier.data.config;

import ch.admin.bag.covidcertificate.backend.verifier.data.AppTokenDataService;
import ch.admin.bag.covidcertificate.backend.verifier.data.VerifierDataService;
import ch.admin.bag.covidcertificate.backend.verifier.data.impl.JdbcAppTokenDataServiceImpl;
import ch.admin.bag.covidcertificate.backend.verifier.data.impl.JdbcVerifierDataServiceImpl;
import javax.sql.DataSource;
import org.springframework.boot.test.context.TestConfiguration;
Expand All @@ -25,4 +27,9 @@ public class TestConfig {
public VerifierDataService verifierDataService(DataSource dataSource) {
return new JdbcVerifierDataServiceImpl(dataSource);
}

@Bean
public AppTokenDataService appTokenDataService(DataSource dataSource) {
return new JdbcAppTokenDataServiceImpl(dataSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import ch.admin.bag.covidcertificate.backend.verifier.data.AppTokenDataService;
import ch.admin.bag.covidcertificate.backend.verifier.ws.config.model.ApiKeyConfig;
import ch.admin.bag.covidcertificate.backend.verifier.ws.controller.RevocationListController;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
Expand All @@ -15,14 +18,18 @@ public class WSSchedulingConfig {
private final ApiKeyConfig apiKeyConfig;
private final AppTokenDataService appTokenDataService;

private static final Logger logger = LoggerFactory.getLogger(WSSchedulingConfig.class);

public WSSchedulingConfig(ApiKeyConfig apiKeyConfig, AppTokenDataService appTokenDataService) {
this.apiKeyConfig = apiKeyConfig;
this.appTokenDataService = appTokenDataService;
}

// Call method every 5 minutes starting at 0am, of every day
@Scheduled(cron = "${ws.authentication.cron:0 0/5 0 ? * *}")
@Scheduled(fixedRate = 30000, initialDelay = 10000)
public void updateAppTokens() {
logger.info("Updating app tokens");
final var appTokens = appTokenDataService.getAppTokens();
final Map<String, String> apiKeys = new HashMap<>();
for (var token : appTokens) {
Expand Down

0 comments on commit 6b6c41e

Please sign in to comment.