// Path: src/main/java/no/asgari/civilization/server/model/PBF.java
// @Data
// @JsonRootName(value = "pbf")
// @XmlRootElement
// @JsonInclude
// @JsonIgnoreProperties(ignoreUnknown = true)
// //Perhaps use this when the object keep getting changed, otherwise jackson throws exception when it cannot map
// public class PBF {
//     @JsonIgnore
//     public static final String COL_NAME = "pbf";
//     @JsonIgnore
//     public static final String NAME = "name";
// 
//     @ObjectId
//     @Id
//     private String id;
// 
//     @NotBlank
//     private String name;
//     private GameType type;
//     private String mapLink;
//     private String assetLink;
// 
//     @JsonSerialize(using = LocalDateTimeSerializer.class)
//     @JsonDeserialize(using = LocalDateTimeDeserializer.class)
//     private LocalDateTime created = LocalDateTime.now();
// 
//     private int numOfPlayers;
//     private boolean active = true;
//     private String winner; //username
//     private List<Item> items = Lists.newArrayList();
//     private List<Playerhand> players = Lists.newArrayList();
//     private List<Tech> techs = Lists.newArrayList();
//     private List<SocialPolicy> socialPolicies = new ArrayList<>(8);
// 
//     //@JsonSerialize(keyUsing=TurnKeySerializer.class)
//     //@JsonDeserialize(keyUsing = TurnKeyDeserializer.class)
//     private Map<String, PlayerTurn> publicTurns = new HashMap<>();
// 
//     //Will use these to reshuffle items which are discarded and can be drawn again
//     private List<Item> discardedItems = new ArrayList<>();
// 
//     //If a player leaves, his items and stuff will be put here
//     private List<Playerhand> withdrawnPlayers = new ArrayList<>();
// 
//     private boolean tournament = false;
// 
//     /**
//      * Returns the username of the player who is start of turn
//      */
//     @JsonIgnore
//     public String getNameOfUsersTurn() {
//         Optional<Playerhand> optional = players.stream()
//                 .filter(Playerhand::isYourTurn)
//                 .findFirst();
// 
//         if (optional.isPresent()) {
//             return optional.get().getUsername();
//         }
// 
//         return "";
//     }
// 
// }
// 
// Path: src/main/java/no/asgari/civilization/server/model/Player.java
// @Data
// @JsonRootName("player")
// @NoArgsConstructor
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Player {
//     @JsonIgnore
//     public static final String COL_NAME = "player";
//     @JsonIgnore
//     public static final String USERNAME = "username";
//     @JsonIgnore
//     public static final String EMAIL = "email";
// 
//     @ObjectId
//     @Id
//     private String id;
// 
//     @NotBlank
//     //Unique
//     private String username;
// 
//     @Email
//     private String email;
// 
//     private boolean disableEmail = false;
// 
//     @NotBlank
//     private String password;
// 
//     private String newPassword;
// 
//     @JsonSerialize(using = LocalDateTimeSerializer.class)
//     @JsonDeserialize(using = LocalDateTimeDeserializer.class)
//     private LocalDateTime emailSent;
// 
//     /**
//      * Set of unique active games This may be reduntant as it can be calculated by looping through all pbfs.players and finding match.
//      */
//     private Set<String> gameIds = new HashSet<>();
// 
//     @JsonIgnore
//     public Optional<LocalDateTime> getIfEmailSent() {
//         return Optional.ofNullable(emailSent);
//     }
// }


import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Cleanup;
import no.asgari.civilization.server.model.PBF;
import no.asgari.civilization.server.model.Player;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.mongojack.DBCursor;
import org.mongojack.WriteResult;
import java.io.IOException;
import static org.junit.Assert.assertNotNull;
package no.asgari.civilization.server.mongodb;




public class MongoDBTest extends AbstractCivilizationTest {

    private static Player createPlayer(String username, String pbfId) throws JsonProcessingException {
        //The Player object should be cached and retrieved from cache
        Player player = new Player();
        player.setUsername(username);
        player.setPassword(DigestUtils.sha1Hex("foo"));
        player.getGameIds().add(pbfId);

        WriteResult<Player, String> writeResult = getApp().playerCollection.insert(player);
        System.out.println("Saved player " + writeResult.toString());
        assertNotNull(writeResult.getSavedId());
        return player;
    }

    @Test
    public void printAllPBFGames() throws IOException {
        @Cleanup DBCursor<PBF> cursor = getApp().pbfCollection.find();
        while (cursor.hasNext()) {
// Path: src/main/java/no/asgari/civilization/server/model/PBF.java
// @Data
// @JsonRootName(value = "pbf")
// @XmlRootElement
// @JsonInclude
// @JsonIgnoreProperties(ignoreUnknown = true)
// //Perhaps use this when the object keep getting changed, otherwise jackson throws exception when it cannot map
// public class PBF {
//     @JsonIgnore
//     public static final String COL_NAME = "pbf";
//     @JsonIgnore
//     public static final String NAME = "name";
// 
//     @ObjectId
//     @Id
//     private String id;
// 
//     @NotBlank
//     private String name;
//     private GameType type;
//     private String mapLink;
//     private String assetLink;
// 
//     @JsonSerialize(using = LocalDateTimeSerializer.class)
//     @JsonDeserialize(using = LocalDateTimeDeserializer.class)
//     private LocalDateTime created = LocalDateTime.now();
// 
//     private int numOfPlayers;
//     private boolean active = true;
//     private String winner; //username
//     private List<Item> items = Lists.newArrayList();
//     private List<Playerhand> players = Lists.newArrayList();
//     private List<Tech> techs = Lists.newArrayList();
//     private List<SocialPolicy> socialPolicies = new ArrayList<>(8);
// 
//     //@JsonSerialize(keyUsing=TurnKeySerializer.class)
//     //@JsonDeserialize(keyUsing = TurnKeyDeserializer.class)
//     private Map<String, PlayerTurn> publicTurns = new HashMap<>();
// 
//     //Will use these to reshuffle items which are discarded and can be drawn again
//     private List<Item> discardedItems = new ArrayList<>();
// 
//     //If a player leaves, his items and stuff will be put here
//     private List<Playerhand> withdrawnPlayers = new ArrayList<>();
// 
//     private boolean tournament = false;
// 
//     /**
//      * Returns the username of the player who is start of turn
//      */
//     @JsonIgnore
//     public String getNameOfUsersTurn() {
//         Optional<Playerhand> optional = players.stream()
//                 .filter(Playerhand::isYourTurn)
//                 .findFirst();
// 
//         if (optional.isPresent()) {
//             return optional.get().getUsername();
//         }
// 
//         return "";
//     }
// 
// }
// 
// Path: src/main/java/no/asgari/civilization/server/model/Player.java
// @Data
// @JsonRootName("player")
// @NoArgsConstructor
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Player {
//     @JsonIgnore
//     public static final String COL_NAME = "player";
//     @JsonIgnore
//     public static final String USERNAME = "username";
//     @JsonIgnore
//     public static final String EMAIL = "email";
// 
//     @ObjectId
//     @Id
//     private String id;
// 
//     @NotBlank
//     //Unique
//     private String username;
// 
//     @Email
//     private String email;
// 
//     private boolean disableEmail = false;
// 
//     @NotBlank
//     private String password;
// 
//     private String newPassword;
// 
//     @JsonSerialize(using = LocalDateTimeSerializer.class)
//     @JsonDeserialize(using = LocalDateTimeDeserializer.class)
//     private LocalDateTime emailSent;
// 
//     /**
//      * Set of unique active games This may be reduntant as it can be calculated by looping through all pbfs.players and finding match.
//      */
//     private Set<String> gameIds = new HashSet<>();
// 
//     @JsonIgnore
//     public Optional<LocalDateTime> getIfEmailSent() {
//         return Optional.ofNullable(emailSent);
//     }
// }


// Path: src/test/java/no/asgari/civilization/server/mongodb/MongoDBTest.java
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Cleanup;
import no.asgari.civilization.server.model.PBF;
import no.asgari.civilization.server.model.Player;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.mongojack.DBCursor;
import org.mongojack.WriteResult;
import java.io.IOException;
import static org.junit.Assert.assertNotNull;

package no.asgari.civilization.server.mongodb;




public class MongoDBTest extends AbstractCivilizationTest {

    private static Player createPlayer(String username, String pbfId) throws JsonProcessingException {
        //The Player object should be cached and retrieved from cache
        Player player = new Player();
        player.setUsername(username);
        player.setPassword(DigestUtils.sha1Hex("foo"));
        player.getGameIds().add(pbfId);

        WriteResult<Player, String> writeResult = getApp().playerCollection.insert(player);
        System.out.println("Saved player " + writeResult.toString());
        assertNotNull(writeResult.getSavedId());
        return player;
    }

    @Test
    public void printAllPBFGames() throws IOException {
        @Cleanup DBCursor<PBF> cursor = getApp().pbfCollection.find();
        while (cursor.hasNext()) {
            PBF pbf = cursor.next();