upgrade spring-boot project, extract auto-config, remove security

This commit is contained in:
Loredana Crusoveanu
2018-05-06 21:19:41 +03:00
parent c0131fdd8a
commit b4d4d4ec08
64 changed files with 325 additions and 373 deletions
@@ -1,27 +0,0 @@
package com.baeldung.autoconfiguration;
import com.baeldung.autoconfiguration.example.AutoconfigurationApplication;
import com.baeldung.autoconfiguration.example.MyUser;
import com.baeldung.autoconfiguration.example.MyUserRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = AutoconfigurationApplication.class)
@EnableJpaRepositories(basePackages = { "com.baeldung.autoconfiguration.example" })
public class AutoconfigurationIntegrationTest {
@Autowired
private MyUserRepository userRepository;
@Test
public void whenSaveUser_thenOk() {
MyUser user = new MyUser("user@email.com");
userRepository.save(user);
}
}
@@ -4,9 +4,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
@@ -16,7 +16,7 @@ import com.baeldung.servletinitializer.WarInitializerApplication.WarInitializerC
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = WarInitializerController.class)
public class WarInitializerApplicationTest {
public class WarInitializerApplicationIntegrationTest {
@Autowired
private MockMvc mockMvc;
@@ -47,7 +47,7 @@ public class ToggleIntegrationTest {
mockMvc.perform(post("/increaseSalary").param("id", emp.getId() + "")).andExpect(status().is(200));
emp = employeeRepository.findOne(1L);
emp = employeeRepository.findById(1L).orElse(null);
assertEquals("salary incorrect", 2000, emp.getSalary(), 0.5);
}
@@ -60,7 +60,7 @@ public class ToggleIntegrationTest {
mockMvc.perform(post("/increaseSalary").param("id", emp.getId() + "")).andExpect(status().is(200));
emp = employeeRepository.findOne(1L);
emp = employeeRepository.findById(1L).orElse(null);
assertEquals("salary incorrect", 2200, emp.getSalary(), 0.5);
}
}
@@ -22,7 +22,7 @@ public class SpringBootH2IntegrationTest {
@Test
public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() {
GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test"));
GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId());
GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null);
assertNotNull(foundEntity);
assertEquals(genericEntity.getValue(), foundEntity.getValue());
}
@@ -21,7 +21,7 @@ public class SpringBootJPAIntegrationTest {
@Test
public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() {
GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test"));
GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId());
GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null);
assertNotNull(foundEntity);
assertEquals(genericEntity.getValue(), foundEntity.getValue());
}
@@ -24,7 +24,7 @@ public class SpringBootProfileIntegrationTest {
@Test
public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() {
GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test"));
GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId());
GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null);
assertNotNull(foundEntity);
assertEquals(genericEntity.getValue(), foundEntity.getValue());
}
@@ -43,13 +43,13 @@ public class EmployeeRepositoryIntegrationTest {
Employee emp = new Employee("test");
entityManager.persistAndFlush(emp);
Employee fromDb = employeeRepository.findById(emp.getId());
Employee fromDb = employeeRepository.findById(emp.getId()).orElse(null);
assertThat(fromDb.getName()).isEqualTo(emp.getName());
}
@Test
public void whenInvalidId_thenReturnNull() {
Employee fromDb = employeeRepository.findById(-11L);
Employee fromDb = employeeRepository.findById(-11l).orElse(null);
assertThat(fromDb).isNull();
}
@@ -50,9 +50,9 @@ public class EmployeeServiceImplIntegrationTest {
Mockito.when(employeeRepository.findByName(john.getName())).thenReturn(john);
Mockito.when(employeeRepository.findByName(alex.getName())).thenReturn(alex);
Mockito.when(employeeRepository.findByName("wrong_name")).thenReturn(null);
Mockito.when(employeeRepository.findById(john.getId())).thenReturn(john);
Mockito.when(employeeRepository.findById(john.getId()).orElse(null)).thenReturn(john);
Mockito.when(employeeRepository.findAll()).thenReturn(allEmployees);
Mockito.when(employeeRepository.findById(-99L)).thenReturn(null);
Mockito.when(employeeRepository.findById(-99L).orElse(null)).thenReturn(null);
}
@Test