Package com.vst.service

Source Code of com.vst.service.ConstructionTypeManagerTest

package com.vst.service;

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

import com.vst.service.BaseManagerTestCase;
import com.vst.dao.ConstructionTypeDao;
import com.vst.model.ConstructionType;
import com.vst.service.impl.ConstructionTypeManagerImpl;

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

public class ConstructionTypeManagerTest extends BaseManagerTestCase {
    private final String constructionTypeId = "1";
    private ConstructionTypeManagerImpl constructionTypeManager = new ConstructionTypeManagerImpl();
    private Mock constructionTypeDao = null;

    protected void setUp() throws Exception {
        super.setUp();
        constructionTypeDao = new Mock(ConstructionTypeDao.class);
        constructionTypeManager.setConstructionTypeDao((ConstructionTypeDao) constructionTypeDao.proxy());
    }

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

    public void testGetConstructionTypes() throws Exception {
        List results = new ArrayList();
        ConstructionType constructionType = new ConstructionType();
        results.add(constructionType);

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

        List constructionTypes = constructionTypeManager.getConstructionTypes(null);
        assertTrue(constructionTypes.size() == 1);
        constructionTypeDao.verify();
    }

    public void testGetConstructionType() throws Exception {
        // set expected behavior on dao
        constructionTypeDao.expects(once()).method("getConstructionType")
            .will(returnValue(new ConstructionType()));
        ConstructionType constructionType = constructionTypeManager.getConstructionType(constructionTypeId);
        assertTrue(constructionType != null);
        constructionTypeDao.verify();
    }

    public void testSaveConstructionType() throws Exception {
        ConstructionType constructionType = new ConstructionType();

        // set expected behavior on dao
        constructionTypeDao.expects(once()).method("saveConstructionType")
            .with(same(constructionType)).isVoid();

        constructionTypeManager.saveConstructionType(constructionType);
        constructionTypeDao.verify();
    }

    public void testAddAndRemoveConstructionType() throws Exception {
        ConstructionType constructionType = new ConstructionType();

        // set required fields

        // set expected behavior on dao
        constructionTypeDao.expects(once()).method("saveConstructionType")
            .with(same(constructionType)).isVoid();
        constructionTypeManager.saveConstructionType(constructionType);
        constructionTypeDao.verify();

        // reset expectations
        constructionTypeDao.reset();

        constructionTypeDao.expects(once()).method("removeConstructionType").with(eq(new Long(constructionTypeId)));
        constructionTypeManager.removeConstructionType(constructionTypeId);
        constructionTypeDao.verify();

        // reset expectations
        constructionTypeDao.reset();
        // remove
        Exception ex = new ObjectRetrievalFailureException(ConstructionType.class, constructionType.getConstructionTypeId());
        constructionTypeDao.expects(once()).method("removeConstructionType").isVoid();
        constructionTypeDao.expects(once()).method("getConstructionType").will(throwException(ex));
        constructionTypeManager.removeConstructionType(constructionTypeId);
        try {
            constructionTypeManager.getConstructionType(constructionTypeId);
            fail("ConstructionType with identifier '" + constructionTypeId + "' found in database");
        } catch (ObjectRetrievalFailureException e) {
            assertNotNull(e.getMessage());
        }
        constructionTypeDao.verify();
    }
}
TOP

Related Classes of com.vst.service.ConstructionTypeManagerTest

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.