package org.slc.sli.api.security.context.traversal;

import static junit.framework.Assert.assertTrue;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.slc.sli.api.security.context.traversal.graph.SecurityNode;
import org.slc.sli.api.test.WebContextTestExecutionListener;
import org.slc.sli.common.constants.EntityNames;

/**
 * Test to see if we can get from one node to another.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/spring/applicationContext-test.xml" })
@TestExecutionListeners({ WebContextTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class })
public class BrutePathFinderTest {

    @Autowired
    private BrutePathFinder pathFinder;
    private List<SecurityNode> path;

    @Before
    public void setUp() throws Exception {
        path = null;
    }
    
    @After
    public void tearDown() throws Exception {
        path = null;
    }

    @Test
    public void testGetSimplePath() throws Exception {
        path = pathFinder.find("teacher", "student");
        assertTrue(path.size() == 3);
        assertTrue(path.get(0).getName().equals("teacher"));
        assertTrue(path.get(1).getName().equals("section"));
        assertTrue(path.get(2).getName().equals("student"));
    }

    @Test
    public void testGetSimplePath3() throws Exception {
        path = pathFinder.find("teacher", "school");
        assertTrue(path.size() == 2);
        assertTrue(path.get(0).getName().equals("teacher"));
        assertTrue(path.get(1).getName().equals("school"));
    }


    @Test
    public void testGet2PartPath() throws Exception {
        path = pathFinder.find("teacher", "section");
        assertTrue(path.size() == 2);
        assertTrue(path.get(0).getName().equals("teacher"));
        assertTrue(path.get(1).getName().equals("section"));
    }
    
    
    @Test
    public void testReverseFind() throws Exception {
        path = pathFinder.find("student", "teacher");
        assertTrue(path.size() == 3);
        assertTrue(path.get(0).getName().equals("student"));
        assertTrue(path.get(1).getName().equals("section"));
        assertTrue(path.get(2).getName().equals("teacher"));
    }


    @Test
    public void testGetPredefinedTest() throws Exception {
        path = pathFinder.getPreDefinedPath("teacher", "teacher");
        assertTrue(path.size() == 3);
        path = pathFinder.getPreDefinedPath("waffles", "pancakes");
        assertTrue(path.size() == 0);
        path = null;
        path = pathFinder.getPreDefinedPath("teacher", "course");
        assertTrue(path.size() == 5);
        assertTrue(path.get(4).getName().equals(EntityNames.COURSE));
    }
    
}

@@ -225,16 +225,196 @@
 unWith;%0A
+import org.slc.sli.api.security.context.traversal.graph.SecurityNode;%0Aimport org.slc.sli.api.test.WebContextTestExecutionListener;%0Aimport org.slc.sli.common.constants.EntityNames;%0A
 import o
@@ -846,189 +846,8 @@
 r;%0A%0A
-import org.slc.sli.api.security.context.traversal.graph.SecurityNode;%0Aimport org.slc.sli.api.test.WebContextTestExecutionListener;%0Aimport org.slc.sli.common.constants.EntityNames;%0A%0A
 /**%0A
@@ -2127,32 +2127,35 @@
 %0A%0A%0A    @Test%0A   
+ //
  public void tes
@@ -2188,32 +2188,35 @@
 eption %7B%0A       
+ //
  path = pathFind
@@ -2245,32 +2245,35 @@
 ction%22);%0A       
+ //
  assertTrue(path
@@ -2286,32 +2286,35 @@
 ) == 2);%0A       
+ //
  assertTrue(path
@@ -2350,32 +2350,35 @@
 cher%22));%0A       
+ //
  assertTrue(path
@@ -2414,24 +2414,27 @@
 tion%22));%0A   
+ //
  %7D%0A    %0A    

Test check