OpenAMClientDAOTest.java revision 073875d677d0cc89aa2cc1187c975225a2ead9d3
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyrighted [year] [name of copyright owner]".
*
* Copyright 2014 ForgeRock AS. All rights reserved.
*/
@PrepareForTest({AMIdentityRepository.class, AMIdentity.class, SSOToken.class, AMIdentityRepositoryFactory.class})
public class OpenAMClientDAOTest extends PowerMockTestCase {
private static final int SINGLE_ELEMENT = 1;
private OpenAMClientDAO openAMClientDAO;
public void oneTimeSetup() {
}
@Test
public void testShouldCreateAClientInTheRepository() {
//given
try {
when(amIdentityRepository.createIdentity(any(IdType.class), anyString(), attributeCaptor.capture()))
} catch (Exception e) {
throw new TestException("FAIL", e);
}
//when
//then
assert(attributes != null);
assert(!attributes.isEmpty());
assert(attributes.get(OAuth2Constants.OAuth2Client.POST_LOGOUT_URI).contains(POST_LOGOUT_REDIRECT_URI) &&
assert(attributes.get(OAuth2Constants.OAuth2Client.REDIRECT_URI).contains(PREFIX + REDIRECTION_URIS_VALUE) &&
attributes.get(OAuth2Constants.OAuth2Client.CLIENT_TYPE).iterator().next().equalsIgnoreCase(CLIENT_TYPE));
assert(attributes.get(OAuth2Constants.OAuth2Client.DEFAULT_SCOPES).contains(PREFIX + DEFAULT_SCOPES_VALUE) &&
assert(attributes.get(OAuth2Constants.OAuth2Client.DESCRIPTION).contains(PREFIX + DISPLAY_DESCRIPTION_VALUE) &&
assert(attributes.get(OAuth2Constants.OAuth2Client.IDTOKEN_SIGNED_RESPONSE_ALG).contains(ID_TOKEN_SIGNED_RESPONSE_ALGORITHM) &&
assert(attributes.get(OAuth2Constants.OAuth2Client.CLIENT_SESSION_URI).contains(CLIENT_SESSION_URI) &&
}
}
return set;
}
}
return formattedSet;
}
}
return unformattedSet;
}
attributeMap.put(OAuth2Constants.OAuth2Client.POST_LOGOUT_URI, createSet(POST_LOGOUT_REDIRECT_URI));
attributeMap.put(OAuth2Constants.OAuth2Client.REDIRECT_URI, formatSet(new HashSet<String>(REDIRECTION_URIS)));
attributeMap.put(OAuth2Constants.OAuth2Client.DEFAULT_SCOPES, formatSet(new HashSet<String>(DEFAULT_SCOPES)));
attributeMap.put(OAuth2Constants.OAuth2Client.DESCRIPTION, formatSet(new HashSet<String>(DISPLAY_DESCRIPTION)));
attributeMap.put(OAuth2Constants.OAuth2Client.IDTOKEN_SIGNED_RESPONSE_ALG, createSet(ID_TOKEN_SIGNED_RESPONSE_ALGORITHM));
return attributeMap;
}
@Test
public void testShouldReadAClientFromTheRepository() {
//given
try {
when(amIdentityRepository.searchIdentities(any(IdType.class), anyString(), any(IdSearchControl.class)))
} catch (Exception e) {
throw new TestException("FAIL", e);
}
//when
//when
assert(attributeMap.get(OAuth2Constants.OAuth2Client.ACCESS_TOKEN).contains(client.getAccessToken()));
assert(attributeMap.get(OAuth2Constants.OAuth2Client.POST_LOGOUT_URI).contains(client.getPostLogoutRedirectionURI()));
assert(unformattedSet(attributeMap.get(OAuth2Constants.OAuth2Client.SCOPES)).containsAll(client.getAllowedGrantScopes()));
assert(unformattedSet(attributeMap.get(OAuth2Constants.OAuth2Client.REDIRECT_URI)).containsAll(client.getRedirectionURIsAsString()));
assert(attributeMap.get(OAuth2Constants.OAuth2Client.CLIENT_TYPE).iterator().next().equalsIgnoreCase(client.getClientType().toString()));
assert(unformattedSet(attributeMap.get(OAuth2Constants.OAuth2Client.NAME)).containsAll(client.getDisplayName()));
assert(unformattedSet(attributeMap.get(OAuth2Constants.OAuth2Client.DEFAULT_SCOPES)).containsAll(client.getDefaultGrantScopes()));
assert( unformattedSet(attributeMap.get(OAuth2Constants.OAuth2Client.DESCRIPTION)).containsAll(client.getDisplayDescription()));
assert( attributeMap.get(OAuth2Constants.OAuth2Client.IDTOKEN_SIGNED_RESPONSE_ALG).contains(client.getIdTokenSignedResponseAlgorithm()));
assert( attributeMap.get(OAuth2Constants.OAuth2Client.CLIENT_SESSION_URI).contains(client.getClientSessionURI()));
}
}