package net.iaeste.iws.fitnesse;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertThat;

import net.iaeste.iws.api.constants.IWSErrors;
import org.junit.After;
import org.junit.Test;

/**
 * @author  Michal Knapik / last $Author:$
 * @version $Revision:$ / $Date:$
 * @since   1.7
 */
public class FetchOffersTest {
    private FetchOffers cut;

    @Test
    public void testInvalidCall() {
        cut = new FetchOffers();
        cut.reset();

        // First we login
        cut.setUsernameAndPassword("austria", "incorrect");
        assertThat(cut.login(), is(false));

        cut.execute();

        assertThat(cut.isRequestOk(), is(false));
        assertThat(cut.errorCode(), is(IWSErrors.VERIFICATION_ERROR.getError()));
        assertThat(cut.errorMessage(), startsWith("Invalid Authentication Token provided."));
    }

    @Test
    public void testFetchCall() {
        cut = new FetchOffers();
        cut.reset();

        // First we login
        cut.setUsernameAndPassword("austria", "austria");
        assertThat(cut.login(), is(true));

        // Set fetch request type
        cut.setRequestType("ALL");

        // Try to fetch offers
        cut.execute();
        assertThat(cut.isRequestOk(), is(true));
        assertThat(cut.errorCode(), is(IWSErrors.SUCCESS.getError()));
        assertThat(cut.numberOfFetchedOffers(), is(4));
    }

    @After
    public void logout() {
        cut.deprecateSession();
        cut = null;
    }
}

@@ -1,8 +1,892 @@
+/*%0A * =============================================================================%0A * Copyright 1998-2013, IAESTE Internet Development Team. All rights reserved.%0A * -----------------------------------------------------------------------------%0A * Project: IntraWeb Services (iws-fitnesse) - net.iaeste.iws.fitnesse.FetchOffersTest%0A * -----------------------------------------------------------------------------%0A * This software is provided by the members of the IAESTE Internet Development%0A * Team (IDT) to IAESTE A.s.b.l. It is for internal use only and may not be%0A * redistributed. IAESTE A.s.b.l. is not permitted to sell this software.%0A *%0A * This software is provided %22as is%22; the IDT or individuals within the IDT%0A * cannot be held legally responsible for any problems the software may cause.%0A * =============================================================================%0A */%0A
 package 

add missing copyright info, refs #283