Merge branch 'eugenp:master' into master

This commit is contained in:
Wynn Teo 2024-04-16 08:28:49 +08:00 committed by GitHub
commit 75cc5fbb2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 110 additions and 305 deletions

View File

@ -0,0 +1,30 @@
package com.baeldung.stringtooffsetdatetime;
import org.junit.Test;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import static org.junit.Assert.assertEquals;
public class StringToOffsetDateTimeUnitTest {
String dateTimeString = "2024-04-11T10:15:30+01:00";
@Test
public void givenDateTimeString_whenUsingOffsetDateTimeParse_thenConvertToOffsetDateTime() {
OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateTimeString);
OffsetDateTime expected = OffsetDateTime.of(2024, 4, 11, 10, 15, 30, 0, OffsetDateTime.parse(dateTimeString).getOffset());
assertEquals(expected, offsetDateTime);
}
@Test
public void givenDateTimeStringAndFormatter_whenUsingDateTimeFormatter_thenConvertToOffsetDateTime() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateTimeString, formatter);
OffsetDateTime expected = OffsetDateTime.of(2024, 4, 11, 10, 15, 30, 0, OffsetDateTime.parse(dateTimeString).getOffset());
assertEquals(expected, offsetDateTime);
}
}

View File

@ -30,7 +30,7 @@ public class SymmetricSubstringMaxLengthUnitTest {
@Test
public void givenString_whenUsingBruteForce_thenFindLongestSymmetricSubstring() {
assertEquals(expected, findLongestSymmetricSubstringUsingBruteForce(input).length());
assertEquals(expected, findLongestSymmetricSubstringUsingBruteForce(input));
}
@Test
@ -38,25 +38,23 @@ public class SymmetricSubstringMaxLengthUnitTest {
assertEquals(expected, findLongestSymmetricSubstringUsingSymmetricApproach(input));
}
private String findLongestSymmetricSubstringUsingBruteForce(String str) {
private int findLongestSymmetricSubstringUsingBruteForce(String str) {
if (str == null || str.length() == 0) {
return "";
return 0;
}
int maxLength = 0;
String longestPalindrome = "";
for (int i = 0; i < str.length(); i++) {
for (int j = i + 1; j <= str.length(); j++) {
String substring = str.substring(i, j);
if (isPalindrome(substring) && substring.length() > maxLength) {
maxLength = substring.length();
longestPalindrome = substring;
}
}
}
return longestPalindrome;
return maxLength;
}
private boolean isPalindrome(String s) {

View File

@ -19,17 +19,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
</project>

View File

@ -19,17 +19,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
</project>

View File

@ -37,17 +37,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
<entitymodule.version>1.0</entitymodule.version>
<daomodule.version>1.0</daomodule.version>
<userdaomodule.version>1.0</userdaomodule.version>

View File

@ -32,10 +32,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -9,12 +9,12 @@
<name>multimodulemavenproject</name>
<packaging>pom</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<!--
No <parent> tag since we want the compiler plugin defined
in the <pluginManagement> to be used in submodules.
Detailed discussion:
https://jira.baeldung.com/browse/BAEL-7813
-->
<modules>
<module>maven-entitymodule</module>

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.jdbc.Sql;
@SpringBootTest
@ActiveProfiles("test")
@Sql(scripts = "/testsequence.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
public class MyEntityRepositoryIntegrationTest {
public class MyEntityRepositoryLiveTest {
@Autowired
private MyEntityRepository myEntityRepository;

View File

@ -42,7 +42,10 @@
</build>
<properties>
<spring-cloud-dependencies.version>2021.0.0</spring-cloud-dependencies.version>
<spring-cloud-dependencies.version>2023.0.1</spring-cloud-dependencies.version>
<spring-boot.version>3.2.4</spring-boot.version>
<logback.version>1.5.4</logback.version>
<org.slf4j.version>2.0.12</org.slf4j.version>
</properties>
</project>

View File

@ -1,70 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>data-flow-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>data-flow-server</name>
<packaging>jar</packaging>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-cloud-data-flow-stream-processing</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-dependencies</artifactId>
<version>${spring-cloud-dataflow-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-dataflow-server-local</artifactId>
<version>1.7.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.compatible.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.compatible.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
</dependencies>
<properties>
<spring-cloud-dataflow-dependencies.version>2.0.0.RELEASE</spring-cloud-dataflow-dependencies.version>
<hibernate.compatible.version>5.6.0.Final</hibernate.compatible.version>
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
<groovy.version>3.0.8</groovy.version>
</properties>
</project>

View File

@ -1,14 +0,0 @@
package com.baeldung.spring.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.dataflow.server.EnableDataFlowServer;
@EnableDataFlowServer
@SpringBootApplication
public class DataFlowServerApplication {
public static void main(String[] args) {
SpringApplication.run(DataFlowServerApplication.class, args);
}
}

View File

@ -1,2 +0,0 @@
#spring.datasource.url=jdbc:h2:mem:dataflow
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

View File

@ -1,16 +0,0 @@
package com.baeldung;
import com.baeldung.spring.cloud.DataFlowServerApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DataFlowServerApplication.class)
public class SpringContextTest {
@Test
public void contextLoads() {
}
}

View File

@ -1,49 +0,0 @@
package com.baeldung.spring.cloud;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.ConfigureRedisAction;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DataFlowServerApplicationIntegrationTest {
@Test
public void contextLoads() {
}
@EnableRedisHttpSession
@Configuration
static class Config {
@Bean
@SuppressWarnings("unchecked")
public RedisSerializer<Object> defaultRedisSerializer() {
return Mockito.mock(RedisSerializer.class);
}
@Bean
public RedisConnectionFactory connectionFactory() {
RedisConnectionFactory factory = Mockito.mock(RedisConnectionFactory.class);
RedisConnection connection = Mockito.mock(RedisConnection.class);
Mockito.when(factory.getConnection()).thenReturn(connection);
return factory;
}
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}
}

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>data-flow-shell</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>data-flow-shell</name>
<packaging>jar</packaging>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-cloud-data-flow-stream-processing</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-dependencies</artifactId>
<version>${spring-cloud-dataflow-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-shell</artifactId>
</dependency>
</dependencies>
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<spring-cloud-dataflow-dependencies.version>1.1.0.RELEASE</spring-cloud-dataflow-dependencies.version>
</properties>
</project>

View File

@ -1,14 +0,0 @@
package com.baeldung.spring.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.dataflow.shell.EnableDataFlowShell;
@EnableDataFlowShell
@SpringBootApplication
public class DataFlowShellApplication {
public static void main(String[] args) {
SpringApplication.run(DataFlowShellApplication.class, args);
}
}

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -1,26 +0,0 @@
package com.baeldung;
import com.baeldung.spring.cloud.DataFlowShellApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* This live test requires:
* complete data-flow server and shell setup running
*
* <br>
* For more info:
* https://www.baeldung.com/spring-cloud-data-flow-stream-processing
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DataFlowShellApplication.class)
public class SpringContextLiveTest {
@Test
public void contextLoads() {
}
}

View File

@ -16,8 +16,6 @@
</parent>
<modules>
<module>data-flow-server</module>
<module>data-flow-shell</module>
<module>time-source</module>
<module>time-processor</module>
<module>log-sink</module>

View File

@ -23,6 +23,7 @@
<module>spring-mvc-basics-3</module>
<module>spring-mvc-basics-4</module>
<module>spring-mvc-basics-5</module>
<module>spring-mvc-basics-6</module>
<module>spring-mvc-crash</module>
<module>spring-mvc-file</module>
<module>spring-mvc-forms-jsp</module>

View File

@ -14,5 +14,4 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring
- [Spring @RequestParam vs @PathVariable Annotations](https://www.baeldung.com/spring-requestparam-vs-pathvariable)
- [@RequestMapping Value in Properties File](https://www.baeldung.com/spring-requestmapping-properties-file)
- [Map a JSON POST to Multiple Spring MVC Parameters](https://www.baeldung.com/spring-mvc-json-param-mapping)
- [Getting Query String Parameters from HttpServletRequest](https://www.baeldung.com/java-httpservletrequest-get-query-parameters)
- More articles: [[<-- prev]](../spring-mvc-basics-4)

View File

@ -0,0 +1,11 @@
## Spring MVC Basics
This module contains articles about the basics of Spring MVC. Articles about more specific areas of Spring MVC have
their own module.
### The Course
The "REST With Spring" Classes: https://bit.ly/restwithspring
### Relevant Articles:
- [Getting Query String Parameters from HttpServletRequest](https://www.baeldung.com/java-httpservletrequest-get-query-parameters)
- More articles: [[<-- prev]](../spring-mvc-basics-4)

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-mvc-basics-6</artifactId>
<version>0.1-SNAPSHOT</version>
<name>spring-mvc-basics-6</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>spring-mvc-basics-5</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.Application</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,11 @@
package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1 @@
server.servlet.context-path=/spring-mvc-basics

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configuration scan="true" scanPeriod="15 seconds" debug="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

View File

@ -35,7 +35,6 @@
<properties>
<mockito-inline.version>4.8.1</mockito-inline.version>
<lombok.version>1.18.30</lombok.version>
</properties>
</project>