package com.capgemini.reports.releasestatus;

import com.capgemini.framework.teamcenter.exceptions.NoTeamcenterConnectionException;
import com.capgemini.framework.teamcenter.object.pom.status.StatusEnum;
import com.capgemini.framework.teamcenter.object.pom.status.TcReleaseStatus;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.framework.teamcenter.queries.saved.modelobject.ItemRevisionQuery;
import com.capgemini.reports.AbstractTeamcenterTest;
import com.teamcenter.soa.client.model.strong.ItemRevision;
import com.teamcenter.soa.client.model.strong.ReleaseStatus;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;


public class TcReleaseStatusTest extends AbstractTeamcenterTest {

    private static final String DET_ID = "620-037-104-0";

    @Test
    public void testGetChosenStatus() throws NoTeamcenterConnectionException {
        // GET ALTERNATE REVISION LIST
        List<ItemRevision> detRevisionList = new ItemRevisionQuery(getSession()).searchIDAndRevision(DET_ID, "A").findAll();
        Assert.assertNotNull(detRevisionList);
        Assert.assertFalse(detRevisionList.isEmpty());

        List<ReleaseStatus> releaseStatusList = TcReleaseStatus.getChosenStatus(getSession(), detRevisionList.get(0), StatusEnum.J3A);
        if (!releaseStatusList.isEmpty()) {
            for (ReleaseStatus status : releaseStatusList) {
                Assert.assertEquals(StatusEnum.J3A.getIdentifier(), status.get_name());
            }
        }
    }

    @Test
    public void testGetAllStatusExceptSome() throws NoTeamcenterConnectionException {
        // GET ALTERNATE REVISION LIST
        List<ItemRevision> detRevisionList = new ItemRevisionQuery(getSession()).searchIDAndRevision(DET_ID, "A").findAll();
        Assert.assertNotNull(detRevisionList);
        Assert.assertFalse(detRevisionList.isEmpty());

        List<ReleaseStatus> releaseStatusList =
                TcReleaseStatus.getAllStatusExceptSome(getSession(), detRevisionList.get(0), StatusEnum.J3A, StatusEnum.J3B, StatusEnum.EFFECTIVITY);
        if (!releaseStatusList.isEmpty()) {
            for (ReleaseStatus status : releaseStatusList) {
                Assert.assertNotSame(StatusEnum.J3A.getIdentifier(), status.get_name());
                Assert.assertNotSame(StatusEnum.J3B.getIdentifier(), status.get_name());
                Assert.assertNotSame(StatusEnum.EFFECTIVITY.getIdentifier(), status.get_name());
            }
        }
    }

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