/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2014 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.server.qualityprofile.ws;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.i18n.I18n;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.qualityprofile.QProfileService;
import org.sonar.server.rule.RuleService;
import org.sonar.server.ws.WsTester;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class QProfilesWsTest {
WebService.Controller controller;
@Before
public void setUp() {
QProfileService profileService = mock(QProfileService.class);
RuleService ruleService = mock(RuleService.class);
I18n i18n = mock(I18n.class);
controller = new WsTester(new QProfilesWs(new QProfileRestoreBuiltInAction(
mock(QProfileService.class)),
new RuleActivationActions(profileService),
new BulkRuleActivationActions(profileService, ruleService, i18n)
)).controller(QProfilesWs.API_ENDPOINT);
}
@Test
public void define_controller() throws Exception {
assertThat(controller).isNotNull();
assertThat(controller.path()).isEqualTo(QProfilesWs.API_ENDPOINT);
assertThat(controller.description()).isNotEmpty();
assertThat(controller.actions()).hasSize(5);
}
@Test
public void define_restore_built_action() throws Exception {
WebService.Action restoreProfiles = controller.action("restore_built_in");
assertThat(restoreProfiles).isNotNull();
assertThat(restoreProfiles.isPost()).isTrue();
assertThat(restoreProfiles.params()).hasSize(1);
}
@Test
public void define_activate_rule_action() throws Exception {
WebService.Action restoreProfiles = controller.action(RuleActivationActions.ACTIVATE_ACTION);
assertThat(restoreProfiles).isNotNull();
assertThat(restoreProfiles.isPost()).isTrue();
assertThat(restoreProfiles.params()).hasSize(5);
}
@Test
public void define_deactivate_rule_action() throws Exception {
WebService.Action restoreProfiles = controller.action(RuleActivationActions.DEACTIVATE_ACTION);
assertThat(restoreProfiles).isNotNull();
assertThat(restoreProfiles.isPost()).isTrue();
assertThat(restoreProfiles.params()).hasSize(2);
}
}