// Path: src/main/java/com/sumologic/jenkins/jenkinssumologicplugin/model/ModelFactory.java
// public class ModelFactory {
// 
//     public static JenkinsModel createJenkinsModel(Jenkins jenkins) {
//         Queue queue = jenkins.getQueue();
//         final Queue.Item[] items = queue.getItems();
//         long maxwait = 0, now = System.currentTimeMillis();
//         for (Queue.Item item : items) {
//             long waiting = now - item.getInQueueSince();
//             maxwait = Math.max(maxwait, waiting);
//         }
// 
//         QueueModel queueModel = new QueueModel();
// 
//         int numFreeExecutors = 0;
// 
//         for (Computer computer : jenkins.getComputers()) {
//             if (computer.isOnline()) {
//                 numFreeExecutors += computer.countIdle();
//             }
// 
//         }
//         AgentModel agentModel = new AgentModel(jenkins.getNumExecutors(), numFreeExecutors);
// 
//         return new JenkinsModel(queueModel, agentModel, jenkins.getDescription());
//     }
// 
//     public static BuildModel createBuildModel(Run build, PluginDescriptorImpl pluginDescriptor) {
//         BuildModel buildModel;
//         if (build instanceof MavenModuleSetBuild) {
//             MavenModuleSetBuildModel mBuildModel = new MavenModuleSetBuildModel();
//             CommonModelFactory.populateGeneric(mBuildModel, build, pluginDescriptor, false);
//             MavenModuleSetBuild mbuild = (MavenModuleSetBuild) build;
//             SurefireAggregatedReport surefireAggregatedReport = mbuild.getAction(SurefireAggregatedReport.class);
//             if (surefireAggregatedReport != null) {
//                 mBuildModel.setTotalTestCount(surefireAggregatedReport.getTotalCount());
//                 mBuildModel.setFailedTestCount(surefireAggregatedReport.getFailCount());
//                 mBuildModel.setSkippedTestCount(surefireAggregatedReport.getSkipCount());
//                 for (TestResult result : surefireAggregatedReport.getFailedTests()) {
//                     mBuildModel.addFailedTest(result.getDisplayName());
//                 }
//             }
//             Map<MavenModule, MavenBuild> modules = mbuild.getModuleLastBuilds();
// 
//             for (MavenBuild module : modules.values()) {
//                 mBuildModel.addModule((MavenModuleBuildModel) createBuildModel(module, pluginDescriptor));
//             }
//             buildModel = mBuildModel;
//         } else if (build instanceof MavenBuild) {
//             MavenBuild mbuild = (MavenBuild) build;
//             MavenModuleBuildModel mBuildModel = new MavenModuleBuildModel();
//             CommonModelFactory.populateGeneric(mBuildModel, mbuild, pluginDescriptor, false);
//             buildModel = mBuildModel;
//         } else {
//             buildModel = new BuildModel();
//             CommonModelFactory.populateGeneric(buildModel, build, pluginDescriptor, false);
//         }
//         return buildModel;
//     }
// }


import com.sumologic.jenkins.jenkinssumologicplugin.model.ModelFactory;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Hudson;
import hudson.model.Result;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.StringContains;
import org.junit.Test;
import java.util.GregorianCalendar;
package com.sumologic.jenkins.jenkinssumologicplugin;



public class ModelFactoryTest extends BaseTest {

