Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bael 8370 new: Add Execution Metadata to Scheduled Tasks in Spring Boot Actuator #18103

Merged
merged 21 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
af025b7
#BAEL-8370-New: add Jobs
hmdrzsharifi Dec 19, 2024
791ed6e
#BAEL-8370-New: add SecurityConfig
hmdrzsharifi Dec 19, 2024
fbf3f91
#BAEL-8370-New: update Spring Boot version to 3.4.0
hmdrzsharifi Dec 19, 2024
ee98476
#BAEL-8370-New: add htmlunit.version to spring-boot-rest module
hmdrzsharifi Dec 19, 2024
4755d9d
#BAEL-8370-New: revert Spring Boot version
hmdrzsharifi Dec 22, 2024
e86405c
#BAEL-8370-NEW: revert htmlunit version
Dec 24, 2024
7a02d82
Merge branch 'master' into BAEL-8370-New
Dec 24, 2024
2f735e1
#BAEL-8370-NEW: update Spring Boot version to 3.4.0
Dec 24, 2024
8ef4986
Merge branch 'master' into BAEL-8370-New
hmdrzsharifi Dec 31, 2024
23e63c0
#BAEL-8370-New: update Spring Boot version to 3.4.1
hmdrzsharifi Dec 31, 2024
45b2ade
#BAEL-8370-New: replace removed method in htmlunit
hmdrzsharifi Dec 31, 2024
e2e4c05
Merge remote-tracking branch 'origin/BAEL-8370-New' into BAEL-8370-New
hmdrzsharifi Dec 31, 2024
78cb5dc
#BAEL-8370-New: add dependency version for htmlunit
hmdrzsharifi Dec 31, 2024
7f52d5d
#BAEL-8370-New: resolve error: com.google.common.util.concurrent.Futu…
hmdrzsharifi Dec 31, 2024
f538904
Merge branch 'master' into BAEL-8370-New
hmdrzsharifi Jan 2, 2025
7e73c07
#BAEL-8370-New: revert parent Spring Boot 3
hmdrzsharifi Jan 2, 2025
144d1cf
#BAEL-8370-New: revert change due to Spring Boot 3 Update
hmdrzsharifi Jan 2, 2025
985718b
#BAEL-8370-New: revert change due to Spring Boot 3 Update
hmdrzsharifi Jan 2, 2025
d896374
#BAEL-8370-New: revert change due to Spring Boot 3 Update
hmdrzsharifi Jan 2, 2025
cb39d22
#BAEL-8370-New: add Spring Boot 3 separately
hmdrzsharifi Jan 2, 2025
52dd018
#BAEL-8370-New: update JUnit to 5
hmdrzsharifi Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions spring-boot-modules/spring-boot-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<packaging>war</packaging>

<parent>
<groupId>com.baeldung.spring-boot-modules</groupId>
<artifactId>spring-boot-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/>
</parent>

<dependencies>
Expand Down Expand Up @@ -106,6 +107,10 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.baeldung.actuator;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
public class JobConfig {

@Scheduled(fixedDelay = 1000L)
public void scheduleFixedDelayTask() {
System.out.println("Fixed delay task - " + System.currentTimeMillis() / 1000);
}

@Scheduled(fixedRate = 1000L)
public void scheduleFixedRateTask() {
System.out.println("Fixed rate task - " + System.currentTimeMillis() / 1000);
}

@Scheduled(cron = "0 15 10 15 * ?")
public void scheduleTaskUsingCronExpression() {
long now = System.currentTimeMillis() / 1000;
System.out.println("schedule tasks using cron jobs - " + now);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.baeldung.actuator;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain securityWebFilterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/**").permitAll()
.anyRequest().authenticated())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.baeldung.actuator;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
public class ActuatorInfoIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@
import com.baeldung.bootstrap.persistence.model.Book;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import java.util.List;

import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SpringBootBootstrapLiveTest {

private static final String API_ROOT = "http://localhost:8080/api/books";
@LocalServerPort
private int port;
private String API_ROOT;

@BeforeEach
public void setUp() {
API_ROOT = "http://localhost:" + port + "/api/books";
RestAssured.port = port;
}

@Test
public void whenGetAllBooks_thenOK() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.baeldung.bootstrap;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class SpringContextTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.baeldung.configurationproperties;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.unit.DataSize;

import java.time.Duration;

import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = PropertiesConversionApplication.class)
@TestPropertySource("classpath:conversion.properties")
public class PropertiesConversionIntegrationTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.baeldung.starter;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand All @@ -18,7 +18,7 @@
import static org.hamcrest.Matchers.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;

@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
public class SpringBootApplicationIntegrationTest {
Expand All @@ -28,7 +28,7 @@ public class SpringBootApplicationIntegrationTest {

private MockMvc mockMvc;

@Before
@BeforeEach
public void setupMockMvc() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.baeldung.starter.domain.GenericEntity;
import com.baeldung.starter.repository.GenericEntityRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class)
public class SpringBootJPAIntegrationTest {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.baeldung.starter;

import jakarta.mail.MessagingException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;

import java.io.IOException;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class)
public class SpringBootMailIntegrationTest {
@Autowired
Expand All @@ -33,14 +33,14 @@ public class SpringBootMailIntegrationTest {
private final String subject = "Test subject";
private final String textMail = "Text subject mail";

@Before
@BeforeEach
public void setUp() {
final int TEST_PORT = 8025;
wiser = Wiser.port(TEST_PORT);
wiser.start();
}

@After
@AfterEach
public void tearDown() {
wiser.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@
<jaxb-runtime.version>4.0.1</jaxb-runtime.version>
<spring-oxm.version>6.1.4</spring-oxm.version>
</properties>
</project>
</project>