From 0da5d1469fe271b8408190b19ad86e18767132a0 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Thu, 24 Oct 2024 16:07:32 +0300 Subject: [PATCH 1/7] feat(#548): http test --- src/it/spring-fat/invoker.properties | 2 +- src/it/spring-fat/pom.xml | 10 +- .../org/eolang/jeo/spring/Application.java | 12 +- .../org/eolang/jeo/spring/Receptionist.java | 14 ++- .../main/resources/META-INF/spring.factories | 103 ++++++++++++++++++ .../eolang/jeo/spring/ApplicationTest.java | 75 +++++++++++++ 6 files changed, 199 insertions(+), 17 deletions(-) create mode 100644 src/it/spring-fat/src/main/resources/META-INF/spring.factories create mode 100644 src/it/spring-fat/src/test/java/org/eolang/jeo/spring/ApplicationTest.java 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 + ) + ); + } + +} From 18d3c00db28babb63557112d58739ca9d85e50d2 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Tue, 5 Nov 2024 20:30:18 +0300 Subject: [PATCH 2/7] feat(#548): all params --- src/it/spring-fat/invoker.properties | 2 +- src/it/spring-fat/pom.xml | 56 +++++++++++-------- .../org/eolang/jeo/spring/Receptionist.java | 4 +- .../eolang/jeo/spring/ApplicationTest.java | 2 +- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/it/spring-fat/invoker.properties b/src/it/spring-fat/invoker.properties index 6db7f0858..a053e09ce 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 diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index 72e6c8a67..1f6f0e409 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -117,6 +117,16 @@ SOFTWARE. + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + -parameters + + + - - org.codehaus.mojo - exec-maven-plugin - 3.5.0 - - - - process-classes - - - exec - - - - - java - - -classpath - ${project.build.outputDirectory} - org.eolang.jeo.spring.Application - - - + + + + + + + + + + + + + + + + + + + + + + + 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 e8550c9fe..c753802f3 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 @@ -35,9 +35,7 @@ public class Receptionist { @GetMapping("/hello") - public String greetings( - @RequestParam(defaultValue = "Fat Spring") final String who - ) { + public String greetings(@RequestParam final String who) { return String.format("Glad to see you, %s...%n", who); } } 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 index ef240bb4f..32dd4a8c5 100644 --- 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 @@ -48,7 +48,7 @@ class ApplicationTest { @Test void startupsServerAndMakesGetRequest() { final ResponseEntity resp = this.template.getForEntity( - String.format("http://localhost:%d/hello", this.port), + String.format("http://localhost:%d/hello?who=FatSpring", this.port), String.class ); Assertions.assertEquals( From d668f073ff149fff8bed75129266930d7711bdc8 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 6 Nov 2024 10:53:09 +0300 Subject: [PATCH 3/7] feat(#548): passes --- .../src/main/java/org/eolang/jeo/spring/Receptionist.java | 6 ++++-- .../test/java/org/eolang/jeo/spring/ApplicationTest.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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 c753802f3..bafbb5eb4 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 @@ -35,7 +35,9 @@ public class Receptionist { @GetMapping("/hello") - public String greetings(@RequestParam final String who) { - return String.format("Glad to see you, %s...%n", who); + public String greetings( + @RequestParam(defaultValue = "Fat Spring") final String who + ) { + return String.format("Glad to see you, %s...", who); } } 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 index 32dd4a8c5..b111684f3 100644 --- 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 @@ -48,7 +48,7 @@ class ApplicationTest { @Test void startupsServerAndMakesGetRequest() { final ResponseEntity resp = this.template.getForEntity( - String.format("http://localhost:%d/hello?who=FatSpring", this.port), + String.format("http://localhost:%d/hello", this.port), String.class ); Assertions.assertEquals( @@ -60,7 +60,7 @@ void startupsServerAndMakesGetRequest() { resp.getBody(), "Response body is empty" ); - final String expected = "Glad to see you, Fat Spring"; + final String expected = "Glad to see you, Fat Spring..."; System.out.printf("Expected %s%n", expected); Assertions.assertTrue( resp.getBody().contains(expected), From 8fd305d52fa0becb074ae9e4e07b781b4c7b75ef Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 6 Nov 2024 11:01:27 +0300 Subject: [PATCH 4/7] feat(#548): clean for qulice --- src/it/spring-fat/pom.xml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index 1f6f0e409..70f383b44 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -152,29 +152,6 @@ SOFTWARE. - - - - - - - - - - - - - - - - - - - - - - - From 57317eab2782b1632a1c8cd8be2e0226f4ceaf45 Mon Sep 17 00:00:00 2001 From: h1alexbel Date: Wed, 6 Nov 2024 12:13:07 +0300 Subject: [PATCH 5/7] feat(#548): redundant plugin --- src/it/spring-fat/pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index 70f383b44..564597c69 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -117,16 +117,6 @@ SOFTWARE. - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - -parameters - - -