package com.capgemini.reports.teamcenter.queries;

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

import java.util.List;

@Slf4j
public class TypeQueryTest extends AbstractTeamcenterTest {

    private static final String REVISION_RULE_NAME = " DMA Configuration Interface";

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

    @Test
    public void testGetRevisionRule() throws NoTeamcenterConnectionException {
        // Execute the query
        List<RevisionRule> list = TypeQuery.getRevisionRule(getSession(), REVISION_RULE_NAME);
        Assert.assertNotNull(list);
        Assert.assertTrue(!list.isEmpty());

        // Parse the content
        for (RevisionRule rule : list) {
            log.info("Revision rule name: \"{}\"", rule.get_object_name());
            Assert.assertEquals(REVISION_RULE_NAME, rule.get_object_name());
        }
    }

    @Test
    public void testGetRevisionRuleWrongName() throws NoTeamcenterConnectionException {
        // Execute the query
        List<RevisionRule> list = TypeQuery.getRevisionRule(getSession(), "babar");
        Assert.assertNotNull(list);
        Assert.assertTrue(list.isEmpty());
    }
}
