package org.opennms.netmgt.jasper.helper;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

public class JRobinDirectoryUtilTest {
    private static String RRD_DIRECTORY = "src/test/resources/share/rrd";
    private static String NODE_ID = "9";
    private static String INTERFACE = "me1-0002baaacffe";
    
    @Before
    public void setup() {
        System.setProperty("org.opennms.rrd.storeByGroup", "true");
    }
    
    @Test
    public void testJRobinDirectoryLookup() throws IOException {
        JRobinDirectoryUtil lookup = new JRobinDirectoryUtil();
        
        assertEquals("src/test/resources/share/rrd/9/me1-0002baaacffe/mib2-interfaces.jrb", lookup.getIfInOctetsJrb(RRD_DIRECTORY, NODE_ID, INTERFACE));
        assertEquals("src/test/resources/share/rrd/9/me1-0002baaacffe/mib2-interfaces.jrb", lookup.getIfOutOctetsJrb( RRD_DIRECTORY, NODE_ID, INTERFACE));
        
        System.setProperty("org.opennms.rrd.storeByGroup", "false");
        
        assertEquals("src/test/resources/share/rrd/9/me1-0002baaacffe/ifHCInOctets.jrb", lookup.getIfInOctetsJrb(RRD_DIRECTORY, NODE_ID, INTERFACE));
        assertEquals("src/test/resources/share/rrd/9/me1-0002baaacffe/ifHCOutOctets.jrb", lookup.getIfOutOctetsJrb(RRD_DIRECTORY, NODE_ID, INTERFACE));
    }
    
    @Test
    public void testGetInterfaceDirectory() {
        JRobinDirectoryUtil lookup = new JRobinDirectoryUtil();
        
        String snmpphysaddr = "0002baaacffe";
        String snmpifname = "me1";
        String snmpifdescr = "me1";
        assertEquals("me1-0002baaacffe", lookup.getInterfaceDirectory(snmpifname, snmpifdescr, snmpphysaddr));
    }
    
    @Test
    public void testGetInterfaceDirectoryNoSnmpIfName() {
        JRobinDirectoryUtil lookup = new JRobinDirectoryUtil();
        
        String snmpphysaddr = "0002baaacffe";
        String snmpifname = null;
        String snmpifdescr = "me1";
        assertEquals("me1-0002baaacffe", lookup.getInterfaceDirectory(snmpifname, snmpifdescr, snmpphysaddr));
    }
    
    @Test
    public void testGetInterfaceDirectoryLocalSystem() throws FileNotFoundException, IOException {
        JRobinDirectoryUtil lookup = new JRobinDirectoryUtil();
        
        String rrdDir = "/Users/thedesloge/git/opennms/target/opennms-1.8.10-SNAPSHOT/share/rrd/snmp/";
        String nodeid = "11";
        String iFace = "eth0-00163e13f215";
        
        System.out.println(lookup.getIfInOctetsJrb(rrdDir, nodeid, iFace));
        File f = new File(lookup.getIfInOctetsJrb(rrdDir, nodeid, iFace));
        if(f.exists()) {
            assertTrue(true);
        }else {
            assertTrue(false);
        }
        
    }
}

@@ -85,110 +85,8 @@
 ls;%0A
-import static org.junit.Assert.assertTrue;%0A%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;
 %0Aimp
@@ -2101,653 +2101,6 @@
    %0A
-    @Test%0A    public void testGetInterfaceDirectoryLocalSystem() throws FileNotFoundException, IOException %7B%0A        JRobinDirectoryUtil lookup = new JRobinDirectoryUtil();%0A        %0A        String rrdDir = %22/Users/thedesloge/git/opennms/target/opennms-1.8.10-SNAPSHOT/share/rrd/snmp/%22;%0A        String nodeid = %2211%22;%0A        String iFace = %22eth0-00163e13f215%22;%0A        %0A        System.out.println(lookup.getIfInOctetsJrb(rrdDir, nodeid, iFace));%0A        File f = new File(lookup.getIfInOctetsJrb(rrdDir, nodeid, iFace));%0A        if(f.exists()) %7B%0A            assertTrue(true);%0A        %7Delse %7B%0A            assertTrue(false);%0A        %7D%0A        %0A    %7D%0A
 %7D%0A

Remove unneeded test