package org.sagebionetworks.dashboard.dao.redshift;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.sagebionetworks.dashboard.dao.BridgeImportDao;
import org.sagebionetworks.dashboard.dao.DwDao;
import org.springframework.test.util.ReflectionTestUtils;

public class BridgeImportDaoImplTest {

    @Test
    public void testCreateDropTable() {

        final String tableName = "test_table";
        final String dateSuffix = "date_suffix";
        final String fullTableName = tableName + "_" + dateSuffix;
        final List<String> tableList = Arrays.asList(fullTableName);
        DwDao mockDwDao = mock(DwDao.class);
        when(mockDwDao.getTables(tableName)).thenReturn(tableList);
        BridgeImportDao dao = new BridgeImportDaoImpl();
        ReflectionTestUtils.setField(dao, "dwDao", mockDwDao, DwDao.class);

        final String tableCreated = dao.createTable(tableName, dateSuffix);
        assertEquals(fullTableName, tableCreated);
        verify(mockDwDao, times(1)).execute(startsWith("CREATE TABLE "));

        final String tableDropped = dao.dropTable(tableName, dateSuffix);
        assertEquals(fullTableName, tableDropped);
        verify(mockDwDao, times(1)).execute(startsWith("DROP TABLE "));
    }
}

@@ -373,16 +373,70 @@
 t.Test;%0A
+import org.sagebionetworks.dashboard.config.DwConfig;%0A
 import o
@@ -1566,11 +1566,1014 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testCopyFromDynamo() %7B%0A        BridgeImportDao dao = new BridgeImportDaoImpl();%0A        DwConfig mockConfig = mock(DwConfig.class);%0A        when(mockConfig.getBridgeAwsAccessKey()).thenReturn(%22accessKey%22);%0A        when(mockConfig.getBridgeAwsSecretKey()).thenReturn(%22secretKey%22);%0A        ReflectionTestUtils.setField(dao, %22dwConfig%22, mockConfig);%0A        DwDao mockDwDao = mock(DwDao.class);%0A        ReflectionTestUtils.setField(dao, %22dwDao%22, mockDwDao, DwDao.class);%0A        dao.copyFromDynamo(%22dynamo%22, %22redshift%22);%0A        verify(mockDwDao, times(1)).execute(startsWith(%22COPY redshift FROM 'dynamodb://'%22));%0A    %7D%0A%0A    @Test%0A    public void testUpdateView() %7B%0A        BridgeImportDao dao = new BridgeImportDaoImpl();%0A        DwDao mockDwDao = mock(DwDao.class);%0A        ReflectionTestUtils.setField(dao, %22dwDao%22, mockDwDao, DwDao.class);%0A        dao.updateView(%22table%22, %22snapshot%22);%0A        verify(mockDwDao, times(1)).execute(startsWith(%22CREATE OR REPLACE VIEW %22));%0A    %7D
 %0A%7D%0A

Add mocked tests