com.formkiq.web.DashboardControllerIntegrationTest.java Source code

Java tutorial

Introduction

Here is the source code for com.formkiq.web.DashboardControllerIntegrationTest.java

Source

/*
 * Copyright (C) 2017 FormKiQ Inc.
 *
 * 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.formkiq.web;

import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;

import java.util.Arrays;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.formkiq.core.domain.type.FolderPermission;
import com.formkiq.core.form.dto.FormJSON;
import com.formkiq.core.form.dto.Workflow;
import com.formkiq.core.testdata.TestDataBuilder;

/**
 * WorkflowController Edit Integration Test.
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = DEFINED_PORT)
@ActiveProfiles("dev")
public class DashboardControllerIntegrationTest extends SeleniumTestBase {

    /**
     * testDashboard01().
     * Designer button is displayed
     *
     * @throws Exception Exception
     */
    @Test
    public void testDashboard01() throws Exception {
        // given
        String token = login();
        FormJSON form = TestDataBuilder.createSimpleForm();
        Workflow workflow = TestDataBuilder.createWorkflow(form);

        String folder = createFolder(token, "test");
        addFileToFolder(token, folder, workflow, form);

        // when
        login(getDefaultEmail());

        // then
        assertEquals("FormKiQ Server - Dashboard", getTitle());
        assertEquals(1, findElements(By.className("button-design")).size());

        // when
        click(By.className("button-design"));

        // then
        assertEquals("FormKiQ Server - Workflow Editor", getTitle());
    }

    /**
     * testDashboard02().
     * Non Admin User with Design permission
     *
     * @throws Exception Exception
     */
    @Test
    public void testDashboard02() throws Exception {
        // given
        String email = "test2@formkiq.com";
        String token = login();
        FormJSON form = TestDataBuilder.createSimpleForm();
        Workflow workflow = TestDataBuilder.createWorkflow(form);

        createUser(token, email, getDefaultPass());
        String folder = createFolder(token, "test");
        addFileToFolder(token, folder, workflow, form);
        inviteToFolder(token, email, folder, Arrays.asList(FolderPermission.PERM_FORM_DESIGN));

        // when
        login(email);

        // then
        assertEquals("FormKiQ Server - Dashboard", getTitle());
        assertEquals(1, findElements(By.className("button-add-workflow")).size());

        // when
        click(By.className("button-add-workflow"));

        // then
        assertEquals("FormKiQ Server - Workflow Editor", getTitle());
    }

    /**
     * testDashboard02().
     * Non Admin User without Design permission
     *
     * @throws Exception Exception
     */
    @Test
    public void testDashboard03() throws Exception {
        // given
        String email = "test3@formkiq.com";
        String token = login();
        FormJSON form = TestDataBuilder.createSimpleForm();
        Workflow workflow = TestDataBuilder.createWorkflow(form);

        createUser(token, email, getDefaultPass());
        String folder = createFolder(token, "test");
        addFileToFolder(token, folder, workflow, form);
        inviteToFolder(token, email, folder, Arrays.asList(FolderPermission.PERM_FORM_ENTRY));

        // when
        login(email);

        // then
        assertEquals("FormKiQ Server - Dashboard", getTitle());
        assertEquals(0, getDriver().findElements(By.className("button-design")).size());
    }
}