PAN-15 fix the request changes
This commit is contained in:
@@ -27,7 +27,7 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Account> getListOfAccount(){
|
public Optional<Account> getListOfAccount(){
|
||||||
final String auth = "";
|
final String auth = null;
|
||||||
final Instant start = Instant.now();
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -60,7 +60,7 @@ public class UserService {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String auth = "";
|
final String auth = null;
|
||||||
final Instant start = Instant.now();
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -92,7 +92,7 @@ public class UserService {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String auth = "";
|
final String auth = null;
|
||||||
final Instant start = Instant.now();
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -208,7 +208,7 @@ public class UserService {
|
|||||||
LOG.info("Returning {}", persistenceApiResponse);
|
LOG.info("Returning {}", persistenceApiResponse);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG.info("Unable to delete user {}", account.toString());
|
LOG.info("Unable to delete user {}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return persistenceApiResponse;
|
return persistenceApiResponse;
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Matchers.*;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
@@ -39,10 +37,41 @@ public class UserServiceTest {
|
|||||||
assertEquals(accountList, response.get());
|
assertEquals(accountList, response.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetListOfAccounts_persistenceApiResponseIsNotPresent(){
|
||||||
|
final Account account1 = createAccount();
|
||||||
|
final Account account2 = createAccount();
|
||||||
|
final List<Account> accountList = new ArrayList<>();
|
||||||
|
accountList.add(account1);
|
||||||
|
accountList.add(account2);
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
final Optional<Account> response = userService.getListOfAccount();
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetListOfAccounts_catchException(){
|
||||||
|
final Account account1 = createAccount();
|
||||||
|
final Account account2 = createAccount();
|
||||||
|
final List<Account> accountList = new ArrayList<>();
|
||||||
|
accountList.add(account1);
|
||||||
|
accountList.add(account2);
|
||||||
|
final Exception e = new Exception();
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
|
.thenThrow(Exception.class);
|
||||||
|
final Optional<Account> response = userService.getListOfAccount();
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccountById(){
|
public void testGetAccountById(){
|
||||||
final Account account = createAccount();
|
final Account account = createAccount();
|
||||||
account.setId(1);
|
|
||||||
|
|
||||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
.thenReturn(Optional.of(account));
|
.thenReturn(Optional.of(account));
|
||||||
@@ -50,20 +79,74 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
assertTrue(response.isPresent());
|
assertTrue(response.isPresent());
|
||||||
assertEquals(account, response.get());
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById_nullId() {
|
||||||
|
final Optional<Account> response = userService.getAccountById(0);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById_persistenceApiResponseIsNotPresent(){
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
final Optional<Account> response = userService.getAccountById(1);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountById_catchException(){
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
|
.thenThrow(Exception.class);
|
||||||
|
final Optional<Account> response = userService.getAccountById(1);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccountByUsername(){
|
public void testGetAccountByUsername(){
|
||||||
final Account account = createAccount();
|
final Account account = createAccount();
|
||||||
final String username = account.getUsername();
|
|
||||||
|
|
||||||
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
.thenReturn(Optional.of(account));
|
.thenReturn(Optional.of(account));
|
||||||
final Optional<Account> response = userService.getAccountByUsername(username);
|
final Optional<Account> response = userService.getAccountByUsername(account.getUsername());
|
||||||
|
|
||||||
assertTrue(response.isPresent());
|
assertTrue(response.isPresent());
|
||||||
assertEquals(account, response.get());
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountByUsername_nullUsername(){
|
||||||
|
final Optional<Account> response = userService.getAccountByUsername(null);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verifyZeroInteractions(restService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAccountByUsername_persistenceApiResponseIsNotPresent(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
|
||||||
|
when(restService.get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
final Optional<Account> response = userService.getAccountByUsername(account.getUsername());
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
verify(restService).get(anyString(),any(TypeToken.class), anyInt(), anyInt(),anyString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateAccount(){
|
public void testCreateAccount(){
|
||||||
final Account account = createAccount();
|
final Account account = createAccount();
|
||||||
@@ -74,6 +157,27 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
assertTrue(response.isPresent());
|
assertTrue(response.isPresent());
|
||||||
assertEquals(account, response.get());
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAccount_NoAccountFound() {
|
||||||
|
final Optional<Account> response = userService.createAccount(null);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verify(restService, times(0)).post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAccount_catchException(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
|
||||||
|
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt())).thenThrow(Exception.class);
|
||||||
|
final Optional<Account> response = userService.createAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,6 +191,54 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
assertTrue(response.isPresent());
|
assertTrue(response.isPresent());
|
||||||
assertEquals(account, response.get());
|
assertEquals(account, response.get());
|
||||||
|
verify(restService).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_nullAccount(){
|
||||||
|
final Optional<Account> response = userService.updateAccount(null);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verify(restService, times(0)).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_nullId(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(0);
|
||||||
|
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
verify(restService, times(0)).patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_PersistenceApiResponseIsNotPresent(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt()))
|
||||||
|
.thenReturn(Optional.empty());
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAccount_catchException(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.patch(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt()))
|
||||||
|
.thenThrow(Exception.class);
|
||||||
|
final Optional<Account> response = userService.updateAccount(account);
|
||||||
|
|
||||||
|
assertFalse(response.isPresent());
|
||||||
|
assertEquals(Optional.empty(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -99,8 +251,59 @@ public class UserServiceTest {
|
|||||||
.thenReturn(response);
|
.thenReturn(response);
|
||||||
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
||||||
|
|
||||||
assertTrue(persistenceApiResponse );
|
assertNotNull(persistenceApiResponse);
|
||||||
assertEquals(response, persistenceApiResponse );
|
assertTrue(persistenceApiResponse);
|
||||||
|
assertEquals(response, persistenceApiResponse);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_nullAccount(){
|
||||||
|
final boolean persistenceApiResponse = userService.deleteAccount(null);
|
||||||
|
|
||||||
|
assertNotNull(persistenceApiResponse);
|
||||||
|
assertFalse(persistenceApiResponse);
|
||||||
|
verify(restService, times(0)).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_nullId(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(0);
|
||||||
|
|
||||||
|
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertNotNull(persistenceApiResponse);
|
||||||
|
assertFalse(persistenceApiResponse);
|
||||||
|
verify(restService, times(0)).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_persistenceApiResponseIsNotPresent(){
|
||||||
|
final boolean response= false;
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any()))
|
||||||
|
.thenReturn(response);
|
||||||
|
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertNotNull(persistenceApiResponse);
|
||||||
|
assertFalse(persistenceApiResponse);
|
||||||
|
assertEquals(response, persistenceApiResponse);
|
||||||
|
verify(restService).delete(anyString(), anyInt(), anyInt(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteAccount_catchException(){
|
||||||
|
final Account account = createAccount();
|
||||||
|
account.setId(1);
|
||||||
|
|
||||||
|
when(restService.delete(anyString(), anyInt(), anyInt(), any())).thenThrow(Exception.class);
|
||||||
|
final boolean persistenceApiResponse = userService.deleteAccount(account);
|
||||||
|
|
||||||
|
assertNotNull(persistenceApiResponse);
|
||||||
|
assertFalse(persistenceApiResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package edu.msudenver.tsp.website.controller;
|
|
||||||
|
|
||||||
import edu.msudenver.tsp.website.forms.TheoremForm;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Controller
|
|
||||||
@AllArgsConstructor
|
|
||||||
@RequestMapping("/login")
|
|
||||||
public class LogInController {
|
|
||||||
@GetMapping({"/",""})
|
|
||||||
public ModelAndView enterTheoremPage() {
|
|
||||||
LOG.info("Received request to display the theorem entry page: returning model with name 'Theorem'");
|
|
||||||
return new ModelAndView("Theorem");
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping({"/",""})
|
|
||||||
public String saveTheorem(@Validated final TheoremForm theoremForm, final Model model) {
|
|
||||||
model.addAttribute("theoremName", theoremForm.getTheoremName());
|
|
||||||
model.addAttribute("theorem", theoremForm.getTheorem());
|
|
||||||
LOG.info("Saving theorem {}...", theoremForm);
|
|
||||||
|
|
||||||
return "success";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user