this.mybatis = mybatis;
}
+ public void insert(QualityProfileDto dto, SqlSession session) {
+ session.getMapper(QualityProfileMapper.class).insert(dto);
+ }
+
+ public void insert(QualityProfileDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ insert(dto, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void update(QualityProfileDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ session.getMapper(QualityProfileMapper.class).update(dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void delete(Integer id) {
+ SqlSession session = mybatis.openSession();
+ try {
+ session.getMapper(QualityProfileMapper.class).delete(id);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
public List<QualityProfileDto> selectAll() {
SqlSession session = mybatis.openSession();
try {
}
}
- public QualityProfileDto selectByNameAndLanguage(String name, String language) {
+ public List<QualityProfileDto> selectChildren(String name, String language) {
SqlSession session = mybatis.openSession();
try {
- return session.getMapper(QualityProfileMapper.class).selectByNameAndLanguage(StringUtils.upperCase(name), language);
+ return session.getMapper(QualityProfileMapper.class).selectChildren(StringUtils.upperCase(name), language);
} finally {
MyBatis.closeQuietly(session);
}
}
- public List<ComponentDto> selectProjects(String propertyKey, String propertyValue) {
+ public int countChildren(String name, String language) {
SqlSession session = mybatis.openSession();
try {
- return session.getMapper(QualityProfileMapper.class).selectProjects(propertyKey, propertyValue);
+ return session.getMapper(QualityProfileMapper.class).countChildren(StringUtils.upperCase(name), language);
} finally {
MyBatis.closeQuietly(session);
}
}
- public void insert(QualityProfileDto dto, SqlSession session) {
- session.getMapper(QualityProfileMapper.class).insert(dto);
- }
-
- public void insert(QualityProfileDto dto) {
+ public QualityProfileDto selectByNameAndLanguage(String name, String language) {
SqlSession session = mybatis.openSession();
try {
- insert(dto, session);
- session.commit();
+ return session.getMapper(QualityProfileMapper.class).selectByNameAndLanguage(StringUtils.upperCase(name), language);
} finally {
MyBatis.closeQuietly(session);
}
}
- public void update(QualityProfileDto dto) {
+ public List<ComponentDto> selectProjects(String propertyKey, String propertyValue) {
SqlSession session = mybatis.openSession();
try {
- session.getMapper(QualityProfileMapper.class).update(dto);
- session.commit();
+ return session.getMapper(QualityProfileMapper.class).selectProjects(propertyKey, propertyValue);
} finally {
MyBatis.closeQuietly(session);
}
}
- public void delete(Integer id) {
+ public int countProjects(String propertyKey, String propertyValue) {
SqlSession session = mybatis.openSession();
try {
- session.getMapper(QualityProfileMapper.class).delete(id);
- session.commit();
+ return session.getMapper(QualityProfileMapper.class).countProjects(propertyKey, propertyValue);
} finally {
MyBatis.closeQuietly(session);
}
public interface QualityProfileMapper {
+ void insert(QualityProfileDto dto);
+
+ void update(QualityProfileDto dto);
+
+ void delete(Integer id);
+
List<QualityProfileDto> selectAll();
@CheckForNull
@CheckForNull
QualityProfileDto selectById(@Param("id") Integer id);
+
+ // INHERITANCE
+
@CheckForNull
QualityProfileDto selectParent(@Param("childId") Integer childId);
- List<ComponentDto> selectProjects(@Param("value") String propertyValue, @Param("key") String propertyKey);
+ List<QualityProfileDto> selectChildren(@Param("name") String name, @Param("language") String language);
- List<QualityProfileDto> selectByProject(@Param("projectId") Long projectId, @Param("key") String propertyKeyPrefix);
+ int countChildren(@Param("name") String name, @Param("language") String language);
- void insert(QualityProfileDto dto);
+ // PROJECTS
- void update(QualityProfileDto dto);
+ List<ComponentDto> selectProjects(@Param("value") String propertyValue, @Param("key") String propertyKey);
+
+ int countProjects(@Param("value") String propertyValue, @Param("key") String propertyKey);
+
+ List<QualityProfileDto> selectByProject(@Param("projectId") Long projectId, @Param("key") String propertyKeyPrefix);
- void delete(Integer id);
}
p.used_profile as used
</sql>
+ <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO rules_profiles (name, language, parent_name, version, used_profile)
+ VALUES (#{name}, #{language}, #{parent}, #{version}, #{used})
+ </insert>
+
+ <update id="update" parameterType="QualityProfile">
+ UPDATE rules_profiles SET
+ name=#{name},
+ language=#{language},
+ parent_name=#{parent},
+ version=#{version},
+ used_profile=#{used}
+ WHERE id=#{id}
+ </update>
+
+ <update id="delete" parameterType="Integer">
+ DELETE FROM rules_profiles WHERE id=#{id}
+ </update>
+
<select id="selectAll" parameterType="map" resultType="QualityProfile">
SELECT <include refid="profilesColumns"/>
FROM rules_profiles p
INNER JOIN rules_profiles child ON child.parent_name=p.name and child.language=p.language and child.id=#{childId}
</select>
+ <select id="selectChildren" parameterType="map" resultType="QualityProfile">
+ SELECT <include refid="profilesColumns"/>
+ FROM rules_profiles p
+ <where>
+ AND UPPER(p.parent_name)=#{name}
+ AND p.language=#{language}
+ </where>
+ ORDER BY p.name
+ </select>
+
+ <select id="countChildren" parameterType="map" resultType="Integer">
+ SELECT count(p.id)
+ FROM rules_profiles p
+ <where>
+ AND UPPER(p.parent_name)=#{name}
+ AND p.language=#{language}
+ </where>
+ </select>
+
<select id="selectDefaultProfile" parameterType="Integer" resultType="QualityProfile">
SELECT <include refid="profilesColumns"/>
FROM rules_profiles p
</where>
</select>
+ <select id="countProjects" parameterType="Integer" resultType="Integer">
+ SELECT count(projects.id)
+ FROM projects projects
+ LEFT JOIN properties ON properties.resource_id = projects.id
+ <where>
+ AND properties.resource_id IS NOT NULL
+ AND properties.prop_key=#{key}
+ AND properties.text_value LIKE #{value}
+ </where>
+ </select>
+
<select id="selectByProject" parameterType="map" resultType="QualityProfile">
SELECT DISTINCT <include refid="profilesColumns"/>
FROM rules_profiles p
AND prop.text_value LIKE p.name
</select>
- <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO rules_profiles (name, language, parent_name, version, used_profile)
- VALUES (#{name}, #{language}, #{parent}, #{version}, #{used})
- </insert>
-
- <update id="update" parameterType="QualityProfile">
- UPDATE rules_profiles SET
- name=#{name},
- language=#{language},
- parent_name=#{parent},
- version=#{version},
- used_profile=#{used}
- WHERE id=#{id}
- </update>
-
- <update id="delete" parameterType="Integer">
- DELETE FROM rules_profiles WHERE id=#{id}
- </update>
-
</mapper>
dao = new QualityProfileDao(getMyBatis());
}
+
+ @Test
+ public void insert() {
+ setupData("shared");
+
+ QualityProfileDto dto = new QualityProfileDto()
+ .setName("Sonar Way with Findbugs")
+ .setLanguage("xoo")
+ .setParent("Sonar Way")
+ .setVersion(2)
+ .setUsed(true);
+
+ dao.insert(dto);
+
+ checkTables("insert", "rules_profiles");
+ }
+
+ @Test
+ public void update() {
+ setupData("shared");
+
+ QualityProfileDto dto = new QualityProfileDto()
+ .setId(1)
+ .setName("New Sonar Way with Findbugs")
+ .setLanguage("js")
+ .setParent("New Sonar Way")
+ .setVersion(3)
+ .setUsed(false);
+
+ dao.update(dto);
+
+ checkTables("update", "rules_profiles");
+ }
+
+ @Test
+ public void delete() {
+ setupData("shared");
+
+ dao.delete(1);
+
+ checkTables("delete", "rules_profiles");
+ }
+
@Test
public void select_all() {
setupData("shared");
@Test
public void select_parent() {
- setupData("parent");
+ setupData("inheritance");
QualityProfileDto dto = dao.selectParent(1);
- assertThat(dto.getId()).isEqualTo(2);
+ assertThat(dto.getId()).isEqualTo(3);
}
@Test
- public void select_projects() {
- setupData("projects");
+ public void select_children() {
+ setupData("inheritance");
- assertThat(dao.selectProjects("Sonar Way", "sonar.profile.java")).hasSize(2);
- }
+ List<QualityProfileDto> dtos = dao.selectChildren("Parent", "java");
- @Test
- public void select_by_project() {
- setupData("projects");
+ assertThat(dtos).hasSize(2);
- assertThat(dao.selectByProject(1L, "sonar.profile.%")).hasSize(2);
+ QualityProfileDto dto1 = dtos.get(0);
+ assertThat(dto1.getId()).isEqualTo(1);
+ assertThat(dto1.getName()).isEqualTo("Child1");
+ assertThat(dto1.getLanguage()).isEqualTo("java");
+ assertThat(dto1.getParent()).isEqualTo("Parent");
+
+ QualityProfileDto dto2 = dtos.get(1);
+ assertThat(dto2.getId()).isEqualTo(2);
+ assertThat(dto2.getName()).isEqualTo("Child2");
+ assertThat(dto2.getLanguage()).isEqualTo("java");
+ assertThat(dto2.getParent()).isEqualTo("Parent");
}
@Test
- public void insert() {
- setupData("shared");
+ public void count_children() {
+ setupData("inheritance");
- QualityProfileDto dto = new QualityProfileDto()
- .setName("Sonar Way with Findbugs")
- .setLanguage("xoo")
- .setParent("Sonar Way")
- .setVersion(2)
- .setUsed(true);
-
- dao.insert(dto);
-
- checkTables("insert", "rules_profiles");
+ assertThat(dao.countChildren("Parent", "java")).isEqualTo(2);
}
@Test
- public void update() {
- setupData("shared");
+ public void select_projects() {
+ setupData("projects");
- QualityProfileDto dto = new QualityProfileDto()
- .setId(1)
- .setName("New Sonar Way with Findbugs")
- .setLanguage("js")
- .setParent("New Sonar Way")
- .setVersion(3)
- .setUsed(false);
+ assertThat(dao.selectProjects("Sonar Way", "sonar.profile.java")).hasSize(2);
+ }
- dao.update(dto);
+ @Test
+ public void count_projects() {
+ setupData("projects");
- checkTables("update", "rules_profiles");
+ assertThat(dao.countProjects("Sonar Way", "sonar.profile.java")).isEqualTo(2);
}
@Test
- public void delete() {
- setupData("shared");
-
- dao.delete(1);
+ public void select_by_project() {
+ setupData("projects");
- checkTables("delete", "rules_profiles");
+ assertThat(dao.selectByProject(1L, "sonar.profile.%")).hasSize(2);
}
+
}
--- /dev/null
+<dataset>
+
+ <rules_profiles id="1" name="Child1" language="java" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="2" name="Child2" language="java" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="3" name="Parent" language="java" parent_name="[null]" version="1"
+ used_profile="[false]"/>
+
+ <!-- Same profile for another language -->
+
+ <rules_profiles id="4" name="Child1" language="js" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="5" name="Child2" language="js" parent_name="Parent" version="1"
+ used_profile="[false]"/>
+
+ <rules_profiles id="6" name="Parent" language="js" parent_name="[null]" version="1"
+ used_profile="[false]"/>
+
+</dataset>
+++ /dev/null
-<dataset>
-
- <rules_profiles id="1" name="Child" language="java" parent_name="Parent" version="1"
- used_profile="[false]"/>
-
- <rules_profiles id="2" name="Parent" language="java" parent_name="[null]" version="1"
- used_profile="[false]"/>
-
-</dataset>
package org.sonar.server.qualityprofile;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
public class QProfile {
.setVersion(dto.getVersion())
.setUsed(dto.isUsed());
}
+
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this).toString();
+ }
}
return new QProfileProjects(QProfile.from(qualityProfile), projects);
}
+ public int countProjects(QProfile profile) {
+ return qualityProfileDao.countProjects(profile.name(), PROPERTY_PREFIX + profile.language());
+ }
+
public List<QProfile> profiles(long projectId) {
List<QualityProfileDto> dtos = qualityProfileDao.selectByProject(projectId, PROPERTY_PREFIX + "%");
return newArrayList(Iterables.transform(dtos, new Function<QualityProfileDto, QProfile>() {
*/
package org.sonar.server.qualityprofile;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
import org.sonar.server.rule.RuleDocument;
import javax.annotation.CheckForNull;
+
import java.util.Date;
import java.util.List;
import java.util.Map;
return activeRuleNote;
}
+ @Override
+ public String toString() {
+ return new ReflectionToStringBuilder(this).toString();
+ }
}
}
public List<QProfile> allProfiles() {
- List<QualityProfileDto> dtos = dao.selectAll();
- return newArrayList(Iterables.transform(dtos, new Function<QualityProfileDto, QProfile>() {
- @Override
- public QProfile apply(QualityProfileDto input) {
- return QProfile.from(input);
- }
- }));
+ return toQProfiles(dao.selectAll());
}
@CheckForNull
return null;
}
+ public List<QProfile> children(QProfile profile) {
+ return toQProfiles(dao.selectChildren(profile.name(), profile.language()));
+ }
+
+ public int countChildren(QProfile profile) {
+ return dao.countChildren(profile.name(), profile.language());
+ }
+
+ private List<QProfile> toQProfiles(List<QualityProfileDto> dtos){
+ return newArrayList(Iterables.transform(dtos, new Function<QualityProfileDto, QProfile>() {
+ @Override
+ public QProfile apply(QualityProfileDto input) {
+ return QProfile.from(input);
+ }
+ }));
+ }
}
// TODO
//
// PROFILES
- // list all profiles (including activated rules count)
- // delete profile from profile id (Delete alerts, activeRules, activeRuleParams, activeRuleNotes, Projects)
+ // delete profile from profile id (Delete alerts, activeRules, activeRuleParams, activeRuleNotes, Projects and check profile is not a default one and has no child)
// copy profile
// export profile from profile id
// export profile from profile id and plugin key
// active rule parameter validation (only Integer types are checked)
+ public List<QProfile> allProfiles() {
+ return search.allProfiles();
+ }
+
public QProfile profile(int id) {
return QProfile.from(findNotNull(id));
}
+ @CheckForNull
+ public QProfile defaultProfile(String language) {
+ return search.defaultProfile(language);
+ }
+
@CheckForNull
public QProfile parent(QProfile profile) {
QualityProfileDto parent = findQualityProfile(profile.parent(), profile.language());
return null;
}
- public List<QProfile> allProfiles() {
- return search.allProfiles();
+ public List<QProfile> children(QProfile profile) {
+ return search.children(profile);
}
- @CheckForNull
- public QProfile defaultProfile(String language) {
- return search.defaultProfile(language);
+ public int countChildren(QProfile profile) {
+ return search.countChildren(profile);
}
public NewProfileResult newProfile(String name, String language, Map<String, String> xmlProfilesByPlugin) {
return projectService.projects(qualityProfile);
}
+ public int countProjects(QProfile profile) {
+ return projectService.countProjects(profile);
+ }
+
/**
* Used in /project/profile
*/
return rules.countInactiveProfileRules(query);
}
+ public long countProfileRules(QProfile profile) {
+ return rules.countProfileRules(ProfileRuleQuery.create(profile.id()));
+ }
+
public ProfileRuleChanged activateRule(int profileId, int ruleId, String severity) {
QualityProfileDto qualityProfile = findNotNull(profileId);
RuleDto rule = findRuleNotNull(ruleId);
activeRuleOperations.deleteActiveRuleParam(activeRule, activeRuleParam, userSession);
} else if (activeRuleParam != null) {
activeRuleOperations.updateActiveRuleParam(activeRule, activeRuleParam, value, userSession);
- } else {
- // No active rule param and no value -> do nothing
}
+ // If no active rule param and no value -> do nothing
+
return activeRuleChanged(qualityProfile, activeRule);
}
# GET /profiles/index
def index
add_breadcrumbs ProfilesController::root_breadcrumb
- @profiles = Profile.all
- Api::Utils.insensitive_sort!(@profiles){|profile| profile.name}
+ call_backend do
+ @profiles = Internal.quality_profiles.allProfiles().to_a
+ end
+ Api::Utils.insensitive_sort!(@profiles){|profile| profile.name()}
end
-
# GET /profiles/create_form?language=<language>
def create_form
require_parameters 'language'
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
module ProfilesHelper
+
def languages
controller.java_facade.getLanguages()
end
end
html
end
-end
\ No newline at end of file
+
+ def profile_key(qProfile)
+ "#{qProfile.language().to_s}_#{qProfile.name().to_s}"
+ end
+
+ def alerts_count(qProfile)
+ Alert.count(:all, :conditions => ['profile_id=?', qProfile.id()])
+ end
+
+ def projects_count(qProfile)
+ Internal.quality_profiles.countProjects(qProfile).to_i
+ end
+
+ def profile_rules_count(qProfile)
+ Internal.quality_profiles.countProfileRules(qProfile).to_i
+ end
+
+ def children_count(qProfile)
+ Internal.quality_profiles.countChildren(qProfile).to_i
+ end
+
+end
<%
Api::Utils.insensitive_sort(languages){|l| l.getName()}.each do |language|
+ default_profile = Internal.quality_profiles.defaultProfile(language.getKey())
%>
<div class="line-block">
<% if profiles_administrator? %>
</tr>
</thead>
<tbody>
- <% @profiles.select { |p| p.language == language.getKey() }.each do |profile| %>
- <tr class="<%= cycle 'even', 'odd', :name => language.getKey() -%>" id="<%= u profile.key %>">
+ <% @profiles.select { |p| p.language == language.getKey() }.each do |profile|
+ key = profile_key(profile)
+ alerts_count = alerts_count(profile)
+ projects_count = projects_count(profile)
+ profile_rules_count = profile_rules_count(profile)
+ is_default_profile = !default_profile.nil? && (default_profile.name() == profile.name())
+ %>
+ <tr class="<%= cycle 'even', 'odd', :name => language.getKey() -%>" id="<%= u key %>">
<td width="40%">
- <a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>" id="rules-<%= language.getKey() -%>-<%= u(profile.name) -%>"><%= h profile.name %></a>
+ <a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id() -%>"
+ id="rules-<%= language.getKey() -%>-<%= u(profile.name()) -%>"><%= h profile.name() %></a>
</td>
<td align="right" width="10%">
- <span id="activated_rules_<%= u profile.key -%>"><%= profile.count_active_rules -%></span>
+ <span id="activated_rules_<%= u key -%>"><%= profile_rules_count -%></span>
</td>
- <td align="right" width="10%"><span id="alerts_<%= u profile.key -%>"><%= profile.alerts.size -%></span></td>
+ <td align="right" width="10%"><span id="alerts_<%= u key -%>"><%= alerts_count -%></span></td>
<td align="right" width="10%" nowrap>
- <% unless profile.default_profile? %>
- <span id="projects_<%= u profile.key -%>"><%= profile.projects.size -%></span>
+ <% unless is_default_profile %>
+ <span id="projects_<%= u key -%>"><%= projects_count -%></span>
<% end %>
</td>
<td align="right" width="10%" nowrap>
- <% if !profile.default_profile? && profiles_administrator? %>
- <%= link_to_action message('set_as_default'), "#{ApplicationController.root_context}/profiles/set_as_default?id=#{profile.id}",
- :id => "activate_#{profile.key.parameterize}",
+ <% if !is_default_profile && profiles_administrator? %>
+ <%= link_to_action message('set_as_default'), "#{ApplicationController.root_context}/profiles/set_as_default?id=#{profile.id()}",
+ :id => "activate_#{key.parameterize}",
:class => 'link-action',
:confirm_title => message('set_as_default'),
- :confirm_msg => message('quality_profiles.are_you_sure_want_x_profile_as_default', :params => [profile.name]),
+ :confirm_msg => message('quality_profiles.are_you_sure_want_x_profile_as_default', :params => [profile.name()]),
:confirm_button => message('set_as_default')
-%>
<% end %>
- <% if profile.default_profile? %>
- <%= image_tag 'tick.png', :id => "is_active_#{u profile.key}" %>
+ <% if is_default_profile %>
+ <%= image_tag 'tick.png', :id => "is_active_#{u key}" %>
<% end %>
</td>
-
<% if profiles_administrator? %>
<td align="right" nowrap>
- <form method="post" action="<%= ApplicationController.root_context -%>/profiles/backup/<%= profile.id -%>" id="backup-<%= profile.key.parameterize -%>-form">
- <a href="#" class="link-action" name="button_backup" id="backup_<%= u profile.key %>" onclick="$j('#backup-<%= profile.key.parameterize -%>-form').submit();return false;"><%= message('backup_verb') -%></a>
+ <form method="post" action="<%= ApplicationController.root_context -%>/profiles/backup/<%= profile.id() -%>" id="backup-<%= key.parameterize -%>-form">
+ <a href="#" class="link-action" name="button_backup" id="backup_<%= u key %>" onclick="$j('#backup-<%= key.parameterize -%>-form').submit();return false;"><%= message('backup_verb') -%></a>
</form>
</td>
<td align="right">
- <a id="rename-<%= profile.key.parameterize -%>" href="<%= ApplicationController.root_context -%>/profiles/rename_form/<%= profile.id -%>" class="link-action open-modal"><%= message('rename') -%></a>
+ <a id="rename-<%= key.parameterize -%>" href="<%= ApplicationController.root_context -%>/profiles/rename_form/<%= profile.id() -%>" class="link-action open-modal"><%= message('rename') -%></a>
</td>
<td align="right">
- <a id="copy-<%= profile.key.parameterize -%>" href="<%= ApplicationController.root_context -%>/profiles/copy_form/<%= profile.id -%>" class="link-action open-modal"><%= message('copy') -%></a>
+ <a id="copy-<%= key.parameterize -%>" href="<%= ApplicationController.root_context -%>/profiles/copy_form/<%= profile.id() -%>" class="link-action open-modal"><%= message('copy') -%></a>
</td>
<td>
- <% if profile.deletable? %>
- <%= link_to_action message('delete'), "#{ApplicationController.root_context}/profiles/delete/#{profile.id}",
+ <% if !is_default_profile && (children_count(profile) == 0) %>
+ <%= link_to_action message('delete'), "#{ApplicationController.root_context}/profiles/delete/#{profile.id()}",
:class => 'link-action link-red',
- :id => "delete_#{profile.key.parameterize}",
+ :id => "delete_#{key.parameterize}",
:confirm_button => message('delete'),
:confirm_title => 'quality_profiles.delete_confirm_title',
:confirm_msg => 'quality_profiles.are_you_sure_want_delete_profile_x',
- :confirm_msg_params => [profile.name]
+ :confirm_msg_params => [profile.name()]
-%>
<% end %>
</td>
assertThat(result.projects()).hasSize(1);
}
+ @Test
+ public void count_projects() throws Exception {
+ service.countProjects(new QProfile().setId(1).setName("My profile").setLanguage("java"));
+ verify(qualityProfileDao).countProjects("My profile", "sonar.profile.java");
+ }
+
@Test
public void search_profiles_from_project() throws Exception {
QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
assertThat(qProfile.used()).isFalse();
}
+ @Test
+ public void search_children_profiles() throws Exception {
+ search.children(new QProfile().setName("Sonar Way").setLanguage("java"));
+ verify(dao).selectChildren("Sonar Way", "java");
+ }
+
+ @Test
+ public void count_children_profiles() throws Exception {
+ search.countChildren(new QProfile().setName("Sonar Way").setLanguage("java"));
+ verify(dao).countChildren("Sonar Way", "java");
+ }
+
@Test
public void default_profile() throws Exception {
when(dao.selectDefaultProfile("java", "sonar.profile.java")).thenReturn(
verify(qualityProfileDao).selectById(1);
}
+ @Test
+ public void search_profiles() throws Exception {
+ qProfiles.allProfiles();
+ verify(search).allProfiles();
+ }
+
+ @Test
+ public void search_default_profile_by_language() throws Exception {
+ qProfiles.defaultProfile("java");
+ verify(search).defaultProfile("java");
+ }
+
@Test
public void search_parent_profile() throws Exception {
QualityProfileDto parent = new QualityProfileDto().setId(2).setName("Parent").setLanguage("java");
}
@Test
- public void search_profiles() throws Exception {
- qProfiles.allProfiles();
- verify(search).allProfiles();
+ public void search_children() throws Exception {
+ QProfile profile = new QProfile();
+ qProfiles.children(profile);
+ verify(search).children(profile);
}
@Test
- public void search_default_profile_by_language() throws Exception {
- qProfiles.defaultProfile("java");
- verify(search).defaultProfile("java");
+ public void count_children() throws Exception {
+ QProfile profile = new QProfile();
+ qProfiles.countChildren(profile);
+ verify(search).countChildren(profile);
}
@Test
verify(projectService).projects(qualityProfile);
}
+ @Test
+ public void count_projects() throws Exception {
+ QProfile profile = new QProfile();
+ qProfiles.countProjects(profile);
+ verify(projectService).countProjects(profile);
+ }
+
@Test
public void get_profiles_from_project_id() throws Exception {
qProfiles.profiles(1);