NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import com.wyndhamvo.services.ooninvoice.openapi.message.*;
import com.wyndhamvo.services.ooninvoice.repo.trans.GetInvoiceChargeBrkdwnRepo;
import com.wyndhamvo.services.ooninvoice.repo.trans.ResEventAppRepo;
import com.wyndhamvo.services.ooninvoice.repo.trans.ResEventTypeRepo;
import com.wyndhamvo.services.ooninvoice.repo.trans.SaveReservationChargesRepo;
import com.wyndhamvo.services.ooninvoice.repo.trans.entity.BookingInvoiceDTO;
import com.wyndhamvo.services.ooninvoice.repo.trans.entity.GetInvoiceChargeBrkdwnDTO;
import com.wyndhamvo.services.ooninvoice.repo.trans.entity.ResEventAppDTO;
import com.wyndhamvo.services.ooninvoice.repo.trans.entity.ResEventTypeDTO;
import com.wyndhamvo.services.ooninvoice.service.constant.ReservationConstants;
import com.wyndhamvo.services.ooninvoice.service.helper.SaveReservationChargesHelper;
import com.wyndhamvo.services.ooninvoice.util.ServiceUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class ReservationChargesServiceImplTest {

@InjectMocks
private ReservationChargesServiceImpl reservationChargesService;

@Mock
private SaveReservationChargesRepo repo;

@Mock
private GetInvoiceChargeBrkdwnRepo brkdwnRepo;

@Mock
private ResEventAppRepo resEventAppRepo;

@Mock
private ResEventTypeRepo resEventTypeRepo;

@Mock
private Logger logger;

private SaveResvChargesRequestBTO request;
private MessageHeader header;
private BookingInvoiceDTO invoice;
private List<GetInvoiceChargeBrkdwnDTO> chargeBrkdwnDTOList;

@BeforeEach
void setUp() {
request = new SaveResvChargesRequestBTO();
request.setReservationId(12345L);
request.setTotalCashAmt(100.0);
request.setTotalCashCurncy("USD");

header = new MessageHeader();
invoice = new BookingInvoiceDTO();
chargeBrkdwnDTOList = new ArrayList<>();

// Mock the response data
GetInvoiceChargeBrkdwnDTO chargeBreakdown = new GetInvoiceChargeBrkdwnDTO();
chargeBreakdown.setMemberNumKey("123");
chargeBreakdown.setResNumber("ABC123");
chargeBreakdown.setRoomRatePlanId("PLAN123");
chargeBrkdwnDTOList.add(chargeBreakdown);
}

@Test
void testSaveChargesSuccess() {
// Arrange
when(repo.save(any(BookingInvoiceDTO.class))).thenReturn(invoice);
when(brkdwnRepo.getInvoiceChargeBrkdwn(anyLong())).thenReturn(chargeBrkdwnDTOList);
when(resEventAppRepo.saveAndFlush(any(ResEventAppDTO.class))).thenReturn(new ResEventAppDTO());

// Act
SaveResvChargesResponseBTO response = reservationChargesService.saveCharges(request, header);

// Assert
assertEquals(ReservationConstants.SUCCESS, response.getResponses().getResponseType());
assertEquals("123", response.getMemberNumberKey());
assertEquals("ABC123", response.getResvConfirmationNumber());
assertEquals("PLAN123", response.getRoomRatePlanId());

verify(repo, times(1)).save(any(BookingInvoiceDTO.class));
verify(brkdwnRepo, times(1)).getInvoiceChargeBrkdwn(anyLong());
verify(resEventAppRepo, times(1)).saveAndFlush(any(ResEventAppDTO.class));
}

@Test
void testSaveChargesFailure() {
// Arrange
when(repo.save(any(BookingInvoiceDTO.class))).thenThrow(new RuntimeException("Save failed"));

// Act
SaveResvChargesResponseBTO response = reservationChargesService.saveCharges(request, header);

// Assert
assertEquals(ReservationConstants.FAILURE, response.getResponses().getResponseType());
assertEquals("Save failed", response.getResponses().getResponseMessage());

verify(repo, times(1)).save(any(BookingInvoiceDTO.class));
verify(logger, times(1)).error(anyString(), any(Exception.class));
}

@Test
void testSaveResEventAppSuccess() {
// Arrange
ResEventTypeDTO eventType = new ResEventTypeDTO();
when(resEventTypeRepo.getResEventTypeByName(anyString())).thenReturn(eventType);
when(resEventAppRepo.saveAndFlush(any(ResEventAppDTO.class))).thenReturn(new ResEventAppDTO());

// Act
ResEventAppDTO resEventApp = reservationChargesService.saveResEventApp(12345L, 54321L, header);

// Assert
assertEquals(eventType, resEventApp.getResEventType());
verify(resEventAppRepo, times(1)).saveAndFlush(any(ResEventAppDTO.class));
}

@Test
void testSaveResEventAppFailure() {
// Arrange
when(resEventAppRepo.saveAndFlush(any(ResEventAppDTO.class))).thenThrow(new RuntimeException("Event save failed"));

// Act
reservationChargesService.saveResEventApp(12345L, 54321L, header);

// Assert
verify(logger, times(1)).error(anyString(), any(Exception.class));
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.