diff --git a/src/it/spring-fat/invoker.properties b/src/it/spring-fat/invoker.properties index 6db7f0858..b8345f95c 100644 --- a/src/it/spring-fat/invoker.properties +++ b/src/it/spring-fat/invoker.properties @@ -1 +1 @@ -invoker.goals=clean process-classes -e \ No newline at end of file +invoker.goals=clean test -e \ No newline at end of file diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index f332731a9..b3e9707c5 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -58,7 +58,12 @@ SOFTWARE. org.springframework.boot - spring-boot-starter + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test @@ -74,6 +79,9 @@ SOFTWARE. unpack-dependencies + + **/module-info.class + ${project.build.outputDirectory} diff --git a/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Application.java b/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Application.java index 362eb3014..9640156ad 100644 --- a/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Application.java +++ b/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Application.java @@ -23,8 +23,6 @@ */ package org.eolang.jeo.spring; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -33,17 +31,9 @@ * @since 0.2 */ @SpringBootApplication -public class Application implements CommandLineRunner { - - @Autowired - private Receptionist receptionist; +public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } - - @Override - public void run(final String... args) { - this.receptionist.sayHello("Fat Spring"); - } } diff --git a/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Receptionist.java b/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Receptionist.java index 7d3a774d8..e8550c9fe 100644 --- a/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Receptionist.java +++ b/src/it/spring-fat/src/main/java/org/eolang/jeo/spring/Receptionist.java @@ -23,15 +23,21 @@ */ package org.eolang.jeo.spring; -import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * Greeter bean. * @since 0.2 */ -@Component +@RestController public class Receptionist { - public void sayHello(final String who) { - System.out.printf("Glad to see you, %s...%n", who); + + @GetMapping("/hello") + public String greetings( + @RequestParam(defaultValue = "Fat Spring") final String who + ) { + return String.format("Glad to see you, %s...%n", who); } } diff --git a/src/it/spring-fat/src/main/resources/META-INF/spring.factories b/src/it/spring-fat/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..a513d0e4f --- /dev/null +++ b/src/it/spring-fat/src/main/resources/META-INF/spring.factories @@ -0,0 +1,103 @@ +# Logging Systems +org.springframework.boot.logging.LoggingSystemFactory=\ +org.springframework.boot.logging.logback.LogbackLoggingSystem.Factory,\ +org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.Factory,\ +org.springframework.boot.logging.java.JavaLoggingSystem.Factory + +# PropertySource Loaders +org.springframework.boot.env.PropertySourceLoader=\ +org.springframework.boot.env.PropertiesPropertySourceLoader,\ +org.springframework.boot.env.YamlPropertySourceLoader + +# ConfigData Location Resolvers +org.springframework.boot.context.config.ConfigDataLocationResolver=\ +org.springframework.boot.context.config.ConfigTreeConfigDataLocationResolver,\ +org.springframework.boot.context.config.StandardConfigDataLocationResolver + +# ConfigData Loaders +org.springframework.boot.context.config.ConfigDataLoader=\ +org.springframework.boot.context.config.ConfigTreeConfigDataLoader,\ +org.springframework.boot.context.config.StandardConfigDataLoader + +# Application Context Factories +org.springframework.boot.ApplicationContextFactory=\ +org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext.Factory,\ +org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.Factory + +# Run Listeners +org.springframework.boot.SpringApplicationRunListener=\ +org.springframework.boot.context.event.EventPublishingRunListener + +# Error Reporters +org.springframework.boot.SpringBootExceptionReporter=\ +org.springframework.boot.diagnostics.FailureAnalyzers + +# Application Context Initializers +org.springframework.context.ApplicationContextInitializer=\ +org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\ +org.springframework.boot.context.ContextIdApplicationContextInitializer,\ +org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\ +org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer,\ +org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer + +# Application Listeners +org.springframework.context.ApplicationListener=\ +org.springframework.boot.ClearCachesApplicationListener,\ +org.springframework.boot.builder.ParentContextCloserApplicationListener,\ +org.springframework.boot.context.FileEncodingApplicationListener,\ +org.springframework.boot.context.config.AnsiOutputApplicationListener,\ +org.springframework.boot.context.config.DelegatingApplicationListener,\ +org.springframework.boot.context.logging.LoggingApplicationListener,\ +org.springframework.boot.env.EnvironmentPostProcessorApplicationListener + +# Environment Post Processors +org.springframework.boot.env.EnvironmentPostProcessor=\ +org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\ +org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor,\ +org.springframework.boot.env.RandomValuePropertySourceEnvironmentPostProcessor,\ +org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor,\ +org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor,\ +org.springframework.boot.reactor.DebugAgentEnvironmentPostProcessor + +# Failure Analyzers +org.springframework.boot.diagnostics.FailureAnalyzer=\ +org.springframework.boot.context.config.ConfigDataNotFoundFailureAnalyzer,\ +org.springframework.boot.context.properties.IncompatibleConfigurationFailureAnalyzer,\ +org.springframework.boot.context.properties.NotConstructorBoundInjectionFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.BeanCurrentlyInCreationFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.BeanDefinitionOverrideFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.BeanNotOfRequiredTypeFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.BindFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.BindValidationFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.UnboundConfigurationPropertyFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.MutuallyExclusiveConfigurationPropertiesFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.NoUniqueBeanDefinitionFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.PortInUseFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\ +org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\ +org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer,\ +org.springframework.boot.web.context.MissingWebServerFactoryBeanFailureAnalyzer,\ +org.springframework.boot.web.embedded.tomcat.ConnectorStartFailureAnalyzer + +# Failure Analysis Reporters +org.springframework.boot.diagnostics.FailureAnalysisReporter=\ +org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter + +# Database Initializer Detectors +org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\ +org.springframework.boot.flyway.FlywayDatabaseInitializerDetector,\ +org.springframework.boot.jdbc.AbstractDataSourceInitializerDatabaseInitializerDetector,\ +org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializerDetector,\ +org.springframework.boot.liquibase.LiquibaseDatabaseInitializerDetector,\ +org.springframework.boot.orm.jpa.JpaDatabaseInitializerDetector,\ +org.springframework.boot.r2dbc.init.R2dbcScriptDatabaseInitializerDetector + +# Depends On Database Initialization Detectors +org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\ +org.springframework.boot.sql.init.dependency.AnnotationDependsOnDatabaseInitializationDetector,\ +org.springframework.boot.jdbc.SpringJdbcDependsOnDatabaseInitializationDetector,\ +org.springframework.boot.jooq.JooqDependsOnDatabaseInitializationDetector,\ +org.springframework.boot.orm.jpa.JpaDependsOnDatabaseInitializationDetector diff --git a/src/it/spring-fat/src/test/java/org/eolang/jeo/spring/ApplicationTest.java b/src/it/spring-fat/src/test/java/org/eolang/jeo/spring/ApplicationTest.java new file mode 100644 index 000000000..ef240bb4f --- /dev/null +++ b/src/it/spring-fat/src/test/java/org/eolang/jeo/spring/ApplicationTest.java @@ -0,0 +1,75 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2024 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.jeo.spring; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * Integration test for Application. + * @since 0.2 + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class ApplicationTest { + + @Autowired + private TestRestTemplate template; + + @LocalServerPort + private int port; + + @Test + void startupsServerAndMakesGetRequest() { + final ResponseEntity resp = this.template.getForEntity( + String.format("http://localhost:%d/hello", this.port), + String.class + ); + Assertions.assertEquals( + HttpStatus.OK, + resp.getStatusCode(), + "Status code is not OK" + ); + Assertions.assertNotNull( + resp.getBody(), + "Response body is empty" + ); + final String expected = "Glad to see you, Fat Spring"; + System.out.printf("Expected %s%n", expected); + Assertions.assertTrue( + resp.getBody().contains(expected), + String.format( + "Hello response is not correct. The body: %s%n should contain '%s'", + resp.getBody(), + expected + ) + ); + } + +}