Commit 23764554 authored by dietricf's avatar dietricf
Browse files

SONARWORK

parent f1d39e81
......@@ -15,6 +15,8 @@
package org.eclipse.openk.gridfailureinformation.controller;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.enums.OperationType;
import org.eclipse.openk.gridfailureinformation.exceptions.*;
import org.eclipse.openk.gridfailureinformation.service.VersionService;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.VersionDto;
......@@ -23,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
......@@ -54,4 +57,45 @@ public class VersionControllerTest {
.andExpect(jsonPath("dbVersion", is("550")));
}
@Test
public void shouldRaiseBadRequest1() throws Exception {
checkException(new BadRequestException(), HttpStatus.BAD_REQUEST.value());
};
@Test
public void shouldRaiseBadRequest2() throws Exception {
checkException(new BadRequestException("test"), HttpStatus.BAD_REQUEST.value());
};
@Test
public void shouldRaiseConflict() throws Exception {
checkException(new ConflictException("test"), HttpStatus.CONFLICT.value());
};
@Test
public void shouldRaiseInternalServer() throws Exception {
checkException(new InternalServerErrorException("test"), HttpStatus.INTERNAL_SERVER_ERROR.value());
};
@Test
public void shouldRaiseNotFound() throws Exception {
checkException(new NotFoundException("test"), HttpStatus.NOT_FOUND.value());
};
@Test
public void shouldRaiseNotAcceptable() throws Exception {
checkException(new OperationDeniedException(OperationType.CREATE, "test"), HttpStatus.NOT_ACCEPTABLE.value());
};
@Test
public void shouldRaiseUnautorized() throws Exception {
checkException(new UnauthorizedException("test"), HttpStatus.UNAUTHORIZED.value());
};
@Test
private void checkException( Exception ex, int codeToCheck ) throws Exception {
when(versionService.getVersion()).thenThrow(ex);
mockMvc.perform(get("/version")).andExpect(status().is(codeToCheck));
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment