package ch.elexis.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.BeforeClass;
import org.junit.Test;

import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.service.StockService;
import ch.elexis.core.model.IOrderEntry;
import ch.elexis.core.services.IOrderService;
import ch.rgw.tools.JdbcLink;


public class Test_OrderService extends AbstractPersistentObjectTest {
		
	public Test_OrderService(JdbcLink link){
		super(link);
	}

	private static IOrderService orderService = CoreHub.getOrderService();
	
	private static Stock stock_A_5_order;
	private static Artikel artikel_A;
	private static StockEntry stockEntry;
	
	private static StockService stockService = CoreHub.getStockService();
	
	@BeforeClass
	public static void init(){
		stock_A_5_order = new Stock("AOD", 5);
		artikel_A = new Artikel("ArtikelAOrder", "Eigenartikel");
		
		stockEntry = (StockEntry) stockService.storeArticleInStock(stock_A_5_order,
			artikel_A.storeToString());
		stockEntry.setMinimumStock(5);
		stockEntry.setCurrentStock(10);
		stockEntry.setMaximumStock(15);
		
	}
	
	@Test
	public void testAddRefillForStockEntryToOrderAndFindOpenOrder() {
		Bestellung b = new Bestellung("TestBestellung", CoreHub.actUser);
		orderService.addRefillForStockEntryToOrder(stockEntry, b);
		assertEquals(1, b.getEntries().size());
		assertEquals(5,  b.getEntries().get(0).getCount());
	
		IOrderEntry ioe = orderService.findOpenOrderEntryForStockEntry(stockEntry);
		assertNotNull(ioe);
	}
}

@@ -110,16 +110,45 @@
 tNull;%0A%0A
+import org.junit.AfterClass;%0A
 import o
@@ -1167,16 +1167,109 @@
 %09%09%0A%09%7D%0A%09%0A
+%09@AfterClass%0A%09public static void afterClass() %7B%0A%09%09stock_A_5_order.removeFromDatabase();%0A%09%7D%0A%09%0A
 %09@Test%0A%09

Remove stock after Test_OrderService test finished