GenerateRestMockServiceAction extends AbstractSoapUIAction<RestService> { @Override public void perform(RestService restService, Object param) { createDialog(restService); if (dialog.show()) { String mockServiceName = dialog.getValue(Form.MOCKSERVICE_NAME); RestMockService mockService = getMockService(mockServiceName, restService.getProject()); if (mockService != null) { populateMockService(restService, mockService); restService.addEndpoint(mockService.getLocalEndpoint()); UISupport.showDesktopPanel(mockService); Analytics.trackAction(GENERATE_REST_MOCK_FROM_NAVIGATOR); maybeStart(mockService); } } } GenerateRestMockServiceAction(); @Override void perform(RestService restService, Object param);  }
@Test public void shouldGenerateRestMockService() throws SoapUIException { action.perform(restService, null); RestMockService restMockService = getResultingRestMockService(); assertThat(restMockService, is(NotNull.NOT_NULL)); assertThat(restMockService.getName(), is(restMockServiceName)); }
@Test public void shouldGenerateNonStartedRestMockServiceIfSettingIsOff() throws SoapUIException { SoapUI.getSettings().setBoolean(HttpSettings.START_MOCK_SERVICE, FALSE); action.perform(restService, null); RestMockService restMockService = getResultingRestMockService(); assertThat(restMockService.getMockRunner(), is(Null.NULL)); }
@Test public void shouldGenerateRestMockServiceWithResources() { restService.addNewResource("one", "/one"); restService.addNewResource("two", "/two"); action.perform(restService, null); RestMockService restMockService = getResultingRestMockService(); assertThat(restMockService.getMockOperationCount(), is(2)); assertThat(restMockService.getMockOperationAt(1).getName(), is("/two")); for (MockOperation mockAction : restMockService.getMockOperationList()) { assertThat(mockAction.getMockResponseCount(), is(1)); } }
@Test public void shouldGenerateRestMockServiceForNestedResources() { RestResource one = restService.addNewResource("one", "/one{version}"); RestParamProperty path = one.addProperty("version"); path.setValue("v1"); RestResourceConfig nestedResourceConfig = one.getConfig().addNewResource(); nestedResourceConfig.setPath("/path/again"); RestResource three = one.addNewChildResource("three", "/will/be/overwritten"); three.setConfig(nestedResourceConfig); restService.addNewResource("two", "/two"); action.perform(restService, null); RestMockService restMockService = getResultingRestMockService(); assertThat(restMockService.getMockOperationCount(), is(3)); assertMockActionWithPath(restMockService, "/onev1"); assertMockActionWithPath(restMockService, "/one/path/again"); assertMockActionWithPath(restMockService, "/two"); }
@Test public void shouldGenerateRestMockServiceForResourceWithSeveralMethods() { RestResource resource = restService.addNewResource("one", "/one"); addMethod(resource, HttpMethod.GET); addMethod(resource, HttpMethod.POST); action.perform(restService, null); RestMockService restMockService = getResultingRestMockService(); assertThat(restMockService.getMockOperationCount(), is(2)); assertMockAction(HttpMethod.GET, "/one", restMockService.getMockOperationAt(0)); assertMockAction(HttpMethod.POST, "/one", restMockService.getMockOperationAt(1)); }
@Test public void shouldExpandPathParamForEmptyRestMethod() { RestResource resource = restService.addNewResource("one", "/one{version}"); RestParamProperty path = resource.addProperty("version"); path.setValue("v1"); addMethod(resource, HttpMethod.GET); action.perform(restService, null); assertMockAction(HttpMethod.GET, "/onev1", getResultingRestMockService().getMockOperationAt(0)); }