Search in sources :

Example 6 with ApiException

use of com.faforever.api.error.ApiException in project faf-java-api by FAForever.

the class ClanServiceTest method createClanWhereLeaderIsAlreadyInAClan.

@Test
public void createClanWhereLeaderIsAlreadyInAClan() {
    String clanName = "My cool Clan";
    String tag = "123";
    String description = "A cool clan for testing";
    Player creator = new Player();
    creator.setId(1);
    creator.getClanMemberships().add(new ClanMembership());
    try {
        instance.create(clanName, tag, description, creator);
        fail();
    } catch (ApiException e) {
        assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_CREATE_CREATOR_IS_IN_A_CLAN));
    }
    verify(clanRepository, Mockito.never()).save(any(Clan.class));
}
Also used : Player(com.faforever.api.data.domain.Player) Clan(com.faforever.api.data.domain.Clan) ClanMembership(com.faforever.api.data.domain.ClanMembership) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Example 7 with ApiException

use of com.faforever.api.error.ApiException in project faf-java-api by FAForever.

the class ClanServiceTest method createClanWithSameName.

@Test
public void createClanWithSameName() {
    String clanName = "My cool Clan";
    String tag = "123";
    String description = "A cool clan for testing";
    Player creator = new Player();
    creator.setId(1);
    when(clanRepository.findOneByName(clanName)).thenReturn(Optional.of(new Clan()));
    try {
        instance.create(clanName, tag, description, creator);
        fail();
    } catch (ApiException e) {
        assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_NAME_EXISTS));
    }
    ArgumentCaptor<Clan> clanCaptor = ArgumentCaptor.forClass(Clan.class);
    verify(clanRepository, Mockito.times(0)).save(clanCaptor.capture());
}
Also used : Player(com.faforever.api.data.domain.Player) Clan(com.faforever.api.data.domain.Clan) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Example 8 with ApiException

use of com.faforever.api.error.ApiException in project faf-java-api by FAForever.

the class ClanServiceTest method generatePlayerInvitationTokenWithInvalidClan.

@Test
public void generatePlayerInvitationTokenWithInvalidClan() throws IOException {
    Player requester = new Player();
    requester.setId(1);
    try {
        instance.generatePlayerInvitationToken(requester, 45, 42);
        fail();
    } catch (ApiException e) {
        assertThat(e, apiExceptionWithCode(ErrorCode.CLAN_NOT_EXISTS));
    }
    verify(jwtService, Mockito.never()).sign(any());
}
Also used : Player(com.faforever.api.data.domain.Player) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Example 9 with ApiException

use of com.faforever.api.error.ApiException in project faf-java-api by FAForever.

the class MapServiceTest method zipFilenamealreadyExists.

@Test
public void zipFilenamealreadyExists() throws IOException {
    Path clashedMap = finalDirectory.getRoot().toPath().resolve("sludge_test.v0001.zip");
    assertTrue(clashedMap.toFile().createNewFile());
    String zipFilename = "scmp_037.zip";
    when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.empty());
    try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
        try {
            byte[] mapData = ByteStreams.toByteArray(inputStream);
            instance.uploadMap(mapData, zipFilename, author, true);
            fail();
        } catch (ApiException e) {
            assertThat(e, apiExceptionWithCode(ErrorCode.MAP_NAME_CONFLICT));
        }
        verify(mapRepository, never()).save(any(com.faforever.api.data.domain.Map.class));
    }
}
Also used : Path(java.nio.file.Path) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Map(com.faforever.api.config.FafApiProperties.Map) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Example 10 with ApiException

use of com.faforever.api.error.ApiException in project faf-java-api by FAForever.

the class MapServiceTest method fileIsMissingInsideZip.

@TestWith({ "without_savelua.zip", "without_scenariolua.zip", "without_scmap.zip", "without_scriptlua.zip" })
public void fileIsMissingInsideZip(String zipFilename) throws IOException {
    try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
        try {
            byte[] mapData = ByteStreams.toByteArray(inputStream);
            instance.uploadMap(mapData, zipFilename, author, true);
            fail();
        } catch (ApiException e) {
            assertThat(e, apiExceptionWithCode(ErrorCode.MAP_FILE_INSIDE_ZIP_MISSING));
        }
        verify(mapRepository, never()).save(any(com.faforever.api.data.domain.Map.class));
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Map(com.faforever.api.config.FafApiProperties.Map) ApiException(com.faforever.api.error.ApiException) TestWith(com.googlecode.zohhak.api.TestWith)

Aggregations

ApiException (com.faforever.api.error.ApiException)48 Error (com.faforever.api.error.Error)29 Player (com.faforever.api.data.domain.Player)18 Test (org.junit.Test)18 ProgrammingError (com.faforever.api.error.ProgrammingError)13 SneakyThrows (lombok.SneakyThrows)11 Clan (com.faforever.api.data.domain.Clan)10 ClanMembership (com.faforever.api.data.domain.ClanMembership)7 InputStream (java.io.InputStream)7 Path (java.nio.file.Path)7 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 ArrayList (java.util.ArrayList)6 ZipInputStream (java.util.zip.ZipInputStream)6 Map (com.faforever.api.config.FafApiProperties.Map)5 Vote (com.faforever.api.data.domain.Vote)5 VotingSubject (com.faforever.api.data.domain.VotingSubject)5 NotFoundApiException (com.faforever.api.error.NotFoundApiException)5 Jwt (org.springframework.security.jwt.Jwt)5 LuaValue (org.luaj.vm2.LuaValue)4