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 UnitQueryTest extends AbstractTeamcenterTest {

    @Test
    public void testSearchUnit() throws NoTeamcenterConnectionException {
        UnitQuery query = new UnitQuery(getSession());
        query.addEndItemID("65A1");

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

    @Test
    public void testSearchUnitWithWorkflow() throws NoTeamcenterConnectionException {
        UnitQuery query = new UnitQuery(getSession(), UnitQuery.UNIT_VALIDATION_UNIT_PAR_SO);
        query.addEndItemID("*"); // Search any unit with this workflow

        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) {
            log.info(" + " + item.get_item_id());
        }
    }

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

}
