--- /dev/null
+/*
+ * 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.core.qualityprofile.db;
+
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ActiveRuleKeyTest {
+
+ @Test
+ public void of() throws Exception {
+ RuleKey ruleKey = RuleKey.of("xoo", "R1");
+ ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey);
+ assertThat(key.qProfile()).isEqualTo("P1");
+ assertThat(key.ruleKey()).isSameAs(ruleKey);
+ assertThat(key.toString()).isEqualTo("P1:xoo:R1");
+ }
+
+ @Test
+ public void parse() throws Exception {
+ ActiveRuleKey key = ActiveRuleKey.parse("P1:xoo:R1");
+ assertThat(key.qProfile()).isEqualTo("P1");
+ assertThat(key.ruleKey().repository()).isEqualTo("xoo");
+ assertThat(key.ruleKey().rule()).isEqualTo("R1");
+ }
+
+ @Test
+ public void equals_and_hashcode() throws Exception {
+ ActiveRuleKey key1 = ActiveRuleKey.parse("P1:xoo:R1");
+ ActiveRuleKey key1b = ActiveRuleKey.parse("P1:xoo:R1");
+ ActiveRuleKey key2 = ActiveRuleKey.parse("P1:xoo:R2");
+ ActiveRuleKey key3 = ActiveRuleKey.parse("P2:xoo:R1");
+ assertThat(key1.equals(key1)).isTrue();
+ assertThat(key1.equals(key1b)).isTrue();
+ assertThat(key1.equals(null)).isFalse();
+ assertThat(key1.equals("P1:xoo:R1")).isFalse();
+ assertThat(key1.equals(key2)).isFalse();
+ assertThat(key1.equals(key3)).isFalse();
+
+ assertThat(key1.hashCode()).isEqualTo(key1.hashCode());
+ }
+}
this.deleteDocument(additionalKey);
}
} catch (Exception e) {
- throw new IllegalStateException("Could not DELETE _id = '" + this.getKeyValue(key) + "' " +
- "for index '" + this.getIndexName() + "': " + e.getMessage());
+ throw new IllegalStateException(String.format("Could not DELETE _id = '%s' for index '%s",
+ getKeyValue(key), getIndexName()), e);
}
}
this.deleteDocument(additionalItem.getKey());
}
} catch (Exception e) {
- throw new IllegalStateException("Could not DELETE _id = '" + this.getKeyValue(item.getKey()) + "' " +
- "for index '" + this.getIndexName() + "': " + e.getMessage());
+ throw new IllegalStateException(String.format("Could not DELETE _id = '%s' for index '%s",
+ getKeyValue(item.getKey()), getIndexName()), e);
}
}
return get(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage, (String[]) availableMeasures);
}
- public List<ViewProxy<Page>> getResourceTabs() {
- return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null, null);
- }
-
public List<ViewProxy<Page>> getResourceTabs(String scope, String qualifier, String language, Object[] availableMeasures) {
return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, scope, qualifier, language, (String[]) availableMeasures);
}