Search in sources :

Example 1 with Configuration

use of com.qasymphony.ci.plugin.model.Configuration in project jenkin-qtest-plugin by QASymphony.

the class TestResultFromxUnit method testParser.

@LocalData
@Test
public void testParser() throws InterruptedException, ExecutionException, TimeoutException, IOException {
    project = j.createFreeStyleProject("xunit-project");
    Configuration configuration = Configuration.newInstance();
    configuration.setReadFromJenkins(true);
    configuration.setProjectName("TestResultFromxUnitProject");
    // configuration.setAppSecretKey("34428172-cdba-4c97-aefb-b2ee5ae5db99");
    configuration.setAppSecretKey("5d65f50e-b368-47a1-9bff-e0a710011a3f");
    configuration.setReleaseId(1L);
    configuration.setId(1L);
    configuration.setProjectId(1L);
    configuration.setUrl("https://localhost:7443");
    configuration.setJenkinsProjectName("TestResultFromxUnitProject");
    configuration.setJenkinsServerUrl("http://localhost:8080/jenkins");
    TestResultFromxUnitProject testResultFromxUnitProject = new TestResultFromxUnitProject(configuration);
    configuration.setResultPattern("*.xml");
    project.getBuildersList().add(testResultFromxUnitProject);
    FreeStyleBuild build = project.scheduleBuild2(0).get(100, TimeUnit.MINUTES);
    assertNotNull("", testResultFromxUnitProject.getAutomationTestResultList());
    assertNotNull("Build is: ", build);
    String buildNumber = "1";
    String buildPath = "/jobs/TestResultFromxUnitProject/" + buildNumber;
    JunitSubmitterRequest submitterRequest = configuration.createJunitSubmitRequest();
    try {
        AutomationTestService.push(buildNumber, buildPath, testResultFromxUnitProject.getAutomationTestResultList(), submitterRequest, configuration.getAppSecretKey());
    } catch (SubmittedException e) {
        e.printStackTrace();
    }
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) Configuration(com.qasymphony.ci.plugin.model.Configuration) FreeStyleBuild(hudson.model.FreeStyleBuild) JunitSubmitterRequest(com.qasymphony.ci.plugin.submitter.JunitSubmitterRequest) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Example 2 with Configuration

use of com.qasymphony.ci.plugin.model.Configuration in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method fetchAll.

@Override
public ReadSubmitLogResult fetchAll(ReadSubmitLogRequest request) throws StoreResultException {
    FilePath resultPath = JobUtils.isPipelineJob(request.getJob()) == false ? getResultFolder(request.getProject()) : getResultFolder(request.getJob());
    Map<Integer, SubmittedResult> buildResults = new HashMap<>();
    int numOrder = request.getCurrentBuildNumber() / BREAK_FILE_BY;
    // get saved configuration
    Configuration configuration = null;
    if (JobUtils.isFreeStyleProjectJob(request.getProject()) == true) {
        configuration = ConfigService.getPluginConfiguration(request.getProject());
    }
    String qTestUrl = configuration == null ? "" : configuration.getUrl();
    Long projectId = configuration == null ? 0L : configuration.getProjectId();
    try {
        if (numOrder <= 0) {
            FilePath resultFile = getResultFile(resultPath, numOrder);
            buildResults.putAll(readResult(resultFile, qTestUrl, projectId));
        } else {
            for (int i = 0; i < numOrder; i++) {
                FilePath resultFile = getResultFile(resultPath, i);
                buildResults.putAll(readResult(resultFile, qTestUrl, projectId));
            }
        }
    } catch (Exception e) {
        throw new StoreResultException(e);
    }
    return new ReadSubmitLogResult().setResults(buildResults).setTotal(buildResults.size());
}
Also used : FilePath(hudson.FilePath) SubmittedResult(com.qasymphony.ci.plugin.model.SubmittedResult) Configuration(com.qasymphony.ci.plugin.model.Configuration) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException)

