package com.capgemini.reports.reports.parameters;

import com.capgemini.framework.teamcenter.exceptions.NoTeamcenterConnectionException;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.reports.AbstractTeamcenterTest;
import com.capgemini.reports.exceptions.InvalidUserInputException;
import com.capgemini.reports.exceptions.NotFoundException;
import com.teamcenter.soa.client.model.strong.Item;
import org.junit.Assert;
import org.junit.Test;


public class ProductUnitTest extends AbstractTeamcenterTest {

    private static final String PRODUCT_ID = "97R0";

    private static final int GOOD_UNIT = 520;
    private static final String GOOD_UNIT_STR = "520";
    private static final String BAD_UNIT_STR = "520adf";

    @Override
    public PolicyLocation getPropertyPolicyIdentifier() {
        return DEFAULT_POLICY;
    }

    /**
     * JUnit test.
     * 
     * @throws InvalidUserInputException should not happen
     */
    @Test
    public void parseUserUnitTest() throws InvalidUserInputException {
        ProductUnit productUnit = new ProductUnit(PRODUCT_ID, GOOD_UNIT_STR);
        productUnit.parseUserUnit();
        Assert.assertEquals(GOOD_UNIT, productUnit.getUnit());
    }

    /**
     * JUnit test.
     * 
     * @throws InvalidUserInputException should not happen
     */
    @Test(expected = InvalidUserInputException.class)
    public void parseUserUnitTestFail() throws InvalidUserInputException {
        ProductUnit productUnit = new ProductUnit(PRODUCT_ID, BAD_UNIT_STR);
        productUnit.parseUserUnit();
    }

    @Test
    public void getProductTest() throws NotFoundException, NoTeamcenterConnectionException {
        ProductUnit productUnit = new ProductUnit(PRODUCT_ID, BAD_UNIT_STR);
        Item item = productUnit.getProduct(getSession());
        Assert.assertEquals(PRODUCT_ID, item.get_item_id());
    }

}
