// Path: src/main/java/com/storage/mywarehouse/Dao/ProductDAO.java
// public class ProductDAO {
// 
//     @SuppressWarnings("unchecked")
//     public static List<Product> findAll() {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         List products = session.createCriteria(Product.class).list();
//         transaction.commit();
//         session.close();
//         return products;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static List<Product> findAllByBrandAndTypeStartLike(String brand, String type) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         List products = session.createCriteria(Product.class).add(
//                 and(eq("brand", brand),
//                         Restrictions.like("type", type, MatchMode.START)))
//                 .list();
//         session.close();
//         return products;
//     }
// 
//     public static Product findById(int productId) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         List products = session.createCriteria(Product.class)
//                 .add(Restrictions.eq("productId", productId))
//                 .list();
//         Product pr = (Product) products.get(0);
//         transaction.commit();
//         session.close();
//         return pr;
//     }
// 
//     public static Product findByBrandAndName(String brand, String type) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         Product existingProduct = (Product) session.createCriteria(Product.class)
//                 .add(and(eq("brand", brand), eq("type", type)))
//                 .uniqueResult();
//         transaction.commit();
//         session.close();
//         return existingProduct;
//     }
// 
//     public static Product save(Product product) {
//         int productId;
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         Product productWithHighestId = (Product) session.createCriteria(Product.class)
//                 .addOrder(Order.desc("productId"))
//                 .setMaxResults(1)
//                 .uniqueResult();
//         transaction.commit();
//         if (productWithHighestId == null) {
//             productId = 0;
//         } else {
//             productId = productWithHighestId.getProductId() + 1;
//         }
//         product.setProductId(productId);
//         transaction = session.beginTransaction();
//         session.save(product);
//         transaction.commit();
//         session.close();
//         return product;
//     }
// 
//     public static void deleteAll(List<Product> products) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         for (Product p : products) {
//             session.delete(p);
//         }
//         transaction.commit();
//         session.close();
//     }
// 
//     public static void delete(Product product) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         session.delete(product);
//         transaction.commit();
//         session.close();
//     }
// }
// 
// Path: src/main/java/com/storage/mywarehouse/Entity/Product.java
// public class Product implements java.io.Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private int productId;
// 	private String brand;
// 	private String type;
// 	private String description;
// 	private double price;
// 
// 	public Product() {
// 	}
// 
// 	public Product(int productId, String brand, String type, double price) {
// 		this.productId = productId;
// 		this.brand = brand;
// 		this.type = type;
// 		this.price = price;
// 	}
// 
// 	public Product(int productId, String brand, String type, String description, double price) {
// 		this.productId = productId;
// 		this.brand = brand;
// 		this.type = type;
// 		this.description = description;
// 		this.price = price;
// 	}
// 
// 	public Product(String brand, String type, String description, double price) {
// 		this.brand = brand;
// 		this.type = type;
// 		this.description = description;
// 		this.price = price;
// 	}
// 
// 	public int getProductId() {
// 		return this.productId;
// 	}
// 
// 	public void setProductId(int productId) {
// 		this.productId = productId;
// 	}
// 
// 	public String getBrand() {
// 		return this.brand;
// 	}
// 
// 	public void setBrand(String brand) {
// 		this.brand = brand;
// 	}
// 
// 	public String getType() {
// 		return this.type;
// 	}
// 
// 	public void setType(String type) {
// 		this.type = type;
// 	}
// 
// 	public String getDescription() {
// 		return this.description;
// 	}
// 
// 	public void setDescription(String description) {
// 		this.description = description;
// 	}
// 
// 	public double getPrice() {
// 		return this.price;
// 	}
// 
// 	public void setPrice(double price) {
// 		this.price = price;
// 	}
// 
// }


import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.storage.mywarehouse.Dao.ProductDAO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.storage.mywarehouse.Entity.Product;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.storage.mywarehouse;






/**
 *
 * @author veruz
 */
public class UtilsImportProductsFromCsvTest {

	private File file = new File("src/test/resources/products.csv");

	@AfterEach
	public void tearDown() {
		deleteTestEntries();
	}

