package kg.apc.jmeter.reporters;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.jmeter.samplers.SampleResult;
import org.junit.*;

import static org.junit.Assert.assertEquals;

public class LoadosophiaAggregatorTest {

    public LoadosophiaAggregatorTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void testAddSample() {
        System.out.println("addSample");
        LoadosophiaAggregator instance = new LoadosophiaAggregator();
        instance.addSample(new SampleResult());
        assertEquals(false, instance.haveDataToSend());
        instance.addSample(new SampleResult(System.currentTimeMillis() + 1000, 1));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 2000, 1));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 3000, 1));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 3000, 3));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 3000, 2));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 4000, 1));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 5000, 1));
        instance.addSample(new SampleResult(System.currentTimeMillis() + 6000, 1));
        assertEquals(true, instance.haveDataToSend());
        String str = instance.getDataToSend().toString();
        System.out.println("JSON: " + str);
        Assert.assertTrue(!str.equals("[]"));
        Assert.assertTrue(!str.equals(""));
        JSONArray test = JSONArray.fromObject(str);
        Assert.assertEquals(5, test.size());
        assertEquals(false, instance.haveDataToSend());
    }

    @Test
    public void testHaveDataToSend() {
        System.out.println("haveDataToSend");
        LoadosophiaAggregator instance = new LoadosophiaAggregator();
        boolean result = instance.haveDataToSend();
        Assert.assertEquals(false, result);
    }

    @Test
    public void testGetDataToSend() {
        System.out.println("getDataToSend");
        LoadosophiaAggregator instance = new LoadosophiaAggregator();
        String expResult = "[]";
        JSONArray result = instance.getDataToSend();
        Assert.assertEquals(expResult, result.toString());
    }

    @Test
    public void testGetQuantiles() {
        System.out.println("getQuantiles");
        Long[] rtimes = {1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L};
        JSONObject result = LoadosophiaAggregator.getQuantilesJSON(rtimes);
        Assert.assertEquals("{\"100.0\":10,\"99.0\":10,\"98.0\":10,\"95.0\":10,\"90.0\":9,\"80.0\":8,\"75.0\":8,\"50.0\":5,\"25.0\":3}", result.toString());
    }

    /**
     * Test of getQuantilesJSON method, of class LoadosophiaAggregator.
     */
    @Test
    public void testGetQuantilesJSON() {
        System.out.println("getQuantilesJSON");
        Long[] rtimes = new Long[0];
        JSONObject result = LoadosophiaAggregator.getQuantilesJSON(rtimes);
    }
}

@@ -88,16 +88,63 @@
 Object;%0A
+import org.apache.jmeter.samplers.SampleEvent;%0A
 import o
@@ -736,32 +736,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult());
@@ -774,16 +774,21 @@
 Result()
+, %22%22)
 );%0A     
@@ -861,32 +861,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -931,24 +931,29 @@
 ) + 1000, 1)
+, %22%22)
 );%0A        i
@@ -966,32 +966,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -1036,24 +1036,29 @@
 ) + 2000, 1)
+, %22%22)
 );%0A        i
@@ -1071,32 +1071,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -1141,24 +1141,29 @@
 ) + 3000, 1)
+, %22%22)
 );%0A        i
@@ -1176,32 +1176,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -1250,16 +1250,21 @@
 3000, 3)
+, %22%22)
 );%0A     
@@ -1281,32 +1281,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -1355,16 +1355,21 @@
 3000, 2)
+, %22%22)
 );%0A     
@@ -1386,32 +1386,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -1456,24 +1456,29 @@
 ) + 4000, 1)
+, %22%22)
 );%0A        i
@@ -1491,32 +1491,48 @@
 e.addSample(new 
+SampleEvent(new 
 SampleResult(Sys
@@ -1561,24 +1561,29 @@
 ) + 5000, 1)
+, %22%22)
 );%0A        i
@@ -1600,24 +1600,40 @@
 dSample(new 
+SampleEvent(new 
 SampleResult
@@ -1670,16 +1670,21 @@
 6000, 1)
+, %22%22)
 );%0A     

Fix test