package com.trs.example;

import com.trs.DreamFactory;
import com.trs.TRSWCMBaseTest;
import com.trs.components.wcm.content.domain.DocumentMgr;
import com.trs.components.wcm.content.persistent.Channel;
import com.trs.components.wcm.content.persistent.Documents;
import com.trs.infra.util.CMyException;

public class WCMExampleForJUnitTest extends TRSWCMBaseTest {
    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger
            .getLogger(WCMExampleForJUnitTest.class);

    public WCMExampleForJUnitTest(String name) {
        super(name);
    }

    public void testQueryDocuments() {
        try {
            // 1 构造测试数据并且校验测试数据的有效性
            int nChannelId = 10;
            Channel channel = Channel.findById(nChannelId);
            assertNotNull("指定的栏目不存在！[栏目ID=" + nChannelId + "]", channel);

            // 2 获取指定栏目的文档
            // 2.1 获取文档的业务对象(历史代码，目前规范应该是IDocumentMgr)
            DocumentMgr oDocumentMgr = (DocumentMgr) DreamFactory
                    .createObjectById("DocumentMgr");
            // 2.2 获取指定栏目的文档，并且判断有效性
            Documents documents = oDocumentMgr.getDocuments(channel, null);
            assertTrue("返回的数据不符合预期！", documents.size() >= 0);
        } catch (Exception ex) {
            logger.error("测试[testQueryDocuments]出现异常！", ex);
            fail("测试[testQueryDocuments]出现异常！\n"
                    + CMyException.getStackTraceText(ex));
        }
    }
}
