package com.oneandone.snmpman;

import com.oneandone.snmpman.exception.InitializationException;
import org.mockito.Mockito;
import org.snmp4j.agent.BaseAgent;
import org.snmp4j.smi.OID;
import org.snmp4j.util.TableEvent;
import org.testng.annotations.Test;

import java.util.Collections;
import java.util.List;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;

public class SnmpmanTest extends AbstractSnmpmanTest {

    @Test
    public void testSnmpGetBulk() throws Exception {
        assertEquals(snmpman.getAgents().size(), 11);

        List<TableEvent> responses = getResponse(new OID("1.3.6.1.2.1"), 10000);
        assertEquals(responses.size(), 19);

        responses = getResponse(new OID("1.3.6.1.2.1.31"), 10000);
        assertEquals(responses.size(), 10);

        responses = getResponse(new OID(".1.3.6.1.2.1.2"), 10000);
        assertEquals(responses.size(), 7);

        responses = getResponse(new OID(".1.3"), 10010);
        assertEquals(responses.size(), 30);

        responses = getResponse(new OID(".1.0"), 10010);
        assertEquals(responses.size(), 8);
    }

    @Test
    public void testWithCommunityIndex() throws Exception {
        assertEquals(snmpman.getAgents().size(), 11);

        final String oid = "1.3.6.1.2.1.17.2.4";
        List<TableEvent> responses1 = getResponse(new OID(oid), 10009, "public@42");
        assertEquals(responses1.size(), 1);
        assertTrue(containsColumn(responses1, oid, "150"));

        List<TableEvent> responses2 = getResponse(new OID(oid), 10009, "public@9");
        assertEquals(responses2.size(), 1);
        assertTrue(containsColumn(responses2, oid, "120"));

        List<TableEvent> responses3 = getResponse(new OID(oid), 10009, "public");
        assertEquals(responses3.size(), 1);
        assertTrue(containsColumn(responses3, oid, "0"));
    }

    @Test(expectedExceptions = InitializationException.class)
    public void startWithAlreadyStoppedAgent() {
        final SnmpmanAgent mock = Mockito.mock(SnmpmanAgent.class);
        Mockito.when(mock.getAgentState()).thenReturn(BaseAgent.STATE_STOPPED);

        final List<SnmpmanAgent> snmpmanAgents = Collections.singletonList(mock);
        Snmpman.start(snmpmanAgents);
    }

    @Test
    public void testModifier() throws Exception {
        final String oid = "1.3.6.1.2.1.2.2.1.13";
        List<TableEvent> responses1 = SnmpmanTest.getResponse(new OID(oid), 10009, "public");
        List<TableEvent> responses2 = SnmpmanTest.getResponse(new OID(oid), 10009, "public");

        assertNotEquals(responses1.get(0).getColumns(), responses2.get(0).getColumns(),
                "repeated call should return a different result");
    }

}
@@ -1407,37 +1407,36 @@
 e(new OID(oid), 
-10009
+PORT
 , %22public@42%22);%0A
@@ -1596,37 +1596,36 @@
 e(new OID(oid), 
-10009
+PORT
 , %22public@9%22);%0A 
@@ -1788,39 +1788,39 @@
 w OID(oid), 
-10009, %22public%22
+PORT, COMMUNITY
 );%0A        a
@@ -2493,31 +2493,31 @@
 D(oid), 
-10009, %22public%22
+PORT, COMMUNITY
 );%0A     
@@ -2591,23 +2591,23 @@
 d), 
-10009, %22public%22
+PORT, COMMUNITY
 );%0A%0A
@@ -2771,6 +2771,6 @@
   %7D%0A
-%0A
 %7D
+%0A

Replace magic variables with constants from parent class. Add line feed at the end of the file.