use of com.faforever.api.data.domain.MapVersion in project faf-java-api by FAForever.
the class MapServiceTest method positiveUploadTest.
@Test
public void positiveUploadTest() throws IOException {
String zipFilename = "scmp_037.zip";
when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.empty());
try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
byte[] mapData = ByteStreams.toByteArray(inputStream);
Path tmpDir = temporaryDirectory.getRoot().toPath();
instance.uploadMap(mapData, zipFilename, author, true);
ArgumentCaptor<com.faforever.api.data.domain.Map> mapCaptor = ArgumentCaptor.forClass(com.faforever.api.data.domain.Map.class);
verify(mapRepository, Mockito.times(1)).save(mapCaptor.capture());
assertEquals("Sludge_Test", mapCaptor.getValue().getDisplayName());
assertEquals("skirmish", mapCaptor.getValue().getMapType());
assertEquals("FFA", mapCaptor.getValue().getBattleType());
assertEquals(1, mapCaptor.getValue().getVersions().size());
MapVersion mapVersion = mapCaptor.getValue().getVersions().get(0);
assertEquals("The thick, brackish water clings to everything, staining anything it touches. If it weren't for this planet's proximity to the Quarantine Zone, no one would ever bother coming here.", mapVersion.getDescription());
assertEquals(1, mapVersion.getVersion());
assertEquals(256, mapVersion.getHeight());
assertEquals(256, mapVersion.getWidth());
assertEquals(3, mapVersion.getMaxPlayers());
assertEquals("maps/sludge_test.v0001.zip", mapVersion.getFilename());
assertFalse(Files.exists(tmpDir));
Path generatedFile = finalDirectory.getRoot().toPath().resolve("sludge_test.v0001.zip");
assertTrue(Files.exists(generatedFile));
Path generatedFiles = finalDirectory.getRoot().toPath().resolve("generated_files");
try (ZipInputStream inputStreamOfExpectedFile = new ZipInputStream(new BufferedInputStream(new FileInputStream(generatedFile.toFile())))) {
Unzipper.from(inputStreamOfExpectedFile).to(generatedFiles).unzip();
}
Path expectedFiles = finalDirectory.getRoot().toPath().resolve("expected_files");
try (ZipInputStream inputStreamOfExpectedFile = new ZipInputStream(new BufferedInputStream(loadMapResourceAsStream("sludge_test.v0001.zip")))) {
Unzipper.from(inputStreamOfExpectedFile).to(expectedFiles).unzip();
}
expectedFiles = expectedFiles.resolve("sludge_test.v0001");
try (Stream<Path> fileStream = Files.list(expectedFiles)) {
assertEquals(fileStream.count(), (long) 4);
}
try (Stream<Path> fileStream = Files.list(expectedFiles)) {
Path finalGeneratedFile = generatedFiles.resolve("sludge_test.v0001");
fileStream.forEach(expectedFile -> FileAssert.assertEquals("Difference in " + expectedFile.getFileName().toString(), expectedFile.toFile(), finalGeneratedFile.resolve(expectedFile.getFileName().toString()).toFile()));
assertTrue(Files.exists(mapProperties.getDirectoryPreviewPathLarge().resolve("sludge_test.v0001.png")));
assertTrue(Files.exists(mapProperties.getDirectoryPreviewPathSmall().resolve("sludge_test.v0001.png")));
}
}
}
use of com.faforever.api.data.domain.MapVersion in project faf-java-api by FAForever.
the class MapService method updateMapEntities.
private void updateMapEntities(MapUploadData progressData) {
LuaValue scenarioInfo = progressData.getLuaScenarioInfo();
Map map = progressData.getMapEntity();
if (map == null) {
map = new Map();
}
map.setDisplayName(scenarioInfo.get(ScenarioMapInfo.NAME).toString()).setMapType(scenarioInfo.get(ScenarioMapInfo.TYPE).tojstring()).setBattleType(scenarioInfo.get(ScenarioMapInfo.CONFIGURATIONS).get(ScenarioMapInfo.CONFIGURATION_STANDARD).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS).get(1).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS_NAME).tojstring()).setAuthor(progressData.getAuthorEntity());
LuaValue size = scenarioInfo.get(ScenarioMapInfo.SIZE);
MapVersion version = new MapVersion().setDescription(scenarioInfo.get(ScenarioMapInfo.DESCRIPTION).tojstring().replaceAll("<LOC .*?>", "")).setWidth(size.get(1).toint()).setHeight(size.get(2).toint()).setHidden(false).setRanked(progressData.isRanked()).setMaxPlayers(scenarioInfo.get(ScenarioMapInfo.CONFIGURATIONS).get(ScenarioMapInfo.CONFIGURATION_STANDARD).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS).get(1).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS_ARMIES).length()).setVersion(scenarioInfo.get(ScenarioMapInfo.MAP_VERSION).toint());
map.getVersions().add(version);
version.setMap(map);
progressData.setMapEntity(map);
progressData.setMapVersionEntity(version);
version.setFilename(STUPID_MAP_FOLDER_PREFIX + progressData.getFinalZipName());
progressData.setFinalZipFile(this.fafApiProperties.getMap().getTargetDirectory().resolve(progressData.getFinalZipName()));
if (Files.exists(progressData.getFinalZipFile())) {
throw new ApiException(new Error(ErrorCode.MAP_NAME_CONFLICT, progressData.getFinalZipName()));
}
// this triggers validation
mapRepository.save(map);
}
use of com.faforever.api.data.domain.MapVersion 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));
}
}
Aggregations