QuoteService { @HystrixCommand(fallbackMethod = "getMarkitondemandQuotes", commandProperties = {@HystrixProperty(name="execution.timeout.enabled", value="false")}) public List<Quote> getQuotes(String symbols) throws SymbolNotFoundException { logger.debug("retrieving quotes for: " + symbols); if ( symbols.isEmpty() ) return new ArrayList<>(); YahooQuoteResponses responses = restTemplate.getForObject(yahoo_url, YahooQuoteResponses.class, symbols, FMT, ENV); logger.debug("Got responses: " + responses); List<YahooQuote> yahooQuotes = responses.getResults().getQuoteList().getQuote(); Date createDate = responses.getResults().getCreated(); List<Quote> quotes = yahooQuotes .stream() .map(yQuote -> QuoteMapper.INSTANCE.mapFromYahooQuote(yQuote, createDate)) .collect(Collectors.toList()); for (Quote quote : quotes) { if ( quote.getName() == null ) throw new SymbolNotFoundException( quote.getSymbol() + " not found" ); } return quotes; } QuoteService(); @HystrixCommand(fallbackMethod = "getMarkitondemandQuotes", commandProperties = {@HystrixProperty(name="execution.timeout.enabled", value="false")}) List<Quote> getQuotes(String symbols); @HystrixCommand(fallbackMethod = "getQuotesFallback", commandProperties = {@HystrixProperty(name="execution.timeout.enabled", value="false")}) @SuppressWarnings("unused") List<Quote> getMarkitondemandQuotes(String symbols); @HystrixCommand(fallbackMethod = "getCompanyInfoFallback", commandProperties = {@HystrixProperty(name="execution.timeout.enabled", value="false")}) List<CompanyInfo> getCompanyInfo(String name); static final String FMT; }
@Test public void getQuote() throws Exception { Quote quote = service.getQuotes(TestConfiguration.QUOTE_SYMBOL).get(0); assertEquals(TestConfiguration.QUOTE_SYMBOL, quote.getSymbol()); assertEquals(TestConfiguration.QUOTE_NAME, quote.getName()); }
@Test public void getNullQuote() throws Exception{ thrown.expect(com.netflix.hystrix.exception.HystrixRuntimeException.class); thrown.expectCause(isA(SymbolNotFoundException.class)); service.getQuotes(TestConfiguration.NULL_QUOTE_SYMBOL); }
@Test public void getQuotes() throws Exception { List<Quote> quotes = service.getQuotes(TestConfiguration.QUOTE_SYMBOLS); assertNotNull("should have 2 quotes",quotes); assertEquals("should have 2 quotes",quotes.size(), 2); }