use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class GymRepositoryTest method findNonExGym.
@Test
public void findNonExGym() throws Exception {
final Gym gym = repo.findByName("Sköldpaddorna", "norrköping");
assertThat(gym.isExGym(), is(false));
assertThat(gym.getName(), is("Sköldpaddorna"));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class GymRepositoryTest method addTemporaryGymToUppsala.
@Test
public void addTemporaryGymToUppsala() {
Gym gym;
try {
gym = repo.findByName("Mongo", "uppsala");
fail("Gym should not exist yet.");
} catch (GymNotFoundException e) {
// Expected
}
final User userMock = mock(User.class);
when(userMock.getName()).thenReturn("User");
repo.addTemporary(userMock, new Gym("Mongo", "66666666", "50.0001", "25.00001", "Uppsala", false), "uppsala");
gym = repo.findByName("Mongo", "uppsala");
assertThat(gym.getName(), is("Mongo"));
assertThat(gym.isExGym(), is(false));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method moveTimeForGroupWorks.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void moveTimeForGroupWorks() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
when(user.getName()).thenReturn(raidCreatorName);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
try {
repo.newRaid(user, enteiRaid, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
List<User> raiders = new ArrayList<>();
for (int i = 0; i < 5; i++) {
final User raider = mock(User.class);
when(raider.getName()).thenReturn("User" + i);
raiders.add(raider);
}
Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
final LocalDateTime raidGroupTime = endOfRaid.minusMinutes(10);
for (User raider : raiders) {
repo.addSignUp(raider, raid, new SignUp(raider.getName(), 2, raidGroupTime.toLocalTime()));
}
final LocalDateTime newRaidGroupTime = raidGroupTime.plusMinutes(2);
RaidEntity entity = raidEntityRepository.findOne(raid.getId());
repo.moveAllSignUpsForTimeToNewTime(raid.getId(), raidGroupTime, newRaidGroupTime, user);
entity = raidEntityRepository.findOne(raid.getId());
raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
entity = raidEntityRepository.findOne(raid.getId());
assertThat(raid.getSignUps().size(), is(5));
assertThat(raid.getNumberOfPeopleSignedUp(), is(10));
assertThat(raid.getSignUpsAt(newRaidGroupTime.toLocalTime()).size(), is(5));
assertThat(raid.getSignUpsAt(raidGroupTime.toLocalTime()).size(), is(0));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method changeEndOfRaidWorks.
@Test
public void changeEndOfRaidWorks() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
when(user.getName()).thenReturn(raidCreatorName);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
try {
repo.newRaid(user, enteiRaid, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
Raid changedRaid = repo.changeEndOfRaid(raid.getId(), endOfRaid.plusMinutes(5), guild, config, user, "test");
assertThat(raid.getEndOfRaid(), not(changedRaid.getEndOfRaid()));
assertThat(changedRaid.getEndOfRaid(), is(raid.getEndOfRaid().plusMinutes(5)));
assertThat(raid.getGym(), is(changedRaid.getGym()));
assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
assertThat(raid.getRegion(), is(changedRaid.getRegion()));
assertThat(raid.getPokemon().getName(), is(changedRaid.getPokemon().getName()));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class RaidRepository method executeUnsignCommand.
public String executeUnsignCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
String people = args[0];
String userName = user.getName();
if (args.length < 2 || args.length > 10) {
throw new WrongNumberOfArgumentsException(user, localeService, 2, args.length, help);
}
Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 1; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
String gymName = gymNameBuilder.toString().trim();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
Raid raid = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
final RaidEntitySignUp signUp = findEntityByRaidId(raid.getId()).getSignUp(user.getName());
if (signUp == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, user.getName(), gym.getName()));
}
raid = removeFromSignUp(raid.getId(), user, 0, 0, 0, numberOfPeople, LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), signUp.getArrivalTime()));
final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
final Set<SignUp> signUps = raid.getSignUps();
Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
final String allSignUpNames = StringUtils.join(signUpNames, ", ");
final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
return localeService.getMessageFor(LocaleService.UNSIGN, localeForUser, userName, gym.getName(), signUpText);
}
Aggregations