@Test public void testStoreLargeData() { char[] oneMb = new char[1024 * 1024]; Arrays.fill(oneMb, 'a'); String data = new String(oneMb); Timestamp expiresAt = new Timestamp(currentTime.get() + 60000); ExpiringCode expiringCode = new ExpiringCode(null, expiresAt, data, null); ExpiringCode generatedCode = codeStoreEndpoints.generateCode(expiringCode); String code = generatedCode.getCode(); ExpiringCode actualCode = codeStoreEndpoints.retrieveCode(code); assertEquals(generatedCode, actualCode); }
@Test public void testRetrieveCodeWithCodeNotFound() { try { codeStoreEndpoints.retrieveCode("unknown"); fail("Non-existent code, should throw CodeStoreException."); } catch (CodeStoreException e) { assertEquals(e.getStatus(), HttpStatus.NOT_FOUND); } }
@Test public void testRetrieveCodeWithExpiredCode() { String data = "{}"; int expiresIn = 1000; Timestamp expiresAt = new Timestamp(currentTime.get() + expiresIn); ExpiringCode expiringCode = new ExpiringCode(null, expiresAt, data, null); ExpiringCode generatedCode = codeStoreEndpoints.generateCode(expiringCode); currentTime.addAndGet(expiresIn + 1); try { codeStoreEndpoints.retrieveCode(generatedCode.getCode()); fail("code is expired, should throw CodeStoreException."); } catch (CodeStoreException e) { assertEquals(e.getStatus(), HttpStatus.NOT_FOUND); } } }
@Test public void testRetrieveCode() { String data = "{}"; Timestamp expiresAt = new Timestamp(currentTime.get() + 60000); ExpiringCode expiringCode = new ExpiringCode(null, expiresAt, data, null); ExpiringCode generatedCode = codeStoreEndpoints.generateCode(expiringCode); ExpiringCode retrievedCode = codeStoreEndpoints.retrieveCode(generatedCode.getCode()); assertEquals(generatedCode, retrievedCode); try { codeStoreEndpoints.retrieveCode(generatedCode.getCode()); fail("One-use code already retrieved, should throw CodeStoreException."); } catch (CodeStoreException e) { assertEquals(e.getStatus(), HttpStatus.NOT_FOUND); } }
@Test public void testRetrieveCodeWithNullCode() { try { codeStoreEndpoints.retrieveCode(null); fail("code is null, should throw CodeStoreException."); } catch (CodeStoreException e) { assertEquals(e.getStatus(), HttpStatus.BAD_REQUEST); } }