Gdal Support mac,linux,win os

This commit is contained in:
DanielLee
2025-12-16 18:05:59 +09:00
parent 827c056d02
commit 9f0c55fd0c
8 changed files with 359 additions and 42 deletions

View File

@@ -0,0 +1,110 @@
package com.kamco.cd.kamcoback.common.utils;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;
class FIleCheckerTest {
@Test
void testOsDetection() {
// 운영체제 감지 테스트
String osName = System.getProperty("os.name").toLowerCase();
System.out.println("현재 운영체제: " + osName);
boolean isWindows = osName.contains("win");
boolean isMac = osName.contains("mac");
boolean isUnix = osName.contains("nix") || osName.contains("nux") || osName.contains("aix");
// 최소한 하나의 OS는 감지되어야 함
assertTrue(isWindows || isMac || isUnix, "지원되는 운영체제를 감지해야 합니다");
System.out.println("Windows: " + isWindows);
System.out.println("Mac: " + isMac);
System.out.println("Unix/Linux: " + isUnix);
}
@Test
void testCheckTfw_ValidFile(@TempDir File tempDir) throws IOException {
// 임시 유효한 TFW 파일 생성
File tfwFile = new File(tempDir, "test.tfw");
try (FileWriter writer = new FileWriter(tfwFile)) {
writer.write("0.25\n"); // pixel size x
writer.write("0.0\n"); // rotation x
writer.write("0.0\n"); // rotation y
writer.write("-0.25\n"); // pixel size y
writer.write("127.5\n"); // upper left x
writer.write("37.5\n"); // upper left y
}
boolean result = FIleChecker.checkTfw(tfwFile.getAbsolutePath());
assertTrue(result, "유효한 TFW 파일은 true를 반환해야 합니다");
}
@Test
void testCheckTfw_InvalidFile(@TempDir File tempDir) throws IOException {
// 잘못된 TFW 파일 생성 (5줄만)
File tfwFile = new File(tempDir, "invalid.tfw");
try (FileWriter writer = new FileWriter(tfwFile)) {
writer.write("0.25\n");
writer.write("0.0\n");
writer.write("0.0\n");
writer.write("-0.25\n");
writer.write("127.5\n");
// 6번째 줄 누락
}
boolean result = FIleChecker.checkTfw(tfwFile.getAbsolutePath());
assertFalse(result, "잘못된 TFW 파일은 false를 반환해야 합니다");
}
@Test
void testCheckTfw_NonExistentFile() {
boolean result = FIleChecker.checkTfw("/non/existent/path/file.tfw");
assertFalse(result, "존재하지 않는 파일은 false를 반환해야 합니다");
}
@Test
void testCmmndGdalInfo_MethodExists() throws NoSuchMethodException {
// cmmndGdalInfo 메서드가 존재하는지 확인
assertNotNull(FIleChecker.class.getMethod("cmmndGdalInfo", String.class));
System.out.println("cmmndGdalInfo 메서드 존재 확인");
}
@Test
void testCmmndGdalInfo_NonExistentFile() {
// 존재하지 않는 파일은 false를 반환해야 함
boolean result = FIleChecker.cmmndGdalInfo("/non/existent/path/file.tif");
assertFalse(result, "존재하지 않는 파일은 false를 반환해야 합니다");
}
@Test
@EnabledOnOs(OS.WINDOWS)
void testWindowsCommand() {
System.out.println("Windows OS 감지됨 - GDAL 명령어 형식 확인");
String osName = System.getProperty("os.name").toLowerCase();
assertTrue(osName.contains("win"));
}
@Test
@EnabledOnOs(OS.MAC)
void testMacCommand() {
System.out.println("Mac OS 감지됨 - GDAL 명령어 형식 확인");
String osName = System.getProperty("os.name").toLowerCase();
assertTrue(osName.contains("mac"));
}
@Test
@EnabledOnOs(OS.LINUX)
void testLinuxCommand() {
System.out.println("Linux OS 감지됨 - GDAL 명령어 형식 확인");
String osName = System.getProperty("os.name").toLowerCase();
assertTrue(osName.contains("nux") || osName.contains("nix"));
}
}