Skip to content

Commit fa73eb9

Browse files
committed
REST: adapted to changes in anythingworks.
1 parent 52e25b5 commit fa73eb9

File tree

8 files changed

+41
-54
lines changed

8 files changed

+41
-54
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/main/java/org/nameapi/client/services/development/exceptionthrower/ExceptionThrowerCommand.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,6 @@
1212
*/
1313
public class ExceptionThrowerCommand extends NameApiBaseCommand<RestPort, ExceptionThrowerParams, String> {
1414

15-
// @Override
16-
// public String call(@NotNull Optional<ExceptionType> arg, @NotNull ExecutionContext ec) throws Exception {
17-
// SoapExceptionThrower port = getPort(ec);
18-
// SoapContext context = getContext(ec);
19-
// ExceptionType.assertSize(5);
20-
// switch (arg.get()) {
21-
// case InvalidInput:
22-
// return port.throwInvalidInput(context);
23-
// case Internal:
24-
// return port.throwInternal(context);
25-
// case AccessDeniedNoSuchAccount:
26-
// return port.throwAccessDeniedNoSuchAccount(context);
27-
// case AccessDeniedRequestLimitExceeded:
28-
// return port.throwAccessDeniedRequestLimitExceeded(context);
29-
// case AccessDeniedTooManyConcurrentRequests:
30-
// return port.throwAccessDeniedTooManyConcurrentRequests(context);
31-
// default:
32-
// throw new AssertionError("Dead code reached!");
33-
// }
34-
// }
35-
36-
37-
38-
39-
4015
private static final String SERVICE_PATH = "/development/exceptionthrower";
4116

4217
public ExceptionThrowerCommand() {
@@ -45,7 +20,7 @@ public ExceptionThrowerCommand() {
4520

4621
@Override
4722
public String call(@NotNull Optional<ExceptionThrowerParams> arg, @NotNull ExecutionContext ec) throws Exception {
48-
return getPort(ec).call(getApiKey(ec));
23+
return getPort(ec).call(getApiKey(ec), arg.get().getExceptionType(), arg.get().getExceptionChance());
4924
}
5025

5126
@NotNull @Override

src/main/java/org/nameapi/client/services/development/exceptionthrower/ExceptionThrowerParams.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
*/
66
public class ExceptionThrowerParams {
77

8-
public enum ExceptionType {
9-
NotAuthorized,
10-
Forbidden,
11-
BadRequest,
12-
InternalServerError
13-
}
14-
158
public static class Builder {
169
private ExceptionType exceptionType;
1710
private int exceptionChance = 100;

src/main/java/org/nameapi/client/services/development/exceptionthrower/ExceptionType.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*/
66
public enum ExceptionType {
77
InvalidInput,
8-
Internal,
98

109
AccessDeniedNoSuchAccount,
11-
AccessDeniedRequestLimitExceeded,
12-
AccessDeniedTooManyConcurrentRequests;
10+
// AccessDeniedRequestLimitExceeded,
11+
// AccessDeniedTooManyConcurrentRequests,
12+
13+
InternalServerError,
14+
;
1315

1416
/**
1517
* Developer: Call this before doing a switch on an enum value.

src/main/java/org/nameapi/client/services/development/exceptionthrower/RestPort.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public RestPort(RestHttpClient restApiClient, String servicePath) {
1818
super(restApiClient, servicePath);
1919
}
2020

21-
public String call(String apiKey) {
21+
public String call(String apiKey, ExceptionType exceptionType, int exceptionChance) {
2222
QueryParams queryParams = QueryParams.create();
2323
queryParams.add("apiKey", apiKey);
24+
queryParams.add("exceptionType", exceptionType.name());
25+
queryParams.add("exceptionChance", ""+exceptionChance);
2426

2527
RestHttpClientResponse<String> response = restApiClient.invokeGet(
2628
servicePath,
Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
package org.nameapi.client.services.development.exceptionthrower;
22

3+
import com.optimaize.anythingworks.common.fault.exceptions.AccessDeniedServiceException;
4+
import com.optimaize.anythingworks.common.fault.exceptions.BadRequestServiceException;
5+
import com.optimaize.anythingworks.common.fault.exceptions.InternalServerErrorServiceException;
6+
import com.optimaize.anythingworks.common.fault.faultinfo.Blame;
7+
import com.optimaize.anythingworks.common.fault.faultinfo.RetryType;
38
import com.optimaize.command4j.CommandExecutor;
49
import com.optimaize.command4j.Mode;
510
import org.nameapi.client.services.FunctionalTestsNameApiModeFactory;
611
import org.nameapi.client.lib.NameApiRemoteExecutors;
12+
import org.testng.annotations.Test;
13+
14+
import static org.testng.Assert.assertEquals;
15+
import static org.testng.Assert.fail;
716

817
/**
918
*/
1019
public class ExceptionThrowerCommandTest {
1120

1221
private final CommandExecutor executor = NameApiRemoteExecutors.get();
1322

14-
// @Test(expectedExceptions = InvalidInputServiceException.class)
15-
// public void testCall1() throws Exception {
16-
// execute(ExceptionType.InvalidInput);
17-
// }
18-
//
19-
// @Test(expectedExceptions = InternalServiceException.class)
20-
// public void testCall2() throws Exception {
21-
// execute(ExceptionType.Internal);
22-
// }
23-
//
24-
//
25-
// @Test(expectedExceptions = AccessDeniedServiceException.class)
26-
// public void testCall3() throws Exception {
27-
// execute(ExceptionType.AccessDeniedNoSuchAccount);
28-
// }
29-
//
23+
@Test
24+
public void testCall1() throws Exception {
25+
try {
26+
execute(ExceptionType.InvalidInput);
27+
fail("Expected exception!");
28+
} catch (BadRequestServiceException e) {
29+
assertEquals(e.getFaultInfo().getBlame(), Blame.CLIENT);
30+
assertEquals(e.getFaultInfo().getRetrySameLocation().get().getRetryType(), RetryType.NO);
31+
}
32+
}
33+
34+
@Test(expectedExceptions = InternalServerErrorServiceException.class)
35+
public void testCall2() throws Exception {
36+
execute(ExceptionType.InternalServerError);
37+
}
38+
39+
40+
@Test(expectedExceptions = AccessDeniedServiceException.class)
41+
public void testCall3() throws Exception {
42+
execute(ExceptionType.AccessDeniedNoSuchAccount);
43+
}
44+
3045
// @Test(expectedExceptions = AccessDeniedServiceException.class)
3146
// public void testCall4() throws Exception {
3247
// execute(ExceptionType.AccessDeniedRequestLimitExceeded);
@@ -40,6 +55,6 @@ public class ExceptionThrowerCommandTest {
4055
private void execute(ExceptionType type) throws Exception {
4156
ExceptionThrowerCommand command = new ExceptionThrowerCommand();
4257
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
43-
// executor.execute(command, mode, type).get();
58+
executor.execute(command, mode, new ExceptionThrowerParams(type, 100)).get();
4459
}
4560
}

0 commit comments

Comments
 (0)