Package com.vst.service

Source Code of com.vst.service.BuildingObjectManagerTest

package com.vst.service;

import java.util.List;
import java.util.ArrayList;

import com.vst.service.BaseManagerTestCase;
import com.vst.dao.BuildingObjectDao;
import com.vst.model.BuildingObject;
import com.vst.service.impl.BuildingObjectManagerImpl;

import org.jmock.Mock;
import org.springframework.orm.ObjectRetrievalFailureException;

public class BuildingObjectManagerTest extends BaseManagerTestCase {
    private final String buildingObjectId = "1";
    private BuildingObjectManagerImpl buildingObjectManager = new BuildingObjectManagerImpl();
    private Mock buildingObjectDao = null;

    protected void setUp() throws Exception {
        super.setUp();
        buildingObjectDao = new Mock(BuildingObjectDao.class);
        buildingObjectManager.setBuildingObjectDao((BuildingObjectDao) buildingObjectDao.proxy());
    }

    protected void tearDown() throws Exception {
        super.tearDown();
        buildingObjectManager = null;
    }

    public void testGetBuildingObjects() throws Exception {
        List results = new ArrayList();
        BuildingObject buildingObject = new BuildingObject();
        results.add(buildingObject);

        // set expected behavior on dao
        buildingObjectDao.expects(once()).method("getBuildingObjects")
            .will(returnValue(results));

        List buildingObjects = buildingObjectManager.getBuildingObjects(null);
        assertTrue(buildingObjects.size() == 1);
        buildingObjectDao.verify();
    }

    public void testGetBuildingObject() throws Exception {
        // set expected behavior on dao
        buildingObjectDao.expects(once()).method("getBuildingObject")
            .will(returnValue(new BuildingObject()));
        BuildingObject buildingObject = buildingObjectManager.getBuildingObject(buildingObjectId);
        assertTrue(buildingObject != null);
        buildingObjectDao.verify();
    }

    public void testSaveBuildingObject() throws Exception {
        BuildingObject buildingObject = new BuildingObject();

        // set expected behavior on dao
        buildingObjectDao.expects(once()).method("saveBuildingObject")
            .with(same(buildingObject)).isVoid();

        buildingObjectManager.saveBuildingObject(buildingObject);
        buildingObjectDao.verify();
    }

    public void testAddAndRemoveBuildingObject() throws Exception {
        BuildingObject buildingObject = new BuildingObject();

        // set required fields

        // set expected behavior on dao
        buildingObjectDao.expects(once()).method("saveBuildingObject")
            .with(same(buildingObject)).isVoid();
        buildingObjectManager.saveBuildingObject(buildingObject);
        buildingObjectDao.verify();

        // reset expectations
        buildingObjectDao.reset();

        buildingObjectDao.expects(once()).method("removeBuildingObject").with(eq(new Long(buildingObjectId)));
        buildingObjectManager.removeBuildingObject(buildingObjectId);
        buildingObjectDao.verify();

        // reset expectations
        buildingObjectDao.reset();
        // remove
        Exception ex = new ObjectRetrievalFailureException(BuildingObject.class, buildingObject.getObjectId());
        buildingObjectDao.expects(once()).method("removeBuildingObject").isVoid();
        buildingObjectDao.expects(once()).method("getBuildingObject").will(throwException(ex));
        buildingObjectManager.removeBuildingObject(buildingObjectId);
        try {
            buildingObjectManager.getBuildingObject(buildingObjectId);
            fail("BuildingObject with identifier '" + buildingObjectId + "' found in database");
        } catch (ObjectRetrievalFailureException e) {
            assertNotNull(e.getMessage());
        }
        buildingObjectDao.verify();
    }
}
TOP

Related Classes of com.vst.service.BuildingObjectManagerTest

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.