/*
* SonarQube Java
* Copyright (C) 2013-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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 com.sonar.it.java.suite;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.build.MavenBuild;
import com.sonar.orchestrator.locator.FileLocation;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.services.Measure;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
import java.io.File;
import static org.assertj.core.api.Assertions.assertThat;
public class SuppressWarningTest {
@ClassRule
public static final Orchestrator ORCHESTRATOR;
static {
OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv()
.addPlugin(FileLocation.byWildcardMavenFilename(new File("../../../sonar-java-plugin/target"), "sonar-java-plugin-*.jar"))
.restoreProfileAtStartup(FileLocation.ofClasspath("/profile-suppress-warnings.xml"));
orchestratorBuilder.addPlugin(FileLocation.of(TestUtils.pluginJar("java-extension-plugin")));
orchestratorBuilder.addPlugin(FileLocation.ofClasspath("/sonar-checkstyle-plugin-2.4.jar"));
ORCHESTRATOR = orchestratorBuilder.build();
}
/**
* SONARJAVA-19
*/
@Test
public void suppressWarnings_nosonar() throws Exception {
MavenBuild build = MavenBuild.create(TestUtils.projectPom("suppress-warnings"))
.setCleanSonarGoals()
.setProperty("sonar.profile", "suppress-warnings");
ORCHESTRATOR.executeBuild(build);
assertThat(getMeasure("org.example:example", "violations").getValue()).isEqualTo(3);
}
private static Measure getMeasure(String resourceKey, String metricKey) {
Resource resource = ORCHESTRATOR.getServer().getWsClient().find(ResourceQuery.createForMetrics(resourceKey, metricKey));
return resource != null ? resource.getMeasure(metricKey) : null;
}
}