Skip to content

Commit d60a319

Browse files
committed
670 - fix tests
1 parent 8162541 commit d60a319

File tree

8 files changed

+53
-28
lines changed

8 files changed

+53
-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: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
import com.bytechef.component.test.definition.MockParametersFactory;
2828
import com.google.api.services.drive.Drive;
2929
import com.google.api.services.drive.model.File;
30-
import com.google.api.services.drive.model.FileList;
3130
import java.io.IOException;
3231
import java.io.InputStream;
33-
import java.util.List;
3432
import java.util.Map;
3533
import org.junit.jupiter.api.Test;
3634
import org.mockito.ArgumentCaptor;
@@ -42,37 +40,62 @@
4240
class GoogleDriveDownloadFileActionTest extends AbstractGoogleDriveActionTest {
4341

4442
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);
4743
private final FileEntry mockedFileEntry = mock(FileEntry.class);
4844
private final Parameters mockedParameters = MockParametersFactory.create(Map.of(FILE_ID, "fileId"));
49-
private final ArgumentCaptor<String> qArgumentCaptor = ArgumentCaptor.forClass(String.class);
45+
private final Drive.Files.Export mockedExport = mock(Drive.Files.Export.class);
46+
private final ArgumentCaptor<String> exportMimeTypeArgumentCaptor = ArgumentCaptor.forClass(String.class);
5047

5148
@Test
52-
void testPerform() throws IOException {
49+
void testPerformWithGoogleDoc() throws IOException {
5350
when(mockedFiles.get(fileIdArgumentCaptor.capture()))
5451
.thenReturn(mockedGet);
52+
when(mockedGet.execute())
53+
.thenReturn(new File().setName("testDoc")
54+
.setMimeType("application/vnd.google-apps.document"));
55+
56+
when(mockedFiles.export(fileIdArgumentCaptor.capture(), exportMimeTypeArgumentCaptor.capture()))
57+
.thenReturn(mockedExport);
58+
when(mockedExport.executeMediaAsInputStream())
59+
.thenReturn(mockedInputStream);
60+
61+
when(mockedActionContext.mimeType(any()))
62+
.thenReturn("type");
63+
when(mockedActionContext.file(any()))
64+
.thenReturn(mockedFileEntry);
65+
66+
FileEntry result =
67+
GoogleDriveDownloadFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
68+
69+
assertEquals(mockedFileEntry, result);
70+
71+
assertEquals("fileId", fileIdArgumentCaptor.getValue());
72+
assertEquals(
73+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
74+
exportMimeTypeArgumentCaptor.getValue());
75+
}
76+
77+
@Test
78+
void testPerformWithNonGoogleDoc() throws IOException {
79+
when(mockedFiles.get(fileIdArgumentCaptor.capture()))
80+
.thenReturn(mockedGet);
81+
when(mockedGet.execute())
82+
.thenReturn(new File().setName("testDoc")
83+
.setMimeType("application/pdf")
84+
.setFileExtension("pdf"));
85+
5586
when(mockedGet.executeMediaAsInputStream())
5687
.thenReturn(mockedInputStream);
5788

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()))
89+
when(mockedActionContext.mimeType(any()))
90+
.thenReturn("type");
91+
when(mockedActionContext.file(any()))
6992
.thenReturn(mockedFileEntry);
7093

71-
FileEntry result = GoogleDriveDownloadFileAction.perform(mockedParameters, mockedParameters, mockedContext);
94+
FileEntry result =
95+
GoogleDriveDownloadFileAction.perform(mockedParameters, mockedParameters, mockedActionContext);
7296

7397
assertEquals(mockedFileEntry, result);
7498

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

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)