Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -63,6 +63,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.date_migration;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public class NewApi {
|
||||
public void currentTime() {
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
}
|
||||
|
||||
public void specificTime() {
|
||||
LocalDate birthDay = LocalDate.of(1990, Month.DECEMBER, 15);
|
||||
}
|
||||
|
||||
public void extractMonth() {
|
||||
Month month = LocalDateTime.now().getMonth();
|
||||
}
|
||||
|
||||
public void subtractTime() {
|
||||
LocalDateTime fiveHoursBefore = LocalDateTime.now().minusHours(5);
|
||||
}
|
||||
|
||||
public void alterField() {
|
||||
LocalDateTime inJune = LocalDateTime.now().withMonth(Month.JUNE.getValue());
|
||||
}
|
||||
|
||||
public void truncate() {
|
||||
LocalTime truncated = LocalTime.now().truncatedTo(ChronoUnit.HOURS);
|
||||
}
|
||||
|
||||
public void convertTimeZone() {
|
||||
ZonedDateTime centralEastern = LocalDateTime.now().atZone(ZoneId.of("CET"));
|
||||
}
|
||||
|
||||
public void getTimeSpan() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime hourLater = LocalDateTime.now().plusHours(1);
|
||||
Duration span = Duration.between(now, hourLater);
|
||||
}
|
||||
|
||||
public void formatAndParse() throws ParseException {
|
||||
LocalDate now = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
String formattedDate = now.format(formatter);
|
||||
LocalDate parsedDate = LocalDate.parse(formattedDate, formatter);
|
||||
}
|
||||
|
||||
public void daysInMonth() {
|
||||
int daysInMonth = YearMonth.of(1990, 2).lengthOfMonth();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.baeldung.date_migration;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class OldApi {
|
||||
public void currentTime() {
|
||||
Date now = new Date();
|
||||
}
|
||||
|
||||
public void specificTime () {
|
||||
Date birthDay = new GregorianCalendar(1990, Calendar.DECEMBER, 15).getTime();
|
||||
}
|
||||
|
||||
public void extractMonth() {
|
||||
int month = new GregorianCalendar().get(Calendar.MONTH);
|
||||
}
|
||||
|
||||
public void subtractTime() {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.add(Calendar.HOUR_OF_DAY, -5);
|
||||
Date fiveHoursBefore = calendar.getTime();
|
||||
}
|
||||
|
||||
public void alterField() {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.set(Calendar.MONTH, Calendar.JUNE);
|
||||
Date inJune = calendar.getTime();
|
||||
}
|
||||
|
||||
public void truncate() {
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.set(Calendar.MINUTE, 0);
|
||||
now.set(Calendar.SECOND, 0);
|
||||
now.set(Calendar.MILLISECOND, 0);
|
||||
Date truncated = now.getTime();
|
||||
}
|
||||
|
||||
public void convertTimeZone() {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
|
||||
Date centralEastern = calendar.getTime();
|
||||
}
|
||||
|
||||
public void getTimeSpan() {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
Date now = new Date();
|
||||
calendar.add(Calendar.HOUR, 1);
|
||||
Date hourLater = calendar.getTime();
|
||||
long elapsed = hourLater.getTime() - now.getTime();
|
||||
}
|
||||
|
||||
public void formatAndParse() throws ParseException {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date now = new Date();
|
||||
String formattedDate = dateFormat.format(now);
|
||||
Date parsedDate = dateFormat.parse(formattedDate);
|
||||
}
|
||||
|
||||
public void daysInMonth() {
|
||||
Calendar calendar = new GregorianCalendar(1990, Calendar.FEBRUARY, 20);
|
||||
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.date_migration;
|
||||
package com.baeldung.dateapi;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
@@ -7,7 +7,7 @@ import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Conversion {
|
||||
public class ConversionExample {
|
||||
public static void main(String[] args) {
|
||||
Instant instantFromCalendar = GregorianCalendar.getInstance().toInstant();
|
||||
ZonedDateTime zonedDateTimeFromCalendar = new GregorianCalendar().toZonedDateTime();
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.baeldung.dateapi;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.Month;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class JavaUtilTimeTest {
|
||||
|
||||
@Test
|
||||
public void currentTime() {
|
||||
final LocalDate now = LocalDate.now();
|
||||
|
||||
System.out.println(now);
|
||||
// there is not much to test here
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specificTime() {
|
||||
LocalDate birthDay = LocalDate.of(1990, Month.DECEMBER, 15);
|
||||
|
||||
System.out.println(birthDay);
|
||||
// there is not much to test here
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMonth() {
|
||||
Month month = LocalDate.of(1990, Month.DECEMBER, 15).getMonth();
|
||||
|
||||
assertThat(month).isEqualTo(Month.DECEMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subtractTime() {
|
||||
LocalDateTime fiveHoursBefore = LocalDateTime.of(1990, Month.DECEMBER, 15, 15, 0).minusHours(5);
|
||||
|
||||
assertThat(fiveHoursBefore.getHour()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alterField() {
|
||||
LocalDateTime inJune = LocalDateTime.of(1990, Month.DECEMBER, 15, 15, 0).with(Month.JUNE);
|
||||
|
||||
assertThat(inJune.getMonth()).isEqualTo(Month.JUNE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void truncate() {
|
||||
LocalTime truncated = LocalTime.of(15, 12, 34).truncatedTo(ChronoUnit.HOURS);
|
||||
|
||||
assertThat(truncated).isEqualTo(LocalTime.of(15, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimeSpan() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime hourLater = now.plusHours(1);
|
||||
Duration span = Duration.between(now, hourLater);
|
||||
|
||||
assertThat(span).isEqualTo(Duration.ofHours(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatAndParse() throws ParseException {
|
||||
LocalDate someDate = LocalDate.of(2016, 12, 7);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
String formattedDate = someDate.format(formatter);
|
||||
LocalDate parsedDate = LocalDate.parse(formattedDate, formatter);
|
||||
|
||||
assertThat(formattedDate).isEqualTo("2016-12-07");
|
||||
assertThat(parsedDate).isEqualTo(someDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void daysInMonth() {
|
||||
int daysInMonth = YearMonth.of(1990, 2).lengthOfMonth();
|
||||
|
||||
assertThat(daysInMonth).isEqualTo(28);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
=========
|
||||
|
||||
## HttpClient 4.x Cookbooks and Examples
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
## Jackson Cookbooks and Examples
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization)
|
||||
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<easymock.version>3.4</easymock.version>
|
||||
<jmockit.version>1.24</jmockit.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## REST Testing and Examples
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
This project is used to replicate Spring Exceptions only.
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant articles:
|
||||
- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
@@ -1,3 +1,6 @@
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
# About this project
|
||||
This project contains examples from the [Introduction to Spring Data REST](http://www.baeldung.com/spring-data-rest-intro) article from Baeldung.
|
||||
|
||||
|
||||
@@ -2,5 +2,8 @@
|
||||
|
||||
## Java Web Application
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [JSON API in a Java Web Application](http://www.baeldung.com/json-api-java-spring-web-app)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring MVC with Java Configuration Example Project
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring MVC with NO XML Configuration Example Project
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
-
|
||||
-
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
=========
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
## Spring MVC with XML Configuration Example Project
|
||||
- access a sample jsp page at: `http://localhost:8080/spring-mvc-xml/sample.html`
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring REST Example Project
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring @RequestMapping](http://www.baeldung.com/spring-requestmapping)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring Security with Basic Authentication Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Article:
|
||||
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
|
||||
@@ -9,4 +11,4 @@
|
||||
|
||||
|
||||
### Notes
|
||||
- the project includes both views as well as a REST layer
|
||||
- the project includes both views as well as a REST layer
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring Security Login Example Project
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring Security with Digest Authentication Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Article:
|
||||
- [Spring Security Digest Authentication](http://www.baeldung.com/spring-security-digest-authentication)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
## Spring Security with LDAP Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Article:
|
||||
- [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll)
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
## Spring Security Login Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring Security Form Login](http://www.baeldung.com/spring-security-login)
|
||||
- [Spring Security Logout](http://www.baeldung.com/spring-security-logout)
|
||||
- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
|
||||
- [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic)
|
||||
|
||||
|
||||
### Build the Project
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## Spring Security Persisted Remember Me Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring Security Persisted Remember Me](http://www.baeldung.com/spring-security-persistent-remember-me)
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
## Spring Security Login Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Articles:
|
||||
- [HttpSessionListener Example – Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics)
|
||||
- [HttpSessionListener Example – Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics)
|
||||
- [Spring Security Session Management](http://www.baeldung.com/spring-security-session)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
## REST API with Basic Authentication - Example Project
|
||||
|
||||
###The Course
|
||||
The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity
|
||||
|
||||
### Relevant Articles:
|
||||
- [RestTemplate with Basic Authentication in Spring](http://www.baeldung.com/2012/04/16/how-to-use-resttemplate-with-basic-authentication-in-spring-3-1)
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
## Spring Security for REST Example Project
|
||||
|
||||
###The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring Security Authentication Provider](http://www.baeldung.com/spring-security-authentication-provider)
|
||||
- [Retrieve User Information in Spring Security](http://www.baeldung.com/get-user-in-spring-security)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user