<commit_before>package org.sagebionetworks.web.unitclient.widget.entity.file;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.repo.model.EntityBundle;
import org.sagebionetworks.repo.model.FileEntity;
import org.sagebionetworks.repo.model.file.ExternalObjectStoreFileHandle;
import org.sagebionetworks.repo.model.file.FileHandle;
import org.sagebionetworks.repo.model.file.S3FileHandle;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.events.EntityUpdatedHandler;
import org.sagebionetworks.web.client.security.AuthenticationController;
import org.sagebionetworks.web.client.widget.entity.file.FileDownloadButton;
import org.sagebionetworks.web.client.widget.entity.file.FileTitleBar;
import org.sagebionetworks.web.client.widget.entity.file.FileTitleBarView;

import com.google.gwt.user.client.ui.Widget;

import junit.framework.Assert;

public class FileTitleBarTest {
		
	FileTitleBar fileTitleBar;
	FileTitleBarView mockView;
	AuthenticationController mockAuthController;
	
	EntityBundle mockBundle;
	GlobalApplicationState mockGlobalAppState;
	org.sagebionetworks.repo.model.FileEntity mockFileEntity;
	S3FileHandle handle;
	Long synStorageLocationId = 1L;
	@Mock
	FileDownloadButton mockFileDownloadButton;
	@Mock
	EntityUpdatedHandler mockEntityUpdatedHandler;
	@Mock
	ExternalObjectStoreFileHandle mockExternalObjectStoreFileHandle;
	
	@Before
	public void setup(){
		MockitoAnnotations.initMocks(this);
		mockView = mock(FileTitleBarView.class);
		mockAuthController = mock(AuthenticationController.class);
		mockGlobalAppState = mock(GlobalApplicationState.class);
		fileTitleBar = new FileTitleBar(mockView, mockAuthController, mockGlobalAppState, mockFileDownloadButton);
		mockBundle = mock(EntityBundle.class);
		mockFileEntity = mock(org.sagebionetworks.repo.model.FileEntity.class);
		Mockito.when(mockFileEntity.getId()).thenReturn("syn123");
		Mockito.when(mockFileEntity.getName()).thenReturn("syn123");
		Mockito.when(mockFileEntity.getDataFileHandleId()).thenReturn("syn123");
		Mockito.when(mockBundle.getEntity()).thenReturn(mockFileEntity);
		Mockito.when(mockGlobalAppState.getSynapseProperty("org.sagebionetworks.portal.synapse_storage_id"))
				.thenReturn(String.valueOf(synStorageLocationId));
		List<FileHandle> fileHandles = new LinkedList<FileHandle>();
		handle = new S3FileHandle();
		handle.setId("syn123");
		handle.setBucketName("testBucket");
		handle.setKey("testKey");
		handle.setStorageLocationId(synStorageLocationId);
		fileHandles.add(handle);
		Mockito.when(mockBundle.getFileHandles()).thenReturn(fileHandles);
		verify(mockView).setPresenter(fileTitleBar);
		verify(mockView).setFileDownloadButton(any(Widget.class));
	}
	
	@Test
	public void testAsWidget(){
		fileTitleBar.asWidget();
	}
	
	@Test
	public void testIsDataNotInFile() {
		FileEntity fileEntity = new FileEntity();
		fileEntity.setDataFileHandleId(null);
		Assert.assertFalse(FileTitleBar.isDataPossiblyWithin(fileEntity));
	}
	
	@Test
	public void testIsDataInFile() {
		FileEntity fileEntity = new FileEntity();
		fileEntity.setDataFileHandleId("123");
		Assert.assertTrue(FileTitleBar.isDataPossiblyWithin(fileEntity));
	}

	@Test
	public void testSetS3DescriptionForSynapseStorage() {
		fileTitleBar.configure(mockBundle);
		verify(mockView).setFileLocation("| Synapse Storage");
	}

	@Test
	public void testSetS3DescriptionForExternalS3() {
		handle.setStorageLocationId(2L);
		fileTitleBar.configure(mockBundle);
		verify(mockView).setFileLocation("| s3://" + handle.getBucketName() + "/" + handle.getKey());
	}
	
