Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.coronawarn.server.common.persistence.domain.config;

import java.io.IOException;
import java.util.Objects;
import java.util.Properties;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
Expand All @@ -9,20 +9,27 @@
import org.springframework.core.io.support.PropertySourceFactory;

/**
* Because loading yaml files with @PropertySources is not supported in Spring,
* we need this custom implementation for processing the yamls and converting them
* to injectable properties in the Spring application context.
* Because loading yaml files with @PropertySources is not supported in Spring, we need this custom implementation for
* processing the yamls and converting them to injectable properties in the Spring application context.
*/
public class YamlPropertySourceFactory implements PropertySourceFactory {

@Override
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource)
throws IOException {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(encodedResource.getResource());
private final YamlPropertiesFactoryBean factory;

Properties properties = factory.getObject();
public YamlPropertySourceFactory() {
this.factory = new YamlPropertiesFactoryBean();
}

return new PropertiesPropertySource(encodedResource.getResource().getFilename(), properties);
public YamlPropertySourceFactory(YamlPropertiesFactoryBean factory) {
this.factory = factory;
}

@Override
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) {
factory.setResources(encodedResource.getResource());
Properties properties = Objects.requireNonNull(factory.getObject(), "Properties must not be null");
String filename = Objects.requireNonNull(encodedResource.getResource().getFilename(),
"File name must not be null");
return new PropertiesPropertySource(filename, properties);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package app.coronawarn.server.common.persistence.domain.config;

import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

import java.util.Properties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;

@DataJdbcTest
@ExtendWith(MockitoExtension.class)
class YamlPropertySourceFactoryTest {

@Autowired
Expand All @@ -16,13 +29,52 @@ class YamlPropertySourceFactoryTest {
@Autowired
private YamlPropertySourceFactory propertySourceFactory;

@Mock
private YamlPropertiesFactoryBean factoryBean;

@Mock
private Resource resource;

private EncodedResource encodedResource;

@BeforeEach
void setUp() {
encodedResource = new EncodedResource(resource);
}

@Test
void test() {
assertNotNull(tekDerivations);
assertNotNull(propertySourceFactory);
assertThat(tekDerivations.getDaysSinceSymptomsFromTransmissionRiskLevel()).isNotEmpty();
assertThat(tekDerivations.getTransmissionRiskLevelFromDaysSinceSymptoms()).isNotEmpty();
}

@Test
void testCreatePropertySourceWithNullFactoryObjectThrowsException() {
YamlPropertySourceFactory factory = new YamlPropertySourceFactory(factoryBean);
NullPointerException exception = Assertions
.assertThrows(NullPointerException.class,
() -> factory.createPropertySource("test", encodedResource));
assertEquals("Properties must not be null", exception.getMessage());
}

@Test
void testCreatePropertySourceWithNullEncodedResourceFileNameThrowsException() {
when(factoryBean.getObject()).thenReturn(new Properties());
YamlPropertySourceFactory factory = new YamlPropertySourceFactory(factoryBean);
NullPointerException exception = Assertions
.assertThrows(NullPointerException.class,
() -> factory.createPropertySource("test", encodedResource));
assertEquals("File name must not be null", exception.getMessage());
}

assertThat( tekDerivations.getDaysSinceSymptomsFromTransmissionRiskLevel()).isNotEmpty();
assertThat( tekDerivations.getTransmissionRiskLevelFromDaysSinceSymptoms()).isNotEmpty();
@Test
void testCreatePropertySourceShouldBeSuccessfully() {
when(factoryBean.getObject()).thenReturn(new Properties());
when(resource.getFilename()).thenReturn("filename");
YamlPropertySourceFactory factory = new YamlPropertySourceFactory(factoryBean);
PropertySource<?> propertySource = factory.createPropertySource("test", encodedResource);
Assertions.assertEquals("filename", propertySource.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void testDeleteForDate() {
assertThat(federationBatchInfoRepository.countForDate(date1)).isEqualTo(1);
assertThat(federationBatchInfoRepository.countForDate(date2)).isEqualTo(1);
federationBatchInfoRepository.deleteForDate(date1);
assertThat(federationBatchInfoRepository.countForDate(date1)).isEqualTo(0);
assertThat(federationBatchInfoRepository.countForDate(date1)).isZero();
assertThat(federationBatchInfoRepository.countForDate(date2)).isEqualTo(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@

import static app.coronawarn.server.common.persistence.service.DiagnosisKeyServiceTestHelper.assertDiagnosisKeysEqual;
import static app.coronawarn.server.common.persistence.service.DiagnosisKeyServiceTestHelper.buildDiagnosisKeyForSubmissionTimestamp;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import app.coronawarn.server.common.persistence.domain.FederationUploadKey;
import app.coronawarn.server.common.persistence.repository.FederationUploadKeyRepository;
import app.coronawarn.server.common.persistence.service.common.ExpirationPolicy;
import app.coronawarn.server.common.persistence.service.common.KeySharingPoliciesChecker;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import app.coronawarn.server.common.persistence.domain.FederationUploadKey;
import app.coronawarn.server.common.persistence.repository.FederationUploadKeyRepository;
import app.coronawarn.server.common.persistence.service.common.KeySharingPoliciesChecker;
import app.coronawarn.server.common.persistence.service.common.ExpirationPolicy;

@DataJdbcTest
class FederationUploadKeyServiceTest {
Expand Down Expand Up @@ -99,8 +102,9 @@ void shouldRetrieveKeysUnderRetentionOnly() {
when(keySharingPoliciesChecker.canShareKeyAtTime(any(), any(), any())).thenReturn(true);

var actKeys = uploadKeyService.getPendingUploadKeys(ExpirationPolicy.of(0, ChronoUnit.MINUTES), DAYS_TO_RETAIN);
Assertions.assertThat(actKeys).hasSize(1);
Assertions.assertThat(actKeys).doesNotContain(oldKey);
Assertions.assertThat(actKeys)
.hasSize(1)
.doesNotContain(oldKey);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Directory<WritableOnDisk> getDiagnosisKeys() {
* normalized to the Exposure Notification spec.
*/
private List<DiagnosisKey> resetDaysSinceOnsetOfSymptoms(Collection<DiagnosisKey> diagnosisKeys) {
return diagnosisKeys.stream().map(key -> keyWithZeroDaysSinceSymptoms(key)).collect(Collectors.toList());
return diagnosisKeys.stream().map(this::keyWithZeroDaysSinceSymptoms).collect(Collectors.toList());
}

private DiagnosisKey keyWithZeroDaysSinceSymptoms(DiagnosisKey diagnosisKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class DiagnosisKeyBundler {
/**
* Constructs a DiagnosisKeyBundler based on the specified service configuration.
*/
public DiagnosisKeyBundler(DistributionServiceConfig distributionServiceConfig) {
protected DiagnosisKeyBundler(DistributionServiceConfig distributionServiceConfig) {
this.supportedCountries = List.of(distributionServiceConfig.getSupportedCountries());
this.expiryPolicyMinutes = distributionServiceConfig.getExpiryPolicyMinutes();
this.minNumberOfKeysPerBundle = distributionServiceConfig.getShiftingPolicyThreshold();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class AbstractSigningDecorator<W extends Writable<W>> extends Ar
/**
* Creates an AbstractSigningDecorator.
*/
public AbstractSigningDecorator(Archive<W> archive, CryptoProvider cryptoProvider,
protected AbstractSigningDecorator(Archive<W> archive, CryptoProvider cryptoProvider,
DistributionServiceConfig distributionServiceConfig) {
super(archive);
this.cryptoProvider = cryptoProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public abstract class SigningDecoratorOnDisk extends AbstractSigningDecorator<WritableOnDisk> implements
SigningDecorator<WritableOnDisk> {

public SigningDecoratorOnDisk(Archive<WritableOnDisk> archive, CryptoProvider cryptoProvider,
protected SigningDecoratorOnDisk(Archive<WritableOnDisk> archive, CryptoProvider cryptoProvider,
DistributionServiceConfig distributionServiceConfig) {
super(archive, cryptoProvider, distributionServiceConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class AbstractIndexingDecorator<T, W extends Writable<W>> extend
/**
* Creates a new AbstractIndexingDecorator.
*/
public AbstractIndexingDecorator(IndexDirectory<T, W> directory, String indexFileName) {
protected AbstractIndexingDecorator(IndexDirectory<T, W> directory, String indexFileName) {
super(directory);
this.directory = directory;
this.indexFileName = indexFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
Expand Down Expand Up @@ -203,7 +204,7 @@ private boolean hasInvalidTransmissionRiskLevel(TemporaryExposureKey key) {
* @return True if an invalid key was found.
*/
private boolean addViolationForInvalidTek(List<TemporaryExposureKey> exposureKeys,
Function<Stream<TemporaryExposureKey>, Stream<TemporaryExposureKey>> filterFunction,
UnaryOperator<Stream<TemporaryExposureKey>> filterFunction,
ConstraintValidatorContext validatorContext,
Function<TemporaryExposureKey, String> messageConstructor) {
AtomicBoolean foundInvalid = new AtomicBoolean(true);
Expand Down