Untitled

 avatar
unknown
plain_text
9 days ago
4.3 kB
3
Indexable
package com.santander.scib.dlx.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.santander.scib.dlx.model.nativ.*;
import com.santander.scib.dlx.model.web.*;
import com.santander.scib.dlx.service.DlxService;
import com.santander.scib.dlx.util.QueryUtil;
import com.santander.scib.dlx.util.ReplaceUtils;
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.springframework.http.ResponseEntity;

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

@ExtendWith(MockitoExtension.class)
class CalendarServiceImplTest {
    
    @Mock
    private DlxService dlxService;

    @InjectMocks
    private CalendarServiceImpl calendarService;

    private final ObjectMapper objectMapper = new ObjectMapper();
    private final String token = "test-token";
    private final String calendarId = "1234";

    @BeforeEach
    void setUp() {
        // Puedes inicializar datos comunes si es necesario
    }

    @Test
    void createCalendar_Success() {
        CreateCalendarRequest request = new CreateCalendarRequest();
        request.setCalendar("test-calendar");
        NativeCreateCalendarResponse nativeResponse = new NativeCreateCalendarResponse();
        nativeResponse.setCreateCalendar(new GenericResponse("success"));
        DlxGenericResponse<NativeCreateCalendarResponse> dlxResponse = new DlxGenericResponse<>();
        dlxResponse.setData(nativeResponse);
        
        when(dlxService.executeAndResponse(anyString(), anyString())).thenReturn(dlxResponse);
        
        ResponseEntity<GenericResponse> response = calendarService.createCalendar(token, request);
        
        assertNotNull(response);
        assertEquals(201, response.getStatusCodeValue());
        assertEquals("success", response.getBody().getResult());
    }
    
    @Test
    void createCalendar_Failure() {
        CreateCalendarRequest request = new CreateCalendarRequest();
        request.setCalendar("test-calendar");
        DlxGenericResponse<NativeCreateCalendarResponse> dlxResponse = new DlxGenericResponse<>();
        dlxResponse.setErrors("Error message");

        when(dlxService.executeAndResponse(anyString(), anyString())).thenReturn(dlxResponse);
        
        ResponseEntity<GenericResponse> response = calendarService.createCalendar(token, request);
        
        assertNotNull(response);
        assertEquals(500, response.getStatusCodeValue());
    }

    @Test
    void updateCalendar_Success() {
        UpdateCalendarRequest request = new UpdateCalendarRequest();
        request.setCalendarUpdate("updated-calendar");
        NativeUpdateCalendarResponse nativeResponse = new NativeUpdateCalendarResponse();
        nativeResponse.setUpdateCalendar(new GenericResponse("updated"));
        DlxGenericResponse<NativeUpdateCalendarResponse> dlxResponse = new DlxGenericResponse<>();
        dlxResponse.setData(nativeResponse);
        
        when(dlxService.executeAndResponse(anyString(), anyString())).thenReturn(dlxResponse);
        
        ResponseEntity<GenericResponse> response = calendarService.updateCalendar(token, calendarId, request);
        
        assertNotNull(response);
        assertEquals(200, response.getStatusCodeValue());
        assertEquals("updated", response.getBody().getResult());
    }

    @Test
    void deleteCalendar_Success() {
        NativeDeleteCalendarResponse nativeResponse = new NativeDeleteCalendarResponse();
        nativeResponse.setDeleteCalendar(new GenericResponse("deleted"));
        DlxGenericResponse<NativeDeleteCalendarResponse> dlxResponse = new DlxGenericResponse<>();
        dlxResponse.setData(nativeResponse);
        
        when(dlxService.executeAndResponse(anyString(), anyString())).thenReturn(dlxResponse);
        
        ResponseEntity<GenericResponse> response = calendarService.deleteCalendar(token, calendarId);
        
        assertNotNull(response);
        assertEquals(200, response.getStatusCodeValue());
        assertEquals("deleted", response.getBody().getResult());
    }
}
Editor is loading...
Leave a Comment