package com.altimetrik.ee.demo.tests;

import static org.assertj.core.api.Assertions.assertThat;

import com.altimetrik.ee.demo.bean.Stocks;
import com.altimetrik.ee.demo.repository.StocksRepository;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@DataJpaTest
public class StocksRepositoryTest {

  @Autowired
  private StocksRepository stocksRepository;
  @Test
  public void shouldCreateNewStock() throws ParseException {
    String str="2018-09-01 09:01:15";
    Timestamp timestamp= Timestamp.valueOf(str);
    Stocks s1 = new Stocks("HCL-1", "HCL", timestamp, 420.0, "INR");
    stocksRepository.save(s1);
  }

  @Test
  public void shouldGetStocksByName() throws ParseException {
    String str="2018-09-01 09:01:15";
    Timestamp timestamp= Timestamp.valueOf(str);
    Stocks s1 = new Stocks("HCL-1", "HCL", timestamp, 420.0, "INR");
    Stocks s2 = new Stocks("HCL-2", "HCL", timestamp, 520.0, "USD");
    Stocks s3 = new Stocks("HCL-3", "HCL", timestamp, 620.0, "JNY");
    Stocks s4 = new Stocks("HCL-4", "HCL", timestamp, 720.0, "INR");

    List<Stocks> list  = new ArrayList<>();
    list.add(s1);
    list.add(s2);
    list.add(s3);
    list.add(s4);
    stocksRepository.saveAll(list);

    List<String> queries = new ArrayList<>();
    queries.add("HCL-1");
    queries.add("HCL-2");
    queries.add("HCL-3");
    Iterable<Stocks> users = stocksRepository.findByStockQuotes(queries);
    users.forEach(e -> System.out.println(e.toString()));
    assertThat(users).hasSize(3);
  }
}
