package com.capgemini.reports.documentationobjects;

import com.capgemini.framework.teamcenter.exceptions.NoTeamcenterConnectionException;
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 lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

@Slf4j
public class DocTechnicTest extends AbstractTeamcenterTest {

    private static final String DOC_REV = "B";
    private static final String DOC_ID = "DOC-00264940";

    @Test
    public void testBuild() throws NoTeamcenterConnectionException {
        List<ItemRevision> results = new ItemRevisionQuery(getSession()).searchIDAndRevision(DOC_ID, DOC_REV).findAll();
        Assert.assertFalse(results.isEmpty());
        ItemRevision techItemRev = results.get(0);
        DocTechnic docTechnic = new DocTechnic(getSession(), techItemRev);
        log.info("Name           = " + docTechnic.getName());
        Assert.assertNotNull(docTechnic.getName());
        Assert.assertFalse(docTechnic.getName().isEmpty());
        log.info("Revision       = " + docTechnic.getRevision());
        Assert.assertNotNull(docTechnic.getRevision());
        Assert.assertEquals(DOC_REV, docTechnic.getRevision());
        log.info("Indice         = " + docTechnic.getIndice());
        Assert.assertNotNull(docTechnic.getIndice());
        Assert.assertFalse(docTechnic.getIndice().isEmpty());
        log.info("Reference      = " + docTechnic.getReference());
        Assert.assertNotNull(docTechnic.getReference());
        Assert.assertFalse(docTechnic.getReference().isEmpty());
        log.info("Type           = " + docTechnic.getType());
        Assert.assertNotNull(docTechnic.getType());
        Assert.assertFalse(docTechnic.getType().isEmpty());
        log.info("Typedoctechnic = " + docTechnic.getTypeDocTechnic1());
        Assert.assertNotNull(docTechnic.getTypeDocTechnic1());
        Assert.assertTrue(docTechnic.getTypeDocTechnic1().contains("Freeze document"));
    }

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

}
