Skip to content

Commit

Permalink
Merge pull request #6 from pavelfomin/feature/spring-boot-2.5
Browse files Browse the repository at this point in the history
spring boot 2.5
  • Loading branch information
pavelfomin committed Jan 24, 2022
2 parents 77ce045 + faba315 commit ffdf1a3
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: check release tag
if: github.event_name == 'pull_request'
run: scripts/check-release.sh
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

<groupId>com.droidablebee</groupId>
<artifactId>spring-boot-rest-example</artifactId>
<version>2.2.5</version>
<version>2.5.9.0</version>
<name>Spring boot example with REST and spring data JPA</name>

<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<version>2.5.9</version>
</parent>

<properties>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand All @@ -25,6 +25,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-data-jpa</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ management:
endpoints:
web:
exposure:
include: info,health,env
include: info,health
endpoint:
health:
show-details: when-authorized
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.droidablebee.springboot.rest.endpoint;

import net.minidev.json.JSONArray;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
Expand All @@ -16,7 +13,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class ActuatorEndpointTest extends BaseEndpointTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected String json(Object o) throws IOException {

protected SecurityMockMvcRequestPostProcessors.JwtRequestPostProcessor jwtWithScope(String scope) {

return jwt(jwt -> jwt.claims(claims -> claims.put("scope", scope)));
return jwt().jwt(jwt -> jwt.claims(claims -> claims.put("scope", scope)));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.droidablebee.springboot.rest.endpoint;

import com.droidablebee.springboot.rest.domain.Person;
import com.droidablebee.springboot.rest.service.PersonService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.transaction.annotation.Transactional;

import static com.droidablebee.springboot.rest.endpoint.PersonEndpoint.PERSON_READ_PERMISSION;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
Expand All @@ -10,19 +18,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.util.NestedServletException;

import com.droidablebee.springboot.rest.domain.Person;
import com.droidablebee.springboot.rest.service.PersonService;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@Transactional
public class PersonEndpointMockedTest extends BaseEndpointTest {
Expand All @@ -32,7 +27,7 @@ public class PersonEndpointMockedTest extends BaseEndpointTest {

private Person testPerson;

@Before
@BeforeEach
public void setup() throws Exception {

testPerson = new Person(1L, "Jack", "Bauer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import com.droidablebee.springboot.rest.domain.Person;
import com.droidablebee.springboot.rest.service.PersonService;
import net.minidev.json.JSONArray;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
Expand All @@ -24,8 +22,8 @@
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -35,7 +33,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@Transactional
public class PersonEndpointTest extends BaseEndpointTest {
Expand All @@ -49,7 +46,7 @@ public class PersonEndpointTest extends BaseEndpointTest {
private Person testPerson;
private long timestamp;

@Before
@BeforeEach
public void setup() throws Exception {

timestamp = new Date().getTime();
Expand Down Expand Up @@ -233,7 +230,8 @@ public void createPersonValidationUserId() throws Exception {
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(content().contentType(JSON_MEDIA_TYPE))
.andExpect(jsonPath("$.message", containsString("Missing request header '"+ PersonEndpoint.HEADER_USER_ID)))
//"Required request header 'userId' for method parameter type String is not present"
.andExpect(jsonPath("$.message", containsString("Required request header '"+ PersonEndpoint.HEADER_USER_ID)))
;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.droidablebee.springboot.rest.endpoint;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MvcResult;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MvcResult;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class SwaggerEndpointTest extends BaseEndpointTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.droidablebee.springboot.rest.repository;

import com.droidablebee.springboot.rest.domain.Person;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import java.util.Optional;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

@RunWith(SpringJUnit4ClassRunner.class)
@DataJpaTest
/*
By default @DataJpaTest uses embeded h2 databaze and ignores the connection string declared in application.properties.
Expand All @@ -30,33 +29,33 @@ public class PersonRepositoryTest {
@PersistenceContext
EntityManager entityManager;

@Test(expected = javax.persistence.EntityNotFoundException.class)
@Test
public void getOne() {

Person person = personRepository.getOne(Long.MAX_VALUE);
assertNotNull(person);
//access to the Entity's reference state should cause javax.persistence.EntityNotFoundException
assertNotNull(person.getId()); // accessing id won't throw an exception
person.getFirstName(); // will throw exception
assertThrows(javax.persistence.EntityNotFoundException.class, () -> person.getFirstName());
}

@Test(expected = javax.persistence.EntityNotFoundException.class)
@Test
public void getReferenceUsingEntityManager() {

Person person = entityManager.getReference(Person.class, Long.MAX_VALUE);
assertNotNull(person);
//access to the Entity's reference state should cause javax.persistence.EntityNotFoundException
assertNotNull(person.getId()); // accessing id won't throw an exception
person.getFirstName(); // will throw exception
assertThrows(javax.persistence.EntityNotFoundException.class, () -> person.getFirstName());
}

@Test(expected = java.util.NoSuchElementException.class)
@Test
public void findByIdUsingOptional() {

Optional<Person> optional = personRepository.findById(Long.MAX_VALUE);
assertNotNull(optional);
assertFalse(optional.isPresent());
optional.get();
assertThrows(java.util.NoSuchElementException.class, () -> optional.get());
}

@Test
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/application-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# override any values in application.yml using default profile for testing
management:
endpoints:
web:
exposure:
include: info,health,env
30 changes: 0 additions & 30 deletions src/test/resources/application.yml

This file was deleted.

0 comments on commit ffdf1a3

Please sign in to comment.