package org.itevents;

import org.itevents.model.Event;
import org.itevents.model.Location;
import org.itevents.service.EventService;
import org.junit.*;
import org.junit.runners.MethodSorters;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class EventServiceTest {

    private static EventService eventService;
    private static Event addingEvent;
    private static SimpleDateFormat formatter;

    @BeforeClass
    public static void setup() throws ParseException {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] {"applicationContext.xml", "testApplicationContext.xml"});
        eventService = context.getBean("eventService", EventService.class);
        formatter = new SimpleDateFormat("dd.MM.yyyy");
        addingEvent = new Event("Ruby", formatter.parse("20.07.2015"), null, "http://www.ruby.com.ua", "Shulyavska",
                new Location(50.454605, 30.445495), "ruby@gmail.com");
    }

    @AfterClass
    public static void teardown() {
        eventService = null;
        addingEvent = null;
        formatter = null;
    }

    @Test
    public void testGetEventById() throws ParseException {
        Event expectedEvent = new Event(1, "Java", formatter.parse("10.07.2015"), null, "http://www.java.com.ua", "Beresteyska",
                new Location(50.458585, 30.742017), "java@gmail.com");
        Event returnedEvent = eventService.getEvent(1);
        Assert.assertEquals(expectedEvent, returnedEvent);
    }

    @Test
    public void testGetAllEvents() throws ParseException {
        List<Event> returnedEvents = eventService.getAllEvents();
        Assert.assertEquals(returnedEvents.size(), 7);
    }

    @Test
    public void testRemoveEvent() throws ParseException {
        Event expectedEvent = addingEvent;
        eventService.addEvent(expectedEvent);
        Event returnedEvent = eventService.removeEvent(expectedEvent);
        expectedEvent.setId(returnedEvent.getId());
        Assert.assertEquals(expectedEvent, returnedEvent);
    }

    @Test
    public void testAddEvent() throws ParseException {
        eventService.addEvent(addingEvent);
        Event returnedEvent = eventService.getEvent(addingEvent.getId());
        Assert.assertEquals(addingEvent, returnedEvent);
        eventService.removeEvent(returnedEvent);
    }
}
@@ -496,16 +496,96 @@
 Test %7B%0A%0A
+    private final static int ID_1 = 1;%0A    private final static int SIZE_7 = 7;%0A
     priv
@@ -1596,23 +1596,8 @@
 ua%22,
- %22Beresteyska%22,
 %0A   
@@ -1600,32 +1600,47 @@
 %0A               
+ %22Beresteyska%22,
  new Location(50
@@ -1731,16 +1731,19 @@
 etEvent(
+ID_
 1);%0A    
@@ -1865,32 +1865,67 @@
 arseException %7B%0A
+        int expectedSize = SIZE_7;%0A
         List%3CEve
@@ -2002,16 +2002,30 @@
 tEquals(
+expectedSize, 
 returned
@@ -2041,11 +2041,8 @@
 ze()
-, 7
 );%0A 

fix magic numbers in EventServiceTest