org.sventon.web.ctrl.template.GetLatestRevisionsControllerTest.java Source code

Java tutorial

Introduction

Here is the source code for org.sventon.web.ctrl.template.GetLatestRevisionsControllerTest.java

Source

/*
 * ====================================================================
 * Copyright (c) 2005-2012 sventon project. All rights reserved.
 *
 * This software is licensed as described in the file LICENSE, which
 * you should have received as part of this distribution. The terms
 * are also available at http://www.sventon.org.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 * ====================================================================
 */
package org.sventon.web.ctrl.template;

import org.easymock.classextension.EasyMock;
import org.junit.Test;
import org.springframework.web.servlet.ModelAndView;
import org.sventon.TestUtils;
import org.sventon.model.LogEntry;
import org.sventon.model.RepositoryName;
import org.sventon.service.RepositoryService;
import org.sventon.web.UserRepositoryContext;
import org.sventon.web.command.BaseCommand;

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

import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.junit.Assert.assertEquals;

public class GetLatestRevisionsControllerTest {

    @Test
    public void testSvnHandle() throws Exception {
        final UserRepositoryContext userRepositoryContext = new UserRepositoryContext();
        userRepositoryContext.setLatestRevisionsDisplayCount(2);

        final RepositoryService mockService = EasyMock.createMock(RepositoryService.class);

        final GetLatestRevisionsController ctrl = new GetLatestRevisionsController();
        ctrl.setRepositoryService(mockService);

        final BaseCommand command = new BaseCommand();
        command.setName(new RepositoryName("test"));

        final List<LogEntry> revisions = new ArrayList<LogEntry>();
        revisions.add(TestUtils.getLogEntryStub(1));
        revisions.add(TestUtils.getLogEntryStub(2));

        expect(mockService.getLatestRevisions(null, command.getName(),
                userRepositoryContext.getLatestRevisionsDisplayCount())).andStubReturn(revisions);

        replay(mockService);
        final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, userRepositoryContext, null, null,
                null);
        final Map model = modelAndView.getModel();
        verify(mockService);

        assertEquals(1, model.size());
        assertEquals(2, ((List) model.get("revisions")).size());
    }
}