package com.github.angelndevil2.loadt;

import com.github.angelndevil2.loadt.common.HTTPMethod;
import com.github.angelndevil2.loadt.common.JMeterCalculator;
import com.github.angelndevil2.loadt.common.LoadTException;
import com.github.angelndevil2.loadt.common.SystemInfoCollector;
import com.github.angelndevil2.loadt.jetty.JettyServer;
import com.github.angelndevil2.loadt.listener.CSVFileSaver;
import com.github.angelndevil2.loadt.listener.ConsoleResultViewer;
import com.github.angelndevil2.loadt.listener.ConsoleStatisticViewer;
import com.github.angelndevil2.loadt.listener.IResultSaver;
import com.github.angelndevil2.loadt.loadmanager.LoadManagerType;
import com.github.angelndevil2.loadt.util.PropertiesUtil;
import org.junit.Test;

import java.io.IOException;

/**
 * @author k, Created on 16. 2. 6.
 */
public class LoadTTest {

    @Test
    public void testLoadT() throws LoadTException, IOException, InterruptedException {

        LoadT loadT = new LoadT();

        PropertiesUtil.setDirs("src/dist");

        Thread jetty = new Thread(new JettyServer());
        jetty.setDaemon(true);
        jetty.start();

        // set LoadManager
        final String name = "Test load manager";
        loadT.addLoadManager(name, LoadManagerType.JMETER);


        // set options

        // use keepAlive
        loadT.setHttpKeepAlive(name, true);

        // follow redirect
        loadT.setHttpFollowRedirect(name, true);

        // set loop count 10
        loadT.setLoopCount(name,1);

        // set number of thread 100
        loadT.setNumberOfThread(name, 1);

       // add http sampler
        loadT.addHttpSampler(name, "websphere", "localhost", 1080, "/", HTTPMethod.GET, "localhost");

        // add system information collector with domain "192.168.100.241"
        SystemInfoCollector systemInfoCollector = new SystemInfoCollector("localhost");
        loadT.addSystemInfoCollector(systemInfoCollector);
        loadT.startSystemInfoCollectors();

        // add console viewer
        loadT.addListener(name, new ConsoleResultViewer());
        loadT.setViewInterval(1000);
        loadT.addCalculator(name, new JMeterCalculator("TOTAL"));
        loadT.addStatisticSampleListener(name, "TOTAL", new ConsoleStatisticViewer());

        loadT.setSaveInterval(1000);
        IResultSaver saver = new CSVFileSaver("test.csv");
        loadT.addResultSaver(name, saver);
        // result saver is also IResultListener, so register with addStatisticSampleListener or addListener.
        loadT.addStatisticSampleListener(name, "TOTAL", saver);

        // run test
        loadT.runTestAll();
        System.exit(0);
    }
}

@@ -328,24 +328,77 @@
 ettyServer;%0A
+import com.github.angelndevil2.loadt.jetty.PropList;%0A
 import com.g
@@ -777,51 +777,146 @@
 ort 
-org.junit.Test;%0A%0Aimport java.io.IOException
+lombok.extern.slf4j.Slf4j;%0Aimport org.junit.Test;%0A%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.util.Properties
 ;%0A%0A/
@@ -957,16 +957,23 @@
  6.%0A */%0A
+@Slf4j%0A
 public c
@@ -986,24 +986,497 @@
 oadTTest %7B%0A%0A
+    static final Properties jettyProp;%0A    static %7B%0A        try %7B%0A            PropertiesUtil.setDirs(%22src/dist%22);%0A        %7D catch (IOException e) %7B%0A            log.error(%22base directory setting error.%22, e);%0A        %7D%0A%0A        jettyProp = new Properties();%0A%0A        try %7B%0A            jettyProp.load(new FileInputStream(PropertiesUtil.getJettyPropertiesFile()));%0A        %7D catch (IOException e) %7B%0A            log.error(%22error loading jetty properties.%22, e);%0A        %7D%0A    %7D%0A%0A
     @Test%0A  
@@ -1601,53 +1601,8 @@
 );%0A%0A
-        PropertiesUtil.setDirs(%22src/dist%22);%0A%0A
     
@@ -2252,12 +2252,66 @@
 t%22, 
-1080
+Integer.valueOf((String)jettyProp.get(PropList.HTTP_PORT))
 , %22/

read jetty server port from properties for test