Best Testsigma code snippet using com.testsigma.service.TestPlanResultService.findByTestPlanIdAndStatusIsNot
Source:AgentExecutionService.java  
...134      }135    }136  }137  private void checkIfAlreadyHasAnotherRun() throws TestsigmaException {138    TestPlanResult testPlanResult = this.testPlanResultService.findByTestPlanIdAndStatusIsNot(this.testPlan.getId(),139      StatusConstant.STATUS_COMPLETED);140    if (testPlanResult != null) {141      log.info(String.format("Execution [%s] is already running and is in status %s ", this.testPlan.getId(),142        testPlanResult.getStatus()));143      throw new TestsigmaException(AutomatorMessages.EXECUTION_ALREADY_RUNNING);144    }145  }146  // ############################################ RESULT ENTRIES CREATION #############################################147  private void populateResultEntries(boolean setLastRunId) throws TestsigmaException {148    TestPlanResult testPlanResult = createTestPlanResult();149    populateLastRunId(testPlanResult, setLastRunId);150    this.setTestPlanResult(testPlanResult);151    populateEnvironmentResults(testPlanResult);152  }153  private void populateLastRunId(TestPlanResult testPlanResult, boolean setLastRunId) {154    AbstractTestPlan testPlan = this.getTestPlan();155    if (setLastRunId) {156      testPlan.setLastRunId(testPlanResult.getId());157    }158    if (testPlan instanceof TestPlan)159      this.setTestPlan(testPlanService.update((TestPlan) testPlan));160  }161  private void populateEnvironmentResults(TestPlanResult testPlanResult) throws TestsigmaException {162    List<TestDevice> testDevices =163      testDeviceService.findByTestPlanIdAndDisable(this.getTestPlan().getId(), Boolean.FALSE);164    for (TestDevice testDevice : testDevices) {165      log.info("Populating Environment result for environment:" + testDevice);166      TestDeviceResult testDeviceResult = createEnvironmentResult(testPlanResult, testDevice);167      if (testDeviceResult != null) {168        populateTestSuiteResults(testDeviceResult, testDevice);169      }170    }171  }172  private void populateTestSuiteResults(TestDeviceResult testDeviceResult, TestDevice testDevice)173    throws TestsigmaException {174    List<AbstractTestSuite> testSuites = this.testSuiteService.findAllByTestDeviceId(testDeviceResult.getTestDeviceId());175    for (AbstractTestSuite testSuite : testSuites) {176      log.info("Populate TestSuite result for suite:" + testSuite.getName());177      TestSuiteResult testSuiteResult = createTestSuiteResult(testSuite, testDeviceResult, testDevice);178      if (testSuiteResult != null) {179        testSuite.setLastRunId(testSuiteResult.getId());180        if (testPlan instanceof TestPlan)181          this.testSuiteService.updateSuite((TestSuite) testSuite);182        populateTestCaseResults(testSuite, testSuiteResult, testDeviceResult);183      }184    }185  }186  private void populateTestCaseResults(AbstractTestSuite testSuite, TestSuiteResult testSuiteResult,187                                       TestDeviceResult testDeviceResult) throws TestsigmaException {188    List<TestCase> testCases = this.testCaseService.findAllBySuiteId(testSuiteResult.getSuiteId());189    for (TestCase testCase : testCases) {190      TestCaseResult testCaseResult = createTestCaseResult(testSuite, testCase, testDeviceResult, testSuiteResult,191        null);192      if (testCaseResult != null && testPlan instanceof TestPlan) {193        testCase.setLastRunId(testCaseResult.getId());194        testCaseService.update(testCase);195      }196    }197  }198  protected void populateStepGroupTestStepResults(TestStep testStep, TestCaseResult testCaseResult,199                                                  TestDeviceResult testDeviceResult,200                                                  TestStepResult parentTestStepResult) {201    List<TestStep> testSteps = this.testStepService.findAllByTestCaseId(testStep.getStepGroupId());202    for (TestStep step : testSteps) {203      createTestStepResult(step, testDeviceResult, testCaseResult, parentTestStepResult);204    }205  }206  protected void createTestStepResult(TestStep testStep,207                                      TestDeviceResult testDeviceResult,208                                      TestCaseResult testCaseResult,209                                      TestStepResult parentTestStepResult) {210    log.info("Creating TestStepResult for:" + testStep);211    TestStepResult testStepResult = new TestStepResult();212    testStepResult.setEnvRunId(testDeviceResult.getId());213    testStepResult.setResult(ResultConstant.QUEUED);214    testStepResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);215    testStepResult.setStepId(testStep.getId());216    testStepResult.setTestCaseId(testCaseResult.getTestCaseId());217    testStepResult.setStepGroupId(testStep.getStepGroupId());218    testStepResult.setGroupResultId((parentTestStepResult != null) ? parentTestStepResult.getId() : null);219    testStepResult.setTestCaseResultId(testCaseResult.getId());220    testStepResult.setPriority(testStep.getPriority());221    StepDetails stepDetails = new StepDetails();222    stepDetails.setNaturalTextActionId(testStep.getNaturalTextActionId());223    stepDetails.setAction(testStep.getAction());224    stepDetails.setPriority(testStep.getPriority());225    stepDetails.setPreRequisiteStepId(testStep.getPreRequisiteStepId());226    stepDetails.setConditionType(testStep.getConditionType());227    stepDetails.setParentId(testStep.getParentId());228    stepDetails.setType(testStep.getType());229    stepDetails.setStepGroupId(testStep.getStepGroupId());230    stepDetails.setAction(testStep.getAction());231    stepDetails.setPosition(testStep.getPosition());232    stepDetails.setTestDataName(testCaseResult.getTestDataSetName());233    stepDetails.setDataMap(testStep.getDataMapBean());234    testStepResult.setStepDetails(stepDetails);235    if (parentTestStepResult != null) {236      testStepResult.setParentResultId(parentTestStepResult.getId());237    }238    testStepResult = this.testStepResultService.create(testStepResult);239    if (TestStepType.STEP_GROUP.equals(testStep.getType())) {240      populateStepGroupTestStepResults(testStep, testCaseResult, testDeviceResult, testStepResult);241    }242  }243  private void populateDataDrivenTestCaseResults(AbstractTestSuite testSuite,244                                                 TestCase testCase,245                                                 TestDeviceResult testDeviceResult,246                                                 TestSuiteResult testSuiteResult,247                                                 TestCaseResult parentTestCaseResult) throws TestsigmaException {248    log.info("Creating DatadrivenTestcaseResult for testcase:" + testCase.getName());249    TestData testData = testCase.getTestData();250    List<TestDataSet> testDataSets = testData.getData();251    int start = testCase.getTestDataStartIndex() != null ? testCase.getTestDataStartIndex() : 0;252    int end = testCase.getTestDataEndIndex() != null ? testCase.getTestDataEndIndex() : testDataSets.size() - 1;253    for (int i = start; i <= end && i < testDataSets.size(); i++) {254      testCase.setIsDataDriven(false);255      TestDataSet testDataSet = testDataSets.get(i);256      testCase.setIsDataDriven(false);257      testCase.setTestDataStartIndex(testDataSets.indexOf(testDataSet));258      TestCaseResult testCaseResult = createTestCaseResult(testSuite, testCase, testDeviceResult, testSuiteResult,259        parentTestCaseResult);260      if (testCaseResult != null) {261        createTestCaseDataDrivenResult(testDataSet, testCaseResult);262      }263    }264    testCase.setIsDataDriven(true);265    testCase.setTestDataStartIndex(start);266  }267  private TestCaseDataDrivenResult createTestCaseDataDrivenResult(TestDataSet testDataSet, TestCaseResult testCaseResult) {268    TestCaseDataDrivenResult testCaseDataDrivenResult = new TestCaseDataDrivenResult();269    testCaseDataDrivenResult.setEnvRunId(testCaseResult.getEnvironmentResultId());270    testCaseDataDrivenResult.setTestData(new ObjectMapperService().convertToJson(testDataSet));271    testCaseDataDrivenResult.setTestDataName(testDataSet.getName());272    testCaseDataDrivenResult.setTestCaseId(testCaseResult.getTestCaseId());273    testCaseDataDrivenResult.setTestCaseResultId(testCaseResult.getParentId());274    testCaseDataDrivenResult.setIterationResultId(testCaseResult.getId());275    return testCaseDataDrivenResultService.create(testCaseDataDrivenResult);276  }277  private TestCaseResult createTestCaseResult(AbstractTestSuite testSuite,278                                              TestCase testCase,279                                              TestDeviceResult testDeviceResult,280                                              TestSuiteResult testSuiteResult,281                                              TestCaseResult parentTestCaseResult) throws TestsigmaException {282    log.info("Creating TestcaseResult for:" + testCase);283    checkForDataDrivenIntegrity(testCase);284    TestCaseResult testCaseResult = new TestCaseResult();285    testCaseResult = setReRunParentId(testSuiteResult, testCase, testCaseResult, parentTestCaseResult);286    if (testCaseResult == null)287      return null;288    testCaseResult.setEnvironmentResultId(testDeviceResult.getId());289    testCaseResult.setTestPlanResultId(testDeviceResult.getTestPlanResultId());290    testCaseResult.setTestCaseId(testCase.getId());291    testCaseResult.setSuiteId(testSuiteResult.getSuiteId());292    testCaseResult.setSuiteResultId(testSuiteResult.getId());293    testCaseResult.setResult(ResultConstant.QUEUED);294    testCaseResult.setStatus(StatusConstant.STATUS_CREATED);295    testCaseResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);296    testCaseResult.setIsStepGroup(testCase.getIsStepGroup());297    if (parentTestCaseResult != null) {298      testCaseResult.setParentId(parentTestCaseResult.getId());299    }300    if (!testCase.getIsDataDriven()) {301      TestData testData = testCase.getTestData();302      if (testData != null) {303        TestDataSet testDataSet = testData.getData().get(testCase.getTestDataStartIndex());304        testCaseResult.setTestDataSetName(testDataSet.getName());305        if (parentTestCaseResult != null) {306          testCaseResult.setIteration(testDataSet.getName());307        }308      }309    }310    Optional<SuiteTestCaseMapping> suiteTestCaseMapping =311      suiteTestCaseMappingService.findFirstByTestSuiteAndTestCase(testSuite, testCase);312    TestCaseResult finalTestCaseResult = testCaseResult;313    suiteTestCaseMapping314      .ifPresent(suiteMapping -> finalTestCaseResult.setPosition(suiteMapping.getPosition().longValue()));315    if (suiteTestCaseMapping.isPresent()) {316      testCaseResult.setPosition(suiteTestCaseMapping.get().getPosition().longValue());317    }318    testCaseResult.setTestCaseTypeId(testCase.getType());319    testCaseResult.setTestCaseStatus(testCase.getStatus());320    testCaseResult.setPriorityId(testCase.getPriority());321    testCaseResult.setIsDataDriven(testCase.getIsDataDriven());322    testCaseResult.setTestDataId(testCase.getTestDataId());323    testCaseResult.setTestCaseDetails(testCaseDetails(testCaseResult, testCase));324    testCaseResult = this.testCaseResultService.create(testCaseResult);325    if (testCase.getIsDataDriven()) {326      populateDataDrivenTestCaseResults(testSuite, testCase, testDeviceResult, testSuiteResult, testCaseResult);327    }328    return testCaseResult;329  }330  private TestCaseResult setReRunParentId(TestSuiteResult testSuiteResult, TestCase testCase, TestCaseResult testCaseResult, TestCaseResult parentTestCaseResult) {331    if (getIsReRun() && (testSuiteResult.getReRunParentId() != null)) {332      TestCaseResult reRunParentTestCaseResult = testCaseResultsReRunList.stream().filter(333        er -> er.getTestCaseId().equals(testCase.getId()) && er.getIteration() == null).findAny().orElse(null);334      if (reRunParentTestCaseResult != null) {335        testCaseResult.setReRunParentId(reRunParentTestCaseResult.getId());336      } else {337        log.info("Test Case (" + testCase.getId() + ") is not eligible for Re-run. Skipping...");338        return null;339      }340    }341    if (!testCase.getIsDataDriven() && testCase.getTestData() != null && parentTestCaseResult != null) {342      TestData testData = testCase.getTestData();343      TestDataSet testDataSet = testData.getData().get(testCase.getTestDataStartIndex());344      if (getIsReRun() && (testSuiteResult.getReRunParentId() != null)) {345        TestCaseResult reRunParentTestCaseResult = testCaseResultsReRunList.stream().filter(346          er -> er.getTestCaseId().equals(testCase.getId()) && er.getIteration() != null && er.getIteration().equals(testDataSet.getName())).findAny().orElse(null);347        if (reRunParentTestCaseResult != null) {348          testCaseResult.setReRunParentId(reRunParentTestCaseResult.getId());349        } else {350          log.info("Test Case (" + testCase.getId() + ") is not eligible for Re-run. Skipping...");351          return null;352        }353      }354    }355    return testCaseResult;356  }357  private TestCaseDetails testCaseDetails(TestCaseResult testCaseResult, TestCase testCase) {358    TestCaseDetails testCaseDetails = new TestCaseDetails();359    testCaseDetails.setName(testCase.getName());360    testCaseDetails.setTestData(testCaseResult.getIteration());361    testCaseDetails.setTestDataSetName(testCaseResult.getTestDataSetName());362    testCaseDetails.setPrerequisite(testCase.getPreRequisite());363    return testCaseDetails;364  }365  private TestSuiteResult createTestSuiteResult(AbstractTestSuite testSuite, TestDeviceResult testDeviceResult,366                                                TestDevice testDevice) {367    TestSuiteResult testSuiteResult = new TestSuiteResult();368    if (getIsReRun() && (testDeviceResult.getReRunParentId() != null)) {369      TestSuiteResult parentTestSuiteResult = testSuiteResultsReRunList.stream().filter(370        er -> er.getSuiteId().equals(testSuite.getId())).findAny().orElse(null);371      if (parentTestSuiteResult != null) {372        testSuiteResult.setReRunParentId(parentTestSuiteResult.getId());373        fetchTestCaseResultsReRunList(parentTestSuiteResult.getId());374      } else {375        log.info("Test Suite (" + testSuite.getId() + ") is not eligible for Re-run. Skipping...");376        return null;377      }378    }379    testSuiteResult.setEnvironmentResultId(testDeviceResult.getId());380    testSuiteResult.setResult(ResultConstant.QUEUED);381    testSuiteResult.setStatus(StatusConstant.STATUS_CREATED);382    testSuiteResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);383    testSuiteResult.setSuiteId(testSuite.getId());384    testSuiteResult.setStartTime(new Timestamp(System.currentTimeMillis()));385    testSuiteResult.setTestPlanResultId(testDeviceResult.getTestPlanResultId());386    Optional<TestDeviceSuite> environmentSuiteMapping =387      testDeviceSuiteService.findFirstByTestDeviceAndTestSuite(testDevice, testSuite);388    environmentSuiteMapping389      .ifPresent(suiteMapping -> testSuiteResult.setPosition(suiteMapping.getPosition().longValue()));390    TestSuiteResultSuiteDetails suiteDetails = new TestSuiteResultSuiteDetails();391    suiteDetails.setName(testSuite.getName());392    suiteDetails.setPreRequisite(testSuite.getPreRequisite());393    testSuiteResult.setSuiteDetails(suiteDetails);394    return this.testSuiteResultService.create(testSuiteResult);395  }396  private TestDeviceResult createEnvironmentResult(TestPlanResult testPlanResult,397                                                   TestDevice testDevice) throws TestsigmaException {398    TestDeviceResult testDeviceResult = new TestDeviceResult();399    if (getIsReRun() && (testPlanResult.getReRunParentId() != null)) {400      TestDeviceResult parentTestDeviceResult = testDeviceResultsReRunList.stream().filter(401        er -> er.getTestDeviceId().equals(testDevice.getId())).findAny().orElse(null);402      if (parentTestDeviceResult != null) {403        testDeviceResult.setReRunParentId(parentTestDeviceResult.getId());404        fetchTestSuitesResultsReRunList(parentTestDeviceResult.getId());405      } else {406        log.info("Execution Environment (" + testDevice.getId() + ") is not eligible for Re-run. Skipping...");407        return null;408      }409    }410    testDeviceResult.setTestPlanResultId(testPlanResult.getId());411    testDeviceResult.setResult(ResultConstant.QUEUED);412    testDeviceResult.setStatus(StatusConstant.STATUS_CREATED);413    testDeviceResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);414    testDeviceResult.setStartTime(new Timestamp(System.currentTimeMillis()));415    testDeviceResult.setTestDeviceId(testDevice.getId());416    testDeviceResult.setAppUploadVersionId(getUploadVersionId(testDevice));417    testDeviceResult.setTestDeviceSettings(getExecutionTestDeviceSettings(testDevice));418    testDeviceResult = testDeviceResultService.create(testDeviceResult);419    testDeviceResult.setTestDevice(testDevice);420    return testDeviceResult;421  }422  private Long getUploadVersionId(TestDevice testDevice) throws ResourceNotFoundException {423    Long uploadVersionId = getUploadVersionIdFromRuntime(testDevice.getId());424    if (uploadVersionId != null) {425      log.debug("Got uploadVersionId from runTimeData ", uploadVersionId, testDevice.getId());426      uploadVersionId = this.uploadVersionService.find(uploadVersionId).getId();427    } else {428      uploadVersionId = testDevice.getAppUploadVersionId();429      if (uploadVersionId == null && testDevice.getAppUploadId() != null)430        uploadVersionId = uploadService.find(testDevice.getAppUploadId()).getLatestVersionId();431    }432    return uploadVersionId;433  }434  private Long getUploadVersionIdFromRuntime(Long environmentId) {435    log.debug("Fetching uploadVersionId from runTimeData for EnvironmentId::"+environmentId);436    if (getRunTimeData() != null) {437      JSONObject uploadVersions = getRunTimeData().optJSONObject("uploadVersions");438      log.debug("Fetching uploadVersionId from runTimeData for uploadVersions::", uploadVersions);439      if (uploadVersions != null) {440        log.debug("Fetching uploadVersionId from runTimeData for uploadVersions::", uploadVersions);441        return uploadVersions.optLong(environmentId+"");442      }443    }444    return null;445  }446  private TestPlanResult createTestPlanResult() throws ResourceNotFoundException {447    TestPlanResult testPlanResult = new TestPlanResult();448    if (getIsReRun()) {449      if (this.getParentTestPlanResultId() != null) {450        testPlanResult.setReRunParentId(this.getParentTestPlanResultId());451      } else {452        testPlanResult.setReRunParentId(testPlan.getLastRunId());453      }454      testPlanResult.setReRunType(getReRunType());455      fetchEnvironmentResultsReRunList();456    }457    if ((this.getRunTimeData() != null) && (this.getRunTimeData().has("build_number"))) {458      testPlanResult.setBuildNo(this.getRunTimeData().getString("build_number"));459    }460    testPlanResult.setResult(ResultConstant.QUEUED);461    testPlanResult.setStatus(StatusConstant.STATUS_CREATED);462    testPlanResult.setMessage(AutomatorMessages.MSG_EXECUTION_CREATED);463    testPlanResult.setTestPlanId(this.getTestPlan().getId());464    testPlanResult.setStartTime(new Timestamp(System.currentTimeMillis()));465    testPlanResult.setTriggeredType(this.triggeredType);466    testPlanResult.setScheduleId(this.scheduleId);467    TestPlanDetails testPlanDetails = new TestPlanDetails();468    testPlanDetails.setElementTimeout(testPlan.getElementTimeOut());469    testPlanDetails.setPageTimeout(testPlan.getPageTimeOut());470    testPlanDetails.setOnAbortedAction(testPlan.getOnAbortedAction());471    testPlanDetails.setRecoveryAction(testPlan.getRecoveryAction());472    testPlanDetails.setGroupPrerequisiteFail(testPlan.getOnSuitePreRequisiteFail());473    testPlanDetails.setTestCasePrerequisiteFail(testPlan.getOnTestcasePreRequisiteFail());474    testPlanDetails.setTestStepPrerequisiteFail(testPlan.getOnStepPreRequisiteFail());475    testPlanDetails.setScreenshotOption(testPlan.getScreenshot());476    if (this.getTestPlan().getEnvironmentId() != null) {477      Environment environment = environmentService.find(this.getTestPlan().getEnvironmentId());478      testPlanResult.setEnvironmentId(environment.getId());479      testPlanDetails.setEnvironmentParamName(environment.getName());480    }481    testPlanResult.setTestPlanDetails(testPlanDetails);482    return testPlanResultService.create(testPlanResult);483  }484  private void checkForDataDrivenIntegrity(TestCase testCase) throws TestsigmaException {485    TestData testData = testCase.getTestData();486    if (testData == null && testCase.getIsDataDriven()) {487      String errorMessage = com.testsigma.constants.MessageConstants.getMessage(488        MessageConstants.MSG_UNKNOWN_TEST_DATA_DATA_DRIVEN_CASE,489        testCase.getName()490      );491      throw new TestsigmaException(errorMessage);492    }493  }494  private TestDeviceSettings getExecutionTestDeviceSettings(TestDevice testDevice) throws TestsigmaException {495    TestDeviceSettings settings = new TestDeviceSettings();496    TestPlanLabType exeLabType = this.getTestPlan().getTestPlanLabType();497    if (testDevice.getPlatformDeviceId() != null) {498      settings.setDeviceName(platformsService.getPlatformDevice(testDevice.getPlatformDeviceId(), exeLabType).getName());499    }500    if (testDevice.getPlatformBrowserVersionId() != null) {501      PlatformBrowserVersion platformBrowserVersion = platformsService.getPlatformBrowserVersion(testDevice.getPlatformBrowserVersionId(), exeLabType);502      settings.setBrowserVersion(platformBrowserVersion.getVersion());503      settings.setBrowser(platformBrowserVersion.getName().name());504    }505    if (testDevice.getPlatformScreenResolutionId() != null) {506      settings.setResolution(platformsService.getPlatformScreenResolution(testDevice.getPlatformScreenResolutionId(), exeLabType).getResolution());507    }508    if (testDevice.getPlatformOsVersionId() != null) {509      PlatformOsVersion platformOsVersion = platformsService.getPlatformOsVersion(testDevice.getPlatformOsVersionId(), exeLabType);510      settings.setPlatform(platformOsVersion.getPlatform());511      settings.setOsVersion(platformOsVersion.getPlatformVersion());512    }513    if (exeLabType == TestPlanLabType.Hybrid) {514      settings.setBrowser(testDevice.getBrowser());515    }516    settings.setAppActivity(testDevice.getAppActivity());517    settings.setAppPackage(testDevice.getAppPackage());518    settings.setAppPathType(testDevice.getAppPathType());519    settings.setAppUrl(testDevice.getAppUrl());520    settings.setAppUploadId(testDevice.getAppUploadId());521    settings.setTitle(testDevice.getTitle());522    settings.setCreateSessionAtCaseLevel(testDevice.getCreateSessionAtCaseLevel());523    return settings;524  }525  private Boolean isScheduledExecution() {526    return this.triggeredType.equals(ExecutionTriggeredType.SCHEDULED);527  }528  // ############################################ RESULT ENTRIES PROCESSING ###########################################529  private void processResultEntries() throws Exception {530    if (canPushToLabAgent()) {531      processResultEntriesForLabAgent();532    } else if (canPushToHybridAgent()) {533      processResultEntriesForHybridAgent();534    }535  }536  private Boolean canPushToLabAgent() throws IntegrationNotFoundException {537    return !this.testPlan.getTestPlanLabType().equals(TestPlanLabType.Hybrid) && this.integrationsService.findByApplication(Integration.TestsigmaLab) != null;538  }539  private Boolean canPushToHybridAgent() {540    return this.testPlan.getTestPlanLabType().equals(TestPlanLabType.Hybrid);541  }542  private void processResultEntriesForLabAgent() throws Exception {543    List<TestDeviceResult> testDeviceResults = testDeviceResultService.findAllByTestPlanResultId(544      this.testPlanResult.getId());545    processResultEntries(testDeviceResults, StatusConstant.STATUS_CREATED);546  }547  private void processResultEntriesForHybridAgent() throws Exception {548    List<TestDeviceResult> testDeviceResults = testDeviceResultService.findAllByTestPlanResultId(549      this.testPlanResult.getId());550    processResultEntries(testDeviceResults, StatusConstant.STATUS_CREATED);551  }552  public void processResultEntries(List<TestDeviceResult> testDeviceResults, StatusConstant inStatus)553    throws Exception {554    for (TestDeviceResult testDeviceResult : testDeviceResults) {555      if (testDeviceResult.getTestDevice().getAgent() == null && this.getTestPlan().getTestPlanLabType().isHybrid()) {556        testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, AutomatorMessages.AGENT_HAS_BEEN_REMOVED, StatusConstant.STATUS_CREATED);557      } else if (this.getTestPlan().getTestPlanLabType().isHybrid() && !agentService.isAgentActive(testDeviceResult.getTestDevice().getAgentId())) {558          testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult,559            AutomatorMessages.AGENT_INACTIVE, StatusConstant.STATUS_CREATED);560      } else if(this.getTestPlan().getTestPlanLabType().isHybrid() && testDeviceResult.getTestDevice().getDeviceId()!=null &&561        agentService.isAgentActive(testDeviceResult.getTestDevice().getAgentId()) && !agentDeviceService.isDeviceOnline(testDeviceResult.getTestDevice().getDeviceId())){562        testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult,563          agentDeviceService.find(testDeviceResult.getTestDevice().getDeviceId()).getName()+ " "+AutomatorMessages.DEVICE_NOT_ONLINE, StatusConstant.STATUS_CREATED);564      }565      else {566          processEnvironmentResult(testDeviceResult, inStatus);567      }568    }569    testDeviceResultService.updateExecutionConsolidatedResults(this.testPlanResult.getId(),570      Boolean.TRUE);571  }572  public void processEnvironmentResult(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {573    testDeviceResultService.markEnvironmentResultAsInPreFlight(testDeviceResult, inStatus);574    if (!this.getTestPlan().getTestPlanLabType().isHybrid()) {575      EnvironmentEntityDTO environmentEntityDTO = loadEnvironment(testDeviceResult,576        StatusConstant.STATUS_PRE_FLIGHT);577      try {578        pushEnvironmentToLab(testDeviceResult, environmentEntityDTO);579      } catch (Exception e) {580        log.error(e.getMessage(), e);581        testDeviceResultService.markEnvironmentResultAsFailed(testDeviceResult, e.getMessage(),582          StatusConstant.STATUS_PRE_FLIGHT);583      }584    }585  }586  public void processEnvironmentResultInParallel(TestDeviceResult testDeviceResult, StatusConstant inStatus) throws Exception {587    List<TestSuiteResult> testSuiteResults = this.testSuiteResultService.findPendingTestSuiteResults(588      testDeviceResult, inStatus);589    testDeviceResult.setSuiteResults(testSuiteResults);590    for (TestSuiteResult testSuiteResult : testSuiteResults) {591      testSuiteResultService.markTestSuiteResultAsInFlight(testSuiteResult, inStatus);592      if (!this.getTestPlan().getTestPlanLabType().isHybrid()) {593        TestSuiteEntityDTO testSuiteEntity = this.testSuiteResultMapper.map(testSuiteResult);594        testSuiteEntity.setTestCases(loadTestCases(testSuiteResult, StatusConstant.STATUS_PRE_FLIGHT));595        List<TestSuiteEntityDTO> testSuiteEntityDTOS = new ArrayList<>();596        testSuiteEntityDTOS.add(testSuiteEntity);597        EnvironmentEntityDTO environmentEntityDTO = loadEnvironmentDetails(testDeviceResult);598        environmentEntityDTO.setTestSuites(testSuiteEntityDTOS);599        try {600          pushEnvironmentToLab(testDeviceResult, environmentEntityDTO);601        } catch (Exception e) {602          log.error(e.getMessage(), e);603          testSuiteResultService.markTestSuiteResultAsFailed(testSuiteResult, e.getMessage(),604            StatusConstant.STATUS_PRE_FLIGHT);605        }606      }607    }608    testDeviceResultService.updateEnvironmentConsolidatedResults(testDeviceResult);609  }610  public EnvironmentEntityDTO loadEnvironment(TestDeviceResult testDeviceResult, StatusConstant inStatus)611    throws Exception {612    List<TestSuiteEntityDTO> testSuiteEntityDTOS = loadTestSuites(testDeviceResult, inStatus);613    EnvironmentEntityDTO environmentEntityDTO = loadEnvironmentDetails(testDeviceResult);614    environmentEntityDTO.setTestSuites(testSuiteEntityDTOS);615    return environmentEntityDTO;616  }617  public EnvironmentEntityDTO loadEnvironmentDetails(TestDeviceResult testDeviceResult) throws Exception {618    TestPlanSettingEntityDTO testPlanSettingEntityDTO = this.testPlanMapper.mapSettings(this.testPlan);619    EnvironmentEntityDTO environmentEntityDTO = this.testDeviceResultMapper.map(testDeviceResult);620    TestDevice testDevice = testDeviceResult.getTestDevice();621    if (testDevice.getDeviceId() != null) {622      AgentDevice agentDevice = agentDeviceService.find(testDevice.getDeviceId());623      environmentEntityDTO.setAgentDeviceUuid(agentDevice.getUniqueId());624    }625    environmentEntityDTO.setStorageType(storageServiceFactory.getStorageService().getStorageType());626    environmentEntityDTO.setWorkspaceType(this.getAppType());627    environmentEntityDTO.setTestPlanSettings(testPlanSettingEntityDTO);628    environmentEntityDTO.setMatchBrowserVersion(testDevice.getMatchBrowserVersion());629    environmentEntityDTO.setCreateSessionAtCaseLevel(testDevice.getCreateSessionAtCaseLevel());630    TestDeviceSettings settings = getExecutionTestDeviceSettings(testDevice);631    settings.setExecutionName(testPlan.getName());632    settings.setEnvironmentParamId(this.testPlan.getEnvironmentId());633    settings.setEnvRunId(testDeviceResult.getId());634    setTestLabDetails(testDevice, settings,environmentEntityDTO);635    environmentEntityDTO.setEnvSettings(this.testPlanMapper.mapToDTO(settings));636    Agent agent = null;637    if (testDevice.getAgentId() != null)638      agent = this.agentService.find(testDevice.getAgentId());639    setAgentJWTApiKey(environmentEntityDTO, agent);640    setAvailableFeatures(environmentEntityDTO);641    return environmentEntityDTO;642  }643  private List<TestSuiteEntityDTO> loadTestSuites(TestDeviceResult testDeviceResult, StatusConstant inStatus) {644    List<TestSuiteEntityDTO> testSuiteEntityDTOS = new ArrayList<>();645    List<TestSuiteResult> testSuiteResults = this.testSuiteResultService.findPendingTestSuiteResults(testDeviceResult,646      inStatus);647    for (TestSuiteResult testSuiteResult : testSuiteResults) {648      TestSuiteEntityDTO testSuiteEntity = this.testSuiteResultMapper.map(testSuiteResult);649      testSuiteEntity.setTestCases(loadTestCases(testSuiteResult, inStatus));650      testSuiteEntityDTOS.add(testSuiteEntity);651    }652    return testSuiteEntityDTOS;653  }654  private List<TestCaseEntityDTO> loadTestCases(TestSuiteResult testSuiteResult, StatusConstant inStatus) {655    List<TestCaseResult> testCaseResults = this.testCaseResultService.findActiveSuiteTestCaseResults(656      testSuiteResult.getId(), inStatus);657    List<TestCaseEntityDTO> testCases = new ArrayList<>();658    for (TestCaseResult testCaseResult : testCaseResults) {659      TestCaseEntityDTO testCaseEntity = this.testCaseResultMapper.map(testCaseResult);660      testCaseEntity.setDataDrivenTestCases(loadDataDrivenTestCases(testCaseResult, inStatus));661      testCases.add(testCaseEntity);662    }663    return testCases;664  }665  private List<TestCaseEntityDTO> loadDataDrivenTestCases(TestCaseResult testCaseResult, StatusConstant inStatus) {666    List<TestCaseResult> dataDrivenTestCaseResults =667      this.testCaseResultService.findAllByParentIdAndStatus(testCaseResult.getId(), inStatus);668    return this.testCaseResultMapper.map(dataDrivenTestCaseResults);669  }670  private void setAgentJWTApiKey(EnvironmentEntityDTO environmentEntityDTO, com.testsigma.model.Agent id) throws ResourceNotFoundException {671    TestDeviceSettingsDTO envSettings = environmentEntityDTO.getEnvSettings();672    if (id != null) {673      Agent agent = this.agentService.find(id.getId());674      envSettings.setJwtApiKey(agent.generateJwtApiKey(jwtTokenService.getServerUuid()));675    }676    environmentEntityDTO.setEnvSettings(envSettings);677  }678  private void setAvailableFeatures(EnvironmentEntityDTO dto) throws ResourceNotFoundException, SQLException {679    dto.getTestPlanSettings().setHasSuggestionFeature(true);680  }681  private void pushEnvironmentToLab(TestDeviceResult testDeviceResult, EnvironmentEntityDTO environmentEntityDTO) throws Exception {682    ObjectMapper objectMapper = new ObjectMapper();683    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);684    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);685    TestDeviceEntity testDeviceEntity = objectMapper.readValue(objectMapper.writeValueAsString(environmentEntityDTO),686      TestDeviceEntity.class);687    try {688      testDeviceResultService.markEnvironmentResultAsInProgress(testDeviceResult, StatusConstant.STATUS_PRE_FLIGHT,689        Boolean.TRUE);690      new TestPlanRunTask(testDeviceEntity).start();691      log.info("Successfully pushed Execution Environment[" + testDeviceEntity.getEnvironmentResultId()692        + "] to Testsigma Lab");693    } catch (Exception e) {694      log.error(e.getMessage(), e);695      String message = "Error while pushing environment to agent - " + e.getMessage();696      throw new TestsigmaException(message, message);697    }698  }699  private void saveRunTimeData() {700    JSONObject runtimeJSONObj = this.getRunTimeData();701    if (runtimeJSONObj != null && runtimeJSONObj.has("runtime_data")) {702      RunTimeData runTimeData = new RunTimeData();703      runTimeData.setTestPlanRunId(this.getTestPlanResult().getId());704      if (runtimeJSONObj.has("runtime_data")) {705        runTimeData.setData(runtimeJSONObj.getJSONObject("runtime_data"));706      }707      this.runTimeDataService.create(runTimeData);708    }709  }710  public void checkTestCaseIsInReadyState(TestCase testCase) throws TestsigmaException {711    if (!testCase.getStatus().equals(TestCaseStatus.READY) && testPlan.getEntityType()=="TEST_PLAN") {712      String message = testCase.getIsStepGroup() ? com.testsigma.constants.MessageConstants.getMessage(MessageConstants.STEP_GROUP_NOT_READY, testCase.getName()) :713        MessageConstants.TESTCASE_NOT_READY;714      throw new TestsigmaException(message, message);715    }716  }717  private void fetchEnvironmentResultsReRunList() {718    testDeviceResultsReRunList = new ArrayList<>();719    if (getReRunType() == ReRunType.ALL_TESTS) {720      testDeviceResultsReRunList = testDeviceResultService.findAllByTestPlanResultId(this.getParentTestPlanResultId());721    } else if (getReRunType() == ReRunType.ONLY_FAILED_TESTS) {722      testDeviceResultsReRunList = testDeviceResultService.findAllByTestPlanResultIdAndResultIsNot723        (this.getParentTestPlanResultId(), ResultConstant.SUCCESS);724    }725  }726  private void fetchTestSuitesResultsReRunList(Long parentEnvironmentResultId) {727    testSuiteResultsReRunList = new ArrayList<>();728    try {729      TestDeviceResult parentTestDeviceResult = testDeviceResultService.find(parentEnvironmentResultId);730      List<TestSuiteResult> failedTestSuites;731      if (parentTestDeviceResult != null) {732        if (getReRunType() == ReRunType.ALL_TESTS) {733          testSuiteResultsReRunList = testSuiteResultService.findAllByEnvironmentResultId(parentTestDeviceResult.getId());734        } else if (getReRunType() == ReRunType.ONLY_FAILED_TESTS) {735          failedTestSuites = testSuiteResultService.findAllByEnvironmentResultIdAndResultIsNot736            (parentTestDeviceResult.getId(), ResultConstant.SUCCESS);737          if (failedTestSuites.size() > 0) {738            for (TestSuiteResult testSuiteResult : failedTestSuites) {739              List<Long> testSuitePreRequisiteIds = findTestSuitePreRequisiteIds(testSuiteResult, new ArrayList<>(), 0);740              if (testSuitePreRequisiteIds.size() > 0) {741                List<TestSuiteResult> preRequisiteResults = testSuiteResultService.findBySuiteResultIds(testSuitePreRequisiteIds);742                testSuiteResultsReRunList.addAll(preRequisiteResults);743              }744              testSuiteResultsReRunList.add(testSuiteResult);745            }746          }747        }748      }749    } catch (Exception e) {750      log.error(e.getMessage(), e);751    }752  }753  private List<Long> findTestSuitePreRequisiteIds(TestSuiteResult testSuiteResult, List<Long> testSuitePreRequisiteIds,754                                                  int depth) {755    if (depth < PRE_REQUISITE_DEPTH) {756      TestSuiteResult preReqTestSuiteResult;757      try {758        TestSuite testSuite = testSuiteResult.getTestSuite();759        if (testSuite.getPreRequisite() != null) {760          preReqTestSuiteResult = testSuiteResultService.findByEnvironmentResultIdAndSuiteId(761            testSuiteResult.getEnvironmentResultId(), testSuite.getPreRequisite());762          if (preReqTestSuiteResult != null) {763            testSuitePreRequisiteIds = findTestSuitePreRequisiteIds(preReqTestSuiteResult, testSuitePreRequisiteIds,764              depth + 1);765            testSuitePreRequisiteIds.add(preReqTestSuiteResult.getId());766          }767        }768      } catch (Exception e) {769        log.error(e.getMessage(), e);770      }771    }772    return testSuitePreRequisiteIds;773  }774  private void fetchTestCaseResultsReRunList(Long parentTestSuiteResultId) {775    testCaseResultsReRunList = new ArrayList<>();776    try {777      TestSuiteResult parentTestSuiteResult = testSuiteResultService.find(parentTestSuiteResultId);778      List<TestCaseResult> failedTestCases;779      if (parentTestSuiteResult != null) {780        if (getReRunType() == ReRunType.ALL_TESTS || isTestSuiteAPrerequisite(parentTestSuiteResult)) {781          testCaseResultsReRunList = testCaseResultService.findAllBySuiteResultId(parentTestSuiteResult.getId());782        } else if (getReRunType() == ReRunType.ONLY_FAILED_TESTS) {783          failedTestCases = testCaseResultService.findAllBySuiteResultIdAndResultIsNot784            (parentTestSuiteResult.getId(), ResultConstant.SUCCESS);785          if (failedTestCases.size() > 0) {786            for (TestCaseResult testCaseResult : failedTestCases) {787              List<Long> testCasePreRequisiteIds = findTestCasePreRequisiteIds(testCaseResult, new ArrayList<>(), 0);788              //If a prerequisite is failed, it will be already available in failedTestCases. So we need to add only prerequisites with SUCCESS status.789              List<TestCaseResult> preRequisiteResults = fetchPreRequisiteTestCaseResultsWithSuccessStatus(testCasePreRequisiteIds);790              testCaseResultsReRunList.addAll(preRequisiteResults);791              testCaseResultsReRunList.add(testCaseResult);792            }793          }794        }795      }796    } catch (Exception e) {797      log.error(e.getMessage(), e);798    }799  }800  private List<TestCaseResult> fetchPreRequisiteTestCaseResultsWithSuccessStatus(List<Long> testCasePreRequisiteIds) {801    List<TestCaseResult> preRequisitesWithSuccessStatus = new ArrayList<>();802    List<TestCaseResult> preRequisiteResults = testCaseResultService.findByTestCaseResultIds(testCasePreRequisiteIds);803    for (TestCaseResult testCaseResult : preRequisiteResults) {804      if (testCaseResult.getResult() == ResultConstant.SUCCESS) {805        preRequisitesWithSuccessStatus.add(testCaseResult);806      }807    }808    return preRequisitesWithSuccessStatus;809  }810  private boolean isTestSuiteAPrerequisite(TestSuiteResult testSuiteResult) {811    List<TestSuite> testSuites = testSuiteService.findByPrerequisiteId(testSuiteResult.getSuiteId());812    for (TestSuite testSuite : testSuites) {813      TestSuiteResult baseTestSuiteResult = testSuiteResultService.findByEnvironmentResultIdAndSuiteId(testSuiteResult.getEnvironmentResultId(), testSuite.getId());814      if (baseTestSuiteResult != null) {815        return true;816      }817    }818    return false;819  }820  private List<Long> findTestCasePreRequisiteIds(TestCaseResult testCaseResult, List<Long> testCasePreRequisiteIds,821                                                 int depth) {822    if (depth < PRE_REQUISITE_DEPTH) {823      List<TestCaseResult> preReqTestCaseResults;824      try {825        TestCase testCase = testCaseResult.getTestCase();826        if (testCase.getPreRequisite() != null) {827          //In case of data-driven tests, we have multiple rows in TestCaseResult table for each dataset(each row in testdata profile)828          preReqTestCaseResults = testCaseResultService.findAllBySuiteResultIdAndTestCaseId(829            testCaseResult.getSuiteResultId(), testCase.getPreRequisite());830          if (preReqTestCaseResults != null) {831            for (TestCaseResult preReqTestCaseResult : preReqTestCaseResults) {832              testCasePreRequisiteIds = findTestCasePreRequisiteIds(preReqTestCaseResult, testCasePreRequisiteIds,833                depth + 1);834              testCasePreRequisiteIds.add(preReqTestCaseResult.getId());835            }836          }837        }838      } catch (Exception e) {839        log.error(e.getMessage(), e);840      }841    }842    return testCasePreRequisiteIds;843  }844  // ################################################ AFTER START  ###################################################845  private void afterStart() throws Exception {846    setInitialCounts();847  }848  private void setInitialCounts() {849    List<TestDeviceResult> executionEnvironmentsResults850      = testDeviceResultService.findAllByTestPlanResultId(this.getTestPlanResult().getId());851    for (TestDeviceResult executionTestDeviceResult : executionEnvironmentsResults) {852      List<TestCaseResult> testCaseResults = testCaseResultService.findAllByEnvironmentResultId(executionTestDeviceResult.getId());853      for (TestCaseResult testCaseResult : testCaseResults) {854        testCaseResultService.updateResultCounts(testCaseResult);855      }856      List<TestSuiteResult> testSuitesResults = testSuiteResultService.findAllByEnvironmentResultId(executionTestDeviceResult.getId());857      for (TestSuiteResult testSuiteResult : testSuitesResults) {858        testSuiteResultService.updateResultCounts(testSuiteResult.getId());859      }860      testDeviceResultService.updateResultCounts(executionTestDeviceResult.getId());861    }862  }863  // ################################################  STOP  ###################################################864  public void stop() throws Exception {865    beforeStop();866    stopQueuedEnvironments(AutomatorMessages.MSG_USER_ABORTED_EXECUTION, Boolean.TRUE);867    afterStop();868  }869  private void beforeStop() throws TestsigmaException {870    TestPlanResult testPlanResult = this.testPlanResultService.findByTestPlanIdAndStatusIsNot(this.testPlan.getId(),871      StatusConstant.STATUS_COMPLETED);872    if (testPlanResult == null) {873      throw new TestsigmaException("No Queued executions for test plan - " + this.getTestPlan().getName());874    }875    this.setTestPlanResult(testPlanResult);876  }877  private void stopQueuedEnvironments(String errorMessage, Boolean sendPendingExecutions) {878    List<TestDeviceResult> testDeviceResults = this.testDeviceResultService879      .findAllByTestPlanResultIdAndStatusIsNot(this.testPlanResult.getId(), StatusConstant.STATUS_COMPLETED);880    for (TestDeviceResult testDeviceResult : testDeviceResults) {881      testDeviceResultService.markEnvironmentResultAsStopped(testDeviceResult, errorMessage);882      testDeviceResultService.updateResultCounts(testDeviceResult.getId());883    }884    Timestamp currentTime = new Timestamp(java.lang.System.currentTimeMillis());...Source:TestPlanResultService.java  
...44  }45  public boolean findByReRunParentId(Long reRunParentId){46    return this.testPlanResultRepository.findByReRunParentId(reRunParentId) != null;47  }48  public TestPlanResult findByTestPlanIdAndStatusIsNot(Long testPlanId, StatusConstant status) {49    return this.testPlanResultRepository.findByTestPlanIdAndStatusIsNot(testPlanId, status);50  }51  public TestPlanResult create(TestPlanResult testPlanResult) {52    testPlanResult = this.testPlanResultRepository.save(testPlanResult);53    publishEvent(testPlanResult, EventType.CREATE);54    return testPlanResult;55  }56  public TestPlanResult update(TestPlanResult testPlanResult) {57    testPlanResult = this.testPlanResultRepository.save(testPlanResult);58    publishEvent(testPlanResult, EventType.UPDATE);59    return testPlanResult;60  }61  public TestPlanResult updateExecutionResult(ResultConstant maxResult, TestPlanResult testPlanResult) {62    String message = ResultConstant.SUCCESS.equals(maxResult) ? AutomatorMessages.MSG_EXECUTION_COMPLETED :63      (ResultConstant.STOPPED.equals(maxResult)) ? AutomatorMessages.MSG_TEST_PLAN_STOPPED :...findByTestPlanIdAndStatusIsNot
Using AI Code Generation
1public void testFindByTestPlanIdAndStatusIsNot() {2    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(1L, "Passed");3    assertEquals(1, testPlanResults.size());4}5public void testFindByTestPlanIdAndStatus() {6    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatus(1L, "Passed");7    assertEquals(1, testPlanResults.size());8}9public void testFindByTestPlanIdAndStatusIn() {10    List<String> statuses = new ArrayList<>();11    statuses.add("Passed");12    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIn(1L, statuses);13    assertEquals(1, testPlanResults.size());14}15public void testFindByTestPlanId() {16    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanId(1L);17    assertEquals(2, testPlanResults.size());18}19public void testFindByTestPlanIdAndTestSuiteIdAndStatus() {20    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndTestSuiteIdAndStatus(1L, 1L, "Passed");21    assertEquals(1, testPlanResults.size());22}23public void testFindByTestPlanIdAndTestSuiteIdAndStatusIn() {24    List<String> statuses = new ArrayList<>();25    statuses.add("Passed");26    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndTestSuiteIdAndStatusIn(1L, 1LfindByTestPlanIdAndStatusIsNot
Using AI Code Generation
1public void testFindByTestPlanIdAndStatusIsNot() {2    Long testPlanId = 1L;3    TestPlanResult.Status status = TestPlanResult.Status.PASSED;4    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(testPlanId, status);5    assertThat(testPlanResults.size()).isEqualTo(2);6}7public void testFindByTestPlanIdAndStatus() {8    Long testPlanId = 1L;9    TestPlanResult.Status status = TestPlanResult.Status.PASSED;10    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatus(testPlanId, status);11    assertThat(testPlanResults.size()).isEqualTo(2);12}13public void testFindByTestPlanIdAndStatus() {14    Long testPlanId = 1L;15    TestPlanResult.Status status = TestPlanResult.Status.PASSED;16    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatus(testPlanId, status);17    assertThat(testPlanResults.size()).isEqualTo(2);18}19public void testFindByTestPlanIdAndStatus() {20    Long testPlanId = 1L;21    TestPlanResult.Status status = TestPlanResult.Status.PASSED;22    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatus(testPlanId, status);23    assertThat(testPlanResults.size()).isEqualTo(2);24}25public void testFindByTestPlanIdAndStatus() {findByTestPlanIdAndStatusIsNot
Using AI Code Generation
1public void findByTestPlanIdAndStatusIsNotTest() {2	TestPlanResult testPlanResult = new TestPlanResult();3	testPlanResult.setId(1L);4	testPlanResult.setTestPlanId(1L);5	testPlanResult.setStatus("passed");6	testPlanResult.setTestPlanName("test plan name");7	testPlanResult.setTestPlanResultId(1L);8	testPlanResult.setTestPlanStartTime(new Date());9	testPlanResult.setTestPlanEndTime(new Date());10	testPlanResult.setTestPlanStatus("passed");11	testPlanResult.setTotalTestCases(1);12	testPlanResult.setTotalTestCasesPassed(1);13	testPlanResult.setTotalTestCasesFailed(0);14	testPlanResult.setTotalTestCasesSkipped(0);15	testPlanResult.setTotalTestCasesBlocked(0);16	testPlanResult.setTotalTestCasesNotExecuted(0);17	testPlanResult.setTotalTestCasesPassedPercentage(100);18	testPlanResult.setTotalTestCasesFailedPercentage(0);19	testPlanResult.setTotalTestCasesSkippedPercentage(0);20	testPlanResult.setTotalTestCasesBlockedPercentage(0);21	testPlanResult.setTotalTestCasesNotExecutedPercentage(0);22	testPlanResult.setTotalTestCasesPassedDuration(1L);23	testPlanResult.setTotalTestCasesFailedDuration(0L);24	testPlanResult.setTotalTestCasesSkippedDuration(0L);25	testPlanResult.setTotalTestCasesBlockedDuration(0L);26	testPlanResult.setTotalTestCasesNotExecutedDuration(0L);27	testPlanResult.setTotalTestCasesPassedDurationPercentage(100);28	testPlanResult.setTotalTestCasesFailedDurationPercentage(0);29	testPlanResult.setTotalTestCasesSkippedDurationPercentage(0);30	testPlanResult.setTotalTestCasesBlockedDurationPercentage(0);31	testPlanResult.setTotalTestCasesNotExecutedDurationPercentage(0);32	testPlanResult.setTotalTestCasesPassedDurationInHHMMSS("00:00:01");33	testPlanResult.setTotalTestCasesFailedDurationInHHMMSS("00:00:00");34	testPlanResult.setTotalTestCasesSkippedDurationInHHMMSS("00:00:00");35	testPlanResult.setTotalTestCasesBlockedDurationInHHMMSS("00:00:00");36	testPlanResult.setTotalTestCasesNotExecutedDurationInHHMMSS("00:00:00");findByTestPlanIdAndStatusIsNot
Using AI Code Generation
1package com.testsigma;2import java.util.List;3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.stereotype.Service;5import com.testsigma.model.TestPlanResult;6import com.testsigma.repository.TestPlanResultRepository;7public class TestPlanResultService {8	private TestPlanResultRepository testPlanResultRepository;9	public List<TestPlanResult> findByTestPlanIdAndStatusIsNot(Long testPlanId, String status) {10		return testPlanResultRepository.findByTestPlanIdAndStatusIsNot(testPlanId, status);11	}12}13package com.testsigma;14import java.util.List;15import org.springframework.beans.factory.annotation.Autowired;16import org.springframework.stereotype.Service;17import com.testsigma.model.TestPlanResult;18import com.testsigma.repository.TestPlanResultRepository;19public class TestPlanResultService {20	private TestPlanResultRepository testPlanResultRepository;21	public List<TestPlanResult> findByTestPlanId(Long testPlanId) {22		return testPlanResultRepository.findByTestPlanId(testPlanId);23	}24}25package com.testsigma;26import java.util.List;27import org.springframework.beans.factory.annotation.Autowired;28import org.springframework.stereotype.Service;29import com.testsigma.model.TestPlanResult;30import com.testsigma.repository.TestPlanResultRepository;31public class TestPlanResultService {32	private TestPlanResultRepository testPlanResultRepository;33	public List<TestPlanResult> findByTestPlanIdAndStatus(Long testPlanId, String status) {34		return testPlanResultRepository.findByTestPlanIdAndStatus(testPlanId, status);35	}36}37package com.testsigma;38import java.util.List;39import org.springframework.beans.factory.annotation.Autowired;40import org.springframework.stereotype.Service;41import com.testsigma.model.TestPlanResult;42importfindByTestPlanIdAndStatusIsNot
Using AI Code Generation
1public void testFindByTestPlanIdAndStatusIsNot() {2  List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(testPlanId, status);3  assertNotNull(testPlanResults);4  assertFalse(testPlanResults.isEmpty());5  assertEquals(1, testPlanResults.size());6  assertEquals(testPlanResult, testPlanResults.get(0));7}8public void testFindByTestPlanIdAndStatus() {9  List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatus(testPlanId, status);10  assertNotNull(testPlanResults);11  assertFalse(testPlanResults.isEmpty());12  assertEquals(1, testPlanResults.size());13  assertEquals(testPlanResult, testPlanResults.get(0));14}15public void testFindByTestPlanIdAndStatus() {16  List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatus(testPlanId, status);17  assertNotNull(testPlanResults);findByTestPlanIdAndStatusIsNot
Using AI Code Generation
1public void testFindByTestPlanIdAndStatusIsNot() {2    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(1, "Passed");3    assertEquals(1, testPlanResults.size());4}5public void testFindByTestPlanIdAndStatusIsNot() {6    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(1, "Failed");7    assertEquals(1, testPlanResults.size());8}9public void testFindByTestPlanIdAndStatusIsNot() {10    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(1, "Skipped");11    assertEquals(1, testPlanResults.size());12}13public void testFindByTestPlanIdAndStatusIsNot() {14    List<TestPlanResult> testPlanResults = testPlanResultService.findByTestPlanIdAndStatusIsNot(1, "Blocked");15    assertEquals(1, testPlanResults.size());16}17public void testFindByTestPlanIdAndStatusIsNot() {Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
