@PUT @Path("/testcases") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateTestCase( com.photon.phresco.commons.model.TestCase testCase, @QueryParam("testSuiteName") String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo responseData = new ResponseInfo(); try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); frameworkUtil.readManualTestCaseFile(sb.toString(), testSuiteName, testCase); ResponseInfo finalOutput = responseDataEvaluation(responseData, null, testCase, RESPONSE_STATUS_SUCCESS, PHRQ400006); return Response.status(Status.OK).entity(finalOutput).build(); } catch (PhrescoException e) { ResponseInfo finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410008); return Response.status(Status.OK).entity(finalOutput).build(); } }
@POST @Path(REST_API_TESTSUITES) @Produces(MediaType.APPLICATION_JSON) public Response createTestSuite( @QueryParam(REST_API_TESTSUITE) String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo responseData = new ResponseInfo(); try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); String cellValue[] = {"", "", testSuiteName, "", "", "", "", "", "", "", "", "", ""}; frameworkUtil.addNew(sb.toString(), testSuiteName, cellValue); ResponseInfo finalOutput = responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_SUCCESS, PHRQ400004); return Response.status(Status.OK).entity(finalOutput).build(); } catch (PhrescoException e) { e.printStackTrace(); ResponseInfo finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410006); return Response.status(Status.OK).entity(finalOutput).build(); } }
@DELETE @Path(REST_API_TESTSUITES_DELETE) @Produces(MediaType.APPLICATION_JSON) public Response deleteTestSuites( @QueryParam(REST_API_TESTSUITE) String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo<String> responseData = new ResponseInfo<String>(); ManualTestResult createManualTestResult = null; ResponseInfo<Boolean> finalOutput = null; try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); File manualFilePath = new File(sb.toString()); if (!manualFilePath.exists()) { finalOutput = responseDataEvaluation( responseData, null, createManualTestResult, RESPONSE_STATUS_FAILURE, PHRQ000003); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } boolean deleteManualTestSuiteFile = frameworkUtil.deleteManualTestSuiteFile(sb.toString(), testSuiteName); finalOutput = responseDataEvaluation( responseData, null, deleteManualTestSuiteFile, RESPONSE_STATUS_SUCCESS, PHRQ400008); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } catch (Exception e) { finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410004); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } }
@POST @Path(REST_API_TESTCASES) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response createTestCase( com.photon.phresco.commons.model.TestCase testCase, @QueryParam("testSuiteName") String testSuiteName, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo responseData = new ResponseInfo(); try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); String cellValue[] = { "", testCase.getFeatureId(), "", testCase.getTestCaseId(), testCase.getDescription(), testCase.getPreconditions(), testCase.getSteps(), "", "", testCase.getExpectedResult(), testCase.getActualResult(), testCase.getStatus(), testCase.getBugComment() }; frameworkUtil.addNewTestCase(sb.toString(), testSuiteName, cellValue, testCase.getStatus()); ResponseInfo finalOutput = responseDataEvaluation(responseData, null, testCase, RESPONSE_STATUS_SUCCESS, PHRQ400005); return Response.status(Status.OK).entity(finalOutput).build(); } catch (PhrescoException e) { e.printStackTrace(); ResponseInfo finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410007); return Response.status(Status.OK).entity(finalOutput).build(); } }
@GET @Path(REST_API_TESTCASE_VALIDATION) @Produces(MediaType.APPLICATION_JSON) public Response testCaseValidation( @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_TESTCASE_NAME) String testCaseId, @QueryParam("testSuiteName") String testsuitename, @QueryParam(REST_QUERY_MODULE_NAME) String moduleName) throws PhrescoException { ResponseInfo<String> responseData = new ResponseInfo<String>(); List<com.photon.phresco.commons.model.TestCase> readTestCase = null; boolean hasError = true; try { String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } FrameworkUtil frameworkUtil = FrameworkUtil.getInstance(); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName); StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir); readTestCase = frameworkUtil.readManualTestCaseFile(sb.toString(), testsuitename, null); for (com.photon.phresco.commons.model.TestCase testCase : readTestCase) { if (testCase.getTestCaseId().equalsIgnoreCase(testCaseId)) { hasError = false; break; } } ResponseInfo<Boolean> finalOutput = responseDataEvaluation(responseData, null, hasError, RESPONSE_STATUS_SUCCESS, PHRQ400007); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } catch (Exception e) { ResponseInfo<Boolean> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410009); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } }
@POST @Path(REST_API_UPLOADTEMPLATE) @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response uploadManualTemplate( @Context HttpServletRequest request, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName) throws PhrescoException { ResponseInfo response = new ResponseInfo(); try { String uploadedFileName = request.getHeader(FrameworkConstants.X_FILE_NAME); String fileName = URLDecoder.decode(uploadedFileName, "UTF-8"); InputStream inputStream = request.getInputStream(); String moduleName = request.getHeader("moduleName"); String rootModulePath = ""; String subModuleName = ""; if (StringUtils.isNotEmpty(moduleName)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = moduleName; } else { rootModulePath = Utility.getProjectHome() + appDirName; } String manualTestPath = getManualTestReportDir(rootModulePath, subModuleName); ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName); File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName); StringBuilder builder = new StringBuilder(manualDir.toString()); builder.append(manualTestPath); File existingFile = new File(builder.toString()); FileUtils.cleanDirectory(existingFile); File file = new File(builder.toString() + File.separator + fileName); FileUtils.copyInputStreamToFile(inputStream, file); } catch (Exception e) { ResponseInfo finalOutput = responseDataEvaluation(response, e, null, RESPONSE_STATUS_ERROR, PHRQ410002); return Response.status(Status.OK) .entity(finalOutput) .header("Access-Control-Allow-Origin", "*") .build(); } ResponseInfo responseData = responseDataEvaluation(response, null, null, RESPONSE_STATUS_SUCCESS, PHRQ400001); return Response.status(Status.OK) .header("Access-Control-Allow-Origin", "*") .entity(responseData) .build(); }