package com.cloudbees.breizhcamp.services;

import static org.fest.assertions.Assertions.assertThat;

import java.net.URL;
import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.cloudbees.breizhcamp.PersistenceTestCase;
import com.cloudbees.breizhcamp.Schedule;
import com.cloudbees.breizhcamp.domain.Speaker;
import com.cloudbees.breizhcamp.domain.Talk;
import com.cloudbees.breizhcamp.domain.Theme;

/**
 * @author: <a hef="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
 */
public class ScheduleTest extends PersistenceTestCase {

    @Autowired
    private Schedule schedule;

    @Test
    public void basicTest() throws Exception {
        Speaker speaker = new Speaker();
        speaker.setFirstName("James");
        speaker.setLastName("Gosling");
        speaker.setPicture(new URL("http://upload.wikimedia.org/wikipedia/commons/0/00/James_Gosling_2005.jpg"));

        Talk talk = new Talk();
        talk.setTitle("Java and more");
        talk.setAbstract("What's coming in Java 9, 1O, 11");
        talk.setRoom("Amphi");
        talk.setStart(new Date(123456789012L));
        talk.setEnd(new Date(123456789999L));
        talk.setTheme(Theme.DECOUVRIR);

        talk.getSpeakers().add(speaker);
        speaker.getTalks().add(talk);

        em.persist(speaker);
        em.persist(talk);
        em.flush();

        List<Talk> talks = schedule.getSchedule("Amphi");
        assertThat(talks).isNotNull().hasSize(1).containsExactly(talk);
    }
}

@@ -668,16 +668,21 @@
 chedule;
+%0A    
 %0A%0A    @T
@@ -705,17 +705,35 @@
 oid 
-basicTest
+should_get_schedule_by_room
 () t
@@ -1576,10 +1576,497 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void should_find_speaker() throws Exception%7B%0A        Speaker speaker = new Speaker();%0A        speaker.setFirstName(%22James%22);%0A        speaker.setLastName(%22Gosling%22);%0A        speaker.setPicture(new URL(%22http://upload.wikimedia.org/wikipedia/commons/0/00/James_Gosling_2005.jpg%22));%0A        %0A        em.persist(speaker);%0A        em.flush();%0A        %0A        Speaker result = schedule.getSpeaker(1L);%0A        assertThat(result).isNotNull().isEqualTo(speaker);%0A    %7D%0A
 %7D%0A

add test on schedule getSpeaker