From 8f54d78cc2054274b61682d05103e34b1c90fb13 Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Thu, 29 Aug 2024 10:58:29 -0700 Subject: [PATCH 1/4] SWC-7047 --- .../web/client/PortalGinInjector.java | 26 +++- .../web/client/mvp/AppActivityMapper.java | 2 + .../web/client/mvp/AppPlaceHistoryMapper.java | 2 + .../web/client/place/TrustCenterPlace.java | 36 +++++ .../client/presenter/BulkPresenterProxy.java | 19 +++ .../presenter/TrustCenterPresenter.java | 124 ++++++++++++++++++ .../view/SynapseStandaloneWikiView.java | 2 +- .../view/SynapseStandaloneWikiViewImpl.java | 5 + .../view/SynapseStandaloneWikiViewImpl.ui.xml | 2 +- 9 files changed, 214 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java create mode 100644 src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java diff --git a/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java b/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java index 8ba3d51241..e57ee108be 100644 --- a/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java +++ b/src/main/java/org/sagebionetworks/web/client/PortalGinInjector.java @@ -46,6 +46,7 @@ import org.sagebionetworks.web.client.presenter.TeamPresenter; import org.sagebionetworks.web.client.presenter.TeamSearchPresenter; import org.sagebionetworks.web.client.presenter.TrashPresenter; +import org.sagebionetworks.web.client.presenter.TrustCenterPresenter; import org.sagebionetworks.web.client.presenter.TwoFactorAuthPresenter; import org.sagebionetworks.web.client.presenter.WikiDiffPresenter; import org.sagebionetworks.web.client.presenter.users.PasswordResetPresenter; @@ -91,8 +92,28 @@ import org.sagebionetworks.web.client.widget.docker.modal.AddExternalRepoModal; import org.sagebionetworks.web.client.widget.doi.CreateOrUpdateDoiModal; import org.sagebionetworks.web.client.widget.doi.DoiWidgetV2; -import org.sagebionetworks.web.client.widget.entity.*; +import org.sagebionetworks.web.client.widget.entity.ChallengeBadge; +import org.sagebionetworks.web.client.widget.entity.EditFileMetadataModalWidget; +import org.sagebionetworks.web.client.widget.entity.EditProjectMetadataModalWidget; +import org.sagebionetworks.web.client.widget.entity.EntityListRowBadge; +import org.sagebionetworks.web.client.widget.entity.EntityMetadata; +import org.sagebionetworks.web.client.widget.entity.EntityTreeItem; +import org.sagebionetworks.web.client.widget.entity.MarkdownWidget; +import org.sagebionetworks.web.client.widget.entity.ModifiedCreatedByWidget; +import org.sagebionetworks.web.client.widget.entity.MoreTreeItem; +import org.sagebionetworks.web.client.widget.entity.PreviewWidget; +import org.sagebionetworks.web.client.widget.entity.ProjectBadge; +import org.sagebionetworks.web.client.widget.entity.PromptForValuesModalView; +import org.sagebionetworks.web.client.widget.entity.RegisterTeamDialog; +import org.sagebionetworks.web.client.widget.entity.RenameEntityModalWidget; import org.sagebionetworks.web.client.widget.entity.SqlDefinedEditorModalWidget; +import org.sagebionetworks.web.client.widget.entity.TutorialWizard; +import org.sagebionetworks.web.client.widget.entity.VersionHistoryRowView; +import org.sagebionetworks.web.client.widget.entity.VersionHistoryWidget; +import org.sagebionetworks.web.client.widget.entity.WikiMarkdownEditor; +import org.sagebionetworks.web.client.widget.entity.WikiPageDeleteConfirmationDialog; +import org.sagebionetworks.web.client.widget.entity.WikiPageWidget; +import org.sagebionetworks.web.client.widget.entity.WikiVersionAnchorListItem; import org.sagebionetworks.web.client.widget.entity.act.ApproveUserAccessModal; import org.sagebionetworks.web.client.widget.entity.act.RejectReasonWidget; import org.sagebionetworks.web.client.widget.entity.act.UserBadgeItem; @@ -194,7 +215,6 @@ import org.sagebionetworks.web.client.widget.sharing.AccessControlListModalWidget; import org.sagebionetworks.web.client.widget.sharing.AclAddPeoplePanel; import org.sagebionetworks.web.client.widget.sharing.EntityAccessControlListModalWidget; -import org.sagebionetworks.web.client.widget.sharing.EntityAccessControlListModalWidgetImpl; import org.sagebionetworks.web.client.widget.sharing.SharingPermissionsGrid; import org.sagebionetworks.web.client.widget.statistics.StatisticsPlotWidget; import org.sagebionetworks.web.client.widget.table.TableEntityListGroupItem; @@ -874,4 +894,6 @@ public interface PortalGinInjector extends Ginjector { EntityTypeIcon getEntityTypeIcon(); FeatureFlagConfig getFeatureFlagConfig(); + + TrustCenterPresenter getTrustCenterPresenter(); } diff --git a/src/main/java/org/sagebionetworks/web/client/mvp/AppActivityMapper.java b/src/main/java/org/sagebionetworks/web/client/mvp/AppActivityMapper.java index 57ff46942a..8e7f2b077c 100644 --- a/src/main/java/org/sagebionetworks/web/client/mvp/AppActivityMapper.java +++ b/src/main/java/org/sagebionetworks/web/client/mvp/AppActivityMapper.java @@ -37,6 +37,7 @@ import org.sagebionetworks.web.client.place.Team; import org.sagebionetworks.web.client.place.TeamSearch; import org.sagebionetworks.web.client.place.Trash; +import org.sagebionetworks.web.client.place.TrustCenterPlace; import org.sagebionetworks.web.client.place.Wiki; import org.sagebionetworks.web.client.place.users.PasswordReset; import org.sagebionetworks.web.client.place.users.RegisterAccount; @@ -101,6 +102,7 @@ public AppActivityMapper( openAccessPlaces.add(EmailInvitation.class); openAccessPlaces.add(AccessRequirementsPlace.class); openAccessPlaces.add(AccessRequirementPlace.class); + openAccessPlaces.add(TrustCenterPlace.class); excludeFromLastPlace = new ArrayList(); excludeFromLastPlace.add(Home.class); diff --git a/src/main/java/org/sagebionetworks/web/client/mvp/AppPlaceHistoryMapper.java b/src/main/java/org/sagebionetworks/web/client/mvp/AppPlaceHistoryMapper.java index f44b0e52eb..1ab260ec92 100644 --- a/src/main/java/org/sagebionetworks/web/client/mvp/AppPlaceHistoryMapper.java +++ b/src/main/java/org/sagebionetworks/web/client/mvp/AppPlaceHistoryMapper.java @@ -40,6 +40,7 @@ import org.sagebionetworks.web.client.place.Team; import org.sagebionetworks.web.client.place.TeamSearch; import org.sagebionetworks.web.client.place.Trash; +import org.sagebionetworks.web.client.place.TrustCenterPlace; import org.sagebionetworks.web.client.place.TwoFactorAuthPlace; import org.sagebionetworks.web.client.place.Wiki; import org.sagebionetworks.web.client.place.WikiDiff; @@ -96,6 +97,7 @@ OAuthClientEditorPlace.Tokenizer.class, TwoFactorAuthPlace.Tokenizer.class, FollowingPlace.Tokenizer.class, + TrustCenterPlace.Tokenizer.class, } ) public interface AppPlaceHistoryMapper extends PlaceHistoryMapper {} diff --git a/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java b/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java new file mode 100644 index 0000000000..eaf3362da0 --- /dev/null +++ b/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java @@ -0,0 +1,36 @@ +package org.sagebionetworks.web.client.place; + +import com.google.gwt.place.shared.Place; +import com.google.gwt.place.shared.PlaceTokenizer; +import com.google.gwt.place.shared.Prefix; + +public class TrustCenterPlace extends Place { + + private String documentKey; + + public TrustCenterPlace(String token) { + this.documentKey = token; + } + + public String toToken() { + return documentKey; + } + + public String getDocumentKey() { + return documentKey; + } + + @Prefix("TrustCenter") + public static class Tokenizer implements PlaceTokenizer { + + @Override + public String getToken(TrustCenterPlace place) { + return place.toToken(); + } + + @Override + public TrustCenterPlace getPlace(String token) { + return new TrustCenterPlace(token); + } + } +} diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/BulkPresenterProxy.java b/src/main/java/org/sagebionetworks/web/client/presenter/BulkPresenterProxy.java index 77c0ae484f..0da422e2da 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/BulkPresenterProxy.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/BulkPresenterProxy.java @@ -56,6 +56,7 @@ import org.sagebionetworks.web.client.place.Team; import org.sagebionetworks.web.client.place.TeamSearch; import org.sagebionetworks.web.client.place.Trash; +import org.sagebionetworks.web.client.place.TrustCenterPlace; import org.sagebionetworks.web.client.place.TwoFactorAuthPlace; import org.sagebionetworks.web.client.place.Wiki; import org.sagebionetworks.web.client.place.WikiDiff; @@ -864,6 +865,24 @@ public void onSuccess() { presenter.start(panel, eventBus); } + @Override + public void onFailure(Throwable caught) { + loadError(caught); + } + } + ); + } else if (place instanceof TrustCenterPlace) { + GWT.runAsync( + TrustCenterPlace.class, + new RunAsyncCallback() { + @Override + public void onSuccess() { + TrustCenterPresenter presenter = + ginjector.getTrustCenterPresenter(); + presenter.setPlace((TrustCenterPlace) place); + presenter.start(panel, eventBus); + } + @Override public void onFailure(Throwable caught) { loadError(caught); diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java new file mode 100644 index 0000000000..27ae406d2e --- /dev/null +++ b/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java @@ -0,0 +1,124 @@ +package org.sagebionetworks.web.client.presenter; + +import com.google.gwt.activity.shared.AbstractActivity; +import com.google.gwt.event.shared.EventBus; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.http.client.Response; +import com.google.gwt.user.client.ui.AcceptsOneWidget; +import com.google.inject.Inject; +import java.util.HashMap; +import java.util.Map; +import org.sagebionetworks.web.client.RequestBuilderWrapper; +import org.sagebionetworks.web.client.view.MapView; +import org.sagebionetworks.web.client.view.SynapseStandaloneWikiView; +import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert; +import org.sagebionetworks.web.shared.WebConstants; + +public class TrustCenterPresenter + extends AbstractActivity + implements + Presenter, + MapView.Presenter { + + SynapseStandaloneWikiView view; + RequestBuilderWrapper requestBuilder; + SynapseAlert synAlert; + + private static Map documentKeyToGithubUrl = new HashMap<>(); + + static { + documentKeyToGithubUrl.put( + "TermsOfService", + "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/Terms.md" + ); + documentKeyToGithubUrl.put( + "PrivacyPolicy", + "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/privacy.md" + ); + documentKeyToGithubUrl.put( + "Cookies", + "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/cookies.md" + ); + documentKeyToGithubUrl.put( + "Subprocessors", + "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/subprocessors.md" + ); + } + + @Inject + public TrustCenterPresenter( + SynapseStandaloneWikiView view, + RequestBuilderWrapper requestBuilder, + SynapseAlert synAlert + ) { + this.view = view; + this.requestBuilder = requestBuilder; + this.synAlert = synAlert; + } + + @Override + public void start(AcceptsOneWidget panel, EventBus eventBus) { + panel.setWidget(view.asWidget()); + } + + @Override + public void setPlace( + org.sagebionetworks.web.client.place.TrustCenterPlace place + ) { + synAlert.clear(); + String documentKey = place.getDocumentKey(); + String documentUrl = documentKeyToGithubUrl.get(documentKey); + if (documentUrl == null) { + synAlert.showError("Unrecognized document key: " + documentKey); + } else { + showFileContent(documentUrl); + } + } + + public void showFileContent(String url) { + requestBuilder.configure(RequestBuilder.GET, url); + requestBuilder.setHeader( + WebConstants.CONTENT_TYPE, + WebConstants.TEXT_PLAIN_CHARSET_UTF8 + ); + try { + requestBuilder.sendRequest( + null, + new RequestCallback() { + @Override + public void onResponseReceived(Request request, Response response) { + int statusCode = response.getStatusCode(); + if (statusCode == Response.SC_OK) { + String md = response.getText(); + view.configure(md); + } else { + onError( + null, + new IllegalArgumentException( + "Unable to retrieve file content " + + url + + ". Reason: " + + response.getStatusText() + ) + ); + } + } + + @Override + public void onError(Request request, Throwable exception) { + synAlert.handleException(exception); + } + } + ); + } catch (final Exception e) { + synAlert.handleException(e); + } + } + + @Override + public String mayStop() { + return null; + } +} diff --git a/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiView.java b/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiView.java index 9625dc475b..d586ef1f2f 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiView.java +++ b/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiView.java @@ -5,6 +5,6 @@ public interface SynapseStandaloneWikiView extends IsWidget { void configure(String markdown, WikiPageKey wikiKey); - + void configure(String markdown); void setSynAlert(IsWidget w); } diff --git a/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.java b/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.java index ef4706df88..688d11a879 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.java @@ -51,6 +51,11 @@ public void configure(String markdown, WikiPageKey wikiKey) { Window.scrollTo(0, 0); // scroll user to top of page } + @Override + public void configure(String markdown) { + configure(markdown, null); + } + @Override public void setSynAlert(IsWidget w) { synAlertContainer.clear(); diff --git a/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml b/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml index d78ce1dfc3..84c36c0783 100644 --- a/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml +++ b/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml @@ -10,7 +10,7 @@ type='org.sagebionetworks.web.client.SageImageBundle' /> - + From 8a43f2d91074be98dfd94a3fa40b7dbd686b16f0 Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Thu, 29 Aug 2024 11:04:35 -0700 Subject: [PATCH 2/4] after testing with invalid document key --- .../web/client/presenter/TrustCenterPresenter.java | 1 + .../web/client/view/SynapseStandaloneWikiViewImpl.ui.xml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java index 27ae406d2e..e7d2971c21 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java @@ -56,6 +56,7 @@ public TrustCenterPresenter( this.view = view; this.requestBuilder = requestBuilder; this.synAlert = synAlert; + view.setSynAlert(synAlert); } @Override diff --git a/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml b/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml index 84c36c0783..59b12426ae 100644 --- a/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml +++ b/src/main/resources/org/sagebionetworks/web/client/view/SynapseStandaloneWikiViewImpl.ui.xml @@ -10,16 +10,16 @@ type='org.sagebionetworks.web.client.SageImageBundle' /> - + + - From f6e56453d3cd1b4c11109f66ebc06849ba1c07a2 Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Thu, 29 Aug 2024 11:38:07 -0700 Subject: [PATCH 3/4] add unit tests --- .../web/client/place/TrustCenterPlace.java | 5 + .../presenter/TrustCenterPresenter.java | 9 +- .../presenter/TrustCenterPresenterTest.java | 122 ++++++++++++++++++ 3 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java diff --git a/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java b/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java index eaf3362da0..b1dae94004 100644 --- a/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java +++ b/src/main/java/org/sagebionetworks/web/client/place/TrustCenterPlace.java @@ -6,6 +6,11 @@ public class TrustCenterPlace extends Place { + public static final String SUBPROCESSORS_KEY = "Subprocessors"; + public static final String COOKIES_KEY = "Cookies"; + public static final String PRIVACY_POLICY_KEY = "PrivacyPolicy"; + public static final String TERMS_OF_SERVICE_KEY = "TermsOfService"; + private String documentKey; public TrustCenterPlace(String token) { diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java index e7d2971c21..7a9fe7509d 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/TrustCenterPresenter.java @@ -11,6 +11,7 @@ import java.util.HashMap; import java.util.Map; import org.sagebionetworks.web.client.RequestBuilderWrapper; +import org.sagebionetworks.web.client.place.TrustCenterPlace; import org.sagebionetworks.web.client.view.MapView; import org.sagebionetworks.web.client.view.SynapseStandaloneWikiView; import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert; @@ -30,19 +31,19 @@ public class TrustCenterPresenter static { documentKeyToGithubUrl.put( - "TermsOfService", + TrustCenterPlace.TERMS_OF_SERVICE_KEY, "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/Terms.md" ); documentKeyToGithubUrl.put( - "PrivacyPolicy", + TrustCenterPlace.PRIVACY_POLICY_KEY, "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/privacy.md" ); documentKeyToGithubUrl.put( - "Cookies", + TrustCenterPlace.COOKIES_KEY, "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/cookies.md" ); documentKeyToGithubUrl.put( - "Subprocessors", + TrustCenterPlace.SUBPROCESSORS_KEY, "https://raw.githubusercontent.com/Sage-Bionetworks/Sage-Governance-Documents/main/subprocessors.md" ); } diff --git a/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java b/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java new file mode 100644 index 0000000000..f8ba5a969d --- /dev/null +++ b/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java @@ -0,0 +1,122 @@ +package org.sagebionetworks.web.unitclient.presenter; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.sagebionetworks.web.client.presenter.SynapseForumPresenter.DEFAULT_IS_MODERATOR; + +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestException; +import com.google.gwt.http.client.Response; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.sagebionetworks.repo.model.AccessControlList; +import org.sagebionetworks.repo.model.discussion.Forum; +import org.sagebionetworks.web.client.GlobalApplicationState; +import org.sagebionetworks.web.client.PlaceChanger; +import org.sagebionetworks.web.client.RequestBuilderWrapper; +import org.sagebionetworks.web.client.SynapseProperties; +import org.sagebionetworks.web.client.place.ParameterizedToken; +import org.sagebionetworks.web.client.place.SynapseForumPlace; +import org.sagebionetworks.web.client.place.TrustCenterPlace; +import org.sagebionetworks.web.client.presenter.SynapseForumPresenter; +import org.sagebionetworks.web.client.presenter.TrustCenterPresenter; +import org.sagebionetworks.web.client.utils.Callback; +import org.sagebionetworks.web.client.utils.CallbackP; +import org.sagebionetworks.web.client.view.SynapseForumView; +import org.sagebionetworks.web.client.view.SynapseStandaloneWikiView; +import org.sagebionetworks.web.client.widget.discussion.ForumWidget; +import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert; +import org.sagebionetworks.web.client.widget.entity.menu.v3.EntityActionMenu; +import org.sagebionetworks.web.shared.WebConstants; +import org.sagebionetworks.web.test.helper.RequestBuilderMockStubber; + +public class TrustCenterPresenterTest { + + @Mock + SynapseStandaloneWikiView mockView; + + @Mock + RequestBuilderWrapper mockRequestBuilder; + + @Mock + Response mockResponse; + + @Mock + SynapseAlert mockSynAlert; + + @Mock + TrustCenterPlace mockPlace; + + TrustCenterPresenter presenter; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + presenter = + new TrustCenterPresenter(mockView, mockRequestBuilder, mockSynAlert); + } + + @Test + public void testValidDocumentKey() throws RequestException { + when(mockResponse.getStatusCode()).thenReturn(Response.SC_OK); + String markdown = "Privacy Policy **markdown**"; + when(mockResponse.getText()).thenReturn(markdown); + RequestBuilderMockStubber + .callOnResponseReceived(null, mockResponse) + .when(mockRequestBuilder) + .sendRequest(any(), any()); + when(mockPlace.getDocumentKey()) + .thenReturn(TrustCenterPlace.PRIVACY_POLICY_KEY); + + presenter.setPlace(mockPlace); + + verify(mockSynAlert, atLeastOnce()).clear(); + verify(mockRequestBuilder).configure(eq(RequestBuilder.GET), anyString()); + verify(mockRequestBuilder) + .setHeader( + WebConstants.CONTENT_TYPE, + WebConstants.TEXT_PLAIN_CHARSET_UTF8 + ); + verify(mockSynAlert, never()).handleException(any(Throwable.class)); + verify(mockView).configure(markdown); + } + + @Test + public void testInvalidDocumentKey() throws RequestException { + when(mockResponse.getStatusCode()).thenReturn(Response.SC_OK); + when(mockPlace.getDocumentKey()).thenReturn("Invalid Key"); + + presenter.setPlace(mockPlace); + + verify(mockSynAlert, atLeastOnce()).clear(); + verify(mockSynAlert).showError(any()); + verify(mockRequestBuilder, never()) + .configure(eq(RequestBuilder.GET), any()); + } + + @Test + public void testUnableToGetMarkdown() throws RequestException { + when(mockResponse.getStatusCode()).thenReturn(Response.SC_OK); + when(mockPlace.getDocumentKey()) + .thenReturn(TrustCenterPlace.PRIVACY_POLICY_KEY); + RequestBuilderMockStubber + .callOnError(null, new Exception()) + .when(mockRequestBuilder) + .sendRequest(any(), any()); + + presenter.setPlace(mockPlace); + + verify(mockRequestBuilder).configure(eq(RequestBuilder.GET), any()); + verify(mockSynAlert, atLeastOnce()).clear(); + verify(mockSynAlert).handleException(any()); + } +} From 4a636e3eb9cb4cb8bebfaf65c1d256a9d069161f Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Thu, 29 Aug 2024 11:38:57 -0700 Subject: [PATCH 4/4] clean imports --- .../presenter/TrustCenterPresenterTest.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java b/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java index f8ba5a969d..4efac8c4a4 100644 --- a/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java +++ b/src/test/java/org/sagebionetworks/web/unitclient/presenter/TrustCenterPresenterTest.java @@ -3,13 +3,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.sagebionetworks.web.client.presenter.SynapseForumPresenter.DEFAULT_IS_MODERATOR; import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestException; @@ -18,24 +15,11 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.sagebionetworks.repo.model.AccessControlList; -import org.sagebionetworks.repo.model.discussion.Forum; -import org.sagebionetworks.web.client.GlobalApplicationState; -import org.sagebionetworks.web.client.PlaceChanger; import org.sagebionetworks.web.client.RequestBuilderWrapper; -import org.sagebionetworks.web.client.SynapseProperties; -import org.sagebionetworks.web.client.place.ParameterizedToken; -import org.sagebionetworks.web.client.place.SynapseForumPlace; import org.sagebionetworks.web.client.place.TrustCenterPlace; -import org.sagebionetworks.web.client.presenter.SynapseForumPresenter; import org.sagebionetworks.web.client.presenter.TrustCenterPresenter; -import org.sagebionetworks.web.client.utils.Callback; -import org.sagebionetworks.web.client.utils.CallbackP; -import org.sagebionetworks.web.client.view.SynapseForumView; import org.sagebionetworks.web.client.view.SynapseStandaloneWikiView; -import org.sagebionetworks.web.client.widget.discussion.ForumWidget; import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert; -import org.sagebionetworks.web.client.widget.entity.menu.v3.EntityActionMenu; import org.sagebionetworks.web.shared.WebConstants; import org.sagebionetworks.web.test.helper.RequestBuilderMockStubber;