Package com.vst.service

Source Code of com.vst.service.ObjectConstructionManagerTest

package com.vst.service;

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

import com.vst.service.BaseManagerTestCase;
import com.vst.dao.ObjectConstructionDao;
import com.vst.model.ObjectConstruction;
import com.vst.service.impl.ObjectConstructionManagerImpl;

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

public class ObjectConstructionManagerTest extends BaseManagerTestCase {
    private final String objectConstructionId = "1";
    private ObjectConstructionManagerImpl objectConstructionManager = new ObjectConstructionManagerImpl();
    private Mock objectConstructionDao = null;

    protected void setUp() throws Exception {
        super.setUp();
        objectConstructionDao = new Mock(ObjectConstructionDao.class);
        objectConstructionManager.setObjectConstructionDao((ObjectConstructionDao) objectConstructionDao.proxy());
    }

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

    public void testGetObjectConstructions() throws Exception {
        List results = new ArrayList();
        ObjectConstruction objectConstruction = new ObjectConstruction();
        results.add(objectConstruction);

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

        List objectConstructions = objectConstructionManager.getObjectConstructions(null);
        assertTrue(objectConstructions.size() == 1);
        objectConstructionDao.verify();
    }

    public void testGetObjectConstruction() throws Exception {
        // set expected behavior on dao
        objectConstructionDao.expects(once()).method("getObjectConstruction")
            .will(returnValue(new ObjectConstruction()));
        ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(objectConstructionId);
        assertTrue(objectConstruction != null);
        objectConstructionDao.verify();
    }

    public void testSaveObjectConstruction() throws Exception {
        ObjectConstruction objectConstruction = new ObjectConstruction();

        // set expected behavior on dao
        objectConstructionDao.expects(once()).method("saveObjectConstruction")
            .with(same(objectConstruction)).isVoid();

        objectConstructionManager.saveObjectConstruction(objectConstruction);
        objectConstructionDao.verify();
    }

    public void testAddAndRemoveObjectConstruction() throws Exception {
        ObjectConstruction objectConstruction = new ObjectConstruction();

        // set required fields

        // set expected behavior on dao
        objectConstructionDao.expects(once()).method("saveObjectConstruction")
            .with(same(objectConstruction)).isVoid();
        objectConstructionManager.saveObjectConstruction(objectConstruction);
        objectConstructionDao.verify();

        // reset expectations
        objectConstructionDao.reset();

        objectConstructionDao.expects(once()).method("removeObjectConstruction").with(eq(new Long(objectConstructionId)));
        objectConstructionManager.removeObjectConstruction(objectConstructionId);
        objectConstructionDao.verify();

        // reset expectations
        objectConstructionDao.reset();
        // remove
        Exception ex = new ObjectRetrievalFailureException(ObjectConstruction.class, objectConstruction.getTypeId());
        objectConstructionDao.expects(once()).method("removeObjectConstruction").isVoid();
        objectConstructionDao.expects(once()).method("getObjectConstruction").will(throwException(ex));
        objectConstructionManager.removeObjectConstruction(objectConstructionId);
        try {
            objectConstructionManager.getObjectConstruction(objectConstructionId);
            fail("ObjectConstruction with identifier '" + objectConstructionId + "' found in database");
        } catch (ObjectRetrievalFailureException e) {
            assertNotNull(e.getMessage());
        }
        objectConstructionDao.verify();
    }
}
TOP

Related Classes of com.vst.service.ObjectConstructionManagerTest

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.