<commit_before>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.poulpe.web.controller.section;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.jtalks.poulpe.model.entity.Branch;
import org.jtalks.poulpe.model.entity.Section;
import org.jtalks.poulpe.model.entity.TopicType;
import org.testng.annotations.Test;

/**
 * The test class for {@link TreeNodeFactory}
 * 
 * @author costa
 * 
 */
public class TreeNodeFactoryTest {

    private static final String SECTION_DESCRIPTION = "Test section description";
    private static final String SECTION_NAME = "Test section name";
    private static final String BRANCH_DESCRIPTION = "Test branch description";
    private static final String BRANCH_NAME = "Test branch name";
    private static final String BRANCH_UIID = "Test branch uiid";
    private static final int SECTION_ID = 1;
    private static final int SECTION_POSITION = 1;

    private Section createTestSection() {
        Section section = new Section();
        section.setDescription(SECTION_DESCRIPTION);
        section.setName(SECTION_NAME);
        section.setId(SECTION_ID);
        section.setPosition(SECTION_POSITION);
        return section;
    }

    private Branch createTestBranch() {
        Branch branch = new Branch();
        branch.setDeleted(false);
        branch.setDescription(BRANCH_DESCRIPTION);
        branch.setName(BRANCH_NAME);
        branch.setUuid(BRANCH_UIID);
        return branch;
    }

    private Section createTestSectionWithBranches() {
        Section section = createTestSection();
        section.setBranches(new ArrayList<Branch>());
        section.getBranches().add(createTestBranch());
        section.getBranches().add(createTestBranch());
        section.getBranches().add(createTestBranch());
        return section;
    }

    /**
     * Test single suitable entities
     */
    @Test
    public void getTreeNodeTest() {
        Section sectionWithOutChildren = createTestSection();
        ExtendedTreeNode testNode = TreeNodeFactory
                .getTreeNode(sectionWithOutChildren);

        assertEquals(testNode.getData(), sectionWithOutChildren);
        assertEquals(testNode.getChildren(), null);
        assertEquals(testNode.isExpanded(), true);

        Branch testBranch = createTestBranch();
        testNode = TreeNodeFactory.getTreeNode(testBranch);

        assertEquals(testNode.getData(), testBranch);
        assertEquals(testNode.getChildren(),null);
        assertEquals(testNode.isExpanded(), true);
        assertEquals(testNode.isLeaf(), true);
        
        testNode = TreeNodeFactory.getTreeNode(null);
        assertNull(testNode);
        
        testNode = TreeNodeFactory.getTreeNode(new TopicType());
        assertNull(testNode);
    }

    /**
     * Test suitable entities with relations
     */
    @Test
    public void getTreeNodeWithRelationsTest() {
        Section sectionWithBranchs = createTestSectionWithBranches();
        ExtendedTreeNode testNode = TreeNodeFactory
                .getTreeNode(sectionWithBranchs);

        assertEquals(testNode.getData(), sectionWithBranchs);
        assertEquals(testNode.getChildren().size(), 3);
        assertEquals(testNode.isExpanded(), true);
        assertNotNull(testNode.getChildAt(0));
        assertTrue(testNode.getChildAt(0).getData() instanceof Branch);
        assertEquals(testNode.getChildAt(0).getData(), sectionWithBranchs
                .getBranches().get(0));<commit_msg>* unit test was corrected<commit_after>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.poulpe.web.controller.section;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.jtalks.common.model.entity.Entity;
import org.jtalks.poulpe.model.entity.Branch;
import org.jtalks.poulpe.model.entity.Section;
import org.jtalks.poulpe.model.entity.TopicType;
import org.testng.annotations.Test;

/**
 * The test class for {@link TreeNodeFactory}
 * 
 * @author costa
 * 
 */
public class TreeNodeFactoryTest {

    private static final String SECTION_DESCRIPTION = "Test section description";
    private static final String SECTION_NAME = "Test section name";
    private static final String BRANCH_DESCRIPTION = "Test branch description";
    private static final String BRANCH_NAME = "Test branch name";
    private static final String BRANCH_UIID = "Test branch uiid";
    private static final int SECTION_ID = 1;
    private static final int SECTION_POSITION = 1;

    private Section createTestSection() {
        Section section = new Section();
        section.setDescription(SECTION_DESCRIPTION);
        section.setName(SECTION_NAME);
        section.setId(SECTION_ID);
        section.setPosition(SECTION_POSITION);
        return section;
    }

    private Branch createTestBranch() {
        Branch branch = new Branch();
        branch.setDeleted(false);
        branch.setDescription(BRANCH_DESCRIPTION);
        branch.setName(BRANCH_NAME);
        branch.setUuid(BRANCH_UIID);
        return branch;
    }

    private Section createTestSectionWithBranches() {
        Section section = createTestSection();
        section.setBranches(new ArrayList<Branch>());
        section.getBranches().add(createTestBranch());
        section.getBranches().add(createTestBranch());
        section.getBranches().add(createTestBranch());
        return section;
    }

    /**
     * Test single suitable entities
     */
    @Test
    public void getTreeNodeTest() {
        Section sectionWithOutChildren = createTestSection();
        ExtendedTreeNode testNode = TreeNodeFactory
                .getTreeNode(sectionWithOutChildren);

        assertEquals(testNode.getData(), sectionWithOutChildren);
        assertEquals(testNode.getChildren(), new ArrayList());
        assertEquals(testNode.isExpanded(), true);

        Branch testBranch = createTestBranch();
        testNode = TreeNodeFactory.getTreeNode(testBranch);

        assertEquals(testNode.getData(), testBranch);
        assertEquals(testNode.getChildren(),null);
        assertEquals(testNode.isExpanded(), true);
        assertEquals(testNode.isLeaf(), true);
        
        testNode = TreeNodeFactory.getTreeNode((Entity) null);
        assertNull(testNode);
        
        testNode = TreeNodeFactory.getTreeNode(new TopicType());
        assertNull(testNode);
    }

    /**
     * Test suitable entities with relations
     */
    @Test
    public void getTreeNodeWithRelationsTest() {
        Section sectionWithBranchs = createTestSectionWithBranches();
        ExtendedTreeNode testNode = TreeNodeFactory
                .getTreeNode(sectionWithBranchs);

        assertEquals(testNode.getData(), sectionWithBranchs);
        assertEquals(testNode.getChildren().size(), 3);
        assertEquals(testNode.isExpanded(), true);
        assertNotNull(testNode.getChildAt(0));
        assertTrue(testNode.getChildAt(0).getData() instanceof Branch);
        assertEquals(testNode.getChildAt(0).getData(), sectionWithBranchs
                .getBranches().get(0));
{'fraction_non_alphanumeric': 0.09042792792792793, 'fraction_numerical': 0.005405405405405406, 'mean_word_length': 3.427218344965105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2411128', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2335, 'n_words': 645}