Search in sources :

Example 1 with MapStats

use of com.faforever.server.entity.MapStats in project faf-java-server by FAForever.

the class MapServiceTest method timesPlayedIsIncreasedCorrectly.

@Test
public void timesPlayedIsIncreasedCorrectly() {
    Map map = new Map().setId(1);
    MapStats features = instance.getMapStats(map);
    assertThat(features.getId(), is(1));
    assertThat(features.getTimesPlayed(), is(41));
    instance.incrementTimesPlayed(map);
    verify(mapStatsRepository).save(features);
    features = instance.getMapStats(map);
    assertThat(features.getId(), is(1));
    assertThat(features.getTimesPlayed(), is(42));
    verifyZeroInteractions(mapVersionRepository);
    verifyZeroInteractions(ladder1v1MapRepository);
}
Also used : Map(com.faforever.server.entity.Map) MapStats(com.faforever.server.entity.MapStats) Test(org.junit.Test)

Example 2 with MapStats

use of com.faforever.server.entity.MapStats in project faf-java-server by FAForever.

the class MapServiceTest method setUp.

@Before
public void setUp() {
    mapVersion = new MapVersion().setId(1).setFilename(MAP_NAME);
    when(mapVersionRepository.findByFilenameIgnoreCase(MAP_NAME)).thenReturn(Optional.of(mapVersion));
    when(mapVersionRepository.findOne(1)).thenReturn(mapVersion);
    MapStats features = new MapStats().setId(1).setTimesPlayed(41);
    when(mapStatsRepository.findOne(1)).thenReturn(features);
    when(mapStatsRepository.save(any(MapStats.class))).thenAnswer(context -> context.getArguments()[0]);
    instance = new MapService(mapVersionRepository, ladder1v1MapRepository, mapStatsRepository);
}
Also used : MapVersion(com.faforever.server.entity.MapVersion) MapStats(com.faforever.server.entity.MapStats) Before(org.junit.Before)

Example 3 with MapStats

use of com.faforever.server.entity.MapStats in project faf-java-server by FAForever.

the class MapService method incrementTimesPlayed.

@Transactional
public void incrementTimesPlayed(Map map) {
    MapStats features = getMapStats(map);
    features.incrementTimesPlayed();
    mapStatsRepository.save(features);
}
Also used : MapStats(com.faforever.server.entity.MapStats) Transactional(javax.transaction.Transactional)

Example 4 with MapStats

use of com.faforever.server.entity.MapStats in project faf-java-server by FAForever.

the class MapService method getMapStats.

@Transactional
public MapStats getMapStats(Map map) {
    MapStats features = mapStatsRepository.findOne(map.getId());
    if (features == null) {
        features = new MapStats().setId(map.getId());
        features = mapStatsRepository.save(features);
    }
    return features;
}
Also used : MapStats(com.faforever.server.entity.MapStats) Transactional(javax.transaction.Transactional)

Example 5 with MapStats

use of com.faforever.server.entity.MapStats in project faf-java-server by FAForever.

the class MapServiceTest method timesPlayedIsInitializedWithZero.

@Test
public void timesPlayedIsInitializedWithZero() {
    int newId = 1342342;
    Map map = new Map().setId(newId);
    MapStats features = instance.getMapStats(map);
    assertThat(features.getId(), is(newId));
    assertThat(features.getTimesPlayed(), is(0));
    verify(mapStatsRepository).save(features);
    verifyZeroInteractions(mapVersionRepository);
    verifyZeroInteractions(ladder1v1MapRepository);
}
Also used : Map(com.faforever.server.entity.Map) MapStats(com.faforever.server.entity.MapStats) Test(org.junit.Test)

Aggregations

MapStats (com.faforever.server.entity.MapStats)5 Map (com.faforever.server.entity.Map)2 Transactional (javax.transaction.Transactional)2 Test (org.junit.Test)2 MapVersion (com.faforever.server.entity.MapVersion)1 Before (org.junit.Before)1