@Test public void shouldReturnEmptyWhenOnlyTableIsExcluded() throws Exception { TableSearchCriteria searchCriteria = new TableSearchCriteria( gameType, variation, clientId, Collections.<String>emptySet(), BigDecimal.valueOf(80)); RandomTableGenerator generator = new RandomTableGenerator(); generator.setGameTypes(gameType); generator.setTemplateNames(toMap(gameType, variation)); generator.setClients(toMap(gameType, clientId)); generator.setFulls(false); generator.setShowInLobbys(true); generator.setAvailableForJoinings(true); generator.setStatii(TableStatus.open); Set<Table> generated = generator.generateTables(1); Table first = generated.iterator().next(); first.setTableId(BigDecimal.valueOf(80)); Collection<TableSearchResult> found = tableSearchService.findTables(BigDecimal.TEN, searchCriteria); assertEquals(0, found.size()); }
@Test public void shouldReturnEmptySetWhenPlayerIsPlayingAtOnlyTableAndTableIsExcluded() throws Exception { RandomTableGenerator generator = new RandomTableGenerator(); generator.setGameTypes(gameType); generator.setTemplateNames(toMap(gameType, variation)); generator.setClients(toMap(gameType, clientId)); generator.setFulls(false); generator.setShowInLobbys(true); generator.setAvailableForJoinings(true); generator.setStatii(TableStatus.open); Set<Table> generated = generator.generateTables(1); Table tableWithPlayer = generated.iterator().next(); tableWithPlayer.addPlayerToTable(new PlayerInformation(BigDecimal.TEN)); generated = generator.generateTables(1); Table excludedTable = generated.iterator().next(); excludedTable.setTableId(BigDecimal.valueOf(45)); gigaSpace.writeMultiple(new Table[] {tableWithPlayer, excludedTable}); Collection<TableSearchResult> found = tableSearchService.findTables( BigDecimal.TEN, new TableSearchCriteria( gameType, variation, clientId, Collections.<String>emptySet(), BigDecimal.valueOf(45))); assertEquals(0, found.size()); }
private static Table tableWithPhase(MockGameStatus.MockGamePhase phase, long gameId) { Table table = new Table( new com.yazino.game.api.GameType("SLOTS", "Slots", Collections.<String>emptySet()), BigDecimal.ONE, "DefaultSlots", true); table.setTableId(BigDecimal.ONE); if (phase != null) { table.setCurrentGame( new GameStatus( MockGameStatus.emptyStatus(new HashMap<String, String>()).withPhase(phase))); } table.setGameId(gameId); return table; }
@Before public void setUp() throws WalletServiceException { MockitoAnnotations.initMocks(this); playerInfo = new PlayerInformation( PLAYER_ID, PLAYER_NAME, PLAYER_ACCOUNT_ID, BigDecimal.TEN, PLAYER_BALANCE); table = new Table(); table.setTableId(TABLE_ID); table.setGameId(GAME_ID); table.addPlayerToTable(playerInfo); when(uuidSource.getNewUUID()).thenReturn(NEW_UUID).thenReturn("anotherUuid"); underTest = new TableBoundGamePlayerWalletFactory(table, gameHostWallet, AUDIT_LABEL, uuidSource); }
@Test public void shouldReturnOneTableWhenOnlyOneMatchesAndClientAndTemplateAreSpecified() throws Exception { RandomTableGenerator generator = new RandomTableGenerator(); generator.setGameTypes("BLACKJACK", "HISSTERIA", "ROULETTE"); Set<Table> nonMatching = generator.generateTables(100); generator.setGameTypes(gameType); generator.setTemplateNames(toMap(gameType, variation)); generator.setClients(toMap(gameType, clientId)); generator.setFulls(false); generator.setShowInLobbys(true); generator.setAvailableForJoinings(true); generator.setStatii(TableStatus.open); GameStatus gameStatus = mock(GameStatus.class); when(gameRepository.getGameRules(anyString())).thenReturn(gameRules); when(gameRules.getJoiningDesirability(gameStatus)).thenReturn(45); Set<Table> matching = generator.generateTables(1); Table generatedTable = matching.iterator().next(); generatedTable.setTableId(BigDecimal.valueOf(67)); generatedTable.setCurrentGame(gameStatus); Set<Table> all = new HashSet<Table>(nonMatching); all.addAll(matching); gigaSpace.writeMultiple(all.toArray(new Table[all.size()])); assertEquals(101, gigaSpace.count(new Table())); Collection<TableSearchResult> found = tableSearchService.findTables( BigDecimal.TEN, new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet())); assertEquals(1, found.size()); TableSearchResult table = found.iterator().next(); assertEquals(BigDecimal.valueOf(67), table.getTableId()); assertEquals(10, table.getSpareSeats()); assertEquals(45, table.getJoiningDesirability()); }
@Test public void shouldReturnTableWhenPlayerIsNotPlayingAtOnlyTable() throws Exception { RandomTableGenerator generator = new RandomTableGenerator(); generator.setGameTypes(gameType); generator.setTemplateNames(toMap(gameType, variation)); generator.setClients(toMap(gameType, clientId)); generator.setFulls(false); generator.setShowInLobbys(true); generator.setAvailableForJoinings(true); generator.setStatii(TableStatus.open); Set<Table> generated = generator.generateTables(1); GameStatus gameStatus = mock(GameStatus.class); when(gameRepository.getGameRules(anyString())).thenReturn(gameRules); when(gameRules.getJoiningDesirability(gameStatus)).thenReturn(45); Table first = generated.iterator().next(); first.addPlayerToTable(new PlayerInformation(BigDecimal.ONE)); first.setTableId(BigDecimal.valueOf(67)); first.setCurrentGame(gameStatus); gigaSpace.writeMultiple(generated.toArray(new Table[generated.size()])); Collection<TableSearchResult> found = tableSearchService.findTables( BigDecimal.TEN, new TableSearchCriteria(gameType, variation, clientId, Collections.<String>emptySet())); assertEquals(1, found.size()); TableSearchResult table = found.iterator().next(); assertEquals(BigDecimal.valueOf(67), table.getTableId()); assertEquals(10, table.getSpareSeats()); assertEquals(10, table.getMaxSeats()); assertEquals(45, table.getJoiningDesirability()); }
private Table createTable() { Table table = new Table(createGameType(), BigDecimal.ONE, CLIENT_ID, true); table.setTableId(BigDecimal.ONE); return table; }
@Before public void setUp() throws com.yazino.game.api.GameException, WalletServiceException { MockitoAnnotations.initMocks(this); timeSource = new SettableTimeSource(System.currentTimeMillis()); command = new CommandWrapper(TABLE_ID, GAME_ID, A_PLAYER.getId(), SESSION_ID, "T"); command.setRequestId(UUID); playerStatisticEventsPublisher = new InMemoryPlayerStatisticEventsPublisher(); table = new Table( new com.yazino.game.api.GameType(GAME_TYPE, "Test", Collections.<String>emptySet()), BigDecimal.ONE, "test", true); table.setTableId(TABLE_ID); table.setTableStatus(TableStatus.open); table.setVariationProperties(new HashMap<String, String>()); when(bufferedGameHostWalletFactory.create(table.getTableId(), command.getRequestId())) .thenReturn(bufferedGameHostWallet); when(bufferedGameHostWalletFactory.create(table.getTableId())) .thenReturn(bufferedGameHostWallet); when(auditor.newLabel()).thenReturn(AUDIT_LABEL); when(bufferedGameHostWallet.getBalance(Mockito.isA(BigDecimal.class))) .thenReturn(BigDecimal.ZERO); when(uuidSource.getNewUUID()).thenReturn(NEW_UUID); when(auditor.newLabel()).thenReturn(AUDIT_LABEL); when(bufferedGameHostWallet.getBalance(Mockito.isA(BigDecimal.class))) .thenReturn(ACCOUNT_BALANCE); when(gameRules.getGameType()).thenReturn("TEST"); when(playerRepository.findSummaryByPlayerAndSession(PLAYER_ID, SESSION_ID)) .thenReturn( aPlayerSessionSummary(PLAYER_ID, "Player", PLAYER_ACCOUNT_ID, BigDecimal.valueOf(100))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER_ID, null)) .thenReturn( aPlayerSessionSummary(PLAYER_ID, "Player", PLAYER_ACCOUNT_ID, BigDecimal.valueOf(100))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER1_ID, null)) .thenReturn( aPlayerSessionSummary( PLAYER1_ID, "Player1", PLAYER1_ACCOUNT_ID, BigDecimal.valueOf(200))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER2_ID, null)) .thenReturn( aPlayerSessionSummary( PLAYER2_ID, "Player2", PLAYER2_ACCOUNT_ID, BigDecimal.valueOf(300))); when(chatRepository.getOrCreateForLocation(TABLE_ID.toPlainString())) .thenReturn(new ChatChannel(TABLE_ID.toPlainString())); }