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 @@ -572,8 +572,7 @@ public ProgressEvent<ModelT, CallbackT> done(Function<ResponseT, ProgressEvent<M
if (e instanceof AwsServiceException) {
AwsServiceException sdkException = (AwsServiceException) e;
AwsErrorDetails details = sdkException.awsErrorDetails();
String errMsg = "Exception=[" + sdkException.getClass() + "] " + "ErrorCode=[" + details.errorCode()
+ "], ErrorMessage=[" + details.errorMessage() + "]";
String errMsg = sdkException.getMessage();
switch (details.sdkHttpResponse().statusCode()) {
case HttpStatusCode.BAD_REQUEST:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,18 @@ public void badRequest() {
.initiate("client:createRespository", proxy.newProxy(() -> mock(ServiceClient.class)), model, context)
.translateToServiceRequest(m -> new CreateRequest.Builder().repoName(m.getRepoName()).build())
.makeServiceCall((r, c) -> {
throw new BadRequestException(mock(AwsServiceException.Builder.class)) {
throw new BadRequestException(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
public AwsErrorDetails awsErrorDetails() {
return AwsErrorDetails.builder().errorCode("BadRequest").errorMessage("Bad Parameter in request")
.sdkHttpResponse(sdkHttpResponse).build();
}
};
}.toBuilder());
}).done(o -> ProgressEvent.success(model, context));
assertThat(result.getStatus()).isEqualTo(OperationStatus.FAILED);
assertThat(result.getMessage()).contains("BadRequest");
assertThat(result.getMessage()).contains("Bad Parameter");
}

@Test
Expand All @@ -470,18 +470,18 @@ public void notFound() {
.initiate("client:createRespository", proxy.newProxy(() -> mock(ServiceClient.class)), model, context)
.translateToServiceRequest(m -> new CreateRequest.Builder().repoName(m.getRepoName()).build())
.makeServiceCall((r, c) -> {
throw new NotFoundException(mock(AwsServiceException.Builder.class)) {
throw new NotFoundException(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
public AwsErrorDetails awsErrorDetails() {
return AwsErrorDetails.builder().errorCode("NotFound").errorMessage("Repo not existing")
.sdkHttpResponse(sdkHttpResponse).build();
}
};
}.toBuilder());
}).done(o -> ProgressEvent.success(model, context));
assertThat(result.getStatus()).isEqualTo(OperationStatus.FAILED);
assertThat(result.getMessage()).contains("NotFound");
assertThat(result.getMessage()).contains("Repo not existing");
}

@Test
Expand All @@ -501,19 +501,18 @@ public void accessDenied() {
.initiate("client:createRespository", proxy.newProxy(() -> mock(ServiceClient.class)), model, context)
.translateToServiceRequest(m -> new CreateRequest.Builder().repoName(m.getRepoName()).build())
.makeServiceCall((r, c) -> {
throw new AccessDenied(AwsServiceException.builder()) {
throw new AccessDenied(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
public AwsErrorDetails awsErrorDetails() {
return AwsErrorDetails.builder().errorCode("AccessDenied: 401").errorMessage("Token Invalid")
.sdkHttpResponse(sdkHttpResponse).build();
}

};
}.toBuilder());
}).done(o -> ProgressEvent.success(model, context));
assertThat(result.getStatus()).isEqualTo(OperationStatus.FAILED);
assertThat(result.getMessage()).contains("AccessDenied");
assertThat(result.getMessage()).contains("Token Invalid");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public void happyCase() {
//
// Now reset expectation to fail with already exists
//
final ExistsException exists = new ExistsException(mock(AwsServiceException.Builder.class)) {
final ExistsException exists = new ExistsException(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
public AwsErrorDetails awsErrorDetails() {
return AwsErrorDetails.builder().errorCode("AlreadyExists").errorMessage("Repo already exists")
.sdkHttpResponse(sdkHttpResponse).build();
}
};
}.toBuilder());
when(serviceClient.createRepository(any(CreateRequest.class))).thenThrow(exists);
StdCallbackContext newContext = new StdCallbackContext();
event = proxy.initiate("client:createRepository", client, model, newContext)
Expand All @@ -124,7 +124,7 @@ public AwsErrorDetails awsErrorDetails() {
.done(r -> ProgressEvent.success(model, context));

assertThat(event.getStatus()).isEqualTo(OperationStatus.FAILED);
assertThat(event.getMessage()).contains("AlreadyExists");
assertThat(event.getMessage()).contains("Repo already exists");
}

private HandlerRequest<Model, StdCallbackContext> prepareRequest(Model model) throws Exception {
Expand Down Expand Up @@ -196,15 +196,15 @@ public void notFound() throws Exception {
final DescribeRequest describeRequest = new DescribeRequest.Builder().repoName(model.getRepoName()).overrideConfiguration(
AwsRequestOverrideConfiguration.builder().credentialsProvider(StaticCredentialsProvider.create(MockCreds)).build())
.build();
final NotFoundException notFound = new NotFoundException(mock(AwsServiceException.Builder.class)) {
final NotFoundException notFound = new NotFoundException(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
public AwsErrorDetails awsErrorDetails() {
return AwsErrorDetails.builder().errorCode("NotFound").errorMessage("Repo not existing")
.sdkHttpResponse(sdkHttpResponse).build();
}
};
}.toBuilder());
when(client.describeRepository(eq(describeRequest))).thenThrow(notFound);

final SdkHttpClient httpClient = mock(SdkHttpClient.class);
Expand All @@ -221,7 +221,7 @@ public AwsErrorDetails awsErrorDetails() {
});
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(OperationStatus.FAILED);
assertThat(response.getMessage()).contains("NotFound");
assertThat(response.getMessage()).contains("Repo not existing");
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -299,15 +299,15 @@ public void createHandlerAlreadyExists() throws Exception {
final SdkHttpResponse sdkHttpResponse = mock(SdkHttpResponse.class);
when(sdkHttpResponse.statusCode()).thenReturn(500);

final ExistsException exists = new ExistsException(mock(AwsServiceException.Builder.class)) {
final ExistsException exists = new ExistsException(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
public AwsErrorDetails awsErrorDetails() {
return AwsErrorDetails.builder().errorCode("AlreadyExists").errorMessage("Repo already exists")
.sdkHttpResponse(sdkHttpResponse).build();
}
};
}.toBuilder());
when(client.createRepository(eq(createRequest))).thenThrow(exists);

final SdkHttpClient httpClient = mock(SdkHttpClient.class);
Expand All @@ -327,7 +327,7 @@ public AwsErrorDetails awsErrorDetails() {
assertThat(request.getRequestData()).isNotNull();
Model responseModel = response.getResourceModel();
assertThat(responseModel.getRepoName()).isEqualTo("repository");
assertThat(response.getMessage()).contains("AlreadyExists");
assertThat(response.getMessage()).contains("Repo already exists");
}

@Order(30)
Expand Down Expand Up @@ -469,7 +469,7 @@ public void accessDenied() throws Exception {
final DescribeRequest describeRequest = new DescribeRequest.Builder().repoName(model.getRepoName()).overrideConfiguration(
AwsRequestOverrideConfiguration.builder().credentialsProvider(StaticCredentialsProvider.create(MockCreds)).build())
.build();
final AccessDenied accessDenied = new AccessDenied(mock(AwsServiceException.Builder.class)) {
final AccessDenied accessDenied = new AccessDenied(new AwsServiceException(AwsServiceException.builder()) {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -478,7 +478,7 @@ public AwsErrorDetails awsErrorDetails() {
.sdkHttpResponse(sdkHttpResponse).build();
}

};
}.toBuilder());
when(client.describeRepository(eq(describeRequest))).thenThrow(accessDenied);

final SdkHttpClient httpClient = mock(SdkHttpClient.class);
Expand All @@ -495,7 +495,7 @@ public AwsErrorDetails awsErrorDetails() {
});
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(OperationStatus.FAILED);
assertThat(response.getMessage()).contains("AccessDenied");
assertThat(response.getMessage()).contains("Token Invalid");
}

}