Package org.spw.controller

Source Code of org.spw.controller.AdvertisementControllerTest

/*
* AdvertisementControllerTest.java
* JUnit based test
*
* Created on 17 August 2007, 07:12
*/

package org.spw.controller;

import java.util.Date;
import junit.framework.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.spw.model.Advertisement;

/**
*
* @author PSe
*/
public class AdvertisementControllerTest extends TestCase {

    private static final Long TEST_ID = 9999999L;
   
    public AdvertisementControllerTest(String testName) {
        super(testName);
    }

    protected void setUp() throws Exception {
        AdvertisementController instance = new AdvertisementController();
        Advertisement ad = new Advertisement();
        ad.setIdAdvertisement(TEST_ID);
        ad.setDateAdvert(new Date());
        ad.setNotes(getName());
        instance.create(ad);
    }

    protected void tearDown() throws Exception {
        AdvertisementController instance = new AdvertisementController();
        instance.delete(instance.read(TEST_ID));
    }

    /**
     * Test of getAdvertisements method, of class org.spw.controller.AdvertisementController.
     */
    public void testGetAdvertisements() {
        boolean found = false;
        System.out.println("getAdvertisements");
       
        AdvertisementController instance = new AdvertisementController();
       
        List<Advertisement> result = instance.getAdvertisements();
        assertNotNull(result);
        assertTrue("The advertisment should contains entities.", result.size() > 0 );
        for(Advertisement ad:result){
            if (ad.getIdAdvertisement() == TEST_ID) found = true;
        }
        assertTrue("Test occurence not found.", found);
    }


}
TOP

Related Classes of org.spw.controller.AdvertisementControllerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.