package model;

import org.junit.Test;

import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
import java.util.ArrayList;
import java.util.NoSuchElementException;

import static org.junit.Assert.*;

public class ClusterDataTest {

    @Test
    public void testClusterData() throws  Exception {
        TitanDSM dsm = new TitanDSM(30);
        File file = new File("./sample/moka/moka_ACDC.clsx");
        ClusterData cluster = new ClusterData(dsm);
        cluster = new ClusterData(file);
    }

    @Test
    public void testLoadClusterData() throws Exception {
        ClusterData cluster = new ClusterData(new DefaultMutableTreeNode());
        File file = new File("./sample/moka/moka_ACDC.clsx");
        cluster.loadClusterData(file);
        assertEquals(cluster.getTree().getNextNode().getUserObject().toString(), "edu.drexel.cs.rise.moka.jre16.parser.MethodParser");
    }

    @Test
    public void testSaveClusterData() throws Exception {
        ClusterData cluster = new ClusterData(new DefaultMutableTreeNode());
        File file = new File("./sample/moka/moka_ACDC.clsx");
        File file2 = new File("./sample/moka/moka_ACDC2.clsx");
        cluster.loadClusterData(file);
        cluster.saveClusterData(file2);
        assertTrue(file.exists());
        file2.delete();
    }

    @Test
    public void testMoveNode() throws Exception {
        ClusterData cluster = new ClusterData(new DefaultMutableTreeNode());
        File file = new File("./sample/moka/moka_ACDC.clsx");
        cluster.loadClusterData(file);
        cluster.moveNode(cluster.getTree().getNextNode(), 2);
        assertEquals(cluster.getTree().getChildAt(2).toString(), "edu.drexel.cs.rise.moka.jre16.parser.MethodParser");
    }

    @Test
    public void testGrouping() throws Exception {
        ClusterData cluster = new ClusterData(new DefaultMutableTreeNode());
        ArrayList<DefaultMutableTreeNode> Array = new ArrayList<DefaultMutableTreeNode>();
        File file = new File("./sample/moka/moka_ACDC.clsx");
        String className = "edu.drexel.cs.rise.moka.jre16.parser.MethodParser";

        cluster.loadClusterData(file);
        Array.add(cluster.getTree().getNextNode());
        cluster.newGroupbyNode(Array, "newGroup");
        assertEquals(cluster.getNode(className).getParent().toString(),"newGroup");
        cluster.freeGroup(cluster.getTree().getNextNode());
        assertEquals(cluster.getTree().getNextNode().getUserObject().toString(), className);
    }

    @Test
    public void testRenameNode() throws Exception {

    }

    @Test
    public void testAddItem() throws Exception {

    }

    @Test(expected = NoSuchElementException.class)
    public void testDeleteItem() throws Exception {
        String filePath = "./sample/titan/titan_ACDC.clsx";
        String className = "edu.drexel.cs.rise.titan.ui.MatrixViewer";
        ClusterData cluster = new ClusterData(new File(filePath));
        cluster.deleteItem((DefaultMutableTreeNode)cluster.getNode(className));
        cluster.getAllowsChildren(className);
    }
}
@@ -9,16 +9,61 @@
 model;%0A%0A
+import model.exception.NotPositiveException;%0A
 import o
@@ -77,16 +77,16 @@
 t.Test;%0A
-
 %0Aimport 
@@ -332,28 +332,28 @@
 a() 
-throws  Exception %7B%0A
+%7B%0A        try %7B%0A    
     
@@ -401,154 +401,178 @@
     
-File file = new File(%22./sample/moka/moka_ACDC.clsx%22);%0A        ClusterData cluster = new ClusterData(dsm);%0A        cluster = new ClusterData(file);
+    ClusterData cluster = new ClusterData(dsm);%0A            assertNotNull(cluster);%0A        %7D catch (NotPositiveException e) %7B%0A            e.printStackTrace();%0A        %7D%0A
 %0A   
@@ -947,39 +947,40 @@
 MethodParser%22);%0A
-
     %7D%0A%0A
+%0A
     @Test%0A    pu

change testNewGroupByNode to testGrouping