generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PO-234: Feature toggle add note (#255)
- Loading branch information
1 parent
aeaeea0
commit 3a908b6
Showing
8 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/uk/gov/hmcts/opal/controllers/advice/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package uk.gov.hmcts.opal.controllers.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import uk.gov.hmcts.opal.launchdarkly.FeatureDisabledException; | ||
|
||
@ControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(FeatureDisabledException.class) | ||
public ResponseEntity<String> handleFeatureDisabledException(FeatureDisabledException ex) { | ||
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(ex.getMessage()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/uk/gov/hmcts/opal/launchdarkly/FeatureDisabledException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package uk.gov.hmcts.opal.launchdarkly; | ||
|
||
|
||
public class FeatureDisabledException extends RuntimeException { | ||
|
||
public FeatureDisabledException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/test/java/uk/gov/hmcts/opal/controllers/advice/GlobalExceptionHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package uk.gov.hmcts.opal.controllers.advice; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import uk.gov.hmcts.opal.launchdarkly.FeatureDisabledException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest | ||
@ContextConfiguration(classes = GlobalExceptionHandler.class) | ||
public class GlobalExceptionHandlerTest { | ||
|
||
@Mock | ||
private FeatureDisabledException exception; | ||
|
||
@InjectMocks | ||
private GlobalExceptionHandler globalExceptionHandler; | ||
|
||
@Test | ||
public void handleFeatureDisabledException_ReturnsMethodNotAllowed() { | ||
// Arrange | ||
String errorMessage = "Feature is disabled"; | ||
when(exception.getMessage()).thenReturn(errorMessage); | ||
|
||
// Act | ||
ResponseEntity<String> response = globalExceptionHandler.handleFeatureDisabledException(exception); | ||
|
||
// Assert | ||
assertEquals(HttpStatus.METHOD_NOT_ALLOWED, response.getStatusCode()); | ||
assertEquals(errorMessage, response.getBody()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/uk/gov/hmcts/opal/launchdarkly/FeatureDisabledExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package uk.gov.hmcts.opal.launchdarkly; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class FeatureDisabledExceptionTest { | ||
|
||
@Test | ||
public void testConstructor() { | ||
// Arrange | ||
String errorMessage = "Feature is disabled"; | ||
|
||
// Act | ||
FeatureDisabledException exception = new FeatureDisabledException(errorMessage); | ||
|
||
// Assert | ||
assertEquals(errorMessage, exception.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters