diff --git a/openerp-client/src/test/java/org/bahmni/openerp/web/ResponseCheckerTest.java b/openerp-client/src/test/java/org/bahmni/openerp/web/ResponseCheckerTest.java index f3b25e6..57ace63 100644 --- a/openerp-client/src/test/java/org/bahmni/openerp/web/ResponseCheckerTest.java +++ b/openerp-client/src/test/java/org/bahmni/openerp/web/ResponseCheckerTest.java @@ -77,4 +77,28 @@ public void shouldThrowOdooRestExceptionWhenResponseIsEmpty() { }); assertEquals("Response is empty", exception.getMessage()); } + + @Test + public void shouldThrowOdooSessionExpiredExceptionWhenOdooSessionExpires() { + ResponseEntity mockResponseEntity = mock(ResponseEntity.class); + when(mockResponseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(mockResponseEntity.getBody()).thenReturn("{\"error\":{\"message\":\"Error message\",\"code\":100}}"); + + OdooSessionExpiredException exception = assertThrows(OdooSessionExpiredException.class, () -> { + responseChecker.checkResponse(mockResponseEntity); + }); + assertEquals("Odoo Session Expired", exception.getMessage()); + } + + @Test + public void shouldThrowOdooSessionExpiredExceptionWhenStatusIsForbidden() { + ResponseEntity mockResponseEntity = mock(ResponseEntity.class); + when(mockResponseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(mockResponseEntity.getBody()).thenReturn("{\"error\":{\"message\":\"Error message\",\"status\":403}}"); + + OdooSessionExpiredException exception = assertThrows(OdooSessionExpiredException.class, () -> { + responseChecker.checkResponse(mockResponseEntity); + }); + assertEquals("Odoo Session Expired", exception.getMessage()); + } }