Search in sources :

Example 1 with Map

use of com.faforever.api.config.FafApiProperties.Map in project faf-java-api by FAForever.

the class MapServiceTest method notCorrectAuthor.

@Test
public void notCorrectAuthor() throws IOException {
    String zipFilename = "scmp_037.zip";
    Player me = new Player();
    me.setId(1);
    Player bob = new Player();
    bob.setId(2);
    com.faforever.api.data.domain.Map map = new com.faforever.api.data.domain.Map().setAuthor(bob);
    when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.of(map));
    try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
        try {
            byte[] mapData = ByteStreams.toByteArray(inputStream);
            instance.uploadMap(mapData, zipFilename, me, true);
            fail();
        } catch (ApiException e) {
            assertThat(e, apiExceptionWithCode(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR));
        }
        verify(mapRepository, never()).save(any(com.faforever.api.data.domain.Map.class));
    }
}
Also used : Player(com.faforever.api.data.domain.Player) 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 2 with Map

use of com.faforever.api.config.FafApiProperties.Map in project faf-java-api by FAForever.

the class MapServiceTest method versionExistsAlready.

@Test
public void versionExistsAlready() throws IOException {
    String zipFilename = "scmp_037.zip";
    Player me = new Player();
    me.setId(1);
    com.faforever.api.data.domain.Map map = new com.faforever.api.data.domain.Map().setAuthor(me).setVersions(Collections.singletonList(new MapVersion().setVersion(1)));
    when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.of(map));
    try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
        try {
            byte[] mapData = ByteStreams.toByteArray(inputStream);
            instance.uploadMap(mapData, zipFilename, me, true);
            fail();
        } catch (ApiException e) {
            assertThat(e, apiExceptionWithCode(ErrorCode.MAP_VERSION_EXISTS));
        }
        verify(mapRepository, never()).save(any(com.faforever.api.data.domain.Map.class));
    }
}
Also used : Player(com.faforever.api.data.domain.Player) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MapVersion(com.faforever.api.data.domain.MapVersion) Map(com.faforever.api.config.FafApiProperties.Map) ApiException(com.faforever.api.error.ApiException) Test(org.junit.Test)

Aggregations

Map (com.faforever.api.config.FafApiProperties.Map)2 Player (com.faforever.api.data.domain.Player)2 ApiException (com.faforever.api.error.ApiException)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ZipInputStream (java.util.zip.ZipInputStream)2 Test (org.junit.Test)2 MapVersion (com.faforever.api.data.domain.MapVersion)1