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.EPMTask;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

@Slf4j
public class WorkflowQueryTest extends AbstractTeamcenterTest {

    @Test
    public void testSearchValidationUnitParSO() throws NoTeamcenterConnectionException {
        WorkflowOnUnitQuery query = WorkflowOnUnitQuery.searchValidationUnitParSO(getSession(), "00041717");
        List<EPMTask> result = query.findAll();
        Assert.assertEquals("Check unit existence", result.isEmpty(), false);

        log.info("Query has found {} item(s)", result.size());
        for (EPMTask task : result) {
            log.info(" + " + task.get_object_name());
            Assert.assertEquals("Task is not Validation Unit", WorkflowOnUnitQuery.UNIT_VALIDATION_UNIT_PAR_SO, task.get_object_name());
        }
    }

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

}