	@Test
	public void testConfigure() {
		FileEntity fileEntity = new FileEntity();
		when(mockBundle.getEntity()).thenReturn(fileEntity);
		fileTitleBar.configure(mockBundle);
		verify(mockFileDownloadButton).configure(mockBundle);
	}
	
	@Test
	public void testSetEntityUpdateHandler() {
		fileTitleBar.setEntityUpdatedHandler(mockEntityUpdatedHandler);
		verify(mockFileDownloadButton).setEntityUpdatedHandler(mockEntityUpdatedHandler);
	}
	
	@Test
	public void testExternalObjectStoreFileHandle() {
		String md5 = "878ac";
		Long contentSize = 73483L;
		when(mockExternalObjectStoreFileHandle.getContentMd5()).thenReturn(md5);
		when(mockExternalObjectStoreFileHandle.getContentSize()).thenReturn();
		when(mockExternalObjectStoreFileHandle.).thenReturn();
		when(mockExternalObjectStoreFileHandle.).thenReturn();
		when(mockExternalObjectStoreFileHandle.).thenReturn();
		when(mockExternalObjectStoreFileHandle.).thenReturn();
		
		Mockito.when(mockBundle.getFileHandles()).thenReturn(Collections.singletonList((FileHandle)mockExternalObjectStoreFileHandle));
		fileTitleBar.configure(mockBundle);
		verify(mockFileDownloadButton).configure(mockBundle);
	}
}<commit_msg>test new external object store file handle rendering in title bar<commit_after>package org.sagebionetworks.web.unitclient.widget.entity.file;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

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

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.repo.model.EntityBundle;
import org.sagebionetworks.repo.model.FileEntity;
import org.sagebionetworks.repo.model.file.ExternalObjectStoreFileHandle;
import org.sagebionetworks.repo.model.file.FileHandle;
import org.sagebionetworks.repo.model.file.S3FileHandle;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.events.EntityUpdatedHandler;
import org.sagebionetworks.web.client.security.AuthenticationController;
import org.sagebionetworks.web.client.widget.entity.file.FileDownloadButton;
import org.sagebionetworks.web.client.widget.entity.file.FileTitleBar;
import org.sagebionetworks.web.client.widget.entity.file.FileTitleBarView;

import com.google.gwt.user.client.ui.Widget;

import junit.framework.Assert;

public class FileTitleBarTest {
		
	FileTitleBar fileTitleBar;
	FileTitleBarView mockView;
	AuthenticationController mockAuthController;
	
	EntityBundle mockBundle;
	GlobalApplicationState mockGlobalAppState;
	org.sagebionetworks.repo.model.FileEntity mockFileEntity;
	S3FileHandle handle;
	Long synStorageLocationId = 1L;
	@Mock
	FileDownloadButton mockFileDownloadButton;
	@Mock
	EntityUpdatedHandler mockEntityUpdatedHandler;
	@Mock
	ExternalObjectStoreFileHandle mockExternalObjectStoreFileHandle;
	public static final String DATA_FILE_HANDLE_ID = "872";
	@Before
	public void setup(){
		MockitoAnnotations.initMocks(this);
		mockView = mock(FileTitleBarView.class);
		mockAuthController = mock(AuthenticationController.class);
		mockGlobalAppState = mock(GlobalApplicationState.class);
		fileTitleBar = new FileTitleBar(mockView, mockAuthController, mockGlobalAppState, mockFileDownloadButton);
		mockBundle = mock(EntityBundle.class);
		mockFileEntity = mock(org.sagebionetworks.repo.model.FileEntity.class);
		Mockito.when(mockFileEntity.getId()).thenReturn("syn123");
		Mockito.when(mockFileEntity.getName()).thenReturn("syn123");
		Mockito.when(mockFileEntity.getDataFileHandleId()).thenReturn(DATA_FILE_HANDLE_ID);
		Mockito.when(mockBundle.getEntity()).thenReturn(mockFileEntity);
		Mockito.when(mockGlobalAppState.getSynapseProperty("org.sagebionetworks.portal.synapse_storage_id"))
				.thenReturn(String.valueOf(synStorageLocationId));
		List<FileHandle> fileHandles = new LinkedList<FileHandle>();
		handle = new S3FileHandle();
		handle.setId(DATA_FILE_HANDLE_ID);
		handle.setBucketName("testBucket");
		handle.setKey("testKey");
		handle.setStorageLocationId(synStorageLocationId);
		fileHandles.add(handle);
		Mockito.when(mockBundle.getFileHandles()).thenReturn(fileHandles);
		verify(mockView).setPresenter(fileTitleBar);
		verify(mockView).setFileDownloadButton(any(Widget.class));
	}
	
