Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
VasylyshynDmytro committed Dec 13, 2024
1 parent 1809259 commit 74d0c29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
10 changes: 4 additions & 6 deletions core/src/test/java/greencity/controller/PlaceControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package greencity.controller;

import greencity.constant.ErrorMessage;
import greencity.converters.UserArgumentResolver;
import greencity.dto.place.*;
import greencity.entity.Place;
import greencity.enums.PlaceStatus;
import greencity.exception.exceptions.NotFoundException;
import greencity.service.UserService;
import java.security.Principal;
import java.time.DayOfWeek;
Expand All @@ -20,7 +22,6 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.Mockito.doNothing;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
Expand Down Expand Up @@ -52,19 +53,16 @@
import static greencity.ModelUtils.getUserVO;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static greencity.ModelUtils.getPrincipal;
import static greencity.enums.PlaceStatus.APPROVED;
import static greencity.enums.PlaceStatus.PROPOSED;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
Expand Down
27 changes: 22 additions & 5 deletions service-api/src/test/java/greencity/client/RestClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static greencity.TestConst.USER_ID;
import static greencity.constant.AppConstant.AUTHORIZATION;
import greencity.dto.econews.InterestingEcoNewsDto;
import greencity.dto.place.UpdatePlaceStatusWithUserEmailDto;
import greencity.dto.user.UserStatusDto;
import greencity.dto.user.UserVO;
import greencity.dto.user.UserManagementDto;
Expand All @@ -22,6 +23,7 @@
import greencity.dto.PageableAdvancedDto;
import greencity.dto.achievement.UserVOAchievement;
import greencity.enums.EmailNotification;
import greencity.enums.PlaceStatus;
import greencity.enums.Role;
import greencity.enums.UserStatus;
import greencity.message.ScheduledEmailMessage;
Expand Down Expand Up @@ -55,11 +57,8 @@
import org.springframework.web.context.request.RequestContextHolder;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class RestClientTest {
Expand Down Expand Up @@ -679,4 +678,22 @@ void sendEmailNotificationPlacesTest() {
verify(restTemplate).exchange(GREEN_CITY_USER_ADDRESS
+ RestTemplateLinks.SEND_SCHEDULED_NOTIFICATION, HttpMethod.POST, entity, Object.class);
}

@Test
void sendEmailNotificationChangesPlaceStatusTest() {
UpdatePlaceStatusWithUserEmailDto message = new UpdatePlaceStatusWithUserEmailDto();
message.setPlaceName("TestPlace");
message.setNewStatus(PlaceStatus.APPROVED);
message.setUserName("TestUser");
message.setEmail("[email protected]");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<UpdatePlaceStatusWithUserEmailDto> entity = new HttpEntity<>(message, headers);
String expectedUrl = GREEN_CITY_USER_ADDRESS + RestTemplateLinks.SEND_NOTIFICATION_STATUS_PLACE;
when(restTemplate.exchange(eq(expectedUrl), eq(HttpMethod.POST), any(HttpEntity.class), eq(Object.class)))
.thenReturn(ResponseEntity.ok().build());
restClient.sendEmailNotificationChangesPlaceStatus(message);
verify(restTemplate, times(1)).exchange(eq(expectedUrl), eq(HttpMethod.POST), any(HttpEntity.class),
eq(Object.class));
}
}

0 comments on commit 74d0c29

Please sign in to comment.