I have been working on a new type of test step - RestTestRequestWithRetryStep, which extends RestTestRequestStep with some basic retry functionality. Everything works well in the client, I can add a new RestTestRequestWithRetryStep and also "add retries" to an existing RestTestRequestStep.
But when I try to save the test, or the entire project, ReadyAPI doesn't save the new steps correctly. Needless to say, when I load the saved project, the new steps are essentially gone. This is what's actually being saved - the new test step doesn't have an ID, nor does it have a config:
...</con:testStep>
<con:testStep type="RestTestRequestWithRetryStep" name="REST Request with Retry"/>
<con:testStep type="restrequest" name="Verify Group with Feature" id="4ac98a7d-b290-4aca-948f-06be471dc4f2"> ...
I hope that I'm missing something simple, can someone please help me? Here's some of my code:
@PluginTestStep(typeName = RestTestRequestWithRetryStep.REST_TEST_REQUEST_WITH_RETRY_STEP, name = "REST Request with Retry", description = "REST Test Request with Retry Step") public class RestTestRequestWithRetryStep extends RestTestRequestStep { public static final String REST_TEST_REQUEST_WITH_RETRY_STEP = "RestTestRequestWithRetryStep"; private int maxRetries; private int retryInterval; private final int DEFAULT_MAX_RETRIES = 3; private final int DEFAULT_RETRY_INTERVAL = 5; public RestTestRequestWithRetryStep(WsdlTestCase testCase, TestStepConfig config, boolean forLoadTest) throws ItemDeletedException { super(testCase, new RestRequestWithRetryStepFactory().createNewTestStep(testCase, config.getName()), forLoadTest); try { setMaxRetries(DEFAULT_MAX_RETRIES); setRetryInterval(DEFAULT_RETRY_INTERVAL); } catch (InvalidSettingException e) { e.printStackTrace(); throw new RuntimeException(e); } } @Override public TestStepResult run(TestCaseRunner testRunner, TestCaseRunContext testRunContext) { int retryCount = 0; TestStepResult stepResult = null; boolean tryAgain; do { stepResult = super.run(testRunner, testRunContext); tryAgain = false; retryCount++; if (retryCount <= getMaxRetries() && stepResult.getStatus().equals(TestStepStatus.FAILED)) { tryAgain = true; try { Thread.sleep(getRetryInterval() * 1000); } catch (InterruptedException e) { e.printStackTrace(); } } } while (tryAgain); return stepResult; } @Override public void resetConfigOnMove(TestStepConfig config) { super.resetConfigOnMove(this.getConfig()); }
public class RestRequestWithRetryStepFactory extends RestRequestStepFactory { @Override public WsdlTestStep buildTestStep(WsdlTestCase testCase, TestStepConfig config, boolean forLoadTest) { try { return new RestTestRequestWithRetryStep(testCase, config, forLoadTest); } catch (ItemDeletedException e) { e.printStackTrace(); throw new RuntimeException(e); } } @Override public boolean canCreate() { return true; } @Override public TestStepConfig createNewTestStep(WsdlTestCase testCase, String name) { WsdlTestStep step = testCase.getTestStepByName(name); if (step == null) { return super.createNewTestStep(testCase, name); } else { TestStepConfig origConfig = step.getConfig(); RestRequestStepConfig origRestRequestStepConfig = (RestRequestStepConfig) origConfig.getConfig(); RestRequestStepConfig newRestRequestStepConfig = RestRequestStepConfig.Factory.newInstance(); newRestRequestStepConfig.setService(origRestRequestStepConfig.getService()); newRestRequestStepConfig.setResourcePath(origRestRequestStepConfig.getResourcePath()); newRestRequestStepConfig.setMethodName(origRestRequestStepConfig.getMethodName()); newRestRequestStepConfig.addNewRestRequest().set(origRestRequestStepConfig.getRestRequest()); TestStepConfig newConfig = TestStepConfig.Factory.newInstance(); newConfig.setConfig(newRestRequestStepConfig); newConfig.setType(RestTestRequestWithRetryStep.REST_TEST_REQUEST_WITH_RETRY_STEP); testCase.removeTestStep(step); return newConfig; } } }
@ActionConfiguration(actionGroup = ActionGroups.REST_TEST_REQUEST_ACTIONS) public class RestTestRequestStepAddRetriesAction extends AbstractSoapUIAction<RestTestRequestStep> { public RestTestRequestStepAddRetriesAction() { super("Add Retries", "Action for adding retry functionality to a REST Request test step"); } @Override public void perform(RestTestRequestStep step, Object o) { TestStepConfig newConfig = TestStepConfig.Factory.newInstance(); newConfig.setType(RestTestRequestWithRetryStep.REST_TEST_REQUEST_WITH_RETRY_STEP); newConfig.setName(step.getName()); WsdlTestCase parentTest = step.getTestCase(); int stepIndex = parentTest.getIndexOfTestStep(step); parentTest.insertTestStep(newConfig, stepIndex); } }