<commit_before>package org.sagebionetworks.web.unitclient.presenter;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace.ACCESS_REQUIREMENT_ID_PARAM;
import static org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace.MAX_DATE_PARAM;
import static org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace.MIN_DATE_PARAM;
import static org.sagebionetworks.web.client.presenter.ACTDataAccessSubmissionsPresenter.SHOW_AR_TEXT;

import java.util.Collections;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.repo.model.ACTAccessRequirement;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmission;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmissionOrder;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmissionPage;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmissionState;
import org.sagebionetworks.repo.model.file.FileHandleAssociateType;
import org.sagebionetworks.repo.model.file.FileHandleAssociation;
import org.sagebionetworks.web.client.DataAccessClientAsync;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace;
import org.sagebionetworks.web.client.presenter.ACTDataAccessSubmissionsPresenter;
import org.sagebionetworks.web.client.utils.Callback;
import org.sagebionetworks.web.client.view.ACTDataAccessSubmissionsView;
import org.sagebionetworks.web.client.widget.Button;
import org.sagebionetworks.web.client.widget.FileHandleWidget;
import org.sagebionetworks.web.client.widget.LoadMoreWidgetContainer;
import org.sagebionetworks.web.client.widget.accessrequirements.ACTAccessRequirementWidget;
import org.sagebionetworks.web.client.widget.accessrequirements.SubjectsWidget;
import org.sagebionetworks.web.client.widget.accessrequirements.submission.ACTDataAccessSubmissionWidget;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
import org.sagebionetworks.web.test.helper.AsyncMockStubber;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;

public class ACTDataAccessSubmissionsPresenterTest {
	
	ACTDataAccessSubmissionsPresenter presenter;
	
	@Mock
	ACTDataAccessSubmissionsPlace mockPlace;
	
	@Mock
	ACTDataAccessSubmissionsView mockView;
	@Mock
	SynapseAlert mockSynAlert;
	@Mock
	PortalGinInjector mockGinInjector;
	@Mock
	GlobalApplicationState mockGlobalApplicationState;
	@Mock
	LoadMoreWidgetContainer mockLoadMoreContainer;
	@Mock
	ACTAccessRequirementWidget mockACTAccessRequirementWidget;
	@Mock
	Button mockButton;
	@Mock
	FileHandleWidget mockDucTemplateFileHandleWidget;
	@Mock
	DataAccessClientAsync mockDataAccessClient;
	
	@Mock
	ACTAccessRequirement mockACTAccessRequirement;
	@Mock
	DataAccessSubmissionPage mockDataAccessSubmissionPage;
	@Mock
	DataAccessSubmission mockDataAccessSubmission;
	@Captor
	ArgumentCaptor<FileHandleAssociation> fhaCaptor;
	@Mock
	ACTDataAccessSubmissionWidget mockACTDataAccessSubmissionWidget;
	@Mock
	SubjectsWidget mockSubjectsWidget;
	public static final String FILE_HANDLE_ID = "9999";
	public static final Long AR_ID = 76555L;
	public static final String NEXT_PAGE_TOKEN = "<PASSWORD>";
	
	@Before
	public void setup(){
		MockitoAnnotations.initMocks(this);
		presenter = new ACTDataAccessSubmissionsPresenter(mockView, mockSynAlert, mockGinInjector, mockGlobalApplicationState, mockLoadMoreContainer, mockACTAccessRequirementWidget, mockButton, mockDucTemplateFileHandleWidget, mockDataAccessClient, mockSubjectsWidget);
		AsyncMockStubber.callSuccessWith(mockACTAccessRequirement).when(mockDataAccessClient).getAccessRequirement(anyLong(), any(AsyncCallback.class));
		AsyncMockStubber.callSuccessWith(mockDataAccessSubmissionPage).when(mockDataAccessClient).getDataAccessSubmissions(anyLong(), anyString(), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));
		when(mockDataAccessSubmissionPage.getResults()).thenReturn(Collections.singletonList(mockDataAccessSubmission));
		when(mockDataAccessSubmissionPage.getNextPageToken()).thenReturn(NEXT_PAGE_TOKEN);
		when(mockACTAccessRequirement.getDucTemplateFileHandleId()).thenReturn(FILE_HANDLE_ID);
		when(mockACTAccessRequirement.getId()).thenReturn(AR_ID);
		when(mockGinInjector.getACTDataAccessSubmissionWidget()).thenReturn(mockACTDataAccessSubmissionWidget);
	}	
	
	@Test
	public void testConstruction() {
		verify(mockView).setStates(anyList());
		verify(mockButton).setText(SHOW_AR_TEXT);
		verify(mockView).setAccessRequirementUIVisible(false);
		verify(mockView).setSynAlert(any(IsWidget.class));
		verify(mockView).setAccessRequirementWidget(any(IsWidget.class));
		verify(mockView).setLoadMoreContainer(any(IsWidget.class));
		verify(mockView).setShowHideButton(any(IsWidget.class));
		verify(mockView).setPresenter(presenter);
		verify(mockLoadMoreContainer).configure(any(Callback.class));
		verify(mockButton).addClickHandler(any(ClickHandler.class));
	}
	
	@Test
	public void testLoadData() {
		String time1 = "8765";
		String time2 = "5678";
		when(mockPlace.getParam(MIN_DATE_PARAM)).thenReturn(time1);
		when(mockPlace.getParam(MAX_DATE_PARAM)).thenReturn(time2);
		when(mockPlace.getParam(ACCESS_REQUIREMENT_ID_PARAM)).thenReturn(AR_ID.toString());
		
		when(mockACTAccessRequirement.getDucTemplateFileHandleId()).thenReturn(FILE_HANDLE_ID);
		when(mockACTAccessRequirement.getAreOtherAttachmentsRequired()).thenReturn(true);
		when(mockACTAccessRequirement.getIsAnnualReviewRequired()).thenReturn(false);
		when(mockACTAccessRequirement.getIsCertifiedUserRequired()).thenReturn(true);
		when(mockACTAccessRequirement.getIsDUCRequired()).thenReturn(false);
		when(mockACTAccessRequirement.getIsIDUPublic()).thenReturn(true);
		when(mockACTAccessRequirement.getIsIRBApprovalRequired()).thenReturn(false);
		when(mockACTAccessRequirement.getIsValidatedProfileRequired()).thenReturn(true);
		
		presenter.setPlace(mockPlace);
		verify(mockDataAccessClient).getAccessRequirement(eq(AR_ID), any(AsyncCallback.class));
		
		//verify duc template file handle widget is configured properly (basd on act duc file handle id)
		verify(mockDucTemplateFileHandleWidget).configure(fhaCaptor.capture());
		FileHandleAssociation fha = fhaCaptor.getValue();
		assertEquals(FileHandleAssociateType.AccessRequirementAttachment, fha.getAssociateObjectType());
		assertEquals(AR_ID.toString(), fha.getAssociateObjectId());
		assertEquals(FILE_HANDLE_ID, fha.getFileHandleId());
				
		verify(mockView).setAreOtherAttachmentsRequired(true);
		verify(mockView).setIsAnnualReviewRequired(false);
		verify(mockView).setIsCertifiedUserRequired(true);
		verify(mockView).setIsDUCRequired(false);
		verify(mockView).setIsIDUPublic(true);
		verify(mockView).setIsIRBApprovalRequired(false);
		verify(mockView).setIsValidatedProfileRequired(true);
		
		verify(mockACTAccessRequirementWidget).setRequirement(mockACTAccessRequirement);
		verify(mockDataAccessClient).getDataAccessSubmissions(anyLong(), eq((String)null), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));

		//verify DataAccessSubmission widget is created/configured for the submission (based on the mockACTAccessRequirement configuration)
		verify(mockGinInjector).getACTDataAccessSubmissionWidget();
		verify(mockACTDataAccessSubmissionWidget).setDucColumnVisible(false);
		verify(mockACTDataAccessSubmissionWidget).setIrbColumnVisible(false);
		verify(mockACTDataAccessSubmissionWidget).setOtherAttachmentsColumnVisible(true);
		verify(mockACTDataAccessSubmissionWidget).setRenewalColumnsVisible(false);
		verify(mockLoadMoreContainer).setIsMore(true);
		
		//verify final load of empty page
		when(mockDataAccessSubmissionPage.getResults()).thenReturn(Collections.EMPTY_LIST);
		when(mockDataAccessSubmissionPage.getNextPageToken()).thenReturn(null);
		presenter.loadMore();
		verify(mockDataAccessClient).getDataAccessSubmissions(anyLong(), eq(NEXT_PAGE_TOKEN), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));
		verify(mockLoadMoreContainer).setIsMore(false);
	}
	
	@Test
	public void testLoadDataFailure() {
		Exception ex = new Exception();
		AsyncMockStubber.callFailureWith(ex).when(mockDataAccessClient).getDataAccessSubmissions(anyLong(), anyString(), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));
		presenter.loadData();
		verify(mockSynAlert).handleException(ex);
		verify(mockLoadMoreContainer).setIsMore(false);
	}
}
<commit_msg>verify subjects widget is configured<commit_after>package org.sagebionetworks.web.unitclient.presenter;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace.ACCESS_REQUIREMENT_ID_PARAM;
import static org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace.MAX_DATE_PARAM;
import static org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace.MIN_DATE_PARAM;
import static org.sagebionetworks.web.client.presenter.ACTDataAccessSubmissionsPresenter.SHOW_AR_TEXT;

