SONAR-6355 Fix IT

This commit is contained in:
Julien Lancelot 2015-10-28 18:04:29 +01:00
parent 86b031b91a
commit bb5e171851
10 changed files with 319 additions and 183 deletions

View File

@ -51,6 +51,7 @@ import it.projectAdministration.BulkDeletionTest;
import it.projectAdministration.ProjectAdministrationTest;
import it.qualityGate.QualityGateNotificationTest;
import it.qualityGate.QualityGateTest;
import it.qualityGate.QualityGateUiTest;
import it.settings.PropertySetsTest;
import it.settings.SettingsTest;
import it.settings.SettingsTestRestartingOrchestrator;
@ -76,6 +77,7 @@ import static util.ItUtils.xooPlugin;
I18nTest.class,
// quality gate
QualityGateTest.class,
QualityGateUiTest.class,
QualityGateNotificationTest.class,
// permission
IssuePermissionTest.class,

View File

@ -35,11 +35,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.wsclient.SonarClient;
import org.sonar.wsclient.base.HttpException;
import org.sonar.wsclient.qualitygate.NewCondition;
import org.sonar.wsclient.qualitygate.QualityGate;
import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonar.wsclient.qualitygate.QualityGateCondition;
import org.sonar.wsclient.qualitygate.UpdateCondition;
import org.sonar.wsclient.services.PropertyQuery;
import org.sonar.wsclient.services.ResourceQuery;
import org.sonar.wsclient.user.UserParameters;
@ -162,59 +157,6 @@ public class ProjectAdministrationTest {
assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(7);
}
// SONAR-3326
// TODO should be moved to qualityGate
@Test
public void display_alerts_correctly_in_history_page() {
QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient();
QualityGate qGate = qgClient.create("AlertsForHistory");
qgClient.setDefault(qGate.id());
// with this configuration, project should have an Orange alert
QualityGateCondition lowThresholds = qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("GT").warningThreshold("5").errorThreshold("50"));
scanSampleWithDate("2012-01-01");
// with this configuration, project should have a Green alert
qgClient.updateCondition(UpdateCondition.create(lowThresholds.id()).metricKey("lines").operator("GT").warningThreshold("5000").errorThreshold("5000"));
scanSampleWithDate("2012-01-02");
Selenese selenese = Selenese.builder()
.setHtmlTestsInClasspath("display-alerts-history-page",
"/projectAdministration/ProjectAdministrationTest/display-alerts-history-page/should-display-alerts-correctly-history-page.html"
).build();
new SeleneseTest(selenese).runOn(orchestrator);
qgClient.unsetDefault();
qgClient.destroy(qGate.id());
}
/**
* SONAR-1352
*/
// TODO should be moved to qualityGate
@Test
public void display_period_alert_on_project_dashboard() {
QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient();
QualityGate qGate = qgClient.create("AlertsForDashboard");
qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("LT").warningThreshold("0").errorThreshold("10")
.period(1));
qgClient.setDefault(qGate.id());
// No alert
scanSampleWithDate("2012-01-01");
// Red alert because lines number has not changed since previous analysis
scanSample();
Selenese selenese = Selenese.builder()
.setHtmlTestsInClasspath("display-period-alerts",
"/projectAdministration/ProjectAdministrationTest/display-alerts/should-display-period-alerts-correctly.html"
).build();
new SeleneseTest(selenese).runOn(orchestrator);
qgClient.unsetDefault();
qgClient.destroy(qGate.id());
}
/**
* SONAR-3425
*/

View File

