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 @@ -76,7 +76,7 @@ public CloseableHttpResponse execute(final HttpUriRequest request) throws Clouds
return execute(request, 0);
}

private CloseableHttpResponse execute(final HttpUriRequest request, final int previousStatusCode) throws CloudstackRESTException {
CloseableHttpResponse execute(final HttpUriRequest request, final int previousStatusCode) throws CloudstackRESTException {
if (counter.hasReachedExecutionLimit()) {
throw new CloudstackRESTException("Reached max executions limit of " + executionLimit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.verifyPrivate;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -47,18 +47,14 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;

import com.cloud.utils.rest.CloudstackRESTException;
import com.cloud.utils.rest.HttpMethods;
import com.cloud.utils.rest.HttpRequestMatcher;
import com.cloud.utils.rest.HttpUriRequestBuilder;

@RunWith(PowerMockRunner.class)
@PrepareForTest(NiciraRestClient.class)
@PowerMockIgnore({"javax.xml.*", "org.w3c.dom.*", "org.apache.xerces.*", "org.apache.log4j.*"})
@RunWith(MockitoJUnitRunner.class)
public class NiciraRestClientTest {

private static final int HTTPS_PORT = 443;
Expand Down Expand Up @@ -120,7 +116,7 @@ public void testExecuteSuccessAtFirstAttempt() throws Exception {

assertThat(response, notNullValue());
assertThat(response, sameInstance(mockResponse));
verifyPrivate(client).invoke("execute", request, 0);
verify(client).execute(request, 0);
}

@Test
Expand All @@ -139,9 +135,9 @@ public void testExecuteUnauthorizedThenSuccess() throws Exception {

assertThat(response, notNullValue());
assertThat(response, sameInstance(mockResponse));
verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(request), eq(0));
verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(loginRequest), eq(401));
verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(request), eq(200));
verify(client).execute((HttpUriRequest)HttpRequestMatcher.eq(request), eq(0));
verify(client).execute((HttpUriRequest)HttpRequestMatcher.eq(request), eq(200));
verify(client).execute((HttpUriRequest)HttpRequestMatcher.eq(loginRequest), eq(401));
}

@Test
Expand All @@ -168,8 +164,8 @@ public void testExecuteTwoConsecutiveUnauthorizedExecutions() throws Exception {
fail("Expected CloudstackRESTException exception");
} catch (final CloudstackRESTException e) {
assertThat(e.getMessage(), not(isEmptyOrNullString()));
verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(request), eq(0));
verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(loginRequest), eq(401));
verify(client).execute((HttpUriRequest)HttpRequestMatcher.eq(request), eq(0));
verify(client).execute((HttpUriRequest)HttpRequestMatcher.eq(loginRequest), eq(401));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline