Skip to content

Commit

Permalink
VIC-35: Make all data accessible per tenant
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
adnanalicic committed Feb 3, 2022
1 parent e354ac2 commit f251b56
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import de.caritas.cob.agencyservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.ApiClient;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.ConsultingTypeControllerApi;
import org.junit.jupiter.api.Test;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import org.junit.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.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@ExtendWith(MockitoExtension.class)
class ConsultingTypeServiceTest {
Expand All @@ -26,14 +30,36 @@ class ConsultingTypeServiceTest {
@Mock
private SecurityHeaderSupplier securityHeaderSupplier;

@Mock
private ServletRequestAttributes requestAttributes;

@Mock
private HttpServletRequest httpServletRequest;

@Mock
private Enumeration<String> headers;

@Test
void getExtendedConsultingTypeResponseDTO_Should_useServicesCorrectly() {
givenRequestContextIsSet();
when(this.consultingTypeControllerApi.getApiClient()).thenReturn(new ApiClient());
when(this.securityHeaderSupplier.getCsrfHttpHeaders()).thenReturn(new HttpHeaders());

this.consultingTypeService.getExtendedConsultingTypeResponseDTO(0);

verify(this.consultingTypeControllerApi, times(1)).getExtendedConsultingTypeById(0);
resetRequestAttributes();
}

private void resetRequestAttributes() {
RequestContextHolder.setRequestAttributes(null);
}

private void givenRequestContextIsSet() {
when(requestAttributes.getRequest()).thenReturn(httpServletRequest);
when(httpServletRequest.getHeaderNames()).thenReturn(headers);
RequestContextHolder.setRequestAttributes(requestAttributes);
}


}

0 comments on commit f251b56

Please sign in to comment.