Skip to content

Commit

Permalink
SWC-6776, SWC-7096 - Fix tests, use AsyncCallback for easier mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Oct 3, 2024
1 parent 33011e3 commit 87a4fd0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3296,32 +3296,31 @@ public FluentFuture<Void> deleteSessionAccessToken() {
return getFuture(cb -> doDelete(url, cb));
}

public FluentFuture<AccessControlList> getEntityBenefactorAcl(
String entityId
public void getEntityBenefactorAcl(
String entityId,
AsyncCallback<AccessControlList> cb
) {
// Retrieving the benefactor ACL is always permitted regardless of permissions, so only retrieve that part of the bundle.
EntityBundleRequest request = new EntityBundleRequest();
request.setIncludeBenefactorACL(true);
String url = getRepoServiceUrl() + ENTITY + "/" + entityId + BUNDLE2;

return getFuture(cb ->
doPost(
url,
request,
OBJECT_TYPE.EntityBundle,
true,
new AsyncCallback<EntityBundle>() {
@Override
public void onFailure(Throwable caught) {
cb.onFailure(caught);
}
doPost(
url,
request,
OBJECT_TYPE.EntityBundle,
true,
new AsyncCallback<EntityBundle>() {
@Override
public void onSuccess(EntityBundle result) {
cb.onSuccess(result.getBenefactorAcl());
}

@Override
public void onSuccess(EntityBundle result) {
cb.onSuccess(result.getBenefactorAcl());
}
@Override
public void onFailure(Throwable caught) {
cb.onFailure(caught);
}
)
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -791,26 +791,29 @@ public void onSuccess(Entity result) {
entity = result;
view.showInfo(DisplayConstants.TEXT_LINK_SUCCESS);
if (successHandler != null) {
jsClient
.getEntityBenefactorAcl(result.getId())
.addCallback(
new FutureCallback<AccessControlList>() {
@Override
public void onSuccess(AccessControlList benefactorAcl) {
jsClient.getEntityBenefactorAcl(
result.getId(),
new AsyncCallback<AccessControlList>() {
@Override
public void onSuccess(AccessControlList benefactorAcl) {
if (benefactorAcl.getId().equals(entity.getId())) {
// Don't show the ACL modal if the entity is its own benefactor
successHandler.onSuccessfulUpload(null);
} else {
successHandler.onSuccessfulUpload(benefactorAcl.getId());
entityUpdated();
}
entityUpdated();
}

@Override
public void onFailure(Throwable caught) {
view.showErrorMessage(caught.getMessage());
// Upload was still a success, benefactor ID is not required to continue
successHandler.onSuccessfulUpload(null);
entityUpdated();
}
},
directExecutor()
);
@Override
public void onFailure(Throwable caught) {
view.showErrorMessage(caught.getMessage());
// Upload was still a success, benefactor ID is not required to continue
successHandler.onSuccessfulUpload(null);
entityUpdated();
}
}
);
}
}

Expand Down Expand Up @@ -1027,26 +1030,29 @@ private void uploadSuccess() {
view.resetToInitialState();
resetUploadProgress();
if (successHandler != null) {
jsClient
.getEntityBenefactorAcl(entityId)
.addCallback(
new FutureCallback<AccessControlList>() {
@Override
public void onSuccess(AccessControlList benefactorAcl) {
jsClient.getEntityBenefactorAcl(
entityId,
new AsyncCallback<AccessControlList>() {
@Override
public void onSuccess(AccessControlList benefactorAcl) {
if (benefactorAcl.getId().equals(entityId)) {
// Don't show the ACL modal if the entity is its own benefactor
successHandler.onSuccessfulUpload(null);
} else {
successHandler.onSuccessfulUpload(benefactorAcl.getId());
entityUpdated();
}
entityUpdated();
}

@Override
public void onFailure(Throwable caught) {
view.showErrorMessage(caught.getMessage());
// Upload was still a success, benefactor ID is not required to continue.
successHandler.onSuccessfulUpload(null);
entityUpdated();
}
},
directExecutor()
);
@Override
public void onFailure(Throwable caught) {
view.showErrorMessage(caught.getMessage());
// Upload was still a success, benefactor ID is not required to continue.
successHandler.onSuccessfulUpload(null);
entityUpdated();
}
}
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public void testSetNewExternalPath() throws Exception {
// associate the path.
AsyncMockStubber
.callSuccessWith(new AccessControlList().setId(UPLOAD_BENEFACTOR_ID))
.when(mockSynapseClient)
.when(mockSynapseJavascriptClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));

uploader.setExternalFilePath(
Expand All @@ -312,7 +312,7 @@ public void testSetNewExternalPath() throws Exception {
eq(storageLocationId),
any()
);
verify(mockSynapseClient)
verify(mockSynapseJavascriptClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));
verify(mockView).showInfo(anyString());
verify(mockUploadSuccessHandler).onSuccessfulUpload(UPLOAD_BENEFACTOR_ID);
Expand Down Expand Up @@ -420,14 +420,14 @@ public void testDirectUploadHappyCase() throws Exception {
.getEntity(anyString(), any(OBJECT_TYPE.class), any(AsyncCallback.class));
AsyncMockStubber
.callSuccessWith(new AccessControlList().setId(UPLOAD_BENEFACTOR_ID))
.when(mockSynapseClient)
.when(mockSynapseJavascriptClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));
uploader.handleUploads();
verify(mockGlobalApplicationState).clearDropZoneHandler(); // SWC-5161 (cleared on handleUploads)
verify(mockView).disableSelectionDuringUpload();
verify(mockSynapseClient)
.setFileEntityFileHandle(any(), any(), any(), any());
verify(mockSynapseClient)
verify(mockSynapseJavascriptClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));
verify(mockView).hideLoading();
assertEquals(UploadType.S3, uploader.getCurrentUploadType());
Expand Down

0 comments on commit 87a4fd0

Please sign in to comment.