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));
}
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());
}
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());
}
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));
}
}
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));
}
}
Aggregations