Search in sources :

Example 1 with ModVersion

use of com.faforever.api.data.domain.ModVersion in project faf-java-api by FAForever.

the class ModServiceTest method processUploadedMod.

@Test
@SuppressWarnings("unchecked")
public void processUploadedMod() throws Exception {
    Path uploadedFile = prepareMod(TEST_MOD);
    Player uploader = new Player();
    instance.processUploadedMod(uploadedFile, uploader);
    assertThat(Files.exists(temporaryFolder.getRoot().toPath().resolve("mods/no_friendly_fire.v0003.zip")), is(true));
    assertThat(Files.exists(temporaryFolder.getRoot().toPath().resolve("thumbnails/no_friendly_fire.v0003.png")), is(true));
    ArgumentCaptor<Mod> modCaptor = ArgumentCaptor.forClass(Mod.class);
    verify(modRepository).save(modCaptor.capture());
    Mod savedMod = modCaptor.getValue();
    assertThat(savedMod.getId(), is(nullValue()));
    assertThat(savedMod.getAuthor(), is("IceDreamer"));
    assertThat(savedMod.getDisplayName(), is("No Friendly Fire"));
    assertThat(savedMod.getUploader(), is(uploader));
    ModVersion savedModVersion = savedMod.getVersions().get(0);
    assertThat(savedModVersion.getId(), is(nullValue()));
    assertThat(savedModVersion.getIcon(), is("no_friendly_fire.v0003.png"));
    assertThat(savedModVersion.getFilename(), is("mods/no_friendly_fire.v0003.zip"));
    assertThat(savedModVersion.getUid(), is("26778D4E-BA75-5CC2-CBA8-63795BDE74AA"));
    assertThat(savedModVersion.getDescription(), is("All friendly fire, including between allies, is turned off."));
    assertThat(savedModVersion.getMod(), is(savedMod));
    assertThat(savedModVersion.isRanked(), is(false));
    assertThat(savedModVersion.isHidden(), is(false));
    ArgumentCaptor<Example<ModVersion>> exampleCaptor = ArgumentCaptor.forClass((Class) ModVersion.class);
    verify(modVersionRepository).exists(exampleCaptor.capture());
    verify(modVersionRepository).existsByUid("26778D4E-BA75-5CC2-CBA8-63795BDE74AA");
}
Also used : Path(java.nio.file.Path) ModVersion(com.faforever.api.data.domain.ModVersion) Player(com.faforever.api.data.domain.Player) Mod(com.faforever.api.data.domain.Mod) Example(org.springframework.data.domain.Example) Test(org.junit.Test)

Example 2 with ModVersion

use of com.faforever.api.data.domain.ModVersion in project faf-java-api by FAForever.

the class ModService method store.

private void store(com.faforever.commons.mod.Mod modInfo, Optional<Path> thumbnailPath, Player uploader, String zipFileName) {
    ModVersion modVersion = new ModVersion().setUid(modInfo.getUid()).setType(modInfo.isUiOnly() ? ModType.UI : ModType.SIM).setDescription(modInfo.getDescription()).setVersion((short) Integer.parseInt(modInfo.getVersion().toString())).setFilename(MOD_PATH_PREFIX + zipFileName).setIcon(thumbnailPath.map(path -> path.getFileName().toString()).orElse(null));
    Mod mod = modRepository.findOneByDisplayName(modInfo.getName()).orElse(new Mod().setAuthor(modInfo.getAuthor()).setDisplayName(modInfo.getName()).setVersions(new ArrayList<>()).setUploader(uploader));
    mod.getVersions().add(modVersion);
    modVersion.setMod(mod);
    mod = modRepository.save(mod);
    modRepository.insertModStats(mod.getDisplayName());
}
Also used : ModVersion(com.faforever.api.data.domain.ModVersion) Mod(com.faforever.api.data.domain.Mod)

Aggregations

Mod (com.faforever.api.data.domain.Mod)2 ModVersion (com.faforever.api.data.domain.ModVersion)2 Player (com.faforever.api.data.domain.Player)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1 Example (org.springframework.data.domain.Example)1