package com.seleniumtests.tests;

import com.seleniumtests.core.Filter;
import com.seleniumtests.core.SeleniumTestPlan;
import com.seleniumtests.dataobject.User;
import com.seleniumtests.util.SpreadSheetUtil;
import com.seleniumtests.util.internal.entity.TestEntity;
import com.seleniumtests.webpage.TestLinkLoginPage;
import org.testng.ITestContext;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedHashMap;

/**
 * Login test for TestLink
 *
 * Date: 10/2/13
 * Time: 6:36 PM
 */
public class TestLinkLoginTest extends SeleniumTestPlan {

    @DataProvider(name = "loginData", parallel = true)
    public static Iterator<Object[]> getUserInfo(Method m,
                                                 ITestContext testContext) throws Exception {
        Filter filter = Filter.equalsIgnoreCase(TestEntity.TEST_METHOD,
                m.getName());

        LinkedHashMap<String, Class<?>> classMap = new LinkedHashMap<String, Class<?>>();
        classMap.put("TestEntity", TestEntity.class);
        classMap.put("User", User.class);

        return SpreadSheetUtil.getEntitiesFromSpreadsheet(
                TestLinkLoginTest.class, classMap, "loginuser.csv", 0,
                null, filter);
    }

    /**
     * Logs in to TestLink as valid user
     *
     * @param testEntity
     * @param user
     * @throws Exception
     */
    @Test(groups = {"loginAsValidUser"}, dataProvider = "loginData",
            description = "Logs in to TestLink as admin")
    public void loginAsValidUser(TestEntity testEntity, final User user)
            throws Exception {

        new TestLinkLoginPage(true)
                .loginAsValidUser(user)
                .verifyDocumentationDropDown();
    }

    /**
     * Logs in to TestLink as invalid user
     *
     * @param testEntity
     * @param user
     * @throws Exception
     */
    @Test(groups = {"loginAsInvalidUser"}, dataProvider = "loginData",
            description = "Logs in to TestLink as invalid user and verifies login is unsuccessful")
    public void loginAsInvalidUser(TestEntity testEntity, final User user)
            throws Exception {

        new TestLinkLoginPage(true)
                .loginAsInvalidUser(user)
                .verifyLoginBoxPresence();
    }

    /**
     * A failed test
     *
     * @param testEntity
     * @param user
     * @throws Exception
     */
    @Test(groups = {"testForFailure"}, dataProvider = "loginData",
            description = "This test is bound to fail")
    public void testForFailure(TestEntity testEntity, final User user)
            throws Exception {

        new TestLinkLoginPage(true)
                .loginAsValidUser(user)
                .verifyDocumentationDropDownFail();
    }
}

@@ -2683,32 +2683,556 @@
 ws Exception %7B%0A%0A
+        new TestLinkLoginPage(true)%0A                .loginAsValidUser(user)%0A                .verifyDocumentationDropDownFail();%0A    %7D%0A%0A    /**%0A     * A failed test%0A     *%0A     * @param testEntity%0A     * @param user%0A     * @throws Exception%0A     */%0A    @Test(groups = %7B%22testsSkippedMethod%22%7D, dataProvider = %22loginData%22,%0A            description = %22This test is also bound to fail%22, dependsOnMethods = %22testForFailure%22)%0A    public void testsSkippedMethod(TestEntity testEntity, final User user)%0A            throws Exception %7B%0A%0A
         new Test

add skipped test