import java.util.Collections;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.repo.model.ACTAccessRequirement;
import org.sagebionetworks.repo.model.RestrictableObjectDescriptor;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmission;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmissionOrder;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmissionPage;
import org.sagebionetworks.repo.model.dataaccess.DataAccessSubmissionState;
import org.sagebionetworks.repo.model.file.FileHandleAssociateType;
import org.sagebionetworks.repo.model.file.FileHandleAssociation;
import org.sagebionetworks.web.client.DataAccessClientAsync;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.place.ACTDataAccessSubmissionsPlace;
import org.sagebionetworks.web.client.presenter.ACTDataAccessSubmissionsPresenter;
import org.sagebionetworks.web.client.utils.Callback;
import org.sagebionetworks.web.client.view.ACTDataAccessSubmissionsView;
import org.sagebionetworks.web.client.widget.Button;
import org.sagebionetworks.web.client.widget.FileHandleWidget;
import org.sagebionetworks.web.client.widget.LoadMoreWidgetContainer;
import org.sagebionetworks.web.client.widget.accessrequirements.ACTAccessRequirementWidget;
import org.sagebionetworks.web.client.widget.accessrequirements.SubjectsWidget;
import org.sagebionetworks.web.client.widget.accessrequirements.submission.ACTDataAccessSubmissionWidget;
import org.sagebionetworks.web.client.widget.entity.controller.SynapseAlert;
import org.sagebionetworks.web.test.helper.AsyncMockStubber;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;

public class ACTDataAccessSubmissionsPresenterTest {
	
	ACTDataAccessSubmissionsPresenter presenter;
	
	@Mock
	ACTDataAccessSubmissionsPlace mockPlace;
	
	@Mock
	ACTDataAccessSubmissionsView mockView;
	@Mock
	SynapseAlert mockSynAlert;
	@Mock
	PortalGinInjector mockGinInjector;
	@Mock
	GlobalApplicationState mockGlobalApplicationState;
	@Mock
	LoadMoreWidgetContainer mockLoadMoreContainer;
	@Mock
	ACTAccessRequirementWidget mockACTAccessRequirementWidget;
	@Mock
	Button mockButton;
	@Mock
	FileHandleWidget mockDucTemplateFileHandleWidget;
	@Mock
	DataAccessClientAsync mockDataAccessClient;
	
	@Mock
	ACTAccessRequirement mockACTAccessRequirement;
	@Mock
	DataAccessSubmissionPage mockDataAccessSubmissionPage;
	@Mock
	DataAccessSubmission mockDataAccessSubmission;
	@Captor
	ArgumentCaptor<FileHandleAssociation> fhaCaptor;
	@Mock
	ACTDataAccessSubmissionWidget mockACTDataAccessSubmissionWidget;
	@Mock
	SubjectsWidget mockSubjectsWidget;
	@Mock
	List<RestrictableObjectDescriptor> mockSubjects;
	public static final String FILE_HANDLE_ID = "9999";
	public static final Long AR_ID = 76555L;
	public static final String NEXT_PAGE_TOKEN = "<PASSWORD>";
	
