-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#213 add integration-test module to test reloading of configurations
- Loading branch information
Thorsten Marx
committed
Jun 24, 2024
1 parent
6329752
commit f96d9b6
Showing
11 changed files
with
311 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.github.thmarx.cms</groupId> | ||
<artifactId>cms-parent</artifactId> | ||
<version>5.1.0</version> | ||
</parent> | ||
<artifactId>integration-tests</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.thmarx.cms</groupId> | ||
<artifactId>cms-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.thmarx.cms</groupId> | ||
<artifactId>cms-filesystem</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## YAML Template. | ||
--- | ||
values: | ||
- id: blue | ||
title: Blau | ||
- id: red | ||
title: Rot | ||
- id: orange | ||
title: Orange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## YAML Template. | ||
--- | ||
taxonomies: | ||
- title: Kategorie | ||
slug: kategorien | ||
field: taxonomy.category | ||
- title: Tags | ||
slug: tags | ||
field: taxonomy.tags | ||
array: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## YAML Template. | ||
--- | ||
values: | ||
- id: blue | ||
title: Blau | ||
- id: red | ||
title: Rot | ||
- id: orange | ||
title: Orange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## YAML Template. | ||
--- | ||
taxonomies: | ||
- title: Kategorie | ||
slug: kategorien | ||
field: taxonomy.category | ||
- title: Tags | ||
slug: tags | ||
field: taxonomy.tags | ||
array: true |
141 changes: 141 additions & 0 deletions
141
.../test/java/com/github/thmarx/cms/integration/tests/ConfigurationManagementReloadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package com.github.thmarx.cms.integration.tests; | ||
|
||
/*- | ||
* #%L | ||
* integration-tests | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
import com.github.thmarx.cms.api.ServerProperties; | ||
import com.github.thmarx.cms.api.configuration.Configuration; | ||
import com.github.thmarx.cms.api.configuration.ConfigurationManagement; | ||
import com.github.thmarx.cms.api.configuration.configs.ServerConfiguration; | ||
import com.github.thmarx.cms.api.eventbus.Event; | ||
import com.github.thmarx.cms.api.eventbus.EventBus; | ||
import com.github.thmarx.cms.api.eventbus.EventListener; | ||
import com.github.thmarx.cms.filesystem.FileDB; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import java.util.Map; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public class ConfigurationManagementReloadTest { | ||
|
||
static FileDB db; | ||
|
||
static Configuration configuration; | ||
|
||
static ConfigurationManagement configurationManagement; | ||
|
||
static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); | ||
|
||
static MockEventBus eventBus = new MockEventBus(); | ||
|
||
@BeforeAll | ||
static void setup() throws IOException { | ||
|
||
var serverProps = Mockito.mock(ServerProperties.class); | ||
|
||
Mockito.when(serverProps.env()).thenReturn("dev"); | ||
|
||
configuration = new Configuration(Path.of("reload/")); | ||
configuration.add(ServerConfiguration.class, new ServerConfiguration(serverProps)); | ||
|
||
db = new FileDB(Path.of("reload/"), eventBus, (path) -> Map.of(), configuration); | ||
db.init(); | ||
|
||
configurationManagement = new ConfigurationManagement(db, configuration, scheduler, eventBus); | ||
configurationManagement.init(0, 5, TimeUnit.SECONDS); | ||
} | ||
|
||
@BeforeEach | ||
void prepare_clean_run () throws IOException { | ||
Files.deleteIfExists(Path.of("reload/config/taxonomy.yaml")); | ||
Files.deleteIfExists(Path.of("reload/config/taxonomy.tags.yaml")); | ||
} | ||
|
||
@AfterAll | ||
static void shutdown() throws Exception { | ||
db.close(); | ||
scheduler.shutdown(); | ||
} | ||
|
||
@Test | ||
void test_taxonomy() throws Exception { | ||
|
||
eventBus.reset(); | ||
Files.copy( | ||
Path.of("reload/taxonomies/taxonomy.yaml"), | ||
Path.of("reload/config/taxonomy.yaml") | ||
); | ||
Files.copy( | ||
Path.of("reload/taxonomies/taxonomy.tags.yaml"), | ||
Path.of("reload/config/taxonomy.tags.yaml") | ||
); | ||
|
||
configurationManagement.reload(); | ||
|
||
Thread.sleep(Duration.ofSeconds(6)); | ||
|
||
Assertions.assertThat(eventBus.pubCounter).isEqualTo(2); | ||
} | ||
|
||
static class MockEventBus implements EventBus { | ||
|
||
private int pubCounter = 0; | ||
|
||
public void reset() { | ||
pubCounter = 0; | ||
} | ||
|
||
@Override | ||
public <T extends Event> void syncPublish(T event) { | ||
} | ||
|
||
@Override | ||
public <T extends Event> void publish(T event) { | ||
pubCounter++; | ||
} | ||
|
||
@Override | ||
public <T extends Event> void register(Class<T> eventClass, EventListener<T> listener) { | ||
} | ||
|
||
@Override | ||
public <T extends Event> void unregister(Class<T> eventClass, EventListener<T> listener) { | ||
} | ||
|
||
@Override | ||
public void unregister(EventListener listener) { | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...-tests/src/test/java/com/github/thmarx/cms/integration/tests/ConfigurationReloadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.github.thmarx.cms.integration.tests; | ||
|
||
/*- | ||
* #%L | ||
* integration-tests | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import com.github.thmarx.cms.api.configuration.Configuration; | ||
import com.github.thmarx.cms.api.configuration.configs.TaxonomyConfiguration; | ||
import com.github.thmarx.cms.api.eventbus.EventBus; | ||
import com.github.thmarx.cms.filesystem.FileSystem; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public class ConfigurationReloadTest { | ||
|
||
static FileSystem fileSystem; | ||
|
||
static Configuration configuration; | ||
|
||
@BeforeAll | ||
static void setup() throws IOException { | ||
|
||
Files.deleteIfExists(Path.of("reload/config/taxonomy.yaml")); | ||
Files.deleteIfExists(Path.of("reload/config/taxonomy.tags.yaml")); | ||
|
||
var eventBus = Mockito.mock(EventBus.class); | ||
|
||
fileSystem = new FileSystem(Path.of("reload/"), eventBus, (file) -> { | ||
try { | ||
return new Yaml().load(Files.readString(file)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
fileSystem.init(); | ||
|
||
configuration = new Configuration(fileSystem.base()); | ||
} | ||
|
||
@AfterAll | ||
static void shutdown () { | ||
fileSystem.shutdown(); | ||
} | ||
|
||
@Test | ||
void test_taxonomy () throws IOException { | ||
|
||
TaxonomyConfiguration config = configuration.get(TaxonomyConfiguration.class); | ||
|
||
Assertions.assertThat(config.getTaxonomies()).isEmpty(); | ||
|
||
Files.copy( | ||
Path.of("reload/taxonomies/taxonomy.yaml"), | ||
Path.of("reload/config/taxonomy.yaml") | ||
); | ||
Files.copy( | ||
Path.of("reload/taxonomies/taxonomy.tags.yaml"), | ||
Path.of("reload/config/taxonomy.tags.yaml") | ||
); | ||
|
||
configuration.reload(TaxonomyConfiguration.class); | ||
|
||
Assertions.assertThat(config.getTaxonomies()).isNotEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters