SessionAdapterTest.java revision b334b83b7ac2d9a8c60d935cad0365506f13333b
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright 2013 ForgeRock, AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms of the Common Development and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Distribution License (the License). You may not use this file except in compliance with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specific language governing permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Software, include this CDDL Header Notice in each file and include
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header, with the fields enclosed by brackets [] replaced by your own identifying
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * information: "Portions copyright [year] [name of copyright owner]".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.dpro.session.service.InternalSession;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.CoreTokenConfig;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.api.fields.SessionTokenField;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.api.tokens.Token;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.api.tokens.TokenIdFactory;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.exceptions.CoreTokenException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.utils.JSONSerialisation;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.utils.LDAPDataConversion;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ldap.utils.blob.TokenBlobUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @author robert.wapshott@forgerock.com
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setup() {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott coreTokenConfig = mock(CoreTokenConfig.class);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster jsonSerialisation = mock(JSONSerialisation.class);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ldapDataConversion = mock(LDAPDataConversion.class);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adapter = new SessionAdapter(tokenIdFactory, coreTokenConfig, jsonSerialisation, ldapDataConversion, blobUtils);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void shouldSerialiseAndDeserialiseToken() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Sessions can only measure time to the closest second.
byte[] mockByteData = {};
@Test
public void shouldRestoreLatestAccessTimeFromAttribute() {
token.setBlob("{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true,\"maxCachingTime\":3}".getBytes());
adapter = new SessionAdapter(tokenIdFactory, coreTokenConfig, serialisation, ldapDataConversion, blobUtils);
@Test
public void shouldAssignAttributeFromSessionLatestAccessTime() {
@Test
String someJSONLikeText = "{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true,\"latestAccessTime\":1376308558,\"maxCachingTime\":3}";
@Test
public void shouldHandleMissingCommaInBlob() {
@Test
@Test
public void shouldLocateValidFieldInJSON() {
String json = "{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true,\"latestAccessTime\":1376308558,\"maxCachingTime\":3}";
@Test
public void shouldIndicateNoValidFieldsInJSON() {