Package com.mysticcoders.webapp

Source Code of com.mysticcoders.webapp.TestPastePage

package com.mysticcoders.webapp;

import com.mysticcoders.integrations.AbstractIntegrationTest;
import com.mysticcoders.mysticpaste.MysticPasteApplication;
import com.mysticcoders.mysticpaste.web.pages.paste.PasteItemPage;
import com.mysticcoders.mysticpaste.web.pages.view.ViewPublicPage;
import com.mysticcoders.mysticpaste.web.pages.history.HistoryPage;
import com.mysticcoders.mysticpaste.persistence.PasteItemDao;
import com.mysticcoders.mysticpaste.services.PasteService;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.spring.test.ApplicationContextMock;
import org.apache.wicket.util.tester.WicketTester;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.application.IComponentInstantiationListener;
import org.junit.Before;
import org.junit.Test;
import org.unitils.spring.annotation.SpringBeanByType;

/**
* Simple test using the WicketTester
*/

public class TestPastePage extends AbstractIntegrationTest {

    @SpringBeanByType
    private PasteService svc;

    @SpringBeanByType
    private PasteItemDao dao;

    @SpringBeanByType
//    private PasteCommentDao commentDao;

    protected WicketTester tester;

    @Before
    public void setup() {
        final ApplicationContextMock appctx = new
                ApplicationContextMock();
        appctx.putBean("pasteDao", dao);
        appctx.putBean("pasteService", svc);
//        appctx.putBean("pasteCommentDao", commentDao);

        tester = new WicketTester(new MysticPasteApplication() {
            @Override
            protected IComponentInstantiationListener getSpringComponentInjector(WebApplication application) {
                return new SpringComponentInjector(application, appctx, true);
            }
        });
    }

    @Test
    public void testRenderMyPage() {
        tester.startPage(PasteItemPage.class);
        tester.assertRenderedPage(PasteItemPage.class);
        FormTester ft = tester.newFormTester("pasteForm");
        ft.select("type", 0);
        ft.setValue("content", "blahblahblah");
        ft.submit();
        tester.assertRenderedPage(ViewPublicPage.class);
        tester.assertContains("blahblahblah");
        tester.assertLabel("type", "as3");
    }

    @Test
    public void testHistoryMenuClick() {
        tester.startPage(PasteItemPage.class);
        tester.assertRenderedPage(PasteItemPage.class);
        tester.clickLink("historyLinkContainer:historyLink");
        tester.assertRenderedPage(HistoryPage.class);
    }
}
TOP

Related Classes of com.mysticcoders.webapp.TestPastePage

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.