-
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.
Update globalexceptionhandler add tests
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
src/test/java/es/in2/vcverifier/exception/handler/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,99 @@ | ||
package es.in2.vcverifier.exception.handler; | ||
|
||
import es.in2.vcverifier.exception.*; | ||
import es.in2.vcverifier.model.GlobalErrorMessage; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest | ||
class GlobalExceptionHandlerTest { | ||
|
||
private GlobalExceptionHandler globalExceptionHandler; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
globalExceptionHandler = new GlobalExceptionHandler(); | ||
} | ||
|
||
@Test | ||
void testHandleResourceNotFoundException() { | ||
ResourceNotFoundException exception = new ResourceNotFoundException("Resource not found"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleResourceNotFoundException(exception); | ||
|
||
assertEquals("", response.title()); | ||
assertEquals("", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
|
||
@Test | ||
void testHandleNoSuchElementException() { | ||
NoSuchElementException exception = new NoSuchElementException("Element not found"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleNoSuchElementException(exception); | ||
|
||
assertEquals("", response.title()); | ||
assertEquals("", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
|
||
@Test | ||
void testHandleQRCodeGenerationException() { | ||
QRCodeGenerationException exception = new QRCodeGenerationException("QR Code Generation Failed"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleQRCodeGenerationException(exception); | ||
|
||
assertEquals("QR Code Generation Failed", response.title()); | ||
assertEquals("", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
|
||
@Test | ||
void testHandleCredentialRevokedException() { | ||
CredentialRevokedException exception = new CredentialRevokedException("Credential revoked"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleException(exception); | ||
|
||
assertEquals("Verifiable presentation failed", response.title()); | ||
assertEquals("", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
|
||
@Test | ||
void testHandleMismatchOrganizationIdentifierException() { | ||
MismatchOrganizationIdentifierException exception = new MismatchOrganizationIdentifierException("Mismatch org identifier"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleException(exception); | ||
|
||
assertEquals("", response.title()); | ||
assertEquals("", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
|
||
@Test | ||
void testHandleGenericException() { | ||
Exception exception = new Exception("Generic error"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleException(exception); | ||
|
||
assertEquals("", response.title()); | ||
assertEquals("", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
|
||
@Test | ||
void testHandleInvalidVPtokenException() { | ||
InvalidVPtokenException exception = new InvalidVPtokenException("Invalid VP token"); | ||
|
||
GlobalErrorMessage response = globalExceptionHandler.handleException(exception); | ||
|
||
assertEquals("VP token is not valid", response.title()); | ||
assertEquals("Invalid VP token", response.message()); | ||
assertEquals("", response.path()); | ||
} | ||
} |