Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using RequestOperationType.PROMOTE for promoteSchema #1569

Merged
merged 8 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -165,7 +165,8 @@ public ResponseEntity<ApiResponse> execSchemaRequestsDecline(
public ResponseEntity<ApiResponse> uploadSchema(
@Valid @RequestBody SchemaRequestModel addSchemaRequest) throws KlawException {
return new ResponseEntity<>(
schemaRegistryControllerService.uploadSchema(addSchemaRequest), HttpStatus.OK);
schemaRegistryControllerService.uploadSchema(addSchemaRequest, RequestOperationType.CREATE),
HttpStatus.OK);
}

@PostMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ public ApiResponse promoteSchema(SchemaPromotion schemaPromotion) throws Excepti
schemaObjects.get(Integer.valueOf(schemaPromotion.getSchemaVersion()));
// Pretty Print the Json String so that it can be seen clearly in the UI.
schemaRequest.setSchemafull(prettyPrintUglyJsonString((String) schemaObject.get("schema")));
return uploadSchema(schemaRequest);
// sending request operation type along with function call
return uploadSchema(schemaRequest, RequestOperationType.PROMOTE);
}

private boolean userAndTopicOwnerAreOnTheSameTeam(
Expand Down Expand Up @@ -491,7 +492,9 @@ private SchemaRequestModel buildSchemaRequestFromPromotionRequest(
return schemaRequest;
}

public ApiResponse uploadSchema(SchemaRequestModel schemaRequest) throws KlawException {
public ApiResponse uploadSchema(
SchemaRequestModel schemaRequest, RequestOperationType requestOperationType)
throws KlawException {
log.info("uploadSchema {}", schemaRequest);
String userName = getUserName();

Expand Down Expand Up @@ -560,7 +563,7 @@ public ApiResponse uploadSchema(SchemaRequestModel schemaRequest) throws KlawExc
schemaRequest.setRequestor(userName);
SchemaRequest schemaRequestDao = new SchemaRequest();
copyProperties(schemaRequest, schemaRequestDao);
schemaRequestDao.setRequestOperationType(RequestOperationType.CREATE.value);
schemaRequestDao.setRequestOperationType(requestOperationType.value);
HandleDbRequests dbHandle = manageDatabase.getHandleDbRequests();
schemaRequestDao.setTenantId(tenantId);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void uploadSchema() throws Exception {
SchemaRequestModel schemaRequest = utilMethods.getSchemaRequests().get(0);
String jsonReq = OBJECT_MAPPER.writer().writeValueAsString(schemaRequest);
ApiResponse apiResponse = ApiResponse.builder().message(ApiResultStatus.SUCCESS.value).build();
when(schemaRegistryControllerService.uploadSchema(any())).thenReturn(apiResponse);
when(schemaRegistryControllerService.uploadSchema(any(), any())).thenReturn(apiResponse);

mvc.perform(
MockMvcRequestBuilders.post("/uploadSchema")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.aiven.klaw.model.enums.ApiResultStatus;
import io.aiven.klaw.model.enums.KafkaClustersType;
import io.aiven.klaw.model.enums.PermissionType;
import io.aiven.klaw.model.enums.RequestOperationType;
import io.aiven.klaw.model.enums.RequestStatus;
import io.aiven.klaw.model.requests.SchemaPromotion;
import io.aiven.klaw.model.requests.SchemaRequestModel;
Expand Down Expand Up @@ -312,7 +313,8 @@ public void uploadSchemaSuccess() throws KlawException {
.thenReturn(List.of(topic));
when(commonUtilsService.getFilteredTopicsForTenant(any())).thenReturn(List.of(topic));

ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest);
ApiResponse resultResp =
schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE);
assertThat(resultResp.isSuccess()).isTrue();
}

Expand All @@ -336,7 +338,7 @@ public void uploadSchemaFailure() throws KlawException {
.thenReturn(buildValidationResponse(true));

try {
schemaRegistryControllerService.uploadSchema(schemaRequest);
schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE);
} catch (KlawException e) {
assertThat(e.getMessage()).contains("Error from schema upload");
}
Expand Down Expand Up @@ -505,7 +507,8 @@ public void uploadSchemaIncompatibleSchemaError() throws KlawException {
when(commonUtilsService.getTenantId(anyString())).thenReturn(101);
when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false);

ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest);
ApiResponse resultResp =
schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE);
assertThat(resultResp.getMessage()).isEqualTo(VALIDATION_FAILURE_MSG);
verify(clusterApiService, times(1))
.validateSchema(anyString(), anyString(), anyString(), anyInt());
Expand Down Expand Up @@ -610,7 +613,8 @@ public void uploadSchema_NoValidationOnSave() throws KlawException {
.thenReturn(List.of(topic));
when(commonUtilsService.getFilteredTopicsForTenant(any())).thenReturn(List.of(topic));

ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest);
ApiResponse resultResp =
schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE);
assertThat(resultResp.getMessage()).isEqualTo(ApiResultStatus.SUCCESS.value);

verify(clusterApiService, times(0))
Expand All @@ -637,7 +641,9 @@ public void uploadSchema_ValidationPropertyNotSet() throws KlawException {
NullPointerException ex =
assertThrows(
NullPointerException.class,
() -> schemaRegistryControllerService.uploadSchema(schemaRequest));
() ->
schemaRegistryControllerService.uploadSchema(
schemaRequest, RequestOperationType.CREATE));
assertThat(ex.getMessage())
.contains("Cannot invoke \"java.lang.Boolean.booleanValue()\"")
.contains("validateCompatiblityOnSave\" is null");
Expand Down