/** * Test of getInfo method, of class OmdbApi. * * @throws OMDBException */ @Test public void testMovieInfo_4args() throws OMDBException { LOG.info("movieInfo - All args"); OmdbVideoFull result = null; for (TestID test : IDS) { LOG.info("Testing: '{}'", test.getTitle()); result = omdb.getInfo( new OmdbBuilder() .setTitle(test.getTitle()) .setYear(test.getYear()) .setPlotLong() .setTomatoes(true) .build()); assertNotNull("Null object returned", result); assertTrue("Error with call", result.isResponse()); assertEquals("Wrong video returned", test.getImdb(), result.getImdbID()); assertTrue("No RT data", StringUtils.isNotBlank(result.getTomatoConsensus())); } try { result = omdb.getInfo(new OmdbBuilder().setTitle("Some movie that can't be found at all").build()); assertFalse("What do you mean this was found?", result.isResponse()); } catch (OMDBException ex) { assertNotNull("Null object returned", result); } }
/** * Using junit 3.x naming standards for unit tests and test method names, attempt to discover the * unit test name from the execution stack. * * @return the unit test id found via execution stack and junit 3.8 naming conventions. * @see #getTestIDAsPath() */ private static TestID getTestID() { StackTraceElement stacked[] = new Throwable().getStackTrace(); for (StackTraceElement stack : stacked) { if (stack.getClassName().endsWith("Test")) { if (stack.getMethodName().startsWith("test")) { TestID testid = new TestID(); testid.classname = stack.getClassName(); testid.methodname = stack.getMethodName(); return testid; } } } // If we have reached this point, we have failed to find the test id String LN = System.getProperty("line.separator"); StringBuilder err = new StringBuilder(); err.append("Unable to find a TestID from a testcase that "); err.append("doesn't follow the standard naming rules."); err.append(LN); err.append("Test class name must end in \"*Test\"."); err.append(LN); err.append("Test method name must start in \"test*\"."); err.append(LN); err.append("Call to ").append(MavenTestingUtils.class.getSimpleName()); err.append(".getTestID(), must occur from within stack frame of "); err.append("test method, not @Before, @After, @BeforeClass, "); err.append("@AfterClass, or Constructors of test case."); Assert.fail(err.toString()); return null; }
/** * Test of getInfo method, of class OmdbApi. * * @throws OMDBException */ @Test public void testMovieInfo_ByTT() throws OMDBException { LOG.info("movieInfo_ByTT"); for (TestID test : IDS) { LOG.info("Testing: '{}'", test.getTitle()); OmdbVideoFull result = omdb.getInfo(new OmdbBuilder().setImdbId(test.getImdb()).build()); assertEquals("Wrong movie returned", test.getTitle(), result.getTitle()); } }
/** * Test of build method, of class OmdbApi. * * @throws OMDBException */ @Test public void testSearch_String_int() throws OMDBException { LOG.info("Search - Title & Year"); for (TestID test : IDS) { LOG.info("Testing: '{}'", test.getTitle()); SearchResults result = omdb.search(test.getTitle(), test.getYear()); assertNotNull("Null search returned", result); assertTrue("Error response", result.isResponse()); assertTrue("No records found", result.getResults().size() > 0); boolean found = false; for (OmdbVideoBasic movie : result.getResults()) { if (StringUtils.equals(test.getImdb(), movie.getImdbID())) { found = true; break; } } assertTrue("Movie not found in search results", found); } }