Skip to content

Commit dfacfc9

Browse files
committed
670 - fix tests
1 parent 0af881b commit dfacfc9

File tree

8 files changed

+48
-28
lines changed

8 files changed

+48
-28
lines changed

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/AbstractGoogleDriveActionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class AbstractGoogleDriveActionTest {
4343
protected ArgumentCaptor<File> fileArgumentCaptor = ArgumentCaptor.forClass(File.class);
4444
protected ArgumentCaptor<String> fileIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
4545
protected MockedStatic<GoogleServices> googleServicesMockedStatic;
46-
protected ActionContext mockedContext = mock(ActionContext.class);
46+
protected ActionContext mockedActionContext = mock(ActionContext.class);
4747
protected Drive.Files.Create mockedCreate = mock(Drive.Files.Create.class);
4848
protected Drive.Files.Copy mockedCopy = mock(Drive.Files.Copy.class);
4949
protected Drive mockedDrive = mock(Drive.class);

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveCopyFileActionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void testPerform() throws IOException {
5353
when(mockedCopy.execute())
5454
.thenReturn(testFile);
5555

56-
File copiedFile = GoogleDriveCopyFileAction.perform(mockInputParameters, mockInputParameters, mockedContext);
56+
File copiedFile =
57+
GoogleDriveCopyFileAction.perform(mockInputParameters, mockInputParameters, mockedActionContext);
5758

5859
verify(mockedDrive.files()).get("originalFileId");
5960
verify(mockedFiles).copy("originalFileId", testFile);

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveCreateNewFolderActionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void testPerform() throws IOException {
4646
when(mockedCreate.execute())
4747
.thenReturn(mockedGoogleFile);
4848

49-
File result = GoogleDriveCreateNewFolderAction.perform(mockedParameters, mockedParameters, mockedContext);
49+
File result = GoogleDriveCreateNewFolderAction.perform(mockedParameters, mockedParameters, mockedActionContext);
5050

5151
assertEquals(mockedGoogleFile, result);
5252

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveCreateNewTextFileActionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void testPerform() throws IOException {
5353
when(mockedCreate.execute())
5454
.thenReturn(mockedGoogleFile);
5555

56-
File result = GoogleDriveCreateNewTextFileAction.perform(mockedParameters, mockedParameters, mockedContext);
56+
File result =
57+
GoogleDriveCreateNewTextFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
5758

5859
assertEquals(mockedGoogleFile, result);
5960

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveDeleteFileActionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void testPerform() throws IOException {
4949
.when(mockedDelete)
5050
.execute();
5151

52-
GoogleDriveDeleteFileAction.perform(mockedParameters, mockedParameters, mockedContext);
52+
GoogleDriveDeleteFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
5353

5454
assertEquals("testId", fileIdArgumentCaptor.getValue());
5555

@@ -66,7 +66,7 @@ void testPerformThrowsIOException() throws IOException {
6666
.execute();
6767

6868
assertThrows(IOException.class,
69-
() -> GoogleDriveDeleteFileAction.perform(mockedParameters, mockedParameters, mockedContext));
69+
() -> GoogleDriveDeleteFileAction.perform(mockedParameters, mockedParameters, mockedActionContext));
7070

7171
assertEquals("testId", fileIdArgumentCaptor.getValue());
7272
}

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveDownloadFileActionTest.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.bytechef.component.google.drive.action;
1818

19+
import static com.bytechef.commons.util.MimeTypeUtils.MIME_APPLICATION_MSWORD_2007;
1920
import static com.bytechef.component.google.drive.constant.GoogleDriveConstants.FILE_ID;
2021
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.mockito.ArgumentMatchers.any;
@@ -27,10 +28,8 @@
2728
import com.bytechef.component.test.definition.MockParametersFactory;
2829
import com.google.api.services.drive.Drive;
2930
import com.google.api.services.drive.model.File;
30-
import com.google.api.services.drive.model.FileList;
3131
import java.io.IOException;
3232
import java.io.InputStream;
33-
import java.util.List;
3433
import java.util.Map;
3534
import org.junit.jupiter.api.Test;
3635
import org.mockito.ArgumentCaptor;
@@ -42,37 +41,56 @@
4241
class GoogleDriveDownloadFileActionTest extends AbstractGoogleDriveActionTest {
4342

4443
private final InputStream mockedInputStream = mock(InputStream.class);
45-
private final Drive.Files.List mockedList = mock(Drive.Files.List.class);
46-
private final FileList mockedFileList = mock(FileList.class);
4744
private final FileEntry mockedFileEntry = mock(FileEntry.class);
4845
private final Parameters mockedParameters = MockParametersFactory.create(Map.of(FILE_ID, "fileId"));
49-
private final ArgumentCaptor<String> qArgumentCaptor = ArgumentCaptor.forClass(String.class);
46+
private final Drive.Files.Export mockedExport = mock(Drive.Files.Export.class);
47+
private final ArgumentCaptor<String> exportMimeTypeArgumentCaptor = ArgumentCaptor.forClass(String.class);
5048

5149
@Test
52-
void testPerform() throws IOException {
50+
void testPerformWithGoogleDoc() throws IOException {
5351
when(mockedFiles.get(fileIdArgumentCaptor.capture()))
5452
.thenReturn(mockedGet);
53+
when(mockedGet.execute())
54+
.thenReturn(new File().setName("testDoc")
55+
.setMimeType("application/vnd.google-apps.document"));
56+
57+
when(mockedFiles.export(fileIdArgumentCaptor.capture(), exportMimeTypeArgumentCaptor.capture()))
58+
.thenReturn(mockedExport);
59+
when(mockedExport.executeMediaAsInputStream())
60+
.thenReturn(mockedInputStream);
61+
62+
when(mockedActionContext.file(any()))
63+
.thenReturn(mockedFileEntry);
64+
65+
FileEntry result =
66+
GoogleDriveDownloadFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
67+
68+
assertEquals(mockedFileEntry, result);
69+
70+
assertEquals("fileId", fileIdArgumentCaptor.getValue());
71+
assertEquals(MIME_APPLICATION_MSWORD_2007, exportMimeTypeArgumentCaptor.getValue());
72+
}
73+
74+
@Test
75+
void testPerformWithNonGoogleDoc() throws IOException {
76+
when(mockedFiles.get(fileIdArgumentCaptor.capture()))
77+
.thenReturn(mockedGet);
78+
when(mockedGet.execute())
79+
.thenReturn(new File().setName("testDoc")
80+
.setMimeType("application/pdf")
81+
.setFileExtension("pdf"));
82+
5583
when(mockedGet.executeMediaAsInputStream())
5684
.thenReturn(mockedInputStream);
5785

58-
when(mockedFiles.list())
59-
.thenReturn(mockedList);
60-
when(mockedList.setQ(qArgumentCaptor.capture()))
61-
.thenReturn(mockedList);
62-
when(mockedList.execute())
63-
.thenReturn(mockedFileList);
64-
when(mockedFileList.getFiles())
65-
.thenReturn(List.of(new File().setId("fileId")
66-
.setName("fileName")));
67-
68-
when(mockedContext.file(any()))
86+
when(mockedActionContext.file(any()))
6987
.thenReturn(mockedFileEntry);
7088

71-
FileEntry result = GoogleDriveDownloadFileAction.perform(mockedParameters, mockedParameters, mockedContext);
89+
FileEntry result =
90+
GoogleDriveDownloadFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
7291

7392
assertEquals(mockedFileEntry, result);
7493

7594
assertEquals("fileId", fileIdArgumentCaptor.getValue());
76-
assertEquals("mimeType != 'application/vnd.google-apps.folder'", qArgumentCaptor.getValue());
7795
}
7896
}

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveGetFileActionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void testPerform() throws IOException {
4848
when(mockedGet.execute())
4949
.thenReturn(testFile);
5050

51-
File retrievedFile = GoogleDriveGetFileAction.perform(mockedParameters, mockedParameters, mockedContext);
51+
File retrievedFile = GoogleDriveGetFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
5252

5353
verify(mockedDrive.files()).get("testId");
5454

server/libs/modules/components/google/google-drive/src/test/java/com/bytechef/component/google/drive/action/GoogleDriveUploadFileActionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ void testPerform() throws IOException {
5050
.thenReturn("name");
5151
when(mockedFileEntry.getMimeType())
5252
.thenReturn("mimeType");
53-
when(mockedContext.file(any()))
53+
when(mockedActionContext.file(any()))
5454
.thenReturn(mockedFile);
5555

5656
when(mockedFiles.create(fileArgumentCaptor.capture(), abstractInputStreamContentArgumentCaptor.capture()))
5757
.thenReturn(mockedCreate);
5858
when(mockedCreate.execute())
5959
.thenReturn(mockedGoogleFile);
6060

61-
File result = GoogleDriveUploadFileAction.perform(mockedParameters, mockedParameters, mockedContext);
61+
File result = GoogleDriveUploadFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
6262

6363
assertEquals(mockedGoogleFile, result);
6464

0 commit comments

Comments
 (0)