package devopsdistilled.operp.server.data.repo;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import devopsdistilled.operp.server.context.AppTestContext;
import devopsdistilled.operp.server.data.entity.Product;

import static org.junit.Assert.assertNotNull;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppTestContext.class)
@Transactional
public class ProductRepositoryTest {
	/*
	 * @PersistenceContext private EntityManager entityManager;
	 */

	@Inject
	ProductRepository productRepository;

	@Before
	public void setUp() throws Exception {
		/*
		 * JpaRepositoryFactory jpaRepositoryFactory = new JpaRepositoryFactory(
		 * entityManager); productRepository = jpaRepositoryFactory
		 * .getRepository(ProductRepository.class);
		 */

		assertNotNull(productRepository);
	}

	@Test
	public void testSave() {
		Product testProduct = new Product();
		testProduct.setProductName("Test Product");
		testProduct = productRepository.save(testProduct);
		Assert.assertEquals(testProduct,
				productRepository.findOne(testProduct.getProductId()));
	}

}

@@ -57,25 +57,83 @@
 java
-x.inject.Inject;%0A
+.util.List;%0A%0Aimport javax.inject.Inject;%0A%0Aimport org.hamcrest.CoreMatchers;
 %0Aimp
@@ -865,16 +865,39 @@
 itory;%0A%0A
+%09Product testProduct;%0A%0A
 %09@Before
@@ -1130,16 +1130,93 @@
 );%0A%09%09 */
+%0A%09%09testProduct = new Product();%0A%09%09testProduct.setProductName(%22Test Product%22);
 %0A%0A%09%09asse
@@ -1284,24 +1284,28 @@
 e() %7B%0A%09%09
+test
 Product 
 testProd
@@ -1300,96 +1300,286 @@
 uct 
-testProduct = new Product();%0A%09%09testProduct.setProductName(%22T
+= productRepository.save(testProduct);%0A%09%09Assert.assertEquals(testProduct,%0A%09%09%09%09productRepository.findOne(testProduct.getProductId()));%0A%09%7D%0A%0A%09@Test%0A%09public void testFindByProductName() %7B%0A%09%09Product savedProduct = productRepository.save(t
 est
- 
 Product
-%22
 );%0A%09%09
-test
+List%3CProduct%3E returned
 Product
+s
  = p
@@ -1598,104 +1598,349 @@
 tory
-.save(testProduct);%0A%09%09Assert.assertEquals(testP
+%0A%09%09%09%09.findByProductName(%22Test Product%22);%0A%09%09assertNotNull(returnedProducts);%0A%09%09System.out.println(returnedProducts.size());%0A%09%09Assert.assertEquals(1, returnedProducts.size());%0A%09%09Assert.assertThat(%0A%09%09%09%09%22Must have saved p
 roduct
+Name%22
 ,%0A%09%09%09%09
-productRepository.findOne(testProduct
+savedProduct.getProductName(),%0A%09%09%09%09CoreMatchers.is(returnedProducts.get(%0A%09%09%09%09%09%09returnedProducts.size() - 1)
 .get
@@ -1938,30 +1938,32 @@
  - 1).getProduct
-Id
+Name
 ()));%0A%09%7D%0A%0A%7D%0A
@@ -1959,11 +1959,10 @@
 )));%0A%09%7D%0A
-%0A
 %7D%0A

Add test for findByProductName()