package de.nicidienase.chaosflix;



import static org.junit.Assert.*;

import org.junit.Test;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import de.nicidienase.chaosflix.entities.Conference;
import de.nicidienase.chaosflix.entities.Conferences;
import de.nicidienase.chaosflix.entities.Event;
import de.nicidienase.chaosflix.entities.Recording;
import de.nicidienase.chaosflix.network.MediaCCCClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by felix on 17.03.17.
 */

public class MediaCCCClientTest{

	@Test
	public void getConferenceTest(){
		try {
			Conference conference = new MediaCCCClient().getConference(101).execute().body();
			assertEquals(conference.getAcronym(),"33c3");
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void getEventTest(){
		try {
			Event event = new MediaCCCClient().getEvent(3674).execute().body();
			assertEquals(event.getGuid(),"bfc2ab1f-8384-4d7d-801a-dde8c81e039c");
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void getEventRecordingsTest(){
		try {
			Event event = new MediaCCCClient().getEvent(3674).execute().body();
			assertEquals(event.getRecordings().size(),9);
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}


	@Test
	public void getRecordingTest(){
		try {
			Recording recording = new MediaCCCClient().getRecording(14142).execute().body();
			assertEquals(recording.getUpdatedAt(), "2016-12-29T03:16:16.105+01:00");
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void getConferencEventListTest(){
		try {
			Conferences conferences = new MediaCCCClient().listConferences().execute().body();
			assertEquals(99,conferences.getConferences().size());
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void eventTagsTest(){
		try {
			Conference conference = new MediaCCCClient().getConference(101).execute().body();
			assertEquals(12,conference.getEventsByTags().keySet().size());
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void sortTest(){
		try {
			final MediaCCCClient client = new MediaCCCClient();
			Conferences conferences = client.listConferences().execute().body();
			Collections.sort(conferences.getConferences());
			for (Conference conf : conferences.getConferences()) {
				List<Event> events =
						client.getConference(conf.getApiID()).execute().body().getEvents();
				Collections.sort(events);
			}
		}catch (IOException e){
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void sortAllEvents(){
		try{
			MediaCCCClient client = new MediaCCCClient();
			Collections.sort(client.getEvents().execute().body());
		} catch (IOException e) {
			e.printStackTrace();
			fail();
		}
	}
}

@@ -623,31 +623,43 @@
 erenceTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09Confer
@@ -787,75 +787,8 @@
 %22);%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -817,31 +817,43 @@
 tEventTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09Event 
@@ -991,75 +991,8 @@
 %22);%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -1031,31 +1031,43 @@
 rdingsTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09Event 
@@ -1181,75 +1181,8 @@
 9);%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -1216,31 +1216,43 @@
 ordingTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09Record
@@ -1406,75 +1406,8 @@
 %22);%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -1449,31 +1449,43 @@
 ntListTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09Confer
@@ -1622,75 +1622,8 @@
 ));%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -1653,31 +1653,43 @@
 ntTagsTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09Confer
@@ -1834,75 +1834,8 @@
 ));%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -1864,23 +1864,35 @@
 rtTest()
-%7B%0A%09%09try
+ throws IOException
  %7B%0A%09%09%09fi
@@ -2260,73 +2260,8 @@
 %09%09%7D%0A
-%09%09%7Dcatch (IOException e)%7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%0A
@@ -2299,15 +2299,28 @@
 ts()
-%7B%0A%09%09try
+ throws IOException 
 %7B%0A%09%09
@@ -2428,75 +2428,8 @@
 ));%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09fail();%0A%09%09%7D%0A
 %09%7D%0A%7D

replace try-catch with throws-declarations