@Override @Before protected void setUp() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/opaf/duke/core/tests/res/springTestContext.xml"); orderBean = (CustomerOrderBean) context.getBean("orderBean"); EntityManagerFactory factory = Persistence.createEntityManagerFactory("duke_corePU"); EntityManager entityManager = factory.createEntityManager(); orderBean.setEntityManager(entityManager); }
@Test public void testCreateCustomerOrder() { CustomerOrder order = new CustomerOrder(25.80f); Customer orderCustomer = new Customer( "Amaury", "Schwartz", "*****@*****.**", "5 rue bayard", "Toulouse", "Defenseur"); order.setCustomer(orderCustomer); OrderStatus orderStatus = new OrderStatus("In Preparation"); order.setStatus(orderStatus); orderBean.create(order); assertNotNull(order.getId()); assertEquals(orderBean.findEntity(order.getId()), order); }
@Override @After protected void tearDown() throws Exception { super.tearDown(); orderBean.setEntityManager(null); }