Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for everriding of configs #351

Merged
merged 1 commit into from
Dec 13, 2024
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
1 change: 1 addition & 0 deletions cms-core/configs/site-dev.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hostname = [ "localhost" ]
2 changes: 1 addition & 1 deletion cms-core/configs/site.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id = "condation"
hostname = [ "condation.com", "localhost" ]
hostname = [ "condation.com"]
baseurl = "https://condation.com"

[template]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,17 @@
import com.condation.cms.api.eventbus.EventBus;
import com.condation.cms.api.scheduler.CronJobContext;
import com.condation.cms.api.scheduler.CronJobScheduler;
import com.condation.cms.api.utils.FileUtils;
import com.condation.cms.core.configuration.reload.CronReload;
import com.condation.cms.api.eventbus.events.ConfigurationReloadEvent;
import com.condation.cms.core.configuration.properties.ExtendedSiteProperties;
import com.condation.cms.core.scheduler.SingleCronJobScheduler;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
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.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
Expand All @@ -58,44 +52,23 @@
@ExtendWith(MockitoExtension.class)
public class SiteConfigurationTest {

SimpleConfiguration configuration;

Scheduler scheduler;
CronJobScheduler cronScheduler;

@Mock
SiteProperties siteProperties;

@Mock
EventBus eventBus;

private ExtendedSiteProperties extSiteProperties;
private SimpleConfiguration siteConfig;
private ExtendedSiteProperties siteProperties;

@BeforeEach
public void setup() throws IOException, SchedulerException {
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
cronScheduler = new SingleCronJobScheduler(scheduler, new CronJobContext(), siteProperties);

configuration = SimpleConfiguration.builder(eventBus)
.id("test-config")
.reloadStrategy(new CronReload("0/10 * * * * ?", cronScheduler))
.addSource(YamlConfigSource.build(Path.of("configs/site.yaml")))
.addSource(TomlConfigSource.build(Path.of("configs/site.toml")))
.build();
siteConfig = ConfigurationFactory.siteConfiguration("dev", Path.of("configs"));

extSiteProperties = new ExtendedSiteProperties(configuration);
siteProperties = new ExtendedSiteProperties(siteConfig);
}

@AfterEach
public void shutdown () throws SchedulerException {
scheduler.clear();
scheduler.shutdown();
}

@Test
public void test_hostname() {
var hostnames = extSiteProperties.hostnames();
var hostnames = siteProperties.hostnames();

Assertions.assertThat(hostnames).contains("localhost", "condation.com");
}
Expand Down
Loading