package pl.exsio.nestedj;

import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import pl.exsio.nestedj.model.TestNodeImpl;
import pl.exsio.nestedj.repository.NestedNodeRepository;

/**
 *
 * @author exsio
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/testContext.xml"})
public abstract class FunctionalNestedjTest {

    @Autowired
    protected NestedNodeRepository<TestNodeImpl> nodeRepository;

    @PersistenceContext
    protected EntityManager em;
    
    
    
    /**
     * 
     *          STARTING NESTED TREE CONDITIONS
     * 
     *                      1 A 16
     *                       / \                    IDS:
     *                      /   \                   A: 1
     *                     /     \                  B: 2
     *                  2 B 7   8 C 15              C: 3
     *                   /         \                D: 4
     *                  /\         /\               E: 5
     *                 /  \       /  \              F: 6
     *                /    \     /    \             G: 7
     *               /   5 E 6  9 F 10 \            H: 8
     *             3 D 4             11 G 14
     *                                   \
     *                                    \
     *                                  12 H 13 
     */

    protected TestNodeImpl findNode(String symbol) {

        Map<String, Long> nodeMap = new HashMap() {
            {
                put("a", new Long(1));
                put("b", new Long(2));
                put("c", new Long(3));
                put("d", new Long(4));
                put("e", new Long(5));
                put("f", new Long(6));
                put("g", new Long(7));
                put("h", new Long(8));
            }
        };

        TestNodeImpl n = this.em.find(TestNodeImpl.class, nodeMap.get(symbol));
        this.em.refresh(n);
        return n;
    }

}

@@ -803,30 +803,314 @@
 ger em;%0A
+%0A
     
-%0A    %0A    
+private final Map%3CString, Long%3E nodeMap = new HashMap() %7B%0A        %7B%0A            put(%22a%22, 1l);%0A            put(%22b%22, 2l);%0A            put(%22c%22, 3l);%0A            put(%22d%22, 4l);%0A            put(%22e%22, 5l);%0A            put(%22f%22, 6l);%0A            put(%22g%22, 7l);%0A            put(%22h%22, 8l);%0A        %7D%0A    %7D;%0A
 %0A    /**
@@ -1911,17 +1911,16 @@
      */%0A
-%0A
     prot
@@ -1969,412 +1969,8 @@
  %7B%0A%0A
-        Map%3CString, Long%3E nodeMap = new HashMap() %7B%0A            %7B%0A                put(%22a%22, new Long(1));%0A                put(%22b%22, new Long(2));%0A                put(%22c%22, new Long(3));%0A                put(%22d%22, new Long(4));%0A                put(%22e%22, new Long(5));%0A                put(%22f%22, new Long(6));%0A                put(%22g%22, new Long(7));%0A                put(%22h%22, new Long(8));%0A            %7D%0A        %7D;%0A%0A
     
@@ -2023,16 +2023,21 @@
 .class, 
+this.
 nodeMap.

make nodeMap an instance variable