Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,11 @@ public void setConnectionTimeout(int connectionTimeout) {
public void setAcceptAllKindsOfCertificates(boolean acceptAllKindOfCertificates) {
this.acceptAllKindsOfCertificates = acceptAllKindOfCertificates;
}

@Override
public String toString() {
return String.format(
"Apache CloudSTackClient for site[%s], parameters: [connectionTimeout=%s, acceptAllKindsOfCertificates=%s, validateServerHttpsCertificate=%s, requestValidity=%d, shouldRequestsExpire=%s]",
this.url, this.connectionTimeout, this.acceptAllKindsOfCertificates, this.validateServerHttpsCertificate, this.requestValidity, this.shouldRequestsExpire);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
* Copyright (C) 2016 Autonomiccs, Inc.
*
* Licensed to the Autonomiccs, Inc. under one
* or more contributor license agreements. See the NOTICE file
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Autonomiccs, Inc. licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
Expand Down Expand Up @@ -139,9 +139,9 @@ public void executeRequestTestExceptionWhenExecutingRequest() throws IOException
}

private void testRequestConfig(final RequestConfig config, final int timeout) {
Assert.assertEquals(config.getConnectTimeout(), timeout * (int) DateUtils.MILLIS_PER_SECOND);
Assert.assertEquals(config.getConnectionRequestTimeout(), timeout * (int) DateUtils.MILLIS_PER_SECOND);
Assert.assertEquals(config.getSocketTimeout(), timeout * (int) DateUtils.MILLIS_PER_SECOND);
Assert.assertEquals(config.getConnectTimeout(), timeout * (int)DateUtils.MILLIS_PER_SECOND);
Assert.assertEquals(config.getConnectionRequestTimeout(), timeout * (int)DateUtils.MILLIS_PER_SECOND);
Assert.assertEquals(config.getSocketTimeout(), timeout * (int)DateUtils.MILLIS_PER_SECOND);
}

@Test
Expand Down Expand Up @@ -376,7 +376,8 @@ public void createHttpContextWithAuthenticatedSessionUsingUserCredentialsIfNeede
public void createHttpContextWithAuthenticatedSessionUsingUserCredentialsIfNeededTestAuthenticationWithUsernameAndPassword() {
CloseableHttpClient closeableHttpClientMock = Mockito.mock(CloseableHttpClient.class);
HttpContext httpContextMock = Mockito.mock(HttpContext.class);
Mockito.doReturn(httpContextMock).when(apacheCloudStackClient).createHttpContextWithAuthenticatedSessionUsingUserCredentials(Mockito.any(closeableHttpClientMock.getClass()));
Mockito.doReturn(httpContextMock).when(apacheCloudStackClient)
.createHttpContextWithAuthenticatedSessionUsingUserCredentials(Mockito.any(closeableHttpClientMock.getClass()));
HttpContext basicHttpContext = apacheCloudStackClient.createHttpContextWithAuthenticatedSessionUsingUserCredentialsIfNeeded(closeableHttpClientMock, false);

Mockito.verify(apacheCloudStackClient, Mockito.times(1)).createHttpContextWithAuthenticatedSessionUsingUserCredentials(Mockito.eq(closeableHttpClientMock));
Expand Down Expand Up @@ -562,7 +563,8 @@ public void executeUserLogoutTest() {
String urlRequest = "urlRequest";

Mockito.doReturn(urlRequest).when(apacheCloudStackClient).createApacheCloudStackApiUrlRequest(Mockito.any(ApacheCloudStackRequest.class), Mockito.eq(false));
Mockito.doReturn("response").when(apacheCloudStackClient).executeRequestGetResponseAsString(Mockito.eq(urlRequest), Mockito.any(CloseableHttpClient.class), Mockito.any(HttpContext.class));
Mockito.doReturn("response").when(apacheCloudStackClient).executeRequestGetResponseAsString(Mockito.eq(urlRequest), Mockito.any(CloseableHttpClient.class),
Mockito.any(HttpContext.class));

apacheCloudStackClient.executeUserLogout(Mockito.mock(CloseableHttpClient.class), Mockito.mock(HttpContext.class));

Expand Down Expand Up @@ -652,4 +654,12 @@ public void createInsecureHostNameVerifierTest() {
Assert.assertTrue(hostNameVerifier.verify("Any other thing", null));

}

@Test
public void toStringTest() {
String toStringValue = apacheCloudStackClient.toString();

String expectedToStringValue = "Apache CloudSTackClient for site[https://cloud.domain.com/client/api], parameters: [connectionTimeout=60, acceptAllKindsOfCertificates=false, validateServerHttpsCertificate=true, requestValidity=30, shouldRequestsExpire=true]";
Assert.assertEquals(expectedToStringValue, toStringValue);
}
}