From 2bd8ab70b4579aff5cfa80bda8d64b8079f330b9 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Fri, 19 Apr 2024 12:09:01 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20more=20tests=20#97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcus Fihlon --- .../apus/configuration/AdminConfigTest.java | 43 +++++++++++++++++ .../apus/configuration/ConfigurationTest.java | 39 +++++++++++++++ .../apus/configuration/FilterConfigTest.java | 48 +++++++++++++++++++ .../plugin/agenda/doag/DoagConfigTest.java | 41 ++++++++++++++++ .../social/mastodon/MastodonConfigTest.java | 45 +++++++++++++++++ src/test/resources/application.properties | 11 +++++ 6 files changed, 227 insertions(+) create mode 100644 src/test/java/swiss/fihlon/apus/configuration/AdminConfigTest.java create mode 100644 src/test/java/swiss/fihlon/apus/configuration/ConfigurationTest.java create mode 100644 src/test/java/swiss/fihlon/apus/configuration/FilterConfigTest.java create mode 100644 src/test/java/swiss/fihlon/apus/plugin/agenda/doag/DoagConfigTest.java create mode 100644 src/test/java/swiss/fihlon/apus/plugin/social/mastodon/MastodonConfigTest.java create mode 100644 src/test/resources/application.properties diff --git a/src/test/java/swiss/fihlon/apus/configuration/AdminConfigTest.java b/src/test/java/swiss/fihlon/apus/configuration/AdminConfigTest.java new file mode 100644 index 0000000..7b0f14b --- /dev/null +++ b/src/test/java/swiss/fihlon/apus/configuration/AdminConfigTest.java @@ -0,0 +1,43 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.configuration; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import swiss.fihlon.apus.util.PasswordUtil; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest +class AdminConfigTest { + + @Autowired + private Configuration configuration; + + @Test + void testAdminConfig() { + final var adminConfig = configuration.getAdmin(); + assertNotNull(adminConfig); + assertFalse(adminConfig.password().isBlank()); + assertTrue(PasswordUtil.matches("12345", adminConfig.password())); + } + +} diff --git a/src/test/java/swiss/fihlon/apus/configuration/ConfigurationTest.java b/src/test/java/swiss/fihlon/apus/configuration/ConfigurationTest.java new file mode 100644 index 0000000..097485e --- /dev/null +++ b/src/test/java/swiss/fihlon/apus/configuration/ConfigurationTest.java @@ -0,0 +1,39 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.configuration; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringBootTest +class ConfigurationTest { + + @Autowired + private Configuration configuration; + + @Test + void testConfiguration() { + assertNotNull(configuration); + assertFalse(configuration.getVersion().isBlank()); + } + +} diff --git a/src/test/java/swiss/fihlon/apus/configuration/FilterConfigTest.java b/src/test/java/swiss/fihlon/apus/configuration/FilterConfigTest.java new file mode 100644 index 0000000..49ccfc7 --- /dev/null +++ b/src/test/java/swiss/fihlon/apus/configuration/FilterConfigTest.java @@ -0,0 +1,48 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.configuration; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertIterableEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest +class FilterConfigTest { + + @Autowired + private Configuration configuration; + + @Test + void testFilterConfig() { + final var filterConfig = configuration.getFilter(); + assertNotNull(filterConfig); + assertEquals(500, filterConfig.length()); + assertFalse(filterConfig.replies()); + assertTrue(filterConfig.sensitive()); + assertIterableEquals(List.of("foo", "bar", "foobar", "barfoo"), filterConfig.words()); + } + +} diff --git a/src/test/java/swiss/fihlon/apus/plugin/agenda/doag/DoagConfigTest.java b/src/test/java/swiss/fihlon/apus/plugin/agenda/doag/DoagConfigTest.java new file mode 100644 index 0000000..30ea518 --- /dev/null +++ b/src/test/java/swiss/fihlon/apus/plugin/agenda/doag/DoagConfigTest.java @@ -0,0 +1,41 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.plugin.agenda.doag; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import swiss.fihlon.apus.configuration.Configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@SpringBootTest +class DoagConfigTest { + + @Autowired + private Configuration configuration; + + @Test + void testDoagConfig() { + final var doagConfig = configuration.getDoag(); + assertNotNull(doagConfig); + assertEquals(-1, doagConfig.eventId()); + } + +} diff --git a/src/test/java/swiss/fihlon/apus/plugin/social/mastodon/MastodonConfigTest.java b/src/test/java/swiss/fihlon/apus/plugin/social/mastodon/MastodonConfigTest.java new file mode 100644 index 0000000..e1bb87e --- /dev/null +++ b/src/test/java/swiss/fihlon/apus/plugin/social/mastodon/MastodonConfigTest.java @@ -0,0 +1,45 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.plugin.social.mastodon; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import swiss.fihlon.apus.configuration.Configuration; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest +class MastodonConfigTest { + + @Autowired + private Configuration configuration; + + @Test + void testMastodonConfig() { + final var mastodonConfig = configuration.getMastodon(); + assertNotNull(mastodonConfig); + assertEquals("mastodon.social", mastodonConfig.instance()); + assertEquals("java", mastodonConfig.hashtag()); + assertTrue(mastodonConfig.imagesEnabled()); + assertEquals(1, mastodonConfig.imageLimit()); + } + +} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..68b8d5c --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,11 @@ +apus.version=@project.version@ +apus.admin.password=$2a$10$nybQbl/iY8SRJkfHJVncS.L5.OC3KJ6VRBYVAID7qnUqwylmn/BtK +apus.filter.length=500 +apus.filter.replies=false +apus.filter.sensitive=true +apus.filter.words=foo, bar, foobar, barfoo +apus.doag.eventId=-1 +apus.mastodon.instance=mastodon.social +apus.mastodon.hashtag=java +apus.mastodon.imagesEnabled=true +apus.mastodon.imageLimit=1