BAEL-20888 Move Spring Boot Testing to Spring Boot Modules
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.boot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
public static void main(String[] args) {
|
||||
applicationContext = SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.boot.controller.rest;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HomeController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String salutation() {
|
||||
return "Welcome !";
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.boot.controller.rest;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/hello")
|
||||
public class WebController {
|
||||
|
||||
private String name;
|
||||
|
||||
@GetMapping
|
||||
public String salutation() {
|
||||
return "Hello " + Optional.ofNullable(name).orElse("world") + '!';
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void setName(@RequestBody final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void resetToDefault() {
|
||||
this.name = null;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.boot.embeddedRedis.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableRedisRepositories
|
||||
public class RedisConfiguration {
|
||||
|
||||
@Bean
|
||||
public LettuceConnectionFactory redisConnectionFactory(final RedisProperties redisProperties) {
|
||||
return new LettuceConnectionFactory(redisProperties.getRedisHost(), redisProperties.getRedisPort());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<?, ?> redisTemplate(final LettuceConnectionFactory connectionFactory) {
|
||||
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
return template;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.boot.embeddedRedis.configuration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RedisProperties {
|
||||
private final int redisPort;
|
||||
private final String redisHost;
|
||||
|
||||
public RedisProperties(@Value("${spring.redis.port}") final int redisPort, @Value("${spring.redis.host}") final String redisHost) {
|
||||
this.redisPort = redisPort;
|
||||
this.redisHost = redisHost;
|
||||
}
|
||||
|
||||
public int getRedisPort() {
|
||||
return redisPort;
|
||||
}
|
||||
|
||||
public String getRedisHost() {
|
||||
return redisHost;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.boot.embeddedRedis.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.redis.core.RedisHash;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RedisHash("user")
|
||||
public class User {
|
||||
@Id private UUID id;
|
||||
private String name;
|
||||
|
||||
public User(UUID id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.boot.embeddedRedis.domain.repository;
|
||||
|
||||
import com.baeldung.boot.embeddedRedis.domain.User;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface UserRepository extends CrudRepository<User, UUID> {
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.component;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class OtherComponent {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OtherComponent.class);
|
||||
|
||||
public void processData() {
|
||||
LOG.trace("This is a TRACE log from another package");
|
||||
LOG.debug("This is a DEBUG log from another package");
|
||||
LOG.info("This is an INFO log from another package");
|
||||
LOG.error("This is an ERROR log from another package");
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.testloglevel;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import com.baeldung.boot.Application;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {"com.baeldung.testloglevel", "com.baeldung.component"})
|
||||
public class TestLogLevelApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.testloglevel;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.component.OtherComponent;
|
||||
|
||||
@RestController
|
||||
public class TestLogLevelController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestLogLevelController.class);
|
||||
|
||||
@Autowired
|
||||
private OtherComponent otherComponent;
|
||||
|
||||
@GetMapping("/testLogLevel")
|
||||
public String testLogLevel() {
|
||||
LOG.trace("This is a TRACE log");
|
||||
LOG.debug("This is a DEBUG log");
|
||||
LOG.info("This is an INFO log");
|
||||
LOG.error("This is an ERROR log");
|
||||
|
||||
otherComponent.processData();
|
||||
|
||||
return "Added some log output to console...";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user