	@Before
	public void setup(){
		MockitoAnnotations.initMocks(this);
		presenter = new ACTDataAccessSubmissionsPresenter(mockView, mockSynAlert, mockGinInjector, mockGlobalApplicationState, mockLoadMoreContainer, mockACTAccessRequirementWidget, mockButton, mockDucTemplateFileHandleWidget, mockDataAccessClient, mockSubjectsWidget);
		AsyncMockStubber.callSuccessWith(mockACTAccessRequirement).when(mockDataAccessClient).getAccessRequirement(anyLong(), any(AsyncCallback.class));
		AsyncMockStubber.callSuccessWith(mockDataAccessSubmissionPage).when(mockDataAccessClient).getDataAccessSubmissions(anyLong(), anyString(), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));
		when(mockDataAccessSubmissionPage.getResults()).thenReturn(Collections.singletonList(mockDataAccessSubmission));
		when(mockDataAccessSubmissionPage.getNextPageToken()).thenReturn(NEXT_PAGE_TOKEN);
		when(mockACTAccessRequirement.getDucTemplateFileHandleId()).thenReturn(FILE_HANDLE_ID);
		when(mockACTAccessRequirement.getId()).thenReturn(AR_ID);
		when(mockGinInjector.getACTDataAccessSubmissionWidget()).thenReturn(mockACTDataAccessSubmissionWidget);
		when(mockACTAccessRequirement.getSubjectIds()).thenReturn(mockSubjects);
	}	
	
	@Test
	public void testConstruction() {
		verify(mockView).setStates(anyList());
		verify(mockButton).setText(SHOW_AR_TEXT);
		verify(mockView).setAccessRequirementUIVisible(false);
		verify(mockView).setSynAlert(any(IsWidget.class));
		verify(mockView).setAccessRequirementWidget(any(IsWidget.class));
		verify(mockView).setLoadMoreContainer(any(IsWidget.class));
		verify(mockView).setShowHideButton(any(IsWidget.class));
		verify(mockView).setPresenter(presenter);
		verify(mockLoadMoreContainer).configure(any(Callback.class));
		verify(mockButton).addClickHandler(any(ClickHandler.class));
	}
	
	@Test
	public void testLoadData() {
		String time1 = "8765";
		String time2 = "5678";
		when(mockPlace.getParam(MIN_DATE_PARAM)).thenReturn(time1);
		when(mockPlace.getParam(MAX_DATE_PARAM)).thenReturn(time2);
		when(mockPlace.getParam(ACCESS_REQUIREMENT_ID_PARAM)).thenReturn(AR_ID.toString());
		
		when(mockACTAccessRequirement.getDucTemplateFileHandleId()).thenReturn(FILE_HANDLE_ID);
		when(mockACTAccessRequirement.getAreOtherAttachmentsRequired()).thenReturn(true);
		when(mockACTAccessRequirement.getIsAnnualReviewRequired()).thenReturn(false);
		when(mockACTAccessRequirement.getIsCertifiedUserRequired()).thenReturn(true);
		when(mockACTAccessRequirement.getIsDUCRequired()).thenReturn(false);
		when(mockACTAccessRequirement.getIsIDUPublic()).thenReturn(true);
		when(mockACTAccessRequirement.getIsIRBApprovalRequired()).thenReturn(false);
		when(mockACTAccessRequirement.getIsValidatedProfileRequired()).thenReturn(true);
		
		presenter.setPlace(mockPlace);
		verify(mockDataAccessClient).getAccessRequirement(eq(AR_ID), any(AsyncCallback.class));
		
		//verify duc template file handle widget is configured properly (basd on act duc file handle id)
		verify(mockDucTemplateFileHandleWidget).configure(fhaCaptor.capture());
		FileHandleAssociation fha = fhaCaptor.getValue();
		assertEquals(FileHandleAssociateType.AccessRequirementAttachment, fha.getAssociateObjectType());
		assertEquals(AR_ID.toString(), fha.getAssociateObjectId());
		assertEquals(FILE_HANDLE_ID, fha.getFileHandleId());
		verify(mockSubjectsWidget).configure(mockSubjects, true);
		verify(mockView).setAreOtherAttachmentsRequired(true);
		verify(mockView).setIsAnnualReviewRequired(false);
		verify(mockView).setIsCertifiedUserRequired(true);
		verify(mockView).setIsDUCRequired(false);
		verify(mockView).setIsIDUPublic(true);
		verify(mockView).setIsIRBApprovalRequired(false);
		verify(mockView).setIsValidatedProfileRequired(true);
		
		verify(mockACTAccessRequirementWidget).setRequirement(mockACTAccessRequirement);
		verify(mockDataAccessClient).getDataAccessSubmissions(anyLong(), eq((String)null), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));

		//verify DataAccessSubmission widget is created/configured for the submission (based on the mockACTAccessRequirement configuration)
		verify(mockGinInjector).getACTDataAccessSubmissionWidget();
		verify(mockACTDataAccessSubmissionWidget).setDucColumnVisible(false);
		verify(mockACTDataAccessSubmissionWidget).setIrbColumnVisible(false);
		verify(mockACTDataAccessSubmissionWidget).setOtherAttachmentsColumnVisible(true);
		verify(mockACTDataAccessSubmissionWidget).setRenewalColumnsVisible(false);
		verify(mockLoadMoreContainer).setIsMore(true);
		
		//verify final load of empty page
		when(mockDataAccessSubmissionPage.getResults()).thenReturn(Collections.EMPTY_LIST);
		when(mockDataAccessSubmissionPage.getNextPageToken()).thenReturn(null);
		presenter.loadMore();
		verify(mockDataAccessClient).getDataAccessSubmissions(anyLong(), eq(NEXT_PAGE_TOKEN), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));
		verify(mockLoadMoreContainer).setIsMore(false);
	}
	
	@Test
	public void testLoadDataFailure() {
		Exception ex = new Exception();
		AsyncMockStubber.callFailureWith(ex).when(mockDataAccessClient).getDataAccessSubmissions(anyLong(), anyString(), any(DataAccessSubmissionState.class), any(DataAccessSubmissionOrder.class), anyBoolean(), any(AsyncCallback.class));
		presenter.loadData();
		verify(mockSynAlert).handleException(ex);
		verify(mockLoadMoreContainer).setIsMore(false);
	}
}

{'fraction_non_alphanumeric': 0.09659540775930324, 'fraction_numerical': 0.0022169437846397467, 'mean_word_length': 9.450082735797022, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5401487', 'n_tokens_mistral': 5923, 'n_tokens_neox': 5694, 'n_words': 686}