/*
 * Copyright 2018 Forschungszentrum Jülich GmbH
 * SPDX-License-Identifier: Apache 2.0
 */
package edu.harvard.iq.dataverse.dataaccess;

import com.amazonaws.services.s3.AmazonS3;
import edu.harvard.iq.dataverse.DataFile;
import edu.harvard.iq.dataverse.Dataset;
import edu.harvard.iq.dataverse.api.UtilIT;
import edu.harvard.iq.dataverse.mocks.MocksFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import java.io.IOException;

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.STRICT_STUBS)
public class S3AccessIOTest {
    
    @Mock
    private AmazonS3 s3client;
    
    private S3AccessIO<Dataset> dataSetAccess;
    private S3AccessIO<DataFile> dataFileAccess;
    private Dataset dataSet;
    private DataFile dataFile;
    private String dataFileId;
    
    @BeforeEach
    public void setup() throws IOException {
        dataFile = MocksFactory.makeDataFile();
        dataSet = MocksFactory.makeDataset();
        dataFile.setOwner(dataSet);
        dataFileId = UtilIT.getRandomIdentifier();
        dataFile.setStorageIdentifier("s3://bucket:"+dataFileId);
        dataSetAccess = new S3AccessIO<>(dataSet, null, s3client);
        dataFileAccess = new S3AccessIO<>(dataFile, null, s3client);
    }
    
    /*
    createTempFile
    getStorageLocation
    getFileSystemPath
    exists?
    getWriteChannel
    getOutputStream
    getDestinationKey
    getMainFileKey
    getUrlExpirationMinutes
     */
    
}

@@ -429,28 +429,113 @@
 api.
-extension.ExtendWith
+Test;%0Aimport org.junit.jupiter.api.extension.ExtendWith;%0Aimport static org.junit.jupiter.api.Assertions.*
 ;%0Aim
@@ -693,24 +693,139 @@
 Strictness;%0A
+import static org.mockito.Mockito.*;%0Aimport static org.mockito.BDDMockito.*;%0A%0Aimport java.io.FileNotFoundException;
 %0Aimport java
@@ -1802,24 +1802,64 @@
 tinationKey%0A
+    %0A    DONE%0A    ---------------------%0A
     getMainF
@@ -1906,10 +1906,1870 @@
 */%0A    %0A
+    @Test%0A    void keyNull_getMainFileKey() throws IOException %7B%0A        // given%0A        String authOwner = dataSet.getAuthority();%0A        String idOwner = dataSet.getIdentifier();%0A        %0A        // when%0A        String key = dataFileAccess.getMainFileKey();%0A        %0A        // then%0A        assertEquals(authOwner+%22/%22+idOwner+%22/%22+dataFileId, key);%0A    %7D%0A    %0A    @Test%0A    void keyNullstorageIdNullOrEmpty_getMainFileKey() throws IOException %7B%0A        // given%0A        dataFile.setStorageIdentifier(null);%0A        // when & then%0A        assertThrows(FileNotFoundException.class, () -%3E %7BdataFileAccess.getMainFileKey(); %7D);%0A    %0A        // given%0A        dataFile.setStorageIdentifier(%22%22);%0A        // when & then%0A        assertThrows(FileNotFoundException.class, () -%3E %7BdataFileAccess.getMainFileKey(); %7D);%0A    %7D%0A    %0A    @Test%0A    void keyNullstorageIdNull_getMainFileKey() throws IOException %7B%0A        // given%0A        dataFile.setStorageIdentifier(%22invalid://abcd%22);%0A        // when & then%0A        assertThrows(IOException.class, () -%3E %7BdataFileAccess.getMainFileKey(); %7D);%0A    %7D%0A    %0A    @Test%0A    void default_getUrlExpirationMinutes() %7B%0A        // given%0A        System.clearProperty(%22dataverse.files.s3-url-expiration-minutes%22);%0A        // when & then%0A        assertEquals(60, dataFileAccess.getUrlExpirationMinutes());%0A    %7D%0A    %0A    @Test%0A    void validSetting_getUrlExpirationMinutes() %7B%0A        // given%0A        System.setProperty(%22dataverse.files.s3-url-expiration-minutes%22, %22120%22);%0A        // when & then%0A        assertEquals(120, dataFileAccess.getUrlExpirationMinutes());%0A    %7D%0A    %0A    @Test%0A    void invalidSetting_getUrlExpirationMinutes() %7B%0A        // given%0A        System.setProperty(%22dataverse.files.s3-url-expiration-minutes%22, %22NaN%22);%0A        // when & then%0A        assertEquals(60, dataFileAccess.getUrlExpirationMinutes());%0A    %7D%0A    %0A
 %7D%0A

Add some very minor unit tests to S3AccessIO. This should be enhanced, as the class could use some refactoring and more documentation.