Merge branch 'master' of github.com:eugenp/tutorials into master
This commit is contained in:
commit
0847734157
|
@ -0,0 +1,100 @@
|
|||
<?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>aws-lambda-examples</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-lambda-examples</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
||||
<version>${aws-java-sdk.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-core</artifactId>
|
||||
<version>${aws-java-sdk.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>${aws-lambda-java-core.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>${aws-lambda-java-events.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>${json-simple.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>${maven-shade-plugin.version}</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<json-simple.version>1.1.1</json-simple.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
||||
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
||||
<gson.version>2.8.2</gson.version>
|
||||
<aws-java-sdk.version>1.11.241</aws-java-sdk.version>
|
||||
<maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -5,95 +5,19 @@
|
|||
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>aws-lambda</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-lambda</name>
|
||||
<packaging>jar</packaging>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
||||
<version>${aws-java-sdk.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-core</artifactId>
|
||||
<version>${aws-java-sdk.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>${aws-lambda-java-core.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>${aws-lambda-java-events.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>${json-simple.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<modules>
|
||||
<module>lambda</module>
|
||||
<module>shipping-tracker/ShippingFunction</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>${maven-shade-plugin.version}</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<json-simple.version>1.1.1</json-simple.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
||||
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
||||
<gson.version>2.8.2</gson.version>
|
||||
<aws-java-sdk.version>1.11.241</aws-java-sdk.version>
|
||||
<maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
.aws-sam/
|
|
@ -0,0 +1,73 @@
|
|||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>ShippingFunction</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Shipping Tracker Lambda Function</name>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<hibernate.version>5.4.21.Final</hibernate.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.11.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-hikaricp</artifactId>
|
||||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,108 @@
|
|||
package com.baeldung.lambda.shipping;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.*;
|
||||
import static org.hibernate.cfg.AvailableSettings.PASS;
|
||||
|
||||
/**
|
||||
* Handler for requests to Lambda function.
|
||||
*/
|
||||
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
|
||||
try (SessionFactory sessionFactory = createSessionFactory()) {
|
||||
ShippingService service = new ShippingService(sessionFactory, new ShippingDao());
|
||||
return routeRequest(input, service);
|
||||
}
|
||||
}
|
||||
|
||||
private APIGatewayProxyResponseEvent routeRequest(APIGatewayProxyRequestEvent input, ShippingService service) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Content-Type", "application/json");
|
||||
headers.put("X-Custom-Header", "application/json");
|
||||
|
||||
Object result = "OK";
|
||||
|
||||
switch (input.getResource()) {
|
||||
case "/consignment":
|
||||
result = service.createConsignment(
|
||||
fromJson(input.getBody(), Consignment.class));
|
||||
break;
|
||||
case "/consignment/{id}":
|
||||
result = service.view(input.getPathParameters().get("id"));
|
||||
break;
|
||||
case "/consignment/{id}/item":
|
||||
service.addItem(input.getPathParameters().get("id"),
|
||||
fromJson(input.getBody(), Item.class));
|
||||
break;
|
||||
case "/consignment/{id}/checkin":
|
||||
service.checkIn(input.getPathParameters().get("id"),
|
||||
fromJson(input.getBody(), Checkin.class));
|
||||
break;
|
||||
}
|
||||
|
||||
return new APIGatewayProxyResponseEvent()
|
||||
.withHeaders(headers)
|
||||
.withStatusCode(200)
|
||||
.withBody(toJson(result));
|
||||
}
|
||||
|
||||
private static <T> String toJson(T object) {
|
||||
try {
|
||||
return OBJECT_MAPPER.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T fromJson(String json, Class<T> type) {
|
||||
try {
|
||||
return OBJECT_MAPPER.readValue(json, type);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static SessionFactory createSessionFactory() {
|
||||
Map<String, String> settings = new HashMap<>();
|
||||
settings.put(URL, System.getenv("DB_URL"));
|
||||
settings.put(DIALECT, "org.hibernate.dialect.PostgreSQLDialect");
|
||||
settings.put(DEFAULT_SCHEMA, "shipping");
|
||||
settings.put(DRIVER, "org.postgresql.Driver");
|
||||
settings.put(USER, System.getenv("DB_USER"));
|
||||
settings.put(PASS, System.getenv("DB_PASSWORD"));
|
||||
settings.put("hibernate.hikari.connectionTimeout", "20000");
|
||||
settings.put("hibernate.hikari.minimumIdle", "1");
|
||||
settings.put("hibernate.hikari.maximumPoolSize", "2");
|
||||
settings.put("hibernate.hikari.idleTimeout", "30000");
|
||||
|
||||
// commented out as we only need them on first use
|
||||
// settings.put(HBM2DDL_AUTO, "create-only");
|
||||
// settings.put(HBM2DDL_DATABASE_ACTION, "create");
|
||||
|
||||
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(settings)
|
||||
.build();
|
||||
|
||||
return new MetadataSources(registry)
|
||||
.addAnnotatedClass(Consignment.class)
|
||||
.addAnnotatedClass(Item.class)
|
||||
.addAnnotatedClass(Checkin.class)
|
||||
.buildMetadata()
|
||||
.buildSessionFactory();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.lambda.shipping;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class Checkin {
|
||||
private String timeStamp;
|
||||
private String location;
|
||||
|
||||
@Column(name = "timestamp")
|
||||
public String getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public void setTimeStamp(String timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
@Column(name = "location")
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.baeldung.lambda.shipping;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.FetchType.EAGER;
|
||||
|
||||
@Entity(name = "consignment")
|
||||
@Table(name = "consignment")
|
||||
public class Consignment {
|
||||
private String id;
|
||||
private String source;
|
||||
private String destination;
|
||||
private boolean isDelivered;
|
||||
private List<Item> items = new ArrayList<>();
|
||||
private List<Checkin> checkins = new ArrayList<>();
|
||||
|
||||
@Id
|
||||
@Column(name = "consignment_id")
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "source")
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Column(name = "destination")
|
||||
public String getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(String destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Column(name = "delivered", columnDefinition = "boolean")
|
||||
public boolean isDelivered() {
|
||||
return isDelivered;
|
||||
}
|
||||
|
||||
public void setDelivered(boolean delivered) {
|
||||
isDelivered = delivered;
|
||||
}
|
||||
|
||||
@ElementCollection(fetch = EAGER)
|
||||
@CollectionTable(name = "consignment_item", joinColumns = @JoinColumn(name = "consignment_id"))
|
||||
@OrderColumn(name = "item_index")
|
||||
public List<Item> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<Item> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@ElementCollection(fetch = EAGER)
|
||||
@CollectionTable(name = "consignment_checkin", joinColumns = @JoinColumn(name = "consignment_id"))
|
||||
@OrderColumn(name = "checkin_index")
|
||||
public List<Checkin> getCheckins() {
|
||||
return checkins;
|
||||
}
|
||||
|
||||
public void setCheckins(List<Checkin> checkins) {
|
||||
this.checkins = checkins;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.baeldung.lambda.shipping;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class Item {
|
||||
private String location;
|
||||
private String description;
|
||||
private String timeStamp;
|
||||
|
||||
@Column(name = "location")
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Column(name = "description")
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Column(name = "timestamp")
|
||||
public String getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public void setTimeStamp(String timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.baeldung.lambda.shipping;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ShippingDao {
|
||||
/**
|
||||
* Save a consignment to the database
|
||||
* @param consignment the consignment to save
|
||||
*/
|
||||
public void save(Session session, Consignment consignment) {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
session.save(consignment);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a consignment in the database by id
|
||||
*/
|
||||
public Optional<Consignment> find(Session session, String id) {
|
||||
return Optional.ofNullable(session.get(Consignment.class, id));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.baeldung.lambda.shipping;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ShippingService {
|
||||
private SessionFactory sessionFactory;
|
||||
private ShippingDao shippingDao;
|
||||
|
||||
public ShippingService(SessionFactory sessionFactory, ShippingDao shippingDao) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
this.shippingDao = shippingDao;
|
||||
}
|
||||
|
||||
public String createConsignment(Consignment consignment) {
|
||||
try (Session session = sessionFactory.openSession()) {
|
||||
consignment.setDelivered(false);
|
||||
consignment.setId(UUID.randomUUID().toString());
|
||||
shippingDao.save(session, consignment);
|
||||
return consignment.getId();
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(String consignmentId, Item item) {
|
||||
try (Session session = sessionFactory.openSession()) {
|
||||
shippingDao.find(session, consignmentId)
|
||||
.ifPresent(consignment -> addItem(session, consignment, item));
|
||||
}
|
||||
}
|
||||
|
||||
private void addItem(Session session, Consignment consignment, Item item) {
|
||||
consignment.getItems()
|
||||
.add(item);
|
||||
shippingDao.save(session, consignment);
|
||||
}
|
||||
|
||||
public void checkIn(String consignmentId, Checkin checkin) {
|
||||
try (Session session = sessionFactory.openSession()) {
|
||||
shippingDao.find(session, consignmentId)
|
||||
.ifPresent(consignment -> checkIn(session, consignment, checkin));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIn(Session session, Consignment consignment, Checkin checkin) {
|
||||
consignment.getCheckins().add(checkin);
|
||||
consignment.getCheckins().sort(Comparator.comparing(Checkin::getTimeStamp));
|
||||
if (checkin.getLocation().equals(consignment.getDestination())) {
|
||||
consignment.setDelivered(true);
|
||||
}
|
||||
shippingDao.save(session, consignment);
|
||||
}
|
||||
|
||||
public Consignment view(String consignmentId) {
|
||||
try (Session session = sessionFactory.openSession()) {
|
||||
return shippingDao.find(session, consignmentId)
|
||||
.orElseGet(Consignment::new);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Transform: AWS::Serverless-2016-10-31
|
||||
Description: >
|
||||
shipping-tracker
|
||||
|
||||
Sample SAM Template for shipping-tracker
|
||||
|
||||
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
|
||||
Globals:
|
||||
Function:
|
||||
Timeout: 20
|
||||
|
||||
Resources:
|
||||
ShippingFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
CodeUri: ShippingFunction
|
||||
Handler: com.baeldung.lambda.shipping.App::handleRequest
|
||||
Runtime: java8
|
||||
MemorySize: 512
|
||||
Environment:
|
||||
Variables:
|
||||
DB_URL: jdbc:postgresql://postgres/postgres
|
||||
DB_USER: postgres
|
||||
DB_PASSWORD: password
|
||||
Events:
|
||||
CreateConsignment:
|
||||
Type: Api
|
||||
Properties:
|
||||
Path: /consignment
|
||||
Method: post
|
||||
AddItem:
|
||||
Type: Api
|
||||
Properties:
|
||||
Path: /consignment/{id}/item
|
||||
Method: post
|
||||
CheckIn:
|
||||
Type: Api
|
||||
Properties:
|
||||
Path: /consignment/{id}/checkin
|
||||
Method: post
|
||||
ViewConsignment:
|
||||
Type: Api
|
||||
Properties:
|
||||
Path: /consignment/{id}
|
||||
Method: get
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
## Core Java 11
|
||||
|
||||
This module contains articles about Java 11 core features
|
||||
|
||||
### Relevant articles
|
||||
- [Guide to Java 8 Optional](https://www.baeldung.com/java-optional)
|
||||
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
|
||||
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
|
@ -0,0 +1,54 @@
|
|||
<?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>core-java-11-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-11-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source.version}</source>
|
||||
<target>${maven.compiler.target.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||
<guava.version>29.0-jre</guava.version>
|
||||
<assertj.version>3.17.2</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public abstract class Animal implements Eating {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Bird extends Animal {
|
||||
private boolean walks;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Eating {
|
||||
String eats();
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Goat extends Animal implements Locomotion {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
@Greeter(greet="Good morning")
|
||||
public class Greetings {
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public interface Locomotion {
|
||||
String getLocomotion();
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Operations {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
|
@ -1,18 +1,11 @@
|
|||
package com.baeldung.streams.collectors;
|
||||
package com.baeldung.collectors;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
|
@ -20,19 +13,7 @@ import java.util.function.Supplier;
|
|||
import java.util.stream.Collector;
|
||||
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static java.util.stream.Collectors.averagingDouble;
|
||||
import static java.util.stream.Collectors.collectingAndThen;
|
||||
import static java.util.stream.Collectors.counting;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static java.util.stream.Collectors.maxBy;
|
||||
import static java.util.stream.Collectors.partitioningBy;
|
||||
import static java.util.stream.Collectors.summarizingDouble;
|
||||
import static java.util.stream.Collectors.summingDouble;
|
||||
import static java.util.stream.Collectors.toCollection;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
|
@ -48,6 +29,14 @@ public class Java8CollectorsUnitTest {
|
|||
assertThat(result).containsAll(givenList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCollectingToUnmodifiableList_shouldCollectToUnmodifiableList() {
|
||||
final List<String> result = givenList.stream().collect(toUnmodifiableList());
|
||||
|
||||
assertThatThrownBy(() -> result.add("foo"))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCollectingToSet_shouldCollectToSet() throws Exception {
|
||||
final Set<String> result = givenList.stream().collect(toSet());
|
||||
|
@ -55,6 +44,14 @@ public class Java8CollectorsUnitTest {
|
|||
assertThat(result).containsAll(givenList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCollectingToUnmodifiableSet_shouldCollectToUnmodifiableSet() {
|
||||
final Set<String> result = givenList.stream().collect(toUnmodifiableSet());
|
||||
|
||||
assertThatThrownBy(() -> result.add("foo"))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenContainsDuplicateElements_whenCollectingToSet_shouldAddDuplicateElementsOnlyOnce() throws Exception {
|
||||
final Set<String> result = listWithDuplicates.stream().collect(toSet());
|
||||
|
@ -84,6 +81,15 @@ public class Java8CollectorsUnitTest {
|
|||
assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("ccc", 3).containsEntry("dd", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCollectingToUnmodifiableMap_shouldCollectToUnmodifiableMap() {
|
||||
final Map<String, Integer> result = givenList.stream()
|
||||
.collect(toUnmodifiableMap(Function.identity(), String::length));
|
||||
|
||||
assertThatThrownBy(() -> result.put("foo", 3))
|
||||
.isInstanceOf(UnsupportedOperationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception {
|
||||
final Map<String, Integer> result = listWithDuplicates.stream().collect(
|
|
@ -7,7 +7,9 @@ import java.util.Optional;
|
|||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class OptionalChainingUnitTest {
|
||||
|
|
@ -9,7 +9,9 @@ import java.util.List;
|
|||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class OptionalUnitTest {
|
||||
|
||||
|
@ -262,6 +264,12 @@ public class OptionalUnitTest {
|
|||
.orElseThrow(IllegalArgumentException::new);
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class)
|
||||
public void whenNoArgOrElseThrowWorks_thenCorrect() {
|
||||
String nullName = null;
|
||||
String name = Optional.ofNullable(nullName).orElseThrow();
|
||||
}
|
||||
|
||||
public String getMyDefault() {
|
||||
LOG.debug("Getting default value...");
|
||||
return "Default Value";
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.java.reflection;
|
||||
package com.baeldung.reflection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -32,23 +32,23 @@ public class ReflectionUnitTest {
|
|||
final Class<?> clazz = goat.getClass();
|
||||
|
||||
assertEquals("Goat", clazz.getSimpleName());
|
||||
assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
|
||||
assertEquals("com.baeldung.java.reflection.Goat", clazz.getCanonicalName());
|
||||
assertEquals("com.baeldung.reflection.Goat", clazz.getName());
|
||||
assertEquals("com.baeldung.reflection.Goat", clazz.getCanonicalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClassName_whenCreatesObject_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> clazz = Class.forName("com.baeldung.java.reflection.Goat");
|
||||
final Class<?> clazz = Class.forName("com.baeldung.reflection.Goat");
|
||||
|
||||
assertEquals("Goat", clazz.getSimpleName());
|
||||
assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
|
||||
assertEquals("com.baeldung.java.reflection.Goat", clazz.getCanonicalName());
|
||||
assertEquals("com.baeldung.reflection.Goat", clazz.getName());
|
||||
assertEquals("com.baeldung.reflection.Goat", clazz.getCanonicalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClass_whenRecognisesModifiers_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||
final Class<?> goatClass = Class.forName("com.baeldung.reflection.Goat");
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.reflection.Animal");
|
||||
final int goatMods = goatClass.getModifiers();
|
||||
final int animalMods = animalClass.getModifiers();
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class ReflectionUnitTest {
|
|||
final Class<?> goatClass = goat.getClass();
|
||||
final Package pkg = goatClass.getPackage();
|
||||
|
||||
assertEquals("com.baeldung.java.reflection", pkg.getName());
|
||||
assertEquals("com.baeldung.reflection", pkg.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -81,8 +81,8 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsImplementedInterfaces_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||
final Class<?> goatClass = Class.forName("com.baeldung.reflection.Goat");
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.reflection.Animal");
|
||||
final Class<?>[] goatInterfaces = goatClass.getInterfaces();
|
||||
final Class<?>[] animalInterfaces = animalClass.getInterfaces();
|
||||
|
||||
|
@ -94,16 +94,16 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsConstructor_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
||||
final Class<?> goatClass = Class.forName("com.baeldung.reflection.Goat");
|
||||
final Constructor<?>[] constructors = goatClass.getConstructors();
|
||||
|
||||
assertEquals(1, constructors.length);
|
||||
assertEquals("com.baeldung.java.reflection.Goat", constructors[0].getName());
|
||||
assertEquals("com.baeldung.reflection.Goat", constructors[0].getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClass_whenGetsFields_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.reflection.Animal");
|
||||
final Field[] fields = animalClass.getDeclaredFields();
|
||||
|
||||
final List<String> actualFields = getFieldNames(fields);
|
||||
|
@ -114,7 +114,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsMethods_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||
final Class<?> animalClass = Class.forName("com.baeldung.reflection.Animal");
|
||||
final Method[] methods = animalClass.getDeclaredMethods();
|
||||
final List<String> actualMethods = getMethodNames(methods);
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsAllConstructors_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Constructor<?>[] constructors = birdClass.getConstructors();
|
||||
|
||||
assertEquals(3, constructors.length);
|
||||
|
@ -132,7 +132,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsEachConstructorByParamTypes_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
birdClass.getConstructor();
|
||||
birdClass.getConstructor(String.class);
|
||||
birdClass.getConstructor(String.class, boolean.class);
|
||||
|
@ -140,7 +140,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenInstantiatesObjectsAtRuntime_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
|
||||
final Constructor<?> cons1 = birdClass.getConstructor();
|
||||
final Constructor<?> cons2 = birdClass.getConstructor(String.class);
|
||||
|
@ -159,7 +159,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsPublicFields_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Field[] fields = birdClass.getFields();
|
||||
assertEquals(1, fields.length);
|
||||
assertEquals("CATEGORY", fields[0].getName());
|
||||
|
@ -168,7 +168,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsPublicFieldByName_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Field field = birdClass.getField("CATEGORY");
|
||||
assertEquals("CATEGORY", field.getName());
|
||||
|
||||
|
@ -176,7 +176,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsDeclaredFields_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Field[] fields = birdClass.getDeclaredFields();
|
||||
assertEquals(1, fields.length);
|
||||
assertEquals("walks", fields[0].getName());
|
||||
|
@ -184,7 +184,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsFieldsByName_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Field field = birdClass.getDeclaredField("walks");
|
||||
assertEquals("walks", field.getName());
|
||||
|
||||
|
@ -192,14 +192,14 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClassField_whenGetsType_thenCorrect() throws Exception {
|
||||
final Field field = Class.forName("com.baeldung.java.reflection.Bird").getDeclaredField("walks");
|
||||
final Field field = Class.forName("com.baeldung.reflection.Bird").getDeclaredField("walks");
|
||||
final Class<?> fieldClass = field.getType();
|
||||
assertEquals("boolean", fieldClass.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
|
||||
final Field field = birdClass.getDeclaredField("walks");
|
||||
field.setAccessible(true);
|
||||
|
@ -216,7 +216,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClassField_whenGetsAndSetsWithNull_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Field field = birdClass.getField("CATEGORY");
|
||||
field.setAccessible(true);
|
||||
|
||||
|
@ -225,7 +225,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsAllPublicMethods_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Method[] methods = birdClass.getMethods();
|
||||
final List<String> methodNames = getMethodNames(methods);
|
||||
|
||||
|
@ -235,7 +235,7 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenClass_whenGetsOnlyDeclaredMethods_thenCorrect() throws ClassNotFoundException {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final List<String> actualMethodNames = getMethodNames(birdClass.getDeclaredMethods());
|
||||
|
||||
final List<String> expectedMethodNames = Arrays.asList("setWalks", "walks", "getSound", "eats");
|
||||
|
@ -248,24 +248,17 @@ public class ReflectionUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenMethodName_whenGetsMethod_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Method walksMethod = birdClass.getDeclaredMethod("walks");
|
||||
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
|
||||
|
||||
assertFalse(walksMethod.isAccessible());
|
||||
assertFalse(setWalksMethod.isAccessible());
|
||||
|
||||
walksMethod.setAccessible(true);
|
||||
setWalksMethod.setAccessible(true);
|
||||
|
||||
assertTrue(walksMethod.isAccessible());
|
||||
assertTrue(setWalksMethod.isAccessible());
|
||||
final Bird bird = new Bird();
|
||||
final Method walksMethod = bird.getClass().getDeclaredMethod("walks");
|
||||
final Method setWalksMethod = bird.getClass().getDeclaredMethod("setWalks", boolean.class);
|
||||
|
||||
assertTrue(walksMethod.canAccess(bird));
|
||||
assertTrue(setWalksMethod.canAccess(bird));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMethod_whenInvokes_thenCorrect() throws Exception {
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||
final Class<?> birdClass = Class.forName("com.baeldung.reflection.Bird");
|
||||
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
|
||||
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
|
||||
final Method walksMethod = birdClass.getDeclaredMethod("walks");
|
|
@ -107,7 +107,7 @@
|
|||
<uberjar.name>benchmarks</uberjar.name>
|
||||
<jmh.version>1.22</jmh.version>
|
||||
<eclipse.collections.version>10.0.0</eclipse.collections.version>
|
||||
<shade.plugin.version>10.0.0</shade.plugin.version>
|
||||
<shade.plugin.version>3.2.4</shade.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package com.baeldung.collections.mapfirstpair;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MapFirstPairUnitTest {
|
||||
|
||||
private Map.Entry<Integer, String> getFirstPairUsingIterator(Map<Integer, String> map) {
|
||||
if (map == null || map.size() == 0)
|
||||
return null;
|
||||
|
||||
Iterator<Map.Entry<Integer, String>> iterator = map.entrySet()
|
||||
.iterator();
|
||||
|
||||
if (iterator.hasNext())
|
||||
return iterator.next();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map.Entry<Integer, String> getFirstPairUsingStream(Map<Integer, String> map) {
|
||||
if (map == null || map.size() == 0)
|
||||
return null;
|
||||
|
||||
Set<Map.Entry<Integer, String>> entrySet = map.entrySet();
|
||||
|
||||
return entrySet.stream()
|
||||
.findFirst()
|
||||
.get();
|
||||
}
|
||||
|
||||
private Map<Integer, String> populateMapValues(Map<Integer, String> map) {
|
||||
if (map != null) {
|
||||
map.put(5, "A");
|
||||
map.put(1, "B");
|
||||
map.put(2, "C");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingIteratorForHashMap_thenFirstPairWhichWasNotInsertedFirst() {
|
||||
Map<Integer, String> hashMap = new HashMap<>();
|
||||
hashMap = populateMapValues(hashMap);
|
||||
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingIterator(hashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(1, "B");
|
||||
Map.Entry<Integer, String> pairInsertedFirst = new AbstractMap.SimpleEntry<Integer, String>(5, "A");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
assertNotEquals(pairInsertedFirst, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingStreamForHashMap_thenFirstPairWhichWasNotInsertedFirst() {
|
||||
Map<Integer, String> hashMap = new HashMap<>();
|
||||
hashMap = populateMapValues(hashMap);
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingStream(hashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(1, "B");
|
||||
Map.Entry<Integer, String> pairInsertedFirst = new AbstractMap.SimpleEntry<Integer, String>(5, "A");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
assertNotEquals(pairInsertedFirst, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingIteratorForLinkedHashMap_thenFirstPairWhichWasInsertedFirst() {
|
||||
Map<Integer, String> linkedHashMap = new LinkedHashMap<>();
|
||||
linkedHashMap = populateMapValues(linkedHashMap);
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingIterator(linkedHashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(5, "A");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingStreamForLinkedHashMap_thenFirstPairWhichWasInsertedFirst() {
|
||||
Map<Integer, String> linkedHashMap = new LinkedHashMap<>();
|
||||
linkedHashMap = populateMapValues(linkedHashMap);
|
||||
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingStream(linkedHashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(5, "A");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddedAnElementInHashMap_thenFirstPairChangedUsingIterator() {
|
||||
Map<Integer, String> hashMap = new HashMap<>();
|
||||
hashMap = populateMapValues(hashMap);
|
||||
|
||||
hashMap.put(0, "D");
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingIterator(hashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(0, "D");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddedAnElementInHashMap_thenFirstPairChangedUsingStream() {
|
||||
Map<Integer, String> hashMap = new HashMap<>();
|
||||
hashMap = populateMapValues(hashMap);
|
||||
|
||||
hashMap.put(0, "D");
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingStream(hashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(0, "D");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddedAnElementInLinkedHashMap_thenFirstPairRemainUnchangedUsingIterator() {
|
||||
Map<Integer, String> linkedHashMap = new LinkedHashMap<>();
|
||||
linkedHashMap = populateMapValues(linkedHashMap);
|
||||
|
||||
linkedHashMap.put(0, "D");
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingIterator(linkedHashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(5, "A");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddedAnElementInLinkedHashMap_thenFirstPairRemainUnchangedUsingStream() {
|
||||
Map<Integer, String> linkedHashMap = new LinkedHashMap<>();
|
||||
linkedHashMap = populateMapValues(linkedHashMap);
|
||||
|
||||
linkedHashMap.put(0, "D");
|
||||
Map.Entry<Integer, String> actualValue = getFirstPairUsingStream(linkedHashMap);
|
||||
Map.Entry<Integer, String> expectedValue = new AbstractMap.SimpleEntry<Integer, String>(5, "A");
|
||||
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.baeldung.checkclassexistence;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CheckClassExistenceUnitTest {
|
||||
|
||||
public static class InitializingClass {
|
||||
static {
|
||||
if (true) { //enable throwing of an exception in a static initialization block
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ClassNotFoundException.class) //thrown when class does not exist
|
||||
public void givenNonExistingClass_whenUsingForName_thenClassNotFound() throws ClassNotFoundException {
|
||||
Class.forName("class.that.does.not.exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenExistingClass_whenUsingForName_thenNoException() throws ClassNotFoundException {
|
||||
Class.forName("java.lang.String");
|
||||
}
|
||||
|
||||
@Test(expected = ExceptionInInitializerError.class) //thrown when exception occurs inside of a static initialization block
|
||||
public void givenInitializingClass_whenUsingForName_thenInitializationError() throws ClassNotFoundException {
|
||||
Class.forName("com.baeldung.checkclassexistence.CheckClassExistenceUnitTest$InitializingClass");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInitializingClass_whenUsingForNameWithoutInitialization_thenNoException() throws ClassNotFoundException {
|
||||
Class.forName("com.baeldung.checkclassexistence.CheckClassExistenceUnitTest$InitializingClass", false, getClass().getClassLoader());
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ This module contains articles about Java Optional.
|
|||
|
||||
### Relevant Articles:
|
||||
- [Java Optional as Return Type](https://www.baeldung.com/java-optional-return)
|
||||
- [Guide to Java 8 Optional](https://www.baeldung.com/java-optional)
|
||||
- [Java Optional – orElse() vs orElseGet()](https://www.baeldung.com/java-optional-or-else-vs-or-else-get)
|
||||
- [Transforming an Empty String into an Empty Optional](https://www.baeldung.com/java-empty-string-to-empty-optional)
|
||||
- [Filtering a Stream of Optionals in Java](https://www.baeldung.com/java-filter-stream-of-optional)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
- [Void Type in Java](https://www.baeldung.com/java-void-type)
|
||||
- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields)
|
||||
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
|
||||
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
|
||||
- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection)
|
||||
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
||||
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
|
||||
|
|
|
@ -6,7 +6,6 @@ This module contains articles about the Stream API in Java.
|
|||
- [The Difference Between map() and flatMap()](https://www.baeldung.com/java-difference-map-and-flatmap)
|
||||
- [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
|
||||
- [The Difference Between Collection.stream().forEach() and Collection.forEach()](https://www.baeldung.com/java-collection-stream-foreach)
|
||||
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
||||
- [Primitive Type Streams in Java 8](https://www.baeldung.com/java-8-primitive-streams)
|
||||
- [Debugging Java 8 Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams)
|
||||
- [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals)
|
||||
|
|
|
@ -78,6 +78,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
apply plugin: "java"
|
||||
apply plugin: "application"
|
||||
description = "Gradle Command Line Arguments examples"
|
||||
|
||||
ext.javaMainClass = "com.baeldung.cmd.MainClass"
|
||||
|
||||
application {
|
||||
mainClassName = javaMainClass
|
||||
}
|
||||
|
||||
task propertyTypes(){
|
||||
doLast{
|
||||
if (project.hasProperty("args")) {
|
||||
println "Our input argument with project property ["+project.getProperty("args")+"]"
|
||||
}
|
||||
println "Our input argument with system property ["+System.getProperty("args")+"]"
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty("args")) {
|
||||
ext.cmdargs = project.getProperty("args")
|
||||
} else {
|
||||
ext.cmdargs = "ls"
|
||||
}
|
||||
|
||||
task cmdLineJavaExec(type: JavaExec) {
|
||||
group = "Execution"
|
||||
description = "Run the main class with JavaExecTask"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
main = javaMainClass
|
||||
args cmdargs.split()
|
||||
}
|
||||
|
||||
task cmdLineExec(type: Exec) {
|
||||
group = "Execution"
|
||||
description = "Run an external program with ExecTask"
|
||||
commandLine cmdargs.split()
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.cmd;
|
||||
|
||||
public class MainClass {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Gradle command line arguments example");
|
||||
for (String arg : args) {
|
||||
System.out.println("Got argument [" + arg + "]");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
rootProject.name='gradle-5-articles'
|
||||
include 'java-exec'
|
||||
include 'unused-dependencies'
|
||||
include 'source-sets'
|
||||
include 'source-sets'
|
||||
include 'cmd-line-args'
|
|
@ -15,6 +15,12 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.17.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.baeldung.arrayconversion;
|
||||
|
||||
import org.assertj.core.api.ListAssert;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -7,8 +8,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ArrayToListConversionUnitTest {
|
||||
|
||||
|
@ -17,8 +17,8 @@ public class ArrayToListConversionUnitTest {
|
|||
String[] stringArray = new String[] { "A", "B", "C", "D" };
|
||||
List<String> stringList = Arrays.asList(stringArray);
|
||||
stringList.set(0, "E");
|
||||
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
|
||||
assertArrayEquals(stringArray, new String[] { "E", "B", "C", "D" });
|
||||
assertThat(stringList).containsExactly("E", "B", "C", "D");
|
||||
assertThat(stringArray).containsExactly("E", "B", "C", "D");
|
||||
stringList.add("F");
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,9 @@ public class ArrayToListConversionUnitTest {
|
|||
String[] stringArray = new String[] { "A", "B", "C", "D" };
|
||||
List<String> stringList = new ArrayList<>(Arrays.asList(stringArray));
|
||||
stringList.set(0, "E");
|
||||
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
|
||||
assertArrayEquals(stringArray, new String[] { "A", "B", "C", "D" });
|
||||
assertThat(stringList).containsExactly("E", "B", "C", "D");
|
||||
assertThat(stringArray).containsExactly("A", "B", "C", "D");
|
||||
stringList.add("F");
|
||||
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D", "F"));
|
||||
assertThat(stringList).containsExactly("E", "B", "C", "D", "F");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>logging-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -79,6 +79,8 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>logging-service</finalName>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -93,13 +95,21 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<finalName>logging-service</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<log4j2.version>2.7</log4j2.version>
|
||||
<disruptor.version>3.3.6</disruptor.version>
|
||||
<jbosslogging.version>3.3.0.Final</jbosslogging.version>
|
||||
<junit-jupiter.version>5.6.2</junit-jupiter.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>logging-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>logging-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>logging-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@ -21,4 +21,17 @@
|
|||
<module>flogger</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<junit-jupiter.version>5.6.2</junit-jupiter.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
<rest-assured.version>3.3.0</rest-assured.version>
|
||||
<!-- plugins -->
|
||||
<thin.version>1.0.22.RELEASE</thin.version>
|
||||
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
|
||||
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
|
||||
<aspectjweaver.version>1.9.1</aspectjweaver.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Tweet {
|
||||
|
||||
private String email;
|
||||
|
||||
private String tweetText;
|
||||
|
||||
private Date dateCreated;
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getTweetText() {
|
||||
return tweetText;
|
||||
}
|
||||
|
||||
public void setTweetText(String tweetText) {
|
||||
this.tweetText = tweetText;
|
||||
}
|
||||
|
||||
public Date getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
public void setDateCreated(Date dateCreated) {
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TweetDao {
|
||||
|
||||
List<Tweet> fetchTweets(String email);
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TweetDaoImpl implements TweetDao {
|
||||
|
||||
@Override
|
||||
public List<Tweet> fetchTweets(String email) {
|
||||
List<Tweet> tweets = new ArrayList<Tweet>();
|
||||
|
||||
//call Twitter API and prepare Tweet object
|
||||
|
||||
return tweets;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
public class User {
|
||||
|
||||
private Long id;
|
||||
private String userName;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String email;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
public interface UserDao {
|
||||
|
||||
void create(User user);
|
||||
|
||||
User read(Long id);
|
||||
|
||||
void update(User user);
|
||||
|
||||
void delete(String userName);
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
public class UserDaoImpl implements UserDao {
|
||||
|
||||
private final EntityManager entityManager;
|
||||
|
||||
public UserDaoImpl(EntityManager entityManager) {
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(User user) {
|
||||
entityManager.persist(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User read(Long id) {
|
||||
return entityManager.find(User.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String userName) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserRepository {
|
||||
|
||||
User get(Long id);
|
||||
|
||||
void add(User user);
|
||||
|
||||
void update(User user);
|
||||
|
||||
void remove(User user);
|
||||
|
||||
User findByUserName(String userName);
|
||||
|
||||
User findByEmail(String email);
|
||||
|
||||
List<Tweet> fetchTweets(User user);
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
private UserDaoImpl userDaoImpl;
|
||||
private TweetDaoImpl tweetDaoImpl;
|
||||
|
||||
@Override
|
||||
public User get(Long id) {
|
||||
UserSocialMedia user = (UserSocialMedia) userDaoImpl.read(id);
|
||||
|
||||
List<Tweet> tweets = tweetDaoImpl.fetchTweets(user.getEmail());
|
||||
user.setTweets(tweets);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(User user) {
|
||||
userDaoImpl.create(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(User user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tweet> fetchTweets(User user) {
|
||||
return tweetDaoImpl.fetchTweets(user.getEmail());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByUserName(String userName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findByEmail(String email) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.repositoryvsdaopattern;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserSocialMedia extends User {
|
||||
|
||||
private List<Tweet> tweets;
|
||||
|
||||
public List<Tweet> getTweets() {
|
||||
return tweets;
|
||||
}
|
||||
|
||||
public void setTweets(List<Tweet> tweets) {
|
||||
this.tweets = tweets;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
package com.baeldung.mongodb;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import com.mongodb.BasicDBObjectBuilder;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.MongoClient;
|
||||
|
||||
import com.mongodb.client.MongoClients;
|
||||
import de.flapdoodle.embed.mongo.MongodExecutable;
|
||||
import de.flapdoodle.embed.mongo.MongodStarter;
|
||||
import de.flapdoodle.embed.mongo.config.IMongodConfig;
|
||||
|
@ -20,8 +10,19 @@ import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
|
|||
import de.flapdoodle.embed.mongo.config.Net;
|
||||
import de.flapdoodle.embed.mongo.distribution.Version;
|
||||
import de.flapdoodle.embed.process.runtime.Network;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ManualEmbeddedMongoDbIntegrationTest {
|
||||
|
||||
private static final String CONNECTION_STRING = "mongodb://%s:%d";
|
||||
|
||||
private MongodExecutable mongodExecutable;
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
|
@ -42,7 +43,7 @@ class ManualEmbeddedMongoDbIntegrationTest {
|
|||
MongodStarter starter = MongodStarter.getDefaultInstance();
|
||||
mongodExecutable = starter.prepare(mongodConfig);
|
||||
mongodExecutable.start();
|
||||
mongoTemplate = new MongoTemplate(new MongoClient(ip, randomPort), "test");
|
||||
mongoTemplate = new MongoTemplate(MongoClients.create(String.format(CONNECTION_STRING, ip, randomPort)),"test");
|
||||
}
|
||||
|
||||
@DisplayName("Given object When save object using MongoDB template Then object can be found")
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
|
||||
<cassandra-unit-spring.version>3.11.2.0</cassandra-unit-spring.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
|||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.spring.jdbc")
|
||||
@ComponentScan("com.baeldung.spring.jdbc.template.guide")
|
||||
public class SpringJdbcConfig {
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -7,7 +7,7 @@ import restx.tests.RestxSpecTestsRunner;
|
|||
|
||||
@RunWith(RestxSpecTestsRunner.class)
|
||||
@FindSpecsIn("specs/hello")
|
||||
public class HelloResourceSpecUnitTest {
|
||||
public class HelloResourceSpecIntegrationTest {
|
||||
|
||||
/**
|
||||
* Useless, thanks to both @RunWith(RestxSpecTestsRunner.class) & @FindSpecsIn()
|
|
@ -1 +1 @@
|
|||
|
||||
spring.data.jpa.repositories.bootstrap-mode=default
|
||||
|
|
|
@ -224,6 +224,7 @@
|
|||
<h2.version>1.4.200</h2.version>
|
||||
<couchbaseMock.version>1.5.23</couchbaseMock.version>
|
||||
<reactor-core.version>3.3.1.RELEASE</reactor-core.version>
|
||||
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.baeldung.reactive.authresolver;
|
|||
|
||||
import java.util.Collections;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.security.authentication.ReactiveAuthenticationManager;
|
||||
import org.springframework.security.authentication.ReactiveAuthenticationManagerResolver;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
@ -15,6 +14,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@EnableWebFluxSecurity
|
||||
|
@ -38,9 +38,10 @@ public class CustomWebSecurityConfig {
|
|||
return new AuthenticationWebFilter(resolver());
|
||||
}
|
||||
|
||||
public ReactiveAuthenticationManagerResolver<ServerHttpRequest> resolver() {
|
||||
return request -> {
|
||||
if (request
|
||||
public ReactiveAuthenticationManagerResolver<ServerWebExchange> resolver() {
|
||||
return exchange -> {
|
||||
if (exchange
|
||||
.getRequest()
|
||||
.getPath()
|
||||
.subPath(0)
|
||||
.value()
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
package com.baeldung.reactive.errorhandling;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.web.error.ErrorAttributeOptions;
|
||||
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -13,13 +15,9 @@ public class GlobalErrorAttributes extends DefaultErrorAttributes{
|
|||
private HttpStatus status = HttpStatus.BAD_REQUEST;
|
||||
private String message = "please provide a name";
|
||||
|
||||
public GlobalErrorAttributes() {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
|
||||
Map<String, Object> map = super.getErrorAttributes(request, includeStackTrace);
|
||||
public Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
|
||||
Map<String, Object> map = super.getErrorAttributes(request, options);
|
||||
map.put("status", getStatus());
|
||||
map.put("message", getMessage());
|
||||
return map;
|
||||
|
|
|
@ -4,6 +4,7 @@ package com.baeldung.reactive.errorhandling;
|
|||
import java.util.Map;
|
||||
import org.springframework.boot.autoconfigure.web.ResourceProperties;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler;
|
||||
import org.springframework.boot.web.error.ErrorAttributeOptions;
|
||||
import org.springframework.boot.web.reactive.error.ErrorAttributes;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
@ -37,7 +38,7 @@ public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHan
|
|||
|
||||
private Mono<ServerResponse> renderErrorResponse(final ServerRequest request) {
|
||||
|
||||
final Map<String, Object> errorPropertiesMap = getErrorAttributes(request, false);
|
||||
final Map<String, Object> errorPropertiesMap = getErrorAttributes(request, ErrorAttributeOptions.defaults());
|
||||
|
||||
return ServerResponse.status(HttpStatus.BAD_REQUEST)
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
|
|
|
@ -29,6 +29,11 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
@ -29,7 +29,7 @@ public class LogbackMultiProfileTestLogLevelIntegrationTest {
|
|||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
private String baseUrl = "/testLogLevel";
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
@ -29,7 +29,7 @@ public class LogbackTestLogLevelIntegrationTest {
|
|||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
private String baseUrl = "/testLogLevel";
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
@ -29,7 +29,7 @@ public class TestLogLevelWithProfileIntegrationTest {
|
|||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
private String baseUrl = "/testLogLevel";
|
||||
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
@ -98,11 +102,6 @@
|
|||
<artifactId>rome</artifactId>
|
||||
<version>${rome.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
|
||||
<spring-cloud-dependencies.version>Hoxton.SR4</spring-cloud-dependencies.version>
|
||||
<postgresql.version>42.2.10</postgresql.version>
|
||||
<bytebuddy.version>1.10.10</bytebuddy.version>
|
||||
|
|
|
@ -62,6 +62,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf</groupId>
|
||||
<artifactId>thymeleaf-spring4</artifactId>
|
||||
<artifactId>thymeleaf-spring5</artifactId>
|
||||
<version>${org.thymeleaf-version}</version>
|
||||
</dependency>
|
||||
|
||||
|
@ -164,7 +164,7 @@
|
|||
<hibernate-validator.version>6.0.10.Final</hibernate-validator.version>
|
||||
<deploy-path>enter-location-of-server</deploy-path>
|
||||
<commons-fileupload.version>1.3.2</commons-fileupload.version>
|
||||
<org.thymeleaf-version>3.0.7.RELEASE</org.thymeleaf-version>
|
||||
<org.thymeleaf-version>3.0.11.RELEASE</org.thymeleaf-version>
|
||||
<groovy.version>2.4.12</groovy.version>
|
||||
<freemarker.version>2.3.27-incubating</freemarker.version>
|
||||
<jade.version>1.2.5</jade.version>
|
||||
|
|
|
@ -11,8 +11,8 @@ import org.springframework.mail.javamail.JavaMailSender;
|
|||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
import org.thymeleaf.spring4.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = { "com.baeldung.spring.mail" })
|
||||
|
|
|
@ -4,9 +4,9 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.thymeleaf.spring4.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue