/*
 * IzPack - Copyright 2001-2012 Julien Ponge, All Rights Reserved.
 *
 * http://izpack.org/
 * http://izpack.codehaus.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.izforge.izpack.panels.pdflicence;

import com.izforge.izpack.api.factory.ObjectFactory;
import com.izforge.izpack.api.resource.Locales;
import com.izforge.izpack.api.rules.RulesEngine;
import com.izforge.izpack.core.resource.ResourceManager;
import com.izforge.izpack.gui.IconsDatabase;
import com.izforge.izpack.installer.data.GUIInstallData;
import com.izforge.izpack.installer.data.UninstallDataWriter;
import com.izforge.izpack.installer.gui.IzPanelView;
import com.izforge.izpack.panels.simplefinish.SimpleFinishPanel;
import com.izforge.izpack.panels.test.AbstractPanelTest;
import com.izforge.izpack.panels.test.TestGUIPanelContainer;
import org.fest.swing.fixture.FrameFixture;
import org.icepdf.core.pobjects.Document;
import org.icepdf.core.pobjects.graphics.text.PageText;
import org.icepdf.ri.common.views.DocumentViewController;
import org.icepdf.ri.common.views.OnePageView;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.Assert.assertThat;

public class PDFLicencePanelTest extends AbstractPanelTest {

	public PDFLicencePanelTest(TestGUIPanelContainer container, GUIInstallData installData,
							   ResourceManager resourceManager, ObjectFactory factory,
							   RulesEngine rules, IconsDatabase icons,
							   UninstallDataWriter uninstallDataWriter, Locales locales)
	{
		super(container, installData, resourceManager, factory, rules, icons, uninstallDataWriter, locales);
	}

	@Before
    public void setUp()
    {
        ResourceManager rm = getResourceManager();
        rm.setResourceBasePath("/com/izforge/izpack/panels/panel/");
    }

	@Test
	public void shouldDisplayLicenceText() throws Exception
	{

		IzPanelView view = createPanelView(PDFLicencePanel.class);
		view.getPanel().setPanelId("licence");

		FrameFixture fixture = show(view);

		OnePageView onePageView = fixture.robot.finder().findByType(OnePageView.class);
		DocumentViewController controller = onePageView.getParentViewController();

		Document document = controller.getDocument();
		assertThat(document, hasProperty("numberOfPages", equalTo(1)));

		PageText pageText = document.getPageText(0);
		pageText.selectAll();

		String textArea = pageText.getSelected().toString();
		assertThat(textArea, containsString("This is a licenSe panel"));
	}

    @Test
    public void shouldSelectLicenceNoRadioByDefault() throws Exception
    {

        IzPanelView view = createPanelView(PDFLicencePanel.class);
        view.getPanel().setPanelId("licence");

        FrameFixture fixture = show(view);

        fixture.radioButton("LicenceNoRadio").requireSelected();
    }

    @Test
    public void shouldDisableNextButtonByDefault() throws Exception
    {

        IzPanelView view = createPanelView(PDFLicencePanel.class);
        view.getPanel().setPanelId("licence");

        FrameFixture fixture = show(view, createPanelView(SimpleFinishPanel.class));

        fixture.button("nextButton").requireDisabled();
    }

    @Test
    public void shouldEnableNextButtonIfLicenceIsAccepted() throws Exception
    {

        IzPanelView view = createPanelView(PDFLicencePanel.class);
        view.getPanel().setPanelId("licence");

        FrameFixture fixture = show(view, createPanelView(SimpleFinishPanel.class));

        fixture.radioButton("LicenceYesRadio").check();

        fixture.button("nextButton").requireEnabled();
    }
}

@@ -2563,18 +2563,16 @@
 on%0D%0A%09%7B%0D%0A
-%0D%0A
 %09%09IzPane
@@ -3277,34 +3277,32 @@
 ception%0D%0A    %7B%0D%0A
-%0D%0A
         IzPanelV
@@ -3603,34 +3603,32 @@
 ception%0D%0A    %7B%0D%0A
-%0D%0A
         IzPanelV
@@ -3979,18 +3979,16 @@
 %0A    %7B%0D%0A
-%0D%0A
         

Fix indentation in PDFLicencePanelTest