Skip to content

Commit

Permalink
Code refactors to simplify code and additional tests to improve coverage
Browse files Browse the repository at this point in the history
Author: Kabilesh <kabilesh@dal.ca>
  • Loading branch information
Kabilesh020799 authored Nov 23, 2023
1 parent d809536 commit 387b9ae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AzureClient extends BaseRemoteEngineApiClient {

private static final Logger LOG = LoggerFactory.getLogger(AzureClient.class);
private static final String USER_AGENT = getUserAgent();
private static final int HTTP_NOT_FOUND = 404;

private final String tenantId;
private final String clientId;
Expand Down Expand Up @@ -105,8 +106,9 @@ protected String buildAuthorizationHeaderValue(Request request) throws IOExcepti
if (request.tag(RequestOrigin.class) == RequestOrigin.LOGIN) {
return null;
}
return "Bearer " + (request.tag(RequestOrigin.class) == RequestOrigin.MANAGEMENT
? getFreshManagementToken() : getFreshLoadTestToken());
String bearerToken = (request.tag(RequestOrigin.class) == RequestOrigin.MANAGEMENT
? getFreshManagementToken() : getFreshLoadTestToken());
return "Bearer " + bearerToken;
}

private enum RequestOrigin {
Expand Down Expand Up @@ -265,7 +267,7 @@ public ResourceGroup findResourceGroup(String name, Subscription subscription)
private <T> Optional<T> execOptionalApiCall(Call<T> call) throws IOException {
retrofit2.Response<T> response = call.execute();
if (!response.isSuccessful()) {
if (response.code() == 404) {
if (response.code() == HTTP_NOT_FOUND) {
return Optional.empty();
}
try (ResponseBody errorBody = response.errorBody()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.abstracta.jmeter.javadsl.dashboard;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static us.abstracta.jmeter.javadsl.JmeterDsl.httpSampler;
import static us.abstracta.jmeter.javadsl.JmeterDsl.testPlan;
import static us.abstracta.jmeter.javadsl.JmeterDsl.threadGroup;
Expand Down Expand Up @@ -35,4 +36,11 @@ public void shouldDisplayGraphsAndSummaryWhenRunTestPlanWithDashboard(TestInfo t
);
}

@Test
public void shouldThrowUnsupportedOperationWhenShowInGuiOnDashboardVisualizer() {
DashboardVisualizer dashboardVisualizer = new DashboardVisualizer();

assertThrows(UnsupportedOperationException.class, dashboardVisualizer::showInGui);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static us.abstracta.jmeter.javadsl.JmeterDsl.testPlan;
import static us.abstracta.jmeter.javadsl.JmeterDsl.threadGroup;
import static us.abstracta.jmeter.javadsl.JmeterDsl.vars;
Expand Down Expand Up @@ -137,6 +138,19 @@ public void shouldSendGraphqlQueryToServerWhenGraphqlSamplerWithHttpGet()
).run();
verify(getRequestedFor(anyUrl()).withQueryParam("query", equalTo(QUERY)));
}
@Test
public void shouldThrowIllegalArgumentWhenGraphqlSamplerWithInvalidVariable() {
DslGraphqlSampler sampler = graphqlSampler("http://localhost", "{ user(id: 1){ name } }");
assertThrows(IllegalArgumentException.class, () -> sampler.variable("invalidVar", new Object()));
}

@Test
public void shouldHandleInvalidJsonInput() {
DslGraphqlSampler sampler = graphqlSampler("http://localhost", "{ user(id: 1){ name } }");
sampler.variablesJson("invalidJson");
}



@Nested
public class CodeBuilderTest extends MethodCallBuilderTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ public DslDefaultThreadGroup holdIterating(String iterations) {
}

private void checkIterationsPreConditions() {
if (!(stages.size() == 1 && !ZERO.equals(stages.get(0).threadCount())
|| stages.size() == 2 && ZERO.equals(stages.get(0).threadCount())
&& !ZERO.equals(stages.get(1).threadCount()))) {
throw new IllegalStateException(
"Holding for iterations is only supported after initial hold and ramp, or ramp.");
boolean isJustRamp = stages.size() == 1 && !ZERO.equals(stages.get(0).threadCount());
boolean isJustDelayAndRamp = stages.size() == 2 && ZERO.equals(stages.get(0).threadCount()) && !ZERO.equals(stages.get(1).threadCount());

if (!(isJustRamp || isJustDelayAndRamp)) {
throw new IllegalStateException("Holding for iterations is only supported after initial hold and ramp, or ramp.");
}
if (ZERO.equals(getLastStage().threadCount())) {
throw new IllegalStateException("Can't hold for iterations with no threads.");
Expand Down

0 comments on commit 387b9ae

Please sign in to comment.