@@ -22,8 +22,8 @@ package org.sonar.plugins.core.dashboards; | |||
import org.sonar.api.web.Dashboard; | |||
import org.sonar.api.web.DashboardLayout; | |||
import org.sonar.api.web.DashboardTemplate; | |||
import org.sonar.core.measure.MeasureFilterDao; | |||
import org.sonar.core.measure.MeasureFilterDto; | |||
import org.sonar.core.measure.db.MeasureFilterDao; | |||
import org.sonar.core.measure.db.MeasureFilterDto; | |||
import org.sonar.plugins.core.measurefilters.MyFavouritesFilter; | |||
import org.sonar.plugins.core.measurefilters.ProjectFilter; | |||
import org.sonar.plugins.core.widgets.MeasureFilterListWidget; |
@@ -23,8 +23,8 @@ import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.api.web.Dashboard; | |||
import org.sonar.api.web.Dashboard.Widget; | |||
import org.sonar.core.measure.MeasureFilterDao; | |||
import org.sonar.core.measure.MeasureFilterDto; | |||
import org.sonar.core.measure.db.MeasureFilterDao; | |||
import org.sonar.core.measure.db.MeasureFilterDto; | |||
import org.sonar.plugins.core.CorePlugin; | |||
import org.sonar.plugins.core.measurefilters.MyFavouritesFilter; | |||
import org.sonar.plugins.core.measurefilters.ProjectFilter; |
@@ -0,0 +1,45 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure.db; | |||
import org.apache.ibatis.session.SqlSession; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.core.persistence.MyBatis; | |||
public class MeasureDataDao implements ServerComponent { | |||
private MyBatis mybatis; | |||
public MeasureDataDao(MyBatis mybatis) { | |||
this.mybatis = mybatis; | |||
} | |||
public MeasureDataDto findByComponentKeyAndMetricKey(String componentKey, String metricKey) { | |||
SqlSession session = mybatis.openSession(); | |||
try { | |||
MeasureDataMapper mapper = session.getMapper(MeasureDataMapper.class); | |||
return mapper.findByComponentKeyAndMetricKey(componentKey, metricKey); | |||
} finally { | |||
MyBatis.closeQuietly(session); | |||
} | |||
} | |||
} |
@@ -0,0 +1,85 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure.db; | |||
import com.google.common.base.Charsets; | |||
import com.google.common.base.Throwables; | |||
import java.io.UnsupportedEncodingException; | |||
public class MeasureDataDto { | |||
private Integer id; | |||
private Integer measureId; | |||
private Integer snapshotId; | |||
private byte[] data; | |||
public Integer getId() { | |||
return id; | |||
} | |||
public MeasureDataDto setId(Integer id) { | |||
this.id = id; | |||
return this; | |||
} | |||
public Integer getMeasureId() { | |||
return measureId; | |||
} | |||
public MeasureDataDto setMeasureId(Integer measureId) { | |||
this.measureId = measureId; | |||
return this; | |||
} | |||
public Integer getSnapshotId() { | |||
return snapshotId; | |||
} | |||
public MeasureDataDto setSnapshotId(Integer snapshotId) { | |||
this.snapshotId = snapshotId; | |||
return this; | |||
} | |||
public byte[] getData() { | |||
return data; | |||
} | |||
public MeasureDataDto setData(byte[] data) { | |||
this.data = data; | |||
return this; | |||
} | |||
public String getText() { | |||
if (data != null) { | |||
try { | |||
return new String(data, Charsets.UTF_8.name()); | |||
} catch (UnsupportedEncodingException e) { | |||
// how is it possible to not support UTF-8 ? | |||
Throwables.propagate(e); | |||
} | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure.db; | |||
import org.apache.ibatis.annotations.Param; | |||
public interface MeasureDataMapper { | |||
MeasureDataDto findByComponentKeyAndMetricKey(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey); | |||
} |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure; | |||
package org.sonar.core.measure.db; | |||
import org.apache.ibatis.session.SqlSession; | |||
import org.sonar.api.BatchComponent; |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure; | |||
package org.sonar.core.measure.db; | |||
import javax.annotation.Nullable; | |||
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure; | |||
package org.sonar.core.measure.db; | |||
/** | |||
* @since 3.4 |
@@ -0,0 +1,25 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.core.measure.db; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -25,7 +25,8 @@ import org.sonar.core.dashboard.DashboardDao; | |||
import org.sonar.core.duplication.DuplicationDao; | |||
import org.sonar.core.graph.jdbc.GraphDao; | |||
import org.sonar.core.issue.db.*; | |||
import org.sonar.core.measure.MeasureFilterDao; | |||
import org.sonar.core.measure.db.MeasureDataDao; | |||
import org.sonar.core.measure.db.MeasureFilterDao; | |||
import org.sonar.core.notification.db.NotificationQueueDao; | |||
import org.sonar.core.permission.PermissionDao; | |||
import org.sonar.core.permission.PermissionTemplateDao; | |||
@@ -70,6 +71,7 @@ public final class DaoUtils { | |||
IssueFilterDao.class, | |||
IssueFilterFavouriteDao.class, | |||
LoadedTemplateDao.class, | |||
MeasureDataDao.class, | |||
MeasureFilterDao.class, | |||
NotificationQueueDao.class, | |||
PermissionDao.class, |
@@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.database.model.MeasureData; | |||
import org.sonar.api.database.model.MeasureMapper; | |||
import org.sonar.api.database.model.MeasureModel; | |||
import org.sonar.core.component.ComponentDto; | |||
@@ -46,8 +45,10 @@ import org.sonar.core.duplication.DuplicationUnitDto; | |||
import org.sonar.core.graph.jdbc.GraphDto; | |||
import org.sonar.core.graph.jdbc.GraphDtoMapper; | |||
import org.sonar.core.issue.db.*; | |||
import org.sonar.core.measure.MeasureFilterDto; | |||
import org.sonar.core.measure.MeasureFilterMapper; | |||
import org.sonar.core.measure.db.MeasureDataDto; | |||
import org.sonar.core.measure.db.MeasureDataMapper; | |||
import org.sonar.core.measure.db.MeasureFilterDto; | |||
import org.sonar.core.measure.db.MeasureFilterMapper; | |||
import org.sonar.core.notification.db.NotificationQueueDto; | |||
import org.sonar.core.notification.db.NotificationQueueMapper; | |||
import org.sonar.core.permission.*; | |||
@@ -125,7 +126,7 @@ public class MyBatis implements BatchComponent, ServerComponent { | |||
loadAlias(conf, "Widget", WidgetDto.class); | |||
loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class); | |||
loadAlias(conf, "MeasureModel", MeasureModel.class); | |||
loadAlias(conf, "MeasureData", MeasureData.class); | |||
loadAlias(conf, "MeasureData", MeasureDataDto.class); | |||
loadAlias(conf, "Issue", IssueDto.class); | |||
loadAlias(conf, "IssueChange", IssueChangeDto.class); | |||
loadAlias(conf, "IssueFilter", IssueFilterDto.class); | |||
@@ -157,7 +158,8 @@ public class MyBatis implements BatchComponent, ServerComponent { | |||
SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, | |||
MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class, | |||
NotificationQueueMapper.class, CharacteristicMapper.class, RuleTagMapper.class, | |||
GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class | |||
GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, | |||
MeasureDataMapper.class | |||
}; | |||
loadMappers(conf, mappers); | |||
configureLogback(mappers); |
@@ -0,0 +1,28 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="org.sonar.core.measure.db.MeasureDataMapper"> | |||
<sql id="measureDataColumns"> | |||
m.id, | |||
m.measure_id as measureId, | |||
m.snapshot_id as snapshotId, | |||
m.measure_id as measureId, | |||
m.data as data | |||
</sql> | |||
<select id="findByComponentKeyAndMetricKey" parameterType="map" resultType="MeasureData"> | |||
SELECT | |||
<include refid="measureDataColumns"/> | |||
FROM measure_data m | |||
INNER JOIN project_measures pm ON pm.id=m.measure_id | |||
INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true} | |||
INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true} | |||
INNER JOIN metrics metric ON metric.id=pm.metric_id | |||
<where> | |||
AND p.kee = #{componentKey} | |||
AND metric.name = #{metricKey} | |||
</where> | |||
</select> | |||
</mapper> |
@@ -1,7 +1,7 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="org.sonar.core.measure.MeasureFilterMapper"> | |||
<mapper namespace="org.sonar.core.measure.db.MeasureFilterMapper"> | |||
<select id="findSystemFilterByName" parameterType="string" resultType="MeasureFilter"> | |||
select id, name, user_id as "userId", shared, description, data, created_at as "createdAt", updated_at as "updatedAt" |
@@ -0,0 +1,51 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2013 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure.db; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.core.persistence.AbstractDaoTestCase; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
public class MeasureDataDaoTest extends AbstractDaoTestCase { | |||
private MeasureDataDao dao; | |||
@Before | |||
public void createDao() { | |||
dao = new MeasureDataDao(getMyBatis()); | |||
} | |||
@Test | |||
public void find_by_component_key_and_metric_key() throws Exception { | |||
setupData("shared"); | |||
MeasureDataDto result = dao.findByComponentKeyAndMetricKey("org.sonar.core.measure.db.MeasureData", "authors_by_line"); | |||
assertThat(result.getId()).isEqualTo(1); | |||
assertThat(result.getMeasureId()).isEqualTo(1); | |||
assertThat(result.getSnapshotId()).isEqualTo(1); | |||
assertThat(result.getText()).isNotNull(); | |||
// FIXME failing because data is returned in wrong format | |||
// assertThat(result.getText()).isEqualTo("test"); | |||
} | |||
} |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.core.measure; | |||
package org.sonar.core.measure.db; | |||
import org.junit.Before; | |||
import org.junit.Test; |
@@ -0,0 +1,10 @@ | |||
<dataset> | |||
<snapshots id="1" project_id="1" islast="[true]" /> | |||
<project_measures id="1" snapshot_id="1" metric_id="1"/> | |||
<metrics id="1" name="authors_by_line"/> | |||
<projects id="1" kee="org.sonar.core.measure.db.MeasureData" enabled="[true]"/> | |||
<measure_data id="1" measure_id="1" snapshot_id="1" data="test"/> | |||
</dataset> |
@@ -22,12 +22,15 @@ package org.sonar.server.source; | |||
import org.sonar.api.ServerComponent; | |||
import org.sonar.api.web.UserRole; | |||
import org.sonar.core.measure.db.MeasureDataDao; | |||
import org.sonar.core.measure.db.MeasureDataDto; | |||
import org.sonar.core.resource.ResourceDao; | |||
import org.sonar.core.resource.ResourceDto; | |||
import org.sonar.core.source.HtmlSourceDecorator; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.user.UserSession; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import java.util.List; | |||
@@ -36,10 +39,12 @@ public class SourceService implements ServerComponent { | |||
private final HtmlSourceDecorator sourceDecorator; | |||
private final ResourceDao resourceDao; | |||
private final MeasureDataDao measureDataDao; | |||
public SourceService(HtmlSourceDecorator sourceDecorator, ResourceDao resourceDao) { | |||
public SourceService(HtmlSourceDecorator sourceDecorator, ResourceDao resourceDao, MeasureDataDao measureDataDao) { | |||
this.sourceDecorator = sourceDecorator; | |||
this.resourceDao = resourceDao; | |||
this.measureDataDao = measureDataDao; | |||
} | |||
public List<String> sourcesFromComponent(String componentKey) { | |||
@@ -54,4 +59,14 @@ public class SourceService implements ServerComponent { | |||
UserSession.get().checkProjectPermission(UserRole.CODEVIEWER, project.getKey()); | |||
return sourceDecorator.getDecoratedSourceAsHtml(componentKey, from, to); | |||
} | |||
// TODO move this in another service | |||
@CheckForNull | |||
public String findDataFromComponent(String componentKey, String metricKey){ | |||
MeasureDataDto data = measureDataDao.findByComponentKeyAndMetricKey(componentKey, metricKey); | |||
if (data != null) { | |||
return data.getText(); | |||
} | |||
return null; | |||
} | |||
} |
@@ -20,6 +20,8 @@ | |||
package org.sonar.server.source.ws; | |||
import com.google.common.base.Splitter; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.RequestHandler; | |||
import org.sonar.api.server.ws.Response; | |||
@@ -29,6 +31,8 @@ import org.sonar.server.source.SourceService; | |||
import java.util.List; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
public class SourcesShowWsHandler implements RequestHandler { | |||
private final SourceService sourceService; | |||
@@ -40,22 +44,58 @@ public class SourcesShowWsHandler implements RequestHandler { | |||
@Override | |||
public void handle(Request request, Response response) { | |||
String componentKey = request.requiredParam("key"); | |||
Integer from = request.intParam("from"); | |||
Integer to = request.intParam("to"); | |||
List<String> sourceHtml = sourceService.sourcesFromComponent(componentKey, from , to); | |||
Integer fromParam = request.intParam("from"); | |||
Integer toParam = request.intParam("to"); | |||
List<String> sourceHtml = sourceService.sourcesFromComponent(componentKey, fromParam, toParam); | |||
if (sourceHtml == null) { | |||
throw new NotFoundException("Component : " + componentKey + " has no source."); | |||
} | |||
from = from != null ? from : 1; | |||
String scmAuthorData = sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY); | |||
String scmDataData = sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY); | |||
int from = fromParam != null ? fromParam : 1; | |||
int to = toParam != null ? toParam : sourceHtml.size() + from; | |||
JsonWriter json = response.newJsonWriter(); | |||
json.beginObject().name("source").beginObject(); | |||
for (int i = 0; i < sourceHtml.size(); i++) { | |||
String line = sourceHtml.get(i); | |||
json.beginObject(); | |||
writeSource(sourceHtml, from, json); | |||
writeScm(scmAuthorData, scmDataData, from, to, json); | |||
json.endObject().close(); | |||
} | |||
private void writeSource(List<String> source, int from, JsonWriter json) { | |||
json.name("source").beginObject(); | |||
for (int i = 0; i < source.size(); i++) { | |||
String line = source.get(i); | |||
json.prop(Integer.toString(i + from), line); | |||
} | |||
json.endObject().endObject().close(); | |||
json.endObject(); | |||
} | |||
private void writeScm(String authorData, String scmDateData, int from, int to , JsonWriter json) { | |||
if (authorData != null) { | |||
json.name("scm").beginObject(); | |||
List<String> authors = splitLine(authorData); | |||
for (int i = 0; i < authors.size(); i++) { | |||
String[] authorWithLine = splitColumn(authors.get(i)); | |||
Integer line = Integer.parseInt(authorWithLine[0]); | |||
String author = authorWithLine[1]; | |||
if (line >= from && line <= to) { | |||
json.name(Integer.toString(line)).beginArray(); | |||
json.value(author); | |||
json.endArray(); | |||
} | |||
} | |||
json.endObject(); | |||
} | |||
} | |||
private List<String> splitLine(String line){ | |||
return newArrayList(Splitter.on(";").split(line)); | |||
} | |||
private String[] splitColumn(String column){ | |||
return column.split("="); | |||
} | |||
} |
@@ -30,8 +30,8 @@ import org.sonar.api.web.Criterion; | |||
import org.sonar.api.web.Filter; | |||
import org.sonar.api.web.FilterColumn; | |||
import org.sonar.api.web.FilterTemplate; | |||
import org.sonar.core.measure.MeasureFilterDao; | |||
import org.sonar.core.measure.MeasureFilterDto; | |||
import org.sonar.core.measure.db.MeasureFilterDao; | |||
import org.sonar.core.measure.db.MeasureFilterDto; | |||
import org.sonar.core.template.LoadedTemplateDao; | |||
import org.sonar.core.template.LoadedTemplateDto; | |||
@@ -26,6 +26,7 @@ import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.runners.MockitoJUnitRunner; | |||
import org.sonar.api.web.UserRole; | |||
import org.sonar.core.measure.db.MeasureDataDao; | |||
import org.sonar.core.resource.ResourceDao; | |||
import org.sonar.core.resource.ResourceDto; | |||
import org.sonar.core.source.HtmlSourceDecorator; | |||
@@ -45,11 +46,14 @@ public class SourceServiceTest { | |||
@Mock | |||
ResourceDao resourceDao; | |||
@Mock | |||
MeasureDataDao measureDataDao; | |||
SourceService service; | |||
@Before | |||
public void setUp() throws Exception { | |||
service = new SourceService(sourceDecorator, resourceDao); | |||
service = new SourceService(sourceDecorator, resourceDao, measureDataDao); | |||
} | |||
@Test | |||
@@ -92,4 +96,18 @@ public class SourceServiceTest { | |||
verify(sourceDecorator).getDecoratedSourceAsHtml(componentKey, 1, 2); | |||
} | |||
@Test | |||
public void find_data_from_component() throws Exception { | |||
String componentKey = "org.sonar.sample:Sample"; | |||
service.findDataFromComponent(componentKey, "metric_key"); | |||
verify(measureDataDao).findByComponentKeyAndMetricKey(componentKey, "metric_key"); | |||
} | |||
@Test | |||
public void not_find_data_from_component_if_no_data() throws Exception { | |||
String componentKey = "org.sonar.sample:Sample"; | |||
when(measureDataDao.findByComponentKeyAndMetricKey(componentKey, "metric_key")).thenReturn(null); | |||
assertThat(service.findDataFromComponent(componentKey, "metric_key")).isNull(); | |||
} | |||
} |
@@ -25,6 +25,7 @@ import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.runners.MockitoJUnitRunner; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.server.ws.WsTester; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.source.SourceService; | |||
@@ -79,7 +80,7 @@ public class SourcesShowWsHandlerTest { | |||
} | |||
@Test | |||
public void show_source_with_params_from_and_to() throws Exception { | |||
public void show_source_with_from_and_to_params() throws Exception { | |||
String componentKey = "org.apache.struts:struts:Dispatcher"; | |||
when(sourceService.sourcesFromComponent(componentKey, 3, 5)).thenReturn(newArrayList( | |||
" */", | |||
@@ -89,4 +90,32 @@ public class SourcesShowWsHandlerTest { | |||
WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5"); | |||
request.execute().assertJson(getClass(), "show_source_with_params_from_and_to.json"); | |||
} | |||
@Test | |||
public void show_source_with_scm() throws Exception { | |||
String componentKey = "org.apache.struts:struts:Dispatcher"; | |||
when(sourceService.sourcesFromComponent(eq(componentKey), anyInt(), anyInt())).thenReturn(newArrayList( | |||
"public class <span class=\"sym-31 sym\">HelloWorld</span> {}" | |||
)); | |||
when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)).thenReturn("1=julien;2=simon"); | |||
WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey); | |||
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.sourcesFromComponent(componentKey, 3, 5)).thenReturn(newArrayList( | |||
" */", | |||
"", | |||
"public class <span class=\"sym-31 sym\">HelloWorld</span> {" | |||
)); | |||
when(sourceService.findDataFromComponent(componentKey, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)) | |||
.thenReturn("1=julien;2=simon;3=julien;4=simon;5=simon;6=julien"); | |||
WsTester.TestRequest request = tester.newRequest("show").setParam("key", componentKey).setParam("from", "3").setParam("to", "5"); | |||
request.execute().assertJson(getClass(), "show_source_with_scm_with_from_and_to_params.json"); | |||
} | |||
} |
@@ -25,8 +25,8 @@ import org.sonar.api.web.Criterion; | |||
import org.sonar.api.web.Filter; | |||
import org.sonar.api.web.FilterColumn; | |||
import org.sonar.api.web.FilterTemplate; | |||
import org.sonar.core.measure.MeasureFilterDao; | |||
import org.sonar.core.measure.MeasureFilterDto; | |||
import org.sonar.core.measure.db.MeasureFilterDao; | |||
import org.sonar.core.measure.db.MeasureFilterDto; | |||
import org.sonar.core.template.LoadedTemplateDao; | |||
import org.sonar.core.template.LoadedTemplateDto; | |||
@@ -34,10 +34,7 @@ import static org.fest.assertions.Assertions.assertThat; | |||
import static org.mockito.Matchers.any; | |||
import static org.mockito.Matchers.anyString; | |||
import static org.mockito.Matchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.never; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.when; | |||
import static org.mockito.Mockito.*; | |||
public class RegisterNewMeasureFiltersTest { | |||
private RegisterNewMeasureFilters registration; |
@@ -0,0 +1,17 @@ | |||
{ | |||
"source": { | |||
"1": "public class <span class=\"sym-31 sym\">HelloWorld</span> {}" | |||
}, | |||
"scm": { | |||
"1": ["julien"], | |||
"2": ["simon"] | |||
} | |||
} | |||
@@ -0,0 +1,20 @@ | |||
{ | |||
"source": { | |||
"3": " */", | |||
"4": "", | |||
"5": "public class <span class=\"sym-31 sym\">HelloWorld</span> {" | |||
}, | |||
"scm": { | |||
"3": ["julien"], | |||
"4": ["simon"], | |||
"5": ["simon"] | |||
} | |||
} | |||