WebtopNamingSiteUtilsTest.java revision 72450cb9c2ca854c6d3479832c2738196c1d3282
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Copyright 2014 ForgeRock AS.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * The contents of this file are subject to the terms of the Common Development and
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Distribution License (the License). You may not use this file except in compliance with the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * specific language governing permission and limitations under the License.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * When distributing Covered Software, include this CDDL Header Notice in each file and include
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Header, with the fields enclosed by brackets [] replaced by your own identifying
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * information: "Portions copyright [year] [name of copyright owner]".
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport com.iplanet.services.naming.ServerEntryNotFoundException;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport com.iplanet.services.naming.WebtopNamingQuery;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport static org.fest.assertions.Assertions.assertThat;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport static org.mockito.Matchers.anyString;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public void setUp() {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott utils = new WebtopNamingSiteUtils(mock(Debug.class), mockQuery);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockSession.getID()).willReturn(mockSessionID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public void shouldResolveServerToBePartOfSite() throws Exception {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockSessionID.getSessionServerID()).willReturn(serverID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getSiteID(eq(serverID))).willReturn(siteID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public void shouldReturnServerIDIfServerNotInSite() {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockSessionID.getSessionServerID()).willReturn(serverID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getSiteID(eq(serverID))).willReturn(null);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott Set<String> result = utils.getSiteNodes(mockSession);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott @Test (expectedExceptions = IllegalStateException.class)
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public void shouldReturnThrowRuntimeIfErrorQueryingWebtopNaming() throws Exception {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockSessionID.getSessionServerID()).willReturn(serverID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getSiteID(eq(serverID))).willReturn(siteID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getSiteNodes(anyString())).willThrow(new Exception());
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott // When / Then
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public void shouldReturnURLsForServersInSite() throws ServerEntryNotFoundException {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockSessionID.getSessionServerID()).willReturn(serverID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getSiteID(eq(serverID))).willReturn(null);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getServerFromID(anyString())).willReturn("http://localhost");
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott Set<URL> result = utils.getSiteNodeURLs(mockSession);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott @Test (expectedExceptions = IllegalStateException.class)
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public void shouldThrowRuntimeExceptionForInvalidURLFormat() throws ServerEntryNotFoundException {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockSessionID.getSessionServerID()).willReturn(serverID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getSiteID(eq(serverID))).willReturn(null);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott given(mockQuery.getServerFromID(anyString())).willReturn("badgerbadger...");
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott // When / Then