    @Test
    public void testGenerateBuildModelForAbstractBuild() throws Exception {

        final String name = "MockJob";
        GregorianCalendar c = new GregorianCalendar();
        final int number = 101;
        Result result = Result.SUCCESS;

        FreeStyleProject project = j.createFreeStyleProject(name);
        project.getPublishersList().add(new SumoBuildNotifier());

        FreeStyleBuild build = project.scheduleBuild2(0).get();

// Path: src/main/java/com/sumologic/jenkins/jenkinssumologicplugin/model/ModelFactory.java
// public class ModelFactory {
// 
//     public static JenkinsModel createJenkinsModel(Jenkins jenkins) {
//         Queue queue = jenkins.getQueue();
//         final Queue.Item[] items = queue.getItems();
//         long maxwait = 0, now = System.currentTimeMillis();
//         for (Queue.Item item : items) {
//             long waiting = now - item.getInQueueSince();
//             maxwait = Math.max(maxwait, waiting);
//         }
// 
//         QueueModel queueModel = new QueueModel();
// 
//         int numFreeExecutors = 0;
// 
//         for (Computer computer : jenkins.getComputers()) {
//             if (computer.isOnline()) {
//                 numFreeExecutors += computer.countIdle();
//             }
// 
//         }
//         AgentModel agentModel = new AgentModel(jenkins.getNumExecutors(), numFreeExecutors);
// 
//         return new JenkinsModel(queueModel, agentModel, jenkins.getDescription());
//     }
// 
//     public static BuildModel createBuildModel(Run build, PluginDescriptorImpl pluginDescriptor) {
//         BuildModel buildModel;
//         if (build instanceof MavenModuleSetBuild) {
//             MavenModuleSetBuildModel mBuildModel = new MavenModuleSetBuildModel();
//             CommonModelFactory.populateGeneric(mBuildModel, build, pluginDescriptor, false);
//             MavenModuleSetBuild mbuild = (MavenModuleSetBuild) build;
//             SurefireAggregatedReport surefireAggregatedReport = mbuild.getAction(SurefireAggregatedReport.class);
//             if (surefireAggregatedReport != null) {
//                 mBuildModel.setTotalTestCount(surefireAggregatedReport.getTotalCount());
//                 mBuildModel.setFailedTestCount(surefireAggregatedReport.getFailCount());
//                 mBuildModel.setSkippedTestCount(surefireAggregatedReport.getSkipCount());
//                 for (TestResult result : surefireAggregatedReport.getFailedTests()) {
//                     mBuildModel.addFailedTest(result.getDisplayName());
//                 }
//             }
//             Map<MavenModule, MavenBuild> modules = mbuild.getModuleLastBuilds();
// 
//             for (MavenBuild module : modules.values()) {
//                 mBuildModel.addModule((MavenModuleBuildModel) createBuildModel(module, pluginDescriptor));
//             }
//             buildModel = mBuildModel;
//         } else if (build instanceof MavenBuild) {
//             MavenBuild mbuild = (MavenBuild) build;
//             MavenModuleBuildModel mBuildModel = new MavenModuleBuildModel();
//             CommonModelFactory.populateGeneric(mBuildModel, mbuild, pluginDescriptor, false);
//             buildModel = mBuildModel;
//         } else {
//             buildModel = new BuildModel();
//             CommonModelFactory.populateGeneric(buildModel, build, pluginDescriptor, false);
//         }
//         return buildModel;
//     }
// }


// Path: src/test/java/com/sumologic/jenkins/jenkinssumologicplugin/ModelFactoryTest.java
import com.sumologic.jenkins.jenkinssumologicplugin.model.ModelFactory;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Hudson;
import hudson.model.Result;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.StringContains;
import org.junit.Test;
import java.util.GregorianCalendar;

package com.sumologic.jenkins.jenkinssumologicplugin;



public class ModelFactoryTest extends BaseTest {

    @Test
    public void testGenerateBuildModelForAbstractBuild() throws Exception {

        final String name = "MockJob";
        GregorianCalendar c = new GregorianCalendar();
        final int number = 101;
        Result result = Result.SUCCESS;

        FreeStyleProject project = j.createFreeStyleProject(name);
        project.getPublishersList().add(new SumoBuildNotifier());

        FreeStyleBuild build = project.scheduleBuild2(0).get();

        String jsonExpected = "\"result\":\"SUCCESS\",\"number\":1,";