	@Test
	public void testExistence() {
// Path: src/main/java/com/storage/mywarehouse/Dao/ProductDAO.java
// public class ProductDAO {
// 
//     @SuppressWarnings("unchecked")
//     public static List<Product> findAll() {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         List products = session.createCriteria(Product.class).list();
//         transaction.commit();
//         session.close();
//         return products;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static List<Product> findAllByBrandAndTypeStartLike(String brand, String type) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         List products = session.createCriteria(Product.class).add(
//                 and(eq("brand", brand),
//                         Restrictions.like("type", type, MatchMode.START)))
//                 .list();
//         session.close();
//         return products;
//     }
// 
//     public static Product findById(int productId) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         List products = session.createCriteria(Product.class)
//                 .add(Restrictions.eq("productId", productId))
//                 .list();
//         Product pr = (Product) products.get(0);
//         transaction.commit();
//         session.close();
//         return pr;
//     }
// 
//     public static Product findByBrandAndName(String brand, String type) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         Product existingProduct = (Product) session.createCriteria(Product.class)
//                 .add(and(eq("brand", brand), eq("type", type)))
//                 .uniqueResult();
//         transaction.commit();
//         session.close();
//         return existingProduct;
//     }
// 
//     public static Product save(Product product) {
//         int productId;
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         Product productWithHighestId = (Product) session.createCriteria(Product.class)
//                 .addOrder(Order.desc("productId"))
//                 .setMaxResults(1)
//                 .uniqueResult();
//         transaction.commit();
//         if (productWithHighestId == null) {
//             productId = 0;
//         } else {
//             productId = productWithHighestId.getProductId() + 1;
//         }
//         product.setProductId(productId);
//         transaction = session.beginTransaction();
//         session.save(product);
//         transaction.commit();
//         session.close();
//         return product;
//     }
// 
//     public static void deleteAll(List<Product> products) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         for (Product p : products) {
//             session.delete(p);
//         }
//         transaction.commit();
//         session.close();
//     }
// 
//     public static void delete(Product product) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction transaction = session.beginTransaction();
//         session.delete(product);
//         transaction.commit();
//         session.close();
//     }
// }
// 
// Path: src/main/java/com/storage/mywarehouse/Entity/Product.java
// public class Product implements java.io.Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private int productId;
// 	private String brand;
// 	private String type;
// 	private String description;
// 	private double price;
// 
// 	public Product() {
// 	}
// 
// 	public Product(int productId, String brand, String type, double price) {
// 		this.productId = productId;
// 		this.brand = brand;
// 		this.type = type;
// 		this.price = price;
// 	}
// 
// 	public Product(int productId, String brand, String type, String description, double price) {
// 		this.productId = productId;
// 		this.brand = brand;
// 		this.type = type;
// 		this.description = description;
// 		this.price = price;
// 	}
// 
// 	public Product(String brand, String type, String description, double price) {
// 		this.brand = brand;
// 		this.type = type;
// 		this.description = description;
// 		this.price = price;
// 	}
// 
// 	public int getProductId() {
// 		return this.productId;
// 	}
// 
// 	public void setProductId(int productId) {
// 		this.productId = productId;
// 	}
// 
// 	public String getBrand() {
// 		return this.brand;
// 	}
// 
// 	public void setBrand(String brand) {
// 		this.brand = brand;
// 	}
// 
// 	public String getType() {
// 		return this.type;
// 	}
// 
// 	public void setType(String type) {
// 		this.type = type;
// 	}
// 
// 	public String getDescription() {
// 		return this.description;
// 	}
// 
// 	public void setDescription(String description) {
// 		this.description = description;
// 	}
// 
// 	public double getPrice() {
// 		return this.price;
// 	}
// 
// 	public void setPrice(double price) {
// 		this.price = price;
// 	}
// 
// }


// Path: src/test/java/com/storage/mywarehouse/UtilsImportProductsFromCsvTest.java
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.storage.mywarehouse.Dao.ProductDAO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.storage.mywarehouse.Entity.Product;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.storage.mywarehouse;






/**
 *
 * @author veruz
 */
public class UtilsImportProductsFromCsvTest {

	private File file = new File("src/test/resources/products.csv");

	@AfterEach
	public void tearDown() {
		deleteTestEntries();
	}

	@Test
	public void testExistence() {
		List<Product> products = ProductDAO.findAllByBrandAndTypeStartLike("unit", "test");