Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MARP-1731 Wrong documentation link for SNAPSHOT versions #264

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.axonivy.market.bo.Artifact;
import com.axonivy.market.service.FileDownloadService;
import com.axonivy.market.util.FileUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.stereotype.Service;
Expand All @@ -20,15 +22,7 @@
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -81,8 +75,9 @@ public String downloadAndUnzipFile(String url, boolean isForce) throws IOExcepti

private Path createTempFileFromUrlAndExtractToLocation(String url, String location,
boolean isForce) throws IOException {
File cacheFolder = new File(location);
if (cacheFolder.exists() && cacheFolder.isDirectory() && !isForce) {
File cacheFolder = FileUtils.createNewFile(location);
if (cacheFolder.exists() && cacheFolder.isDirectory() && ObjectUtils.isNotEmpty(
cacheFolder.listFiles()) && !isForce) {
log.warn("Data is already in {}", location);
return null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public static void writeToFile(File file, String content) throws IOException {
}
}

public static File createNewFile(String location) {
return new File(location);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.axonivy.market.service.impl;

import com.axonivy.market.util.FileUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -16,6 +17,7 @@
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;

@ExtendWith(MockitoExtension.class)
class FileDownloadServiceImplTest {
Expand All @@ -37,6 +39,26 @@ void testDownloadAndUnzipFileWithIssue() {
assertThrows(ResourceAccessException.class, () -> fileDownloadService.downloadAndUnzipFile(DOWNLOAD_URL, true));
}

@Test
void testDownloadAndUnzipFileWithNullTempZipPath() throws IOException {
try (MockedStatic<Files> mockedFiles = Mockito.mockStatic(Files.class);
MockedStatic<FileUtils> mockFileUtils = Mockito.mockStatic(FileUtils.class)) {

File mockChildFile = Mockito.mock(File.class);

File mockFile = Mockito.mock(File.class);
Mockito.when(mockFile.exists()).thenReturn(true);
Mockito.when(mockFile.isDirectory()).thenReturn(true);
Mockito.when(mockFile.listFiles()).thenReturn(new File[]{mockChildFile});

mockFileUtils.when(() -> FileUtils.createNewFile(Mockito.anyString())).thenReturn(mockFile);

var result = fileDownloadService.downloadAndUnzipFile(DOWNLOAD_URL, false);
assertFalse(result.isEmpty());
mockedFiles.verify(() -> Files.delete(any()), Mockito.times(0));
}
}

@Test
void testSupportFunctions() throws IOException {
var mockFile = fileDownloadService.createFolder("unzip");
Expand Down
Loading