From 28ad609e158204a4645092f3699fad9c1479e3d9 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 29 Apr 2014 11:39:55 +0200 Subject: [PATCH] Improve /api/sources/show --- .../server/platform/ServerComponents.java | 4 +- .../sonar/server/source/SourceService.java | 28 ++++--- ...rcesShowWsHandler.java => ShowAction.java} | 76 ++++++++++++++----- .../org/sonar/server/source/ws/SourcesWs.java | 15 +--- .../server/source/SourceServiceTest.java | 16 ++-- ...WsHandlerTest.java => ShowActionTest.java} | 76 +++++++++++-------- .../sonar/server/source/ws/SourcesWsTest.java | 8 +- .../show_source.json | 0 .../show_source_with_params_from_and_to.json | 0 .../show_source_with_scm.json | 0 ...urce_with_scm_with_from_and_to_params.json | 0 ...with_scm_without_repeating_same_lines.json | 0 ..._and_with_from_param_after_repetition.json | 0 13 files changed, 131 insertions(+), 92 deletions(-) rename sonar-server/src/main/java/org/sonar/server/source/ws/{SourcesShowWsHandler.java => ShowAction.java} (60%) rename sonar-server/src/test/java/org/sonar/server/source/ws/{SourcesShowWsHandlerTest.java => ShowActionTest.java} (65%) rename sonar-server/src/test/resources/org/sonar/server/source/ws/{SourcesShowWsHandlerTest => ShowActionTest}/show_source.json (100%) rename sonar-server/src/test/resources/org/sonar/server/source/ws/{SourcesShowWsHandlerTest => ShowActionTest}/show_source_with_params_from_and_to.json (100%) rename sonar-server/src/test/resources/org/sonar/server/source/ws/{SourcesShowWsHandlerTest => ShowActionTest}/show_source_with_scm.json (100%) rename sonar-server/src/test/resources/org/sonar/server/source/ws/{SourcesShowWsHandlerTest => ShowActionTest}/show_source_with_scm_with_from_and_to_params.json (100%) rename sonar-server/src/test/resources/org/sonar/server/source/ws/{SourcesShowWsHandlerTest => ShowActionTest}/show_source_with_scm_without_repeating_same_lines.json (100%) rename sonar-server/src/test/resources/org/sonar/server/source/ws/{SourcesShowWsHandlerTest => ShowActionTest}/show_source_with_scm_without_repeating_same_lines_and_with_from_param_after_repetition.json (100%) diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index 65c0a5c1aa5..472498ba7fb 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -116,7 +116,7 @@ import org.sonar.server.source.CodeColorizers; import org.sonar.server.source.DeprecatedSourceDecorator; import org.sonar.server.source.HtmlSourceDecorator; import org.sonar.server.source.SourceService; -import org.sonar.server.source.ws.SourcesShowWsHandler; +import org.sonar.server.source.ws.ShowAction; import org.sonar.server.source.ws.SourcesWs; import org.sonar.server.startup.*; import org.sonar.server.text.MacroInterpreter; @@ -382,7 +382,7 @@ class ServerComponents { pico.addSingleton(DeprecatedSourceDecorator.class); pico.addSingleton(SourceService.class); pico.addSingleton(SourcesWs.class); - pico.addSingleton(SourcesShowWsHandler.class); + pico.addSingleton(ShowAction.class); // text pico.addSingleton(MacroInterpreter.class); diff --git a/sonar-server/src/main/java/org/sonar/server/source/SourceService.java b/sonar-server/src/main/java/org/sonar/server/source/SourceService.java index 1db10c1b101..07ac61c839a 100644 --- a/sonar-server/src/main/java/org/sonar/server/source/SourceService.java +++ b/sonar-server/src/main/java/org/sonar/server/source/SourceService.java @@ -32,7 +32,6 @@ import org.sonar.server.user.UserSession; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.List; public class SourceService implements ServerComponent { @@ -54,38 +53,37 @@ public class SourceService implements ServerComponent { this.measureDataDao = measureDataDao; } - public List getSourcesForComponent(String componentKey) { - return getSourcesByComponent(componentKey, null, null); + public List getLinesAsHtml(String fileKey) { + return getLinesAsHtml(fileKey, null, null); } - public List getSourcesByComponent(String componentKey, @Nullable Integer from, @Nullable Integer to) { - ResourceDto project = resourceDao.getRootProjectByComponentKey(componentKey); + public List getLinesAsHtml(String fileKey, @Nullable Integer from, @Nullable Integer to) { + ResourceDto project = resourceDao.getRootProjectByComponentKey(fileKey); if (project == null) { - throw new NotFoundException("This component does not exists."); + throw new NotFoundException("File does not exist"); } UserSession.get().checkProjectPermission(UserRole.CODEVIEWER, project.getKey()); - List decoratedSource = sourceDecorator.getDecoratedSourceAsHtml(componentKey, from, to); + List decoratedSource = sourceDecorator.getDecoratedSourceAsHtml(fileKey, from, to); if (!decoratedSource.isEmpty()) { return decoratedSource; - } else { - return deprecatedSourceDecorator.getSourceAsHtml(componentKey, from, to); } + return deprecatedSourceDecorator.getSourceAsHtml(fileKey, from, to); } @CheckForNull - public String getScmAuthorData(String componentKey) { - return findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY); + public String getScmAuthorData(String fileKey) { + return findDataFromComponent(fileKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY); } @CheckForNull - public String getScmDateData(String componentKey) { - return findDataFromComponent(componentKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY); + public String getScmDateData(String fileKey) { + return findDataFromComponent(fileKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY); } @CheckForNull - private String findDataFromComponent(String componentKey, String metricKey) { - MeasureDataDto data = measureDataDao.findByComponentKeyAndMetricKey(componentKey, metricKey); + private String findDataFromComponent(String fileKey, String metricKey) { + MeasureDataDto data = measureDataDao.findByComponentKeyAndMetricKey(fileKey, metricKey); if (data != null) { return data.getText(); } diff --git a/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java b/sonar-server/src/main/java/org/sonar/server/source/ws/ShowAction.java similarity index 60% rename from sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java rename to sonar-server/src/main/java/org/sonar/server/source/ws/ShowAction.java index 27d13cc58bc..9c919ed5afa 100644 --- a/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesShowWsHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/source/ws/ShowAction.java @@ -24,55 +24,91 @@ import com.google.common.base.Splitter; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.RequestHandler; import org.sonar.api.server.ws.Response; +import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.text.JsonWriter; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.source.SourceService; +import javax.annotation.Nullable; +import java.util.Collections; import java.util.List; import static com.google.common.collect.Lists.newArrayList; -public class SourcesShowWsHandler implements RequestHandler { +public class ShowAction implements RequestHandler { private final SourceService sourceService; - public SourcesShowWsHandler(SourceService sourceService) { + public ShowAction(SourceService sourceService) { this.sourceService = sourceService; } + void define(WebService.NewController controller) { + WebService.NewAction action = controller.createAction("show") + .setDescription("Get source code. Parameter 'output' with value 'raw' is missing before being marked as a public WS.") + .setSince("4.2") + .setInternal(true) + .setHandler(this); + + action + .createParam("key") + .setRequired(true) + .setDescription("File key") + .setExampleValue("my_project:/src/foo/Bar.php"); + + action + .createParam("from") + .setDescription("First line to return. Starts at 1.") + .setExampleValue("10") + .setDefaultValue("1"); + + action + .createParam("to") + .setDescription("Last line to return (inclusive)") + .setExampleValue("20"); + + action + .createParam("scm") + .setDescription("Enable loading of SCM information per line") + .setPossibleValues("true", "false") + .setDefaultValue("false"); + } + @Override public void handle(Request request, Response response) { - String componentKey = request.mandatoryParam("key"); - Integer fromParam = request.paramAsInt("from"); + String fileKey = request.mandatoryParam("key"); + int from = Math.max(request.paramAsInt("from", 1), 1); + Integer toParam = request.paramAsInt("to"); - int from = (fromParam != null && fromParam > 0) ? fromParam : 1; - List sourceHtml = sourceService.getSourcesByComponent(componentKey, from, toParam); + + List sourceHtml = sourceService.getLinesAsHtml(fileKey, from, toParam); if (sourceHtml.isEmpty()) { - throw new NotFoundException("Component : " + componentKey + " has no source."); + throw new NotFoundException("File '" + fileKey + "' has no sources"); } - String scmAuthorData = sourceService.getScmAuthorData(componentKey); - String scmDataData = sourceService.getScmDateData(componentKey); - int to = toParam != null ? toParam : sourceHtml.size() + from; - JsonWriter json = response.newJsonWriter(); - json.beginObject(); + JsonWriter json = response.newJsonWriter().beginObject(); writeSource(sourceHtml, from, json); - writeScm(scmAuthorData, scmDataData, from, to, json); + + if (request.paramAsBoolean("scm", false)) { + String scmAuthorData = sourceService.getScmAuthorData(fileKey); + String scmDataData = sourceService.getScmDateData(fileKey); + writeScm(scmAuthorData, scmDataData, from, to, json); + } json.endObject().close(); } - private void writeSource(List source, int from, JsonWriter json) { + private void writeSource(List lines, int from, JsonWriter json) { json.name("source").beginObject(); - for (int i = 0; i < source.size(); i++) { - String line = source.get(i); + for (int i = 0; i < lines.size(); i++) { + String line = lines.get(i); json.prop(Integer.toString(i + from), line); } json.endObject(); } - private void writeScm(String authorData, String scmDateData, int from, int to, JsonWriter json) { + private void writeScm(@Nullable String authorData, @Nullable String scmDateData, int from, int to, JsonWriter json) { if (authorData != null) { json.name("scm").beginObject(); List authors = splitLine(authorData); @@ -107,12 +143,14 @@ public class SourcesShowWsHandler implements RequestHandler { return author.equals(previousAuthor) && date.equals(previousDate); } - private List splitLine(String line) { + private List splitLine(@Nullable String line) { + if (line == null) { + return Collections.emptyList(); + } return newArrayList(Splitter.on(";").omitEmptyStrings().split(line)); } private String[] splitColumn(String column) { return column.split("="); } - } diff --git a/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesWs.java b/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesWs.java index 0530f6f588c..c1bc2c2cea5 100644 --- a/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesWs.java +++ b/sonar-server/src/main/java/org/sonar/server/source/ws/SourcesWs.java @@ -24,23 +24,16 @@ import org.sonar.api.server.ws.WebService; public class SourcesWs implements WebService { - private final SourcesShowWsHandler showHandler; + private final ShowAction showAction; - public SourcesWs(SourcesShowWsHandler showHandler) { - this.showHandler = showHandler; + public SourcesWs(ShowAction showAction) { + this.showAction = showAction; } @Override public void define(Context context) { NewController controller = context.createController("api/sources"); - - controller.createAction("show") - .setDescription("Show source of a component") - .setSince("4.2") - .setInternal(true) - .setHandler(showHandler) - .createParam("key", "Component key"); - + showAction.define(controller); controller.done(); } } diff --git a/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java b/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java index 7dea0debe40..e21d3e43990 100644 --- a/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java @@ -62,26 +62,26 @@ public class SourceServiceTest { } @Test - public void get_sources_by_component() throws Exception { + public void get_lines() throws Exception { String projectKey = "org.sonar.sample"; String componentKey = "org.sonar.sample:Sample"; MockUserSession.set().addProjectPermissions(UserRole.CODEVIEWER, projectKey); when(resourceDao.getRootProjectByComponentKey(componentKey)).thenReturn(new ResourceDto().setKey(projectKey)); - service.getSourcesForComponent(componentKey); + service.getLinesAsHtml(componentKey); verify(sourceDecorator).getDecoratedSourceAsHtml(componentKey, null, null); } @Test - public void fail_to_get_sources_by_component_if_component_not_found() throws Exception { + public void fail_to_get_lines_if_file_not_found() throws Exception { String projectKey = "org.sonar.sample"; String componentKey = "org.sonar.sample:Sample"; MockUserSession.set().addProjectPermissions(UserRole.CODEVIEWER, projectKey); when(resourceDao.getRootProjectByComponentKey(componentKey)).thenReturn(null); try { - service.getSourcesForComponent(componentKey); + service.getLinesAsHtml(componentKey); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(NotFoundException.class); @@ -91,26 +91,26 @@ public class SourceServiceTest { } @Test - public void get_sources_by_component_with_only_given_lines() throws Exception { + public void get_block_of_lines() throws Exception { String projectKey = "org.sonar.sample"; String componentKey = "org.sonar.sample:Sample"; MockUserSession.set().addProjectPermissions(UserRole.CODEVIEWER, projectKey); when(resourceDao.getRootProjectByComponentKey(componentKey)).thenReturn(new ResourceDto().setKey(projectKey)); - service.getSourcesByComponent(componentKey, 1, 2); + service.getLinesAsHtml(componentKey, 1, 2); verify(sourceDecorator).getDecoratedSourceAsHtml(componentKey, 1, 2); } @Test - public void get_sources_by_component_from_deprecated_source_decorator_when_no_data_from_new_decorator() throws Exception { + public void get_lines_from_deprecated_source_decorator_when_no_data_from_new_decorator() throws Exception { String projectKey = "org.sonar.sample"; String componentKey = "org.sonar.sample:Sample"; MockUserSession.set().addProjectPermissions(UserRole.CODEVIEWER, projectKey); when(resourceDao.getRootProjectByComponentKey(componentKey)).thenReturn(new ResourceDto().setKey(projectKey)); when(sourceDecorator.getDecoratedSourceAsHtml(eq(componentKey), anyInt(), anyInt())).thenReturn(Collections.emptyList()); - service.getSourcesByComponent(componentKey, 1, 2); + service.getLinesAsHtml(componentKey, 1, 2); verify(deprecatedSourceDecorator).getSourceAsHtml(componentKey, 1, 2); } diff --git a/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java similarity index 65% rename from sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java rename to sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java index 537e1403974..d723c113d07 100644 --- a/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesShowWsHandlerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) -public class SourcesShowWsHandlerTest { +public class ShowActionTest { @Mock SourceService sourceService; @@ -48,13 +48,13 @@ public class SourcesShowWsHandlerTest { @Before public void setUp() throws Exception { - tester = new WsTester(new SourcesWs(new SourcesShowWsHandler(sourceService))); + tester = new WsTester(new SourcesWs(new ShowAction(sourceService))); } @Test public void show_source() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList( + String componentKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList( "/*", " * Header", " */", @@ -69,8 +69,8 @@ public class SourcesShowWsHandlerTest { @Test public void fail_to_show_source_if_no_source_found() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(anyString(), anyInt(), anyInt())).thenReturn(Collections.emptyList()); + String componentKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(anyString(), anyInt(), anyInt())).thenReturn(Collections.emptyList()); try { WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey); @@ -83,8 +83,8 @@ public class SourcesShowWsHandlerTest { @Test public void show_source_with_from_and_to_params() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(componentKey, 3, 5)).thenReturn(newArrayList( + String componentKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(componentKey, 3, 5)).thenReturn(newArrayList( " */", "", "public class HelloWorld {" @@ -94,80 +94,90 @@ public class SourcesShowWsHandlerTest { } @Test - public void show_source_always_should_not_begin_with_from_0() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(componentKey, 1, 5)).thenReturn(newArrayList( + public void show_source_accept_from_less_than_one() throws Exception { + String fileKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(fileKey, 1, 5)).thenReturn(newArrayList( " */", "", "public class HelloWorld {" )); - WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "0").setParam("to", "5"); + WsTester.TestRequest request = tester.newRequest("show").setParam("key", fileKey).setParam("from", "0").setParam("to", "5"); request.execute(); - verify(sourceService).getSourcesByComponent(componentKey, 1, 5); + verify(sourceService).getLinesAsHtml(fileKey, 1, 5); } @Test public void show_source_with_scm() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList( + String fileKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(eq(fileKey), anyInt(), anyInt())).thenReturn(newArrayList( "public class HelloWorld {}" )); - when(sourceService.getScmAuthorData(componentKey)).thenReturn("1=julien;"); - when(sourceService.getScmDateData(componentKey)).thenReturn("1=2013-03-13T16:22:31+0100;"); + when(sourceService.getScmAuthorData(fileKey)).thenReturn("1=julien;"); + when(sourceService.getScmDateData(fileKey)).thenReturn("1=2013-03-13T16:22:31+0100;"); - WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey); + WsTester.TestRequest request = tester.newRequest("show").setParam("key", fileKey).setParam("scm", "true"); request.execute().assertJson(getClass(), "show_source_with_scm.json"); } @Test public void show_source_with_scm_with_from_and_to_params() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(componentKey, 3, 5)).thenReturn(newArrayList( + String fileKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(fileKey, 3, 5)).thenReturn(newArrayList( " */", "", "public class HelloWorld {" )); - when(sourceService.getScmAuthorData(componentKey)) + when(sourceService.getScmAuthorData(fileKey)) .thenReturn("1=julien;2=simon;3=julien;4=simon;5=jean;6=julien"); - when(sourceService.getScmDateData(componentKey)) + when(sourceService.getScmDateData(fileKey)) .thenReturn("1=2013-03-13T16:22:31+0100;2=2013-03-14T16:22:31+0100;3=2013-03-13T16:22:31+0100;4=2013-03-14T16:22:31+0100;5=2013-03-15T16:22:31+0100;6=2013-03-13T16:22:31+0100;"); - WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5"); + WsTester.TestRequest request = tester.newRequest("show") + .setParam("key", fileKey) + .setParam("from", "3") + .setParam("to", "5") + .setParam("scm", "true"); request.execute().assertJson(getClass(), "show_source_with_scm_with_from_and_to_params.json"); } @Test public void show_source_with_scm_without_repeating_same_lines() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList( + String fileKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(eq(fileKey), anyInt(), anyInt())).thenReturn(newArrayList( " */", "", "public class HelloWorld {" )); - when(sourceService.getScmAuthorData(componentKey)) + when(sourceService.getScmAuthorData(fileKey)) .thenReturn("1=julien;2=julien;3=simon"); - when(sourceService.getScmDateData(componentKey)) + when(sourceService.getScmDateData(fileKey)) .thenReturn("1=2013-03-13T16:22:31+0100;2=2013-03-13T16:22:31+0100;3=2013-03-14T16:22:31+0100;"); - WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey); + WsTester.TestRequest request = tester.newRequest("show") + .setParam("key", fileKey) + .setParam("scm", "true"); request.execute().assertJson(getClass(), "show_source_with_scm_without_repeating_same_lines.json"); } @Test public void show_source_with_scm_when_from_is_after_same_commit() throws Exception { - String componentKey = "org.apache.struts:struts:Dispatcher"; - when(sourceService.getSourcesByComponent(componentKey, 3, 5)).thenReturn(newArrayList( + String fileKey = "src/Foo.java"; + when(sourceService.getLinesAsHtml(fileKey, 3, 5)).thenReturn(newArrayList( " */", "", "public class HelloWorld {" )); // Since line 2, it's the same commit - when(sourceService.getScmAuthorData(componentKey)) + when(sourceService.getScmAuthorData(fileKey)) .thenReturn("1=julien;2=simon;3=simon;4=simon;5=simon;6=simon"); - when(sourceService.getScmDateData(componentKey)) + when(sourceService.getScmDateData(fileKey)) .thenReturn("1=2013-03-13T16:22:31+0100;2=2013-03-14T16:22:31+0100;3=2013-03-14T16:22:31+0100;4=2013-03-14T16:22:31+0100;5=2013-03-14T16:22:31+0100;6=2013-03-14T16:22:31+0100;"); - WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5"); + WsTester.TestRequest request = tester.newRequest("show") + .setParam("key", fileKey) + .setParam("from", "3") + .setParam("to", "5") + .setParam("scm", "true"); request.execute().assertJson(getClass(), "show_source_with_scm_without_repeating_same_lines_and_with_from_param_after_repetition.json"); } } diff --git a/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesWsTest.java b/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesWsTest.java index b24da55479b..f7a37a78a46 100644 --- a/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesWsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/source/ws/SourcesWsTest.java @@ -22,6 +22,7 @@ package org.sonar.server.source.ws; import org.junit.Test; import org.sonar.api.server.ws.WebService; +import org.sonar.server.source.SourceService; import org.sonar.server.ws.WsTester; import static org.fest.assertions.Assertions.assertThat; @@ -29,8 +30,8 @@ import static org.mockito.Mockito.mock; public class SourcesWsTest { - SourcesShowWsHandler showHandler = mock(SourcesShowWsHandler.class); - WsTester tester = new WsTester(new SourcesWs(showHandler)); + ShowAction showAction = new ShowAction(mock(SourceService.class)); + WsTester tester = new WsTester(new SourcesWs(showAction)); @Test public void define_ws() throws Exception { @@ -43,7 +44,6 @@ public class SourcesWsTest { assertThat(show.handler()).isNotNull(); assertThat(show.since()).isEqualTo("4.2"); assertThat(show.isPost()).isFalse(); - assertThat(show.isInternal()).isTrue(); - assertThat(show.handler()).isSameAs(showHandler); + assertThat(show.handler()).isSameAs(showAction); } } diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source.json similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source.json rename to sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source.json diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_params_from_and_to.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_params_from_and_to.json similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_params_from_and_to.json rename to sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_params_from_and_to.json diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm.json similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm.json rename to sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm.json diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm_with_from_and_to_params.json similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_with_from_and_to_params.json rename to sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm_with_from_and_to_params.json diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm_without_repeating_same_lines.json similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines.json rename to sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm_without_repeating_same_lines.json diff --git a/sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines_and_with_from_param_after_repetition.json b/sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm_without_repeating_same_lines_and_with_from_param_after_repetition.json similarity index 100% rename from sonar-server/src/test/resources/org/sonar/server/source/ws/SourcesShowWsHandlerTest/show_source_with_scm_without_repeating_same_lines_and_with_from_param_after_repetition.json rename to sonar-server/src/test/resources/org/sonar/server/source/ws/ShowActionTest/show_source_with_scm_without_repeating_same_lines_and_with_from_param_after_repetition.json -- 2.39.5