Search in sources :

Example 1 with FeaturedModFile

use of com.faforever.api.featuredmods.FeaturedModFile in project faf-java-api by FAForever.

the class LegacyFeaturedModDeploymentTaskTest method testRun.

@Test
@SuppressWarnings("unchecked")
public void testRun() throws Exception {
    instance.setFeaturedMod(new FeaturedMod().setGitBranch("branch").setFileExtension("nx3").setTechnicalName("faf").setAllowOverride(true).setGitUrl("git@example.com/FAForever/faf"));
    Mockito.doAnswer(invocation -> {
        Path repoFolder = invocation.getArgument(0);
        Files.createDirectories(repoFolder.resolve("someDir"));
        Files.copy(LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/mod_info.lua"), repoFolder.resolve("mod_info.lua"));
        Files.copy(LegacyFeaturedModDeploymentTaskTest.class.getResourceAsStream("/featured_mod/someDir/someFile"), repoFolder.resolve("someDir/someFile"));
        return null;
    }).when(gitWrapper).checkoutRef(any(), any());
    when(featuredModService.getFeaturedMods()).thenReturn(Collections.singletonList(new FeaturedMod().setTechnicalName("faf")));
    when(featuredModService.getFileIds("faf")).thenReturn(ImmutableMap.of("ForgedAlliance.exe", (short) 1, "someDir.nx3", (short) 2));
    Path dummyExe = repositoriesFolder.getRoot().toPath().resolve("TemplateForgedAlliance.exe");
    createDummyExe(dummyExe);
    properties.getDeployment().setForgedAllianceExePath(dummyExe.toAbsolutePath().toString());
    instance.run();
    ArgumentCaptor<List<FeaturedModFile>> filesCaptor = ArgumentCaptor.forClass(List.class);
    verify(featuredModService).save(eq("faf"), eq((short) 1337), filesCaptor.capture());
    List<FeaturedModFile> files = filesCaptor.getValue();
    files.sort(Comparator.comparing(FeaturedModFile::getFileId));
    assertThat(files.get(0).getFileId(), is((short) 1));
    assertThat(files.get(0).getMd5(), is("47df959058cb52fe966ea5936dbd8f4c"));
    assertThat(files.get(0).getName(), is("ForgedAlliance.1337.exe"));
    assertThat(files.get(0).getVersion(), is(1337));
    assertThat(files.get(1).getFileId(), is((short) 2));
    assertThat(files.get(1).getMd5(), is(notNullValue()));
    assertThat(files.get(1).getName(), is("someDir.1337.nx3"));
    assertThat(files.get(1).getVersion(), is(1337));
    assertThat(Files.exists(targetFolder.getRoot().toPath().resolve("updates_faf_files/someDir.1337.nx3")), is(true));
    assertThat(Files.exists(targetFolder.getRoot().toPath().resolve("updates_faf_files/ForgedAlliance.1337.exe")), is(true));
}
Also used : Path(java.nio.file.Path) List(java.util.List) FeaturedMod(com.faforever.api.data.domain.FeaturedMod) FeaturedModFile(com.faforever.api.featuredmods.FeaturedModFile) Test(org.junit.Test)

Aggregations

FeaturedMod (com.faforever.api.data.domain.FeaturedMod)1 FeaturedModFile (com.faforever.api.featuredmods.FeaturedModFile)1 Path (java.nio.file.Path)1 List (java.util.List)1 Test (org.junit.Test)1