package com.capgemini.reports.teamcenter.queries.saved;

import com.capgemini.framework.teamcenter.exceptions.NoTeamcenterConnectionException;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.reports.AbstractTeamcenterTest;
import com.teamcenter.soa.client.model.strong.ItemRevision;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

@Slf4j
public class UnitFromCRTest extends AbstractTeamcenterTest {

    private static final String CHANGE_ID = "report_change_id";
    private static final String MOD119895 = "MOD119895";
    private static final String UNIT_REVISION = "Unit Revision";

    @Test
    public void testSearchUnitFromCR() throws NoTeamcenterConnectionException {
        UnitFromChangeRequestQuery query = new UnitFromChangeRequestQuery(getSession());
        query.addParam(CHANGE_ID, MOD119895);

        List<ItemRevision> result = query.findAll();
        Assert.assertEquals("Check unit existence", result.isEmpty(), false);

        log.info("Query has found {} item(s)", result.size());
        for (ItemRevision item : result) {
            if (UNIT_REVISION.equals(item.get_object_type())) {
                log.info(" + " + item.get_object_type() + " " + item.get_item_id());
            }
            Assert.assertEquals(UNIT_REVISION, item.get_object_type());
        }
    }

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