Example 3 with Configuration

use of com.qasymphony.ci.plugin.model.Configuration in project jenkin-qtest-plugin by QASymphony.

the class StoreResultServiceImpl method fetch.

@Override
public ReadSubmitLogResult fetch(ReadSubmitLogRequest request) throws StoreResultException {
    FilePath resultPath = getResultFolder(request.getProject());
    int numOrder = request.getCurrentBuildNumber() / BREAK_FILE_BY;
    List<FileReader> readerList = getReaderList(resultPath, numOrder);
    // get saved configuration
    Configuration configuration = ConfigService.getPluginConfiguration(request.getProject());
    String qTestUrl = configuration == null ? "" : configuration.getUrl();
    Long projectId = configuration == null ? 0L : configuration.getProjectId();
    int total = 0;
    Map<Integer, SubmittedResult> resultMap = new HashMap<>();
    for (FileReader reader : readerList) {
        total += reader.size();
        try {
            resultMap.putAll(buildSubmittedResult(reader.readAll(), qTestUrl, projectId));
        } catch (IOException e) {
            throw new StoreResultException(e.getMessage(), e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                throw new StoreResultException(e.getMessage(), e);
            }
        }
    }
    return new ReadSubmitLogResult().setTotal(total).setResults(resultMap);
}
Also used : FilePath(hudson.FilePath) SubmittedResult(com.qasymphony.ci.plugin.model.SubmittedResult) Configuration(com.qasymphony.ci.plugin.model.Configuration) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException) IOException(java.io.IOException) FileReader(com.qasymphony.ci.plugin.store.file.FileReader)

Example 4 with Configuration

use of com.qasymphony.ci.plugin.model.Configuration in project jenkin-qtest-plugin by QASymphony.

the class TestResultFromxUnit method testSubmit.

@LocalData
@Test
public void testSubmit() throws InterruptedException, ExecutionException, TimeoutException, IOException, SubmittedException {
    project = j.createFreeStyleProject("xunit-project");
    String buildNumber = "1";
    String buildPath = "/jobs/TestResultFromxUnitProject/" + buildNumber;
    String projectName = "TestResultFromxUnitProject";
    String apiKey = "5d65f50e-b368-47a1-9bff-e0a710011a3f";
    Long releaseId = 1L;
    Long ciId = 1L;
    Long qTestProjectId = 1L;
    Configuration configuration = new Configuration(ciId, "https://localhost:7443", apiKey, qTestProjectId, projectName, releaseId, "releaseName", 0L, "environment", 0L, 0L, false, "", false, "{}", false, 0);
    configuration.setResultPattern("*.xml");
    TestResultFromxUnitProject testResultFromxUnitProject = new TestResultFromxUnitProject(configuration);
    project.getBuildersList().add(testResultFromxUnitProject);
    FreeStyleBuild build = project.scheduleBuild2(0).get(100, TimeUnit.MINUTES);
    assertNotNull("Build is: ", build);
    Map<String, String> headers = OauthProvider.buildHeaders(configuration.getUrl(), configuration.getAppSecretKey(), null);
// AutomationTestService.push(buildNumber, buildPath, testResultFromxUnitProject.getAutomationTestResultList(), configuration, headers);
}
Also used : Configuration(com.qasymphony.ci.plugin.model.Configuration) FreeStyleBuild(hudson.model.FreeStyleBuild) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Aggregations

Configuration (com.qasymphony.ci.plugin.model.Configuration)4 StoreResultException (com.qasymphony.ci.plugin.exception.StoreResultException)2 SubmittedResult (com.qasymphony.ci.plugin.model.SubmittedResult)2 FilePath (hudson.FilePath)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 LocalData (org.jvnet.hudson.test.recipes.LocalData)2 SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)1 FileReader (com.qasymphony.ci.plugin.store.file.FileReader)1 JunitSubmitterRequest (com.qasymphony.ci.plugin.submitter.JunitSubmitterRequest)1