From 54d2dab46c0d528862a8c55afb91bf3cde1da03f Mon Sep 17 00:00:00 2001 From: parvathy00 Date: Mon, 25 Mar 2024 16:43:49 +0530 Subject: [PATCH] Parvathy | BAH-3703 | Add. Test Cases For Odoo Session Expiry --- .../openerp/web/ResponseCheckerTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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()); + } }