implemented test for converting imdb data to json

master
Vyacheslav Boyko 2019-01-14 14:08:09 +03:00
parent c8cc887938
commit d519856dfd
2 changed files with 31 additions and 0 deletions

View File

@ -29,6 +29,25 @@
<scope>compile</scope>
</dependency>
<!-- http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.8.6/jackson-core-2.8.6.jar -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.7</version>
</dependency>
<!-- http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.8.6/jackson-annotations-2.8.6.jar -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<!-- http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.8.6/jackson-databind-2.8.6.jar -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -1,5 +1,7 @@
package ru.bvn13.imdbspider.runner;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import ru.bvn13.imdbspider.ImdbSpider;
@ -36,4 +38,14 @@ public class MovieSearchTest
assertEquals("The Terminator", movie.getOriginalTitle());
assertEquals(Integer.valueOf(1984), movie.getYear());
}
@Test
public void testSearchTerminatorReturnsJson() throws ImdbSpiderException, JsonProcessingException {
MovieList result = spider.searchMovieByTitle("Терминатор", 5, EnumSet.of(MovieDataType.ID, MovieDataType.TITLE, MovieDataType.ORIGINAL_TITLE, MovieDataType.YEAR));
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(result);
//System.out.println("JSON = " + json);
assertEquals("{\"retrievedDataTypes\":[\"ELEMENTS\"],\"id\":null,\"url\":\"https://www.imdb.com/find?ref_=nv_sr_fn&q=%D0%A2%D0%B5%D1%80%D0%BC%D0%B8%D0%BD%D0%B0%D1%82%D0%BE%D1%80&s=tt\",\"movies\":[{\"retrievedDataTypes\":[\"ID\",\"TITLE\",\"ORIGINAL_TITLE\",\"YEAR\"],\"id\":\"0088247\",\"url\":\"https://www.imdb.com/title/tt0088247/?ref_=fn_tt_tt_1\",\"title\":\"Терминатор (1984)\",\"originalTitle\":\"The Terminator\",\"year\":1984,\"akas\":{}}]}", json);
}
}