	@Test
	public void testAsWidget(){
		fileTitleBar.asWidget();
	}
	
	@Test
	public void testIsDataNotInFile() {
		FileEntity fileEntity = new FileEntity();
		fileEntity.setDataFileHandleId(null);
		Assert.assertFalse(FileTitleBar.isDataPossiblyWithin(fileEntity));
	}
	
	@Test
	public void testIsDataInFile() {
		FileEntity fileEntity = new FileEntity();
		fileEntity.setDataFileHandleId("123");
		Assert.assertTrue(FileTitleBar.isDataPossiblyWithin(fileEntity));
	}

	@Test
	public void testSetS3DescriptionForSynapseStorage() {
		fileTitleBar.configure(mockBundle);
		verify(mockView).setFileLocation("| Synapse Storage");
	}

	@Test
	public void testSetS3DescriptionForExternalS3() {
		handle.setStorageLocationId(2L);
		fileTitleBar.configure(mockBundle);
		verify(mockView).setFileLocation("| s3://" + handle.getBucketName() + "/" + handle.getKey());
	}
	
	@Test
	public void testConfigure() {
		FileEntity fileEntity = new FileEntity();
		when(mockBundle.getEntity()).thenReturn(fileEntity);
		fileTitleBar.configure(mockBundle);
		verify(mockFileDownloadButton).configure(mockBundle);
	}
	
	@Test
	public void testSetEntityUpdateHandler() {
		fileTitleBar.setEntityUpdatedHandler(mockEntityUpdatedHandler);
		verify(mockFileDownloadButton).setEntityUpdatedHandler(mockEntityUpdatedHandler);
	}
	
	@Test
	public void testExternalObjectStoreFileHandle() {
		String md5 = "878ac";
		String endpoint = "https://test.test";
		String bucket = "mybucket";
		String fileKey = "567898765sdfgfd/test.txt";
		when(mockExternalObjectStoreFileHandle.getId()).thenReturn(DATA_FILE_HANDLE_ID);
		when(mockExternalObjectStoreFileHandle.getContentMd5()).thenReturn(md5);
		when(mockExternalObjectStoreFileHandle.getContentSize()).thenReturn(null);
		
		when(mockExternalObjectStoreFileHandle.getEndpointUrl()).thenReturn(endpoint);
		when(mockExternalObjectStoreFileHandle.getBucket()).thenReturn(bucket);
		when(mockExternalObjectStoreFileHandle.getFileKey()).thenReturn(fileKey);
		
		Mockito.when(mockBundle.getFileHandles()).thenReturn(Collections.singletonList((FileHandle)mockExternalObjectStoreFileHandle));
		fileTitleBar.configure(mockBundle);
		verify(mockFileDownloadButton).configure(mockBundle);
		verify(mockView).setExternalUrlUIVisible(true);
		verify(mockView).setExternalUrl(endpoint + "/" + bucket + "/" + fileKey);
	}
}
{'fraction_non_alphanumeric': 0.1078550697500234, 'fraction_numerical': 0.006647317666885123, 'mean_word_length': 7.471054718477399, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5836164', 'n_tokens_mistral': 3448, 'n_tokens_neox': 3255, 'n_words': 438}