-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mod meta file timestamp handling + cleanups
- Loading branch information
Showing
11 changed files
with
175 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...lomiejstepien/armaserverwebgui/domain/server/storage/util/dotnet/DotnetDateTimeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pl.bartlomiejstepien.armaserverwebgui.domain.server.storage.util.dotnet; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.Month; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
|
||
public final class DotnetDateTimeUtils | ||
{ | ||
public static OffsetDateTime dotnetTicksToOffsetDateTime(final long fromBytes) | ||
{ | ||
// Mask out kind and ticks | ||
int kind = Math.toIntExact((fromBytes >> 62) & 0x3); | ||
long ticks = fromBytes & 0x3FFF_FFFF_FFFF_FFFFL; | ||
LocalDateTime cSharpEpoch = LocalDate.of(1, Month.JANUARY, 1).atStartOfDay(); | ||
// 100 nanosecond units or 10^-7 seconds | ||
final int unitsPerSecond = 10_000_000; | ||
long seconds = ticks / unitsPerSecond; | ||
long nanos = (ticks % unitsPerSecond) * 100; | ||
LocalDateTime localDateTime = cSharpEpoch.plusSeconds(seconds).plusNanos(nanos); | ||
|
||
if (kind > 2 || kind < 0) { | ||
throw new IllegalArgumentException("Invalid ticks kind: " + kind); | ||
} | ||
|
||
return OffsetDateTime.of(localDateTime, ZoneOffset.UTC); | ||
} | ||
|
||
private DotnetDateTimeUtils() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...pl/bartlomiejstepien/armaserverwebgui/domain/server/mod/InstalledModEntityHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package pl.bartlomiejstepien.armaserverwebgui.domain.server.mod; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import pl.bartlomiejstepien.armaserverwebgui.domain.server.mod.model.InstalledModEntity; | ||
import pl.bartlomiejstepien.armaserverwebgui.domain.server.storage.mod.InstalledFileSystemMod; | ||
import pl.bartlomiejstepien.armaserverwebgui.domain.server.storage.mod.MetaCppFile; | ||
import pl.bartlomiejstepien.armaserverwebgui.domain.server.storage.mod.ModDirectory; | ||
import pl.bartlomiejstepien.armaserverwebgui.domain.steam.SteamService; | ||
import pl.bartlomiejstepien.armaserverwebgui.domain.steam.model.WorkshopMod; | ||
|
||
import java.nio.file.Paths; | ||
import java.time.OffsetDateTime; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class InstalledModEntityHelperTest | ||
{ | ||
@Mock | ||
private ModDirectory modDirectory; | ||
|
||
@Mock | ||
private SteamService steamService; | ||
|
||
@InjectMocks | ||
private InstalledModEntityHelper installedModEntityHelper; | ||
|
||
@Test | ||
void shouldConvertInstalledFileSystemModToEntity() | ||
{ | ||
//given | ||
MetaCppFile metaCppFile = mock(MetaCppFile.class); | ||
|
||
given(modDirectory.getModName()).willReturn("ACE"); | ||
given(modDirectory.getMetaCppFile()).willReturn(metaCppFile); | ||
given(modDirectory.getPath()).willReturn(Paths.get("./ace-mod")); | ||
given(metaCppFile.getPublishedFileId()).willReturn(123456789L); | ||
given(metaCppFile.getTimestamp()).willReturn(5250320079498121474L); | ||
|
||
given(steamService.getWorkshopMod(123456789L)).willReturn(WorkshopMod.builder() | ||
.previewUrl("previewurl") | ||
.build()); | ||
|
||
InstalledFileSystemMod installedFileSystemMod = prepareFileSystemMod(); | ||
|
||
// when | ||
InstalledModEntity entity = installedModEntityHelper.toEntity(installedFileSystemMod); | ||
|
||
// then | ||
assertThat(entity.getId()).isNull(); | ||
assertThat(entity.getName()).isEqualTo("ACE"); | ||
assertThat(entity.getWorkshopFileId()).isEqualTo(123456789L); | ||
assertThat(entity.getDirectoryPath()).isEqualTo(Paths.get("./ace-mod").toAbsolutePath().toString()); | ||
assertThat(entity.getCreatedDate()).isBeforeOrEqualTo(OffsetDateTime.now()); | ||
assertThat(entity.getLastWorkshopUpdate()).isEqualTo(OffsetDateTime.parse("2024-10-01T19:01:47.073357Z")); | ||
assertThat(entity.getPreviewUrl()).isEqualTo("previewurl"); | ||
} | ||
|
||
@Test | ||
void shouldNotSetModPreviewWhenCouldNotFetchModInfoFromWorkshop() | ||
{ | ||
//given | ||
MetaCppFile metaCppFile = mock(MetaCppFile.class); | ||
|
||
given(modDirectory.getModName()).willReturn("A3 Thermal Improvement"); | ||
given(modDirectory.getMetaCppFile()).willReturn(metaCppFile); | ||
given(modDirectory.getPath()).willReturn(Paths.get("./@A3-thermal-improvement")); | ||
given(metaCppFile.getPublishedFileId()).willReturn(2041057379L); | ||
given(metaCppFile.getTimestamp()).willReturn(5250320079498121474L); | ||
|
||
given(steamService.getWorkshopMod(2041057379L)).willReturn(null); | ||
|
||
InstalledFileSystemMod installedFileSystemMod = prepareFileSystemMod(); | ||
|
||
// when | ||
InstalledModEntity entity = installedModEntityHelper.toEntity(installedFileSystemMod); | ||
|
||
// then | ||
assertThat(entity.getId()).isNull(); | ||
assertThat(entity.getName()).isEqualTo("A3 Thermal Improvement"); | ||
assertThat(entity.getWorkshopFileId()).isEqualTo(2041057379L); | ||
assertThat(entity.getDirectoryPath()).isEqualTo(Paths.get("./@A3-thermal-improvement").toAbsolutePath().toString()); | ||
assertThat(entity.getCreatedDate()).isBeforeOrEqualTo(OffsetDateTime.now()); | ||
assertThat(entity.getLastWorkshopUpdate()).isEqualTo(OffsetDateTime.parse("2024-10-01T19:01:47.073357Z")); | ||
assertThat(entity.getPreviewUrl()).isNull(); | ||
} | ||
|
||
private InstalledFileSystemMod prepareFileSystemMod() | ||
{ | ||
return InstalledFileSystemMod.from(modDirectory); | ||
} | ||
} |