TokenDocument { public Document asDocument() { Document document = new Document("_id", token.getValue()) .append("created", created) .append("clientId", clientId.getValue()) .append("userInfo", userInfo) .append("type", type.name()); if (sessionId != null) { document.append("sessionId", sessionId.getValue()); } if (expires != null) { document.append("expires", expires); } if (refreshTokenRef != null) { document.append("refreshTokenRef", refreshTokenRef); } return document; } TokenDocument(T token, Date created, ClientID clientId, LoginSessionToken sessionId, UserInfo userInfo);  TokenDocument(T token, Date created, ClientID clientId, LoginSessionToken sessionId, UserInfo userInfo, int refreshTokenLifeTime); Document asDocument(); static TokenDocument<T> from(Document document); T asToken(); boolean isValid(); @Override String toString(); UserInfo getUserInfo(); void setRefreshTokenRef(String refreshTokenRef); String getRefreshTokenRef(); T getToken(); TokenType getType(); Date getCreated(); Date getExpires(); ClientID getClientId(); LoginSessionToken getSessionId();  }
@Test public void testAsDocumentRefreshToken() { UserInfo userInfo = new UserInfo(new Subject("sso")); Date created = new Date(); TokenDocument<RefreshToken> tokenDocument = new TokenDocument<RefreshToken>(new RefreshToken("lOZugWbWUN2rKborv-QqnZWlpAx2w3c_lP_89e89QVE"), created, new ClientID("TESTCLIENTID"), new LoginSessionToken("XXX"), userInfo); Document mongoDocument = tokenDocument.asDocument(); assertEquals("lOZugWbWUN2rKborv-QqnZWlpAx2w3c_lP_89e89QVE", mongoDocument.get("_id")); assertEquals(created, mongoDocument.getDate("created")); assertEquals("TESTCLIENTID", mongoDocument.getString("clientId")); assertEquals("sso", ((Map<String, Object>)mongoDocument.get("userInfo")).get("sub")); assertEquals("REFRESH", mongoDocument.get("type")); assertEquals("XXX", mongoDocument.get("sessionId")); assertEquals(Long.MAX_VALUE, mongoDocument.getDate("expires").getTime()); }