Skip to content

Commit

Permalink
remove code-prefix from exception wrapper constants
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSebastian committed Sep 3, 2024
1 parent 55d9923 commit 4cebd1a
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public class ExceptionConstants {
public static ExceptionDataWrapper GETREFERENDUMVORLAGEN_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("308",
"getReferendumvorlagen: Suchkriterien unvollständig.");

public static ExceptionDataWrapper CODE_GETWAHLEN_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("314",
public static ExceptionDataWrapper GETWAHLEN_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("314",
"getWahlen: Der Wahltag zu den gesuchten Wahlen existiert nicht.");
public static ExceptionDataWrapper CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("317",
public static ExceptionDataWrapper POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("317",
"postWahlen: Suchkriterien unvollständig. Die wahltagID ist leer oder null.");
public static ExceptionDataWrapper CODE_POSTWAHLEN_UNSAVEABLE = new ExceptionDataWrapper("318",
public static ExceptionDataWrapper POSTWAHLEN_UNSAVEABLE = new ExceptionDataWrapper("318",
"postWahlen: Die Wahlen konnten nicht gespeichert werden.");

public static ExceptionDataWrapper CODE_GETWAHLBEZIRKE_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("312",
"getWahlbezirke: Suchkriterien unvollständig. Die wahltagID ist leer oder null.");
public static ExceptionDataWrapper CODE_GETWAHLBEZIRKE_NO_WAHLTAG = new ExceptionDataWrapper("313",
public static ExceptionDataWrapper GETWAHLBEZIRKE_NO_WAHLTAG = new ExceptionDataWrapper("313",
"Es wurde kein Wahltag zu dieser WahltagID gefunden. Bitte legen Sie die Basisdaten an.");

public static final ExceptionDataWrapper GETKOPFDATEN_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("303",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public List<WahlbezirkModel> getWahlbezirke(final String wahltagID) {
}
return wahlbezirkModelMapper.fromListOfWahlbezirkEntityToListOfWahlbezirkModel(wahlbezirkRepository.findByWahltag(wahltagObjekt.getWahltag()));
} else {
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_NO_WAHLTAG);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void validWahltagIDParamOrThrow(final String wahltagID) {

public void validateWahltagForSearchingWahltagID(final Optional<Wahltag> wahltag) {
if (wahltag.isEmpty() || null == wahltag.get().getWahltag()) {
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_NO_WAHLTAG);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void postWahlen(final WahlenWriteModel wahlenWriteModel) {
wahlRepository.saveAll(wahlModelMapper.fromListOfWahlModeltoListOfWahlEntities(wahlenWriteModel.wahlen()));
} catch (Exception e) {
log.error("#postWahlen: Die Wahlen konnten aufgrund eines Fehlers nicht gespeichert werden:", e);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_UNSAVEABLE);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_UNSAVEABLE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class WahlenValidator {

public void validWahlenCriteriaOrThrow(final String wahltagID) {
if (StringUtils.isBlank(wahltagID)) {
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLEN_PARAMETER_UNVOLLSTAENDIG);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLEN_PARAMETER_UNVOLLSTAENDIG);
}
}

public void validWahlenWriteModelOrThrow(final WahlenWriteModel wahlenWriteModel) {
if (wahlenWriteModel == null || StringUtils.isBlank(wahlenWriteModel.wahltagID()) || CollectionUtils.isEmpty(wahlenWriteModel.wahlen())) {
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG);
throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public WahltagModel getWahltagByID(final String wahltagID) {

private Wahltag getWahltagByIDOrThrow(final String wahltagID) {
return wahltagRepository.findById(wahltagID)
.orElseThrow(() -> exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_NO_WAHLTAG));
.orElseThrow(() -> exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_TEST_PROFILE;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.client.WireMock;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.MicroServiceApplication;

import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.WahlenClientMapper;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Wahltag;
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahltagRepository;
Expand Down Expand Up @@ -234,8 +234,8 @@ void fachlicheWlsExceptionWhenRequestIsInvalid() throws Exception {
val response = api.perform(request).andExpect(status().isBadRequest()).andReturn();
val responseBodyAsWlsExceptionDTO = objectMapper.readValue(response.getResponse().getContentAsByteArray(), WlsExceptionDTO.class);

val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG.code(),
serviceID, ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG.message());
val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG.code(),
serviceID, ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG.message());

Assertions.assertThat(responseBodyAsWlsExceptionDTO).isEqualTo(expectedWlsExceptionDTO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void throwsFachlicheWlsExceptionIfNoWahltagPresentInRepository() {
val wahltagID = "_identifikatorWahltag1";
Mockito.when(wahltagRepository.findById(wahltagID)).thenReturn(Optional.empty());
val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage("");
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_NO_WAHLTAG))
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG))
.thenReturn(mockedWlsException);
Assertions.assertThatThrownBy(() -> unitUnderTest.getWahlbezirke(wahltagID)).isInstanceOf(FachlicheWlsException.class);
Mockito.verify(wahlbezirkeValidator).validWahltagIDParamOrThrow(wahltagID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void exceptionWhenWahlIDisEmptyOrHasNoWahltagProperty() {
val noWahltagRequestParam = MockDataFactory.createWahltagList("").stream().findFirst();
noWahltagRequestParam.ifPresent(wahltag -> wahltag.setWahltag(null));

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_NO_WAHLTAG))
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG))
.thenReturn(mockedWlsException);
Assertions.assertThatThrownBy(() -> unitUnderTest.validateWahltagForSearchingWahltagID(emptyRequestParam)).isSameAs(mockedWlsException);
Assertions.assertThatThrownBy(() -> unitUnderTest.validateWahltagForSearchingWahltagID(noWahltagRequestParam)).isSameAs(mockedWlsException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void wlsExceptionWhenSavingFailed() {

Mockito.when(wahlModelMapper.fromListOfWahlModeltoListOfWahlEntities(mockedListOfModels)).thenReturn(mockedListOfEntities);
Mockito.doThrow(mockedRepoSaveException).when(wahlRepository).saveAll(mockedListOfEntities);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_UNSAVEABLE))
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_UNSAVEABLE))
.thenReturn(mockedWlsException);

Assertions.assertThatThrownBy(() -> unitUnderTest.postWahlen(wahlenToWrite)).isSameAs(mockedWlsException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void noExceptionWhenCriteriaIsValid() {
void exceptionWhenCriteriaIsNull() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

Assertions.assertThatThrownBy(() -> unitUnderTest.validWahlenCriteriaOrThrow(null)).isSameAs(mockedException);
}
Expand All @@ -45,7 +45,7 @@ void exceptionWhenCriteriaIsNull() {
void exceptionWhenCriteriaIsEmpty() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

Assertions.assertThatThrownBy(() -> unitUnderTest.validWahlenCriteriaOrThrow("")).isSameAs(mockedException);
}
Expand All @@ -54,7 +54,7 @@ void exceptionWhenCriteriaIsEmpty() {
void exceptionWhenCriteriaIsBlank() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

Assertions.assertThatThrownBy(() -> unitUnderTest.validWahlenCriteriaOrThrow(" ")).isSameAs(mockedException);
}
Expand All @@ -74,7 +74,7 @@ void noExceptionWhenModelIsValid() {
void exceptionWhenWahltagIDIsNull() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

val invalidModel = new WahlenWriteModel(null, List.of(createEmptyWahlModel()));

Expand All @@ -85,7 +85,7 @@ void exceptionWhenWahltagIDIsNull() {
void exceptionWhenWahltagIDIsEmpty() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

val invalidModel = new WahlenWriteModel("", List.of(createEmptyWahlModel()));

Expand All @@ -96,7 +96,7 @@ void exceptionWhenWahltagIDIsEmpty() {
void exceptionWhenWahltagIDIsBlank() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

val invalidModel = new WahlenWriteModel(" ", List.of(createEmptyWahlModel()));

Expand All @@ -107,7 +107,7 @@ void exceptionWhenWahltagIDIsBlank() {
void exceptionWhenWahlenIsNull() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

val invalidModel = new WahlenWriteModel("wahltagID", null);

Expand All @@ -118,7 +118,7 @@ void exceptionWhenWahlenIsNull() {
void exceptionWhenWahlenIsEmpty() {
val mockedException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.POSTWAHLEN_PARAMETER_UNVOLLSTAENDIG)).thenReturn(mockedException);

val invalidModel = new WahlenWriteModel("wahltagID", Collections.emptyList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void exceptionWhenNotFound() {
val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage("");

Mockito.when(wahltagRepository.findById(wahltagID)).thenReturn(Optional.empty());
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.CODE_GETWAHLBEZIRKE_NO_WAHLTAG)).thenReturn(mockedWlsException);
Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.GETWAHLBEZIRKE_NO_WAHLTAG)).thenReturn(mockedWlsException);

Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahltagByID(wahltagID)).isSameAs(mockedWlsException);
}
Expand Down

0 comments on commit 4cebd1a

Please sign in to comment.