@ -11,7 +11,9 @@ import com.sonar.orchestrator.selenium.Selenese;
import it.Category1Suite;
import java.util.Iterator;
import javax.mail.internet.MimeMessage;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.Sonar;
@ -24,11 +26,13 @@ import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
import util.ItUtils;
import util.NetworkUtils;
import util.selenium.SeleneseTest;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.projectDir;
import static util.ItUtils.setServerProperty;
public class QualityGateNotificationTest {
@ -37,6 +41,18 @@ public class QualityGateNotificationTest {
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
@BeforeClass
public static void initPeriods() throws Exception {
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
}
@AfterClass
public static void resetPeriods() throws Exception {
ItUtils.resetPeriods(orchestrator);
}
@Before
public void cleanUp() {
orchestrator.resetData();
@ -57,8 +73,8 @@ public class QualityGateNotificationTest {
Selenese selenese = Selenese
.builder()
.setHtmlTestsInClasspath("notifications",
"/qualitygate/notifications/email_configuration.html",
"/qualitygate/notifications/activate_notification_channels.html").build();
"/qualityGate/notifications/email_configuration.html",
"/qualityGate/notifications/activate_notification_channels.html").build();
new SeleneseTest(selenese).runOn(orchestrator);
// Create quality gate with conditions on variations

View File

@ -0,0 +1,136 @@
/*
* 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 it.qualityGate;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.selenium.Selenese;
import it.Category1Suite;
import javax.annotation.Nullable;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.qualitygate.NewCondition;
import org.sonar.wsclient.qualitygate.QualityGate;
import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonar.wsclient.qualitygate.QualityGateCondition;
import org.sonar.wsclient.qualitygate.UpdateCondition;
import util.ItUtils;
import util.selenium.SeleneseTest;
import static util.ItUtils.projectDir;
import static util.ItUtils.setServerProperty;
public class QualityGateUiTest {
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
@BeforeClass
public static void initPeriods() throws Exception {
setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis");
setServerProperty(orchestrator, "sonar.timemachine.period2", "30");
setServerProperty(orchestrator, "sonar.timemachine.period3", "previous_version");
}
@AfterClass
public static void resetPeriods() throws Exception {
ItUtils.resetPeriods(orchestrator);
}
@Before
public void cleanUp() {
orchestrator.resetData();
}
/**
* SONAR-3326
*/
@Test
public void display_alerts_correctly_in_history_page() {
QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient();
QualityGate qGate = qgClient.create("AlertsForHistory");
qgClient.setDefault(qGate.id());
// with this configuration, project should have an Orange alert
QualityGateCondition lowThresholds = qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("GT").warningThreshold("5").errorThreshold("50"));
scanSampleWithDate("2012-01-01");
// with this configuration, project should have a Green alert
qgClient.updateCondition(UpdateCondition.create(lowThresholds.id()).metricKey("lines").operator("GT").warningThreshold("5000").errorThreshold("5000"));
scanSampleWithDate("2012-01-02");
new SeleneseTest(Selenese.builder()
.setHtmlTestsInClasspath("display-alerts-history-page",
"/qualityGate/QualityGateUiTest/should-display-alerts-correctly-history-page.html"
).build()).runOn(orchestrator);
qgClient.unsetDefault();
qgClient.destroy(qGate.id());
}
/**
* SONAR-1352
*/
@Test
public void display_period_alert_on_project_dashboard() {
QualityGateClient qgClient = orchestrator.getServer().adminWsClient().qualityGateClient();
QualityGate qGate = qgClient.create("AlertsForDashboard");
qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("LT").warningThreshold("0").errorThreshold("10")
.period(1));
qgClient.setDefault(qGate.id());
// No alert
scanSampleWithDate("2012-01-01");
// Red alert because lines number has not changed since previous analysis
scanSample();
new SeleneseTest(Selenese.builder()
.setHtmlTestsInClasspath("display-period-alerts",
"/qualityGate/QualityGateUiTest/should-display-period-alerts-correctly.html"
).build()).runOn(orchestrator);
qgClient.unsetDefault();
qgClient.destroy(qGate.id());
}
private void scanSample() {
scanSample(null, null);
}
private void scanSampleWithDate(String date) {
scanSample(date, null);
}
private void scanSample(@Nullable String date, @Nullable String profile) {
SonarRunner scan = SonarRunner.create(projectDir("shared/xoo-sample"))
.setProperties("sonar.cpd.skip", "true");
if (date != null) {
scan.setProperty("sonar.projectDate", date);
}
if (profile != null) {
scan.setProfile(profile);
}
orchestrator.executeBuild(scan);
}
}

View File

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>should-display-alerts-correctly-history-page</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr>
<td rowspan="1" colspan="3">should-display-alerts-correctly-history-page</td>
</tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/sonar/sessions/login</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>login</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
<td>admin</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>commit</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/sonar/dashboard/index/sample</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=#context-navigation .navbar-admin-link</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>link=History</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=History</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//img[@title='Quality Gate Status: Green (was Orange). ']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//img[@title='Quality Gate Status: Orange. Lines > 5']</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>should-display-alerts-correctly-history-page</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr>
<td rowspan="1" colspan="3">should-display-alerts-correctly-history-page</td>
</tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/sonar/sessions/login</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>login</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
<td>admin</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>commit</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/sonar/widget?id=alerts&amp;resource=sample</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>class=alerts</td>
<td>glob:*Lines*0 &lt; 10*since previous analysis*</td>
</tr>
<tr>
<td>assertText</td>
<td>class=alert_ERROR</td>
<td>0</td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>should-display-alerts-correctly-history-page</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr>
<td rowspan="1" colspan="3">should-display-alerts-correctly-history-page</td>
</tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/sonar/sessions/login</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>login</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
<td>admin</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>commit</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/sonar/dashboard/index/sample</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=#context-navigation .navbar-admin-link</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>link=History</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=History</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//img[@title='Quality Gate Status: Green (was Orange). ']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//img[@title='Quality Gate Status: Orange. Lines > 5']</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>should-display-alerts-correctly-history-page</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr>
<td rowspan="1" colspan="3">should-display-alerts-correctly-history-page</td>
</tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/sonar/sessions/login</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>login</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>password</td>
<td>admin</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>commit</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/sonar/widget?id=alerts&amp;resource=sample</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>class=alerts</td>
<td>glob:*Lines*0 &lt; 10*since previous analysis*</td>
</tr>
<tr>
<td>assertText</td>
<td>class=alert_ERROR</td>
<td>0</td>
</tr>
</tbody>
</table>
</body>
</html>