How to use externallyUsedTestCaseSteps method of org.cerberus.crud.service.impl.TestService class

Best Cerberus-source code snippet using org.cerberus.crud.service.impl.TestService.externallyUsedTestCaseSteps

Source:DeleteTest.java Github

copy

Full Screen

...103 // The service was able to perform the query and confirm the object exist104 Test testData = (Test) resp.getItem();105 // Check if there is no associated Test Cases defining Step which is used OUTSIDE of the deleting Test106 try {107 final Collection<TestCaseStep> externallyUsedTestCaseSteps = externallyUsedTestCaseSteps(testData);108 if (!externallyUsedTestCaseSteps.isEmpty()) {109 String cerberusUrlTemp = parameterService.getParameterStringByKey("cerberus_gui_url", "", "");110 if (StringUtil.isNullOrEmpty(cerberusUrlTemp)) {111 cerberusUrlTemp = parameterService.getParameterStringByKey("cerberus_url", "", "");112 }113 final String cerberusUrl = cerberusUrlTemp;114// final String cerberusUrl = appContext.getBean(IParameterService.class).findParameterByKey("cerberus_url", "").getValue();115 ans.setResultMessage(116 new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED)117 .resolveDescription("ITEM", "Test")118 .resolveDescription("OPERATION", "Delete")119 .resolveDescription(120 "REASON", "You are trying to remove a Test which contains Test Case Steps which are currently used by other Test Case Steps outside of the removing Test. Please remove this link before to proceed: "121 + Collections2.transform(externallyUsedTestCaseSteps, new Function<TestCaseStep, String>() {122 @Override123 @Nullable124 public String apply(@Nullable final TestCaseStep input) {125 return String.format(126 "<a href='%s/TestCaseScript.jsp?test=%s&testcase=%s&step=%s'>%s/%s#%s</a>",127 cerberusUrl,128 input.getTest(),129 input.getTestCase(),130 input.getStep(),131 input.getTest(),132 input.getTestCase(),133 input.getStep()134 );135 }136 }137 )138 )139 );140 } else {141 // Test seems clean, process to delete142 ans = testService.delete(testData);143 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {144 // Delete was successful. Adding Log entry.145 ILogEventService logEventService = appContext.getBean(LogEventService.class);146 logEventService.createForPrivateCalls("/DeleteTest", "DELETE", "Delete Test : ['" + key + "']", request);147 }148 }149 } catch (final CerberusException e) {150 LOGGER.error(e.getMessage(), e);151 ans.setResultMessage(new MessageEvent(152 MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)153 .resolveDescription("DESCRIPTION", "Unexpected error: " + e.getMessage())154 );155 }156 }157 }158 // Formating and returning the json result.159 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());160 jsonResponse.put("message", ans.getResultMessage().getDescription());161 response.getWriter().print(jsonResponse.toString());162 response.getWriter().flush();163 }164 /**165 * Get {@link TestCaseStep} which are using an other {@link TestCaseStep}166 * from the given {@link Test} but which are NOT included into this167 * {@link Test}168 *169 * @param test the {@link Test} from which getting externally used170 * {@link TestCaseStep}s171 * @return a {@link Collection} of {@link TestCaseStep} which are using an172 * other {@link TestCaseStep} from the given {@link Test} but which are NOT173 * included into this {@link Test}174 * @throws CerberusException if an unexpected error occurred175 */176 private Collection<TestCaseStep> externallyUsedTestCaseSteps(final Test test) throws CerberusException {177 // Get the associated ApplicationContext to this servlet178 final ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());179 // Get all TestCaseSteps which are using an other TestCaseSteps from given Test180 final ITestCaseStepService testCaseStepService = applicationContext.getBean(ITestCaseStepService.class);181 final List<TestCaseStep> stepsInUse = testCaseStepService.getTestCaseStepsUsingTestInParameter(test.getTest());182 // Filter the retrieved list to only retain those which are not included from the given Test183 return Collections2.filter(stepsInUse, new Predicate<TestCaseStep>() {184 @Override185 public boolean apply(@Nullable final TestCaseStep input) {186 return !input.getTest().equals(test.getTest());187 }188 @Override189 public boolean test(TestCaseStep t) {190 return Predicate.super.test(t); //To change body of generated methods, choose Tools | Templates....

Full Screen

Full Screen

externallyUsedTestCaseSteps

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseStep;2import org.cerberus.crud.service.impl.TestService;3List<TestCaseStep> testCaseSteps = new TestService().externallyUsedTestCaseSteps("TEST", "TESTCASE");4testCaseSteps.forEach(step -> {5 System.out.println(step.getStep());6});

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful