-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(standalone): add tests and docs
- Loading branch information
Showing
10 changed files
with
181 additions
and
8 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
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
57 changes: 57 additions & 0 deletions
57
...core/src/test/java/io/github/springwolf/core/standalone/DefaultStandaloneFactoryTest.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,57 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.standalone; | ||
|
||
import io.github.springwolf.core.integrationtests.application.basic.TestApplication; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.StandardEnvironment; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Fail.fail; | ||
|
||
class DefaultStandaloneFactoryTest { | ||
|
||
private String applicationPackageName = TestApplication.class.getPackageName(); | ||
|
||
@Test | ||
void shouldCreateStandaloneFactoryForBasicApplication() { | ||
// when | ||
DefaultStandaloneFactory factory = new DefaultStandaloneFactory(TestApplication.class.getPackageName()); | ||
|
||
// then | ||
assertThat(factory.getAsyncApiService().getAsyncAPI()).isNotNull(); | ||
assertThat(factory.getAsyncApiService().getAsyncAPI().getInfo().getTitle()) | ||
.isEqualTo("Springwolf-core"); | ||
} | ||
|
||
@Test | ||
void shouldCreateStandaloneFactoryForBasicApplicationWithProfile() { | ||
// given | ||
ConfigurableEnvironment environment = StandaloneEnvironmentLoader.load(List.of("standalone")); | ||
|
||
// when | ||
DefaultStandaloneFactory factory = | ||
new DefaultStandaloneFactory(TestApplication.class.getPackageName(), environment); | ||
|
||
// then | ||
assertThat(factory.getAsyncApiService().getAsyncAPI()).isNotNull(); | ||
assertThat(factory.getAsyncApiService().getAsyncAPI().getInfo().getTitle()) | ||
.isEqualTo("Springwolf-core-properties"); | ||
} | ||
|
||
@Test | ||
void shouldThrowWhenConfigurationsAreMissing() { | ||
// when | ||
List<Class<?>> standaloneConfigurations = List.of(); | ||
|
||
try { | ||
new DefaultStandaloneFactory(applicationPackageName, new StandardEnvironment(), standaloneConfigurations); | ||
fail(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(NoSuchBeanDefinitionException.class); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...test/java/io/github/springwolf/core/standalone/StandaloneConfigurationDiscovererTest.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,58 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.standalone; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.env.StandardEnvironment; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class StandaloneConfigurationDiscovererTest { | ||
private final ConfigurableEnvironment environment = new StandardEnvironment(); | ||
|
||
@Test | ||
void shouldFindAllCoreStandaloneConfigurations() { | ||
// when | ||
List<String> classes = StandaloneConfigurationDiscoverer.scan(environment).stream() | ||
.map(Class::getName) | ||
.toList(); | ||
|
||
// then | ||
assertThat(classes) | ||
.containsExactlyInAnyOrder( // | ||
"io.github.springwolf.core.configuration.SpringwolfCoreConfiguration", | ||
"io.github.springwolf.core.configuration.SpringwolfPropertiesConfiguration", | ||
"io.github.springwolf.core.configuration.SpringwolfScannerConfiguration", | ||
"io.github.springwolf.addons.common_model_converters.configuration.CommonModelConvertersAutoConfiguration"); | ||
} | ||
|
||
@Test | ||
void shouldFindAllConfigurationsInPackage() { | ||
// when | ||
List<String> classes = | ||
StandaloneConfigurationDiscoverer.scan("io.github.springwolf.non.existing.package", environment) | ||
.stream() | ||
.map(Class::getName) | ||
.toList(); | ||
|
||
// then | ||
assertThat(classes).containsExactlyInAnyOrder(); | ||
} | ||
|
||
@Test | ||
void shouldFindAllCoreConfigurationsInPackage() { | ||
// when | ||
List<String> classes = StandaloneConfigurationDiscoverer.scan("io.github.springwolf.core", environment).stream() | ||
.map(Class::getName) | ||
.toList(); | ||
|
||
// then | ||
assertThat(classes) | ||
.containsExactlyInAnyOrder( | ||
"io.github.springwolf.core.configuration.SpringwolfCoreConfiguration", | ||
"io.github.springwolf.core.configuration.SpringwolfPropertiesConfiguration", | ||
"io.github.springwolf.core.configuration.SpringwolfScannerConfiguration"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...e/src/test/java/io/github/springwolf/core/standalone/StandaloneEnvironmentLoaderTest.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,32 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.standalone; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class StandaloneEnvironmentLoaderTest { | ||
|
||
@Test | ||
void shouldLoadDefaultEnvironmentTest() { | ||
// when | ||
ConfigurableEnvironment environment = StandaloneEnvironmentLoader.load(); | ||
|
||
// then | ||
assertThat(environment.getActiveProfiles()).containsExactly(); | ||
assertThat(environment.getProperty("spring.application.name")).isEqualTo("Springwolf-core"); | ||
} | ||
|
||
@Test | ||
void shouldLoadStandaloneProfileIncludingPropertyFile() { | ||
// when | ||
ConfigurableEnvironment environment = StandaloneEnvironmentLoader.load(List.of("standalone")); | ||
|
||
// then | ||
assertThat(environment.getActiveProfiles()).containsExactly("standalone"); | ||
assertThat(environment.getProperty("spring.application.name")).isEqualTo("Springwolf-core-properties"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
springwolf-core/src/test/resources/application-standalone.properties
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 @@ | ||
spring.application.name=Springwolf-core-properties |
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