package de.flux.playground.deckcompare.importer;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.Test;

import de.flux.playground.deckcompare.dto.Deck;

public class DeckImporterTest {

    private static final int FIRST_SECTION = 0;
    private static final int SECOND_SECTION = 1;

    @Test
    public void importDeck() throws Exception {
        DeckImporter importer = new DeckImporter();

        File deckFile = obtainDeckFile("the-fun-ends-here-shl-jinteki-edition-1st-.o8d");
        Deck deck = importer.importDeck(deckFile);

        assertThat(deck.getGame(), is("0f38e453-26df-4c04-9d67-6d43de939c77"));
        assertSections(deck);
        assertThat(deck.getNotes(), is(not("")));
    }

    private void assertSections(Deck deck) {
        assertThat(deck.getSection().size(), is(2));
        assertIdentity(deck);
        assertCardsOfDeck(deck);
    }

    private void assertIdentity(Deck deck) {
        assertThat(deck.getSection().get(FIRST_SECTION).getCard().size(), is(1));
        // TODO: add more asserts for the identity
    }

    private void assertCardsOfDeck(Deck deck) {
        assertThat(deck.getSection().get(SECOND_SECTION).getCard().size(), is(24));
        // TODO: add more asserts for the cards of the deck
    }

    private File obtainDeckFile(String fileName) throws URISyntaxException {
        URL url = DeckImporterTest.class.getResource(fileName);
        return new File(url.toURI());
    }

}

@@ -331,20 +331,119 @@
 are.dto.
-Deck
+Card;%0Aimport de.flux.playground.deckcompare.dto.Deck;%0Aimport de.flux.playground.deckcompare.dto.Section
 ;%0A%0Apubli
@@ -852,12 +852,10 @@
 .get
-Game
+Id
 (), 
@@ -1065,16 +1065,17 @@
 tSection
+s
 ().size(
@@ -1204,35 +1204,50 @@
 ) %7B%0A        
-assertThat(
+Section identitySection = 
 deck.getSect
@@ -1245,24 +1245,25 @@
 k.getSection
+s
 ().get(FIRST
@@ -1267,32 +1267,68 @@
 RST_SECTION)
+;%0A        assertThat(identitySection
 .getCard
 ().size(), i
@@ -1307,32 +1307,33 @@
 ySection.getCard
+s
 ().size(), is(1)
@@ -1347,50 +1347,343 @@
     
-// TODO: add more asserts for the identity
+assertThat(identitySection.getName(), is(%22Identity%22));%0A%0A        Card identityCard = identitySection.getCards().get(0);%0A        assertThat(identityCard.getId(), is(%22bc0f047c-01b1-427f-a439-d451eda07029%22));%0A        assertThat(identityCard.getQuantity(), is(1));%0A        assertThat(identityCard.getValue(), is(%22MaxX: Maximum Punk Rock%22));
 %0A   
@@ -1738,35 +1738,47 @@
 ) %7B%0A        
-assertThat(
+Section cardsSection = 
 deck.getSect
@@ -1780,16 +1780,17 @@
 tSection
+s
 ().get(S
@@ -1803,24 +1803,57 @@
 SECTION)
+;%0A        assertThat(cardsSection
 .getCard
 ().size(
@@ -1844,16 +1844,17 @@
 .getCard
+s
 ().size(
@@ -1877,59 +1877,361 @@
     
-// TODO: add more asserts for the cards of the deck
+assertThat(cardsSection.getName(), is(%22R&D / Stack%22));%0A%0A        // assert all values of one card%0A        Card regularCard = cardsSection.getCards().get(0);%0A        assertThat(regularCard.getId(), is(%22bc0f047c-01b1-427f-a439-d451eda01002%22));%0A        assertThat(regularCard.getQuantity(), is(3));%0A        assertThat(regularCard.getValue(), is(%22D%C3%A9j%C3%A0 Vu%22));
 %0A   

Add more asserts to ensure a successful import