<commit_before>package com.revature.orderys.test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.revature.orderys.bean.Order;
import com.revature.orderys.bean.User;
import com.revature.orderys.dao.OrderDao;
import com.revature.orderys.dao.UserDao;

public class OrderDaoTests {

	@Test
	public void testCreateOrder() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		userDao.createUser(user);
		
		Order order = new Order();
		order.setCustomerId(user);
		order.setPaymentMethod((short)0);
		
		Order copy = new Order();
		copy.setCustomerId(order.getCustomer());
		copy.setPaymentMethod(order.getPaymentMethod());
		
		orderDao.createOrder(order);
		copy.setId(order.getId());
		
		assertTrue(haveSamePropertyValues(copy, order));
	}
	
	private static boolean haveSamePropertyValues(Order expected, Order actual) {
		boolean result = true;
		
		if(expected.getId() != actual.getId()) {
			result = false;
		}
		if(expected.getCustomer().getId() != actual.getCustomer().getId()) {
			result = false;
		}
		if(expected.getPaymentMethod() != actual.getPaymentMethod()) {
			result = false;
		}
		
		return result;
	}
	
	@Test
	public void testGetOrderById() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		userDao.createUser(user);
		
		Order order = new Order();
		order.setCustomerId(user);
		order.setPaymentMethod((short)0);
		
		orderDao.createOrder(order);
		
		order = orderDao.getOrderById(order.getId());
		
		assertNotNull(order);
	}
	
	// TODO: Test getOrdersByBusiness method once it is implemented.
	
	@Test
	public void testGetOrdersByCustomer() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		userDao.createUser(user);
		
		Order order1 = new Order();
		order1.setCustomerId(user);
		order1.setPaymentMethod((short)0);
		
		orderDao.createOrder(order1);
		
		Order order2 = new Order();
		order2.setCustomerId(user);
		order2.setPaymentMethod((short) 1);
		
		orderDao.createOrder(order2);
		
		User user2 = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		ArrayList<Order> allOrders = (ArrayList<Order>) orderDao.getOrdersByCustomer(user);
		
		assertEquals(2, allOrders.size());
	}
	
	@Test
	public void testGetAllOrders() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);<commit_msg>corrected a typo<commit_after>package com.revature.orderys.test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.revature.orderys.bean.Order;
import com.revature.orderys.bean.User;
import com.revature.orderys.dao.OrderDao;
import com.revature.orderys.dao.UserDao;

public class OrderDaoTests {

	@Test
	public void testCreateOrder() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		userDao.createUser(user);
		
		Order order = new Order();
		order.setCustomerId(user);
		order.setPaymentMethod((short)0);
		
		Order copy = new Order();
		copy.setCustomerId(order.getCustomer());
		copy.setPaymentMethod(order.getPaymentMethod());
		
		orderDao.createOrder(order);
		copy.setId(order.getId());
		
		assertTrue(haveSamePropertyValues(copy, order));
	}
	
	private static boolean haveSamePropertyValues(Order expected, Order actual) {
		boolean result = true;
		
		if(expected.getId() != actual.getId()) {
			result = false;
		}
		if(expected.getCustomer().getId() != actual.getCustomer().getId()) {
			result = false;
		}
		if(expected.getPaymentMethod() != actual.getPaymentMethod()) {
			result = false;
		}
		
		return result;
	}
	
	@Test
	public void testGetOrderById() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		userDao.createUser(user);
		
		Order order = new Order();
		order.setCustomerId(user);
		order.setPaymentMethod((short)0);
		
		orderDao.createOrder(order);
		
		order = orderDao.getOrderById(order.getId());
		
		assertNotNull(order);
	}
	
	// TODO: Test getOrdersByBusiness method once it is implemented.
	
	@Test
	public void testGetOrdersByCustomer() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
		
		userDao.createUser(user);
		
		Order order1 = new Order();
		order1.setCustomerId(user);
		order1.setPaymentMethod((short)0);
		
		orderDao.createOrder(order1);
		
		Order order2 = new Order();
		order2.setCustomerId(user);
		order2.setPaymentMethod((short) 1);
		
		orderDao.createOrder(order2);
		
		User user2 = new User();
		user2.setEmail("<EMAIL>");
		user2.setPasswordHash("<PASSWORD>");
		user2.setFirstName("first");
		user2.setLastName("last");
		user2.setRole(User.Role.CUSTOMER);
		
		ArrayList<Order> allOrders = (ArrayList<Order>) orderDao.getOrdersByCustomer(user);
		
		assertEquals(2, allOrders.size());
	}
	
	@Test
	public void testGetAllOrders() {
		AbstractApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		UserDao userDao = (UserDao) ac.getBean("userDao");
		OrderDao orderDao = (OrderDao) ac.getBean("orderDao");
		
		User user = new User();
		user.setEmail("<EMAIL>");
		user.setPasswordHash("<PASSWORD>");
		user.setFirstName("first");
		user.setLastName("last");
		user.setRole(User.Role.CUSTOMER);
{'fraction_non_alphanumeric': 0.14465894465894466, 'fraction_numerical': 0.0042471042471042475, 'mean_word_length': 5.000772200772201, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404336', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2546, 'n_words': 431}