From 183b104dadd5b350d4d00a1ef2336094755e5f4f Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 17 Jun 2015 18:57:35 +0200 Subject: [PATCH] Remove Hibernate entity "MeasureModel" --- .../org/sonar/core/persistence/MyBatis.java | 2 - .../main/resources/META-INF/persistence.xml | 1 - .../jpa/session/DatabaseSessionTest.java | 38 +- .../api/database/model/MeasureModel.java | 469 ------------------ .../api/database/model/ResourceModel.java | 38 -- .../sonar/api/database/model/Snapshot.java | 465 ----------------- .../api/database/model/MeasureModelTest.java | 37 -- .../api/database/model/SnapshotTest.java | 29 +- 8 files changed, 11 insertions(+), 1068 deletions(-) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureModelTest.java diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 7a646a05c29..4c7e567f7b5 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -36,7 +36,6 @@ import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.type.JdbcType; import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; -import org.sonar.api.database.model.MeasureModel; import org.sonar.api.server.ServerSide; import org.sonar.core.activity.db.ActivityDto; import org.sonar.core.activity.db.ActivityMapper; @@ -215,7 +214,6 @@ public class MyBatis { loadAlias(conf, "UserGroup", UserGroupDto.class); loadAlias(conf, "Widget", WidgetDto.class); loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class); - loadAlias(conf, "MeasureModel", MeasureModel.class); loadAlias(conf, "Measure", MeasureDto.class); loadAlias(conf, "Issue", IssueDto.class); loadAlias(conf, "IssueChange", IssueChangeDto.class); diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml index 1fef6ef6052..d8b0e5613fd 100644 --- a/sonar-core/src/main/resources/META-INF/persistence.xml +++ b/sonar-core/src/main/resources/META-INF/persistence.xml @@ -8,7 +8,6 @@ org.sonar.api.database.model.User org.sonar.api.database.model.Snapshot - org.sonar.api.database.model.MeasureModel org.sonar.api.measures.Metric org.sonar.api.database.model.ResourceModel org.sonar.api.rules.Rule diff --git a/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java b/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java index ff941b979c9..d66bd9fae00 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/session/DatabaseSessionTest.java @@ -19,26 +19,23 @@ */ package org.sonar.jpa.session; +import java.util.List; +import javax.persistence.NonUniqueResultException; import org.hamcrest.Matchers; import org.hamcrest.core.IsCollectionContaining; import org.junit.Before; import org.junit.Test; -import org.sonar.api.database.model.MeasureModel; import org.sonar.api.database.model.ResourceModel; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.jpa.dao.MeasuresDao; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import javax.persistence.NonUniqueResultException; -import java.sql.Date; -import java.util.List; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; public class DatabaseSessionTest extends AbstractDbUnitTestCase { - private static final Long NB_INSERTS = 20000l; private ResourceModel project1; private ResourceModel project2; @@ -49,25 +46,6 @@ public class DatabaseSessionTest extends AbstractDbUnitTestCase { project2 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact1", "JAV", null, "my name 2"); } - @Test - public void performanceTestOnBatchInserts() { - getSession().save(project1); - Snapshot snapshot = new Snapshot(project1, true, "", new Date(1)); - getSession().save(snapshot); - getSession().save(CoreMetrics.CLASSES); - getSession().commit(); - - Metric metric = new MeasuresDao(getSession()).getMetric(CoreMetrics.CLASSES_KEY); - for (int i = 0; i < NB_INSERTS; i++) { - MeasureModel pm = new MeasureModel(metric.getId(), 1.0).setSnapshotId(snapshot.getId()); - getSession().save(pm); - } - - getSession().commit(); - assertEquals(NB_INSERTS, getHQLCount(MeasureModel.class)); - - } - @Test public void testGetSingleResultWithNoResults() { assertNull(getSession().getSingleResult(ResourceModel.class, "name", "test")); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java deleted file mode 100644 index 4c1d8da1a22..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java +++ /dev/null @@ -1,469 +0,0 @@ -/* - * 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.api.database.model; - -import com.google.common.base.Throwables; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import javax.annotation.CheckForNull; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.database.DatabaseSession; -import org.sonar.api.measures.Metric; - -/** - * This class is the Hibernate model to store a measure in the DB - */ -@Entity -@Table(name = "project_measures") -public class MeasureModel implements Cloneable { - - public static final int TEXT_VALUE_LENGTH = 4000; - - @Id - @Column(name = "id") - @GeneratedValue - private Long id; - - @Column(name = "value", updatable = true, nullable = true, precision = 30, scale = 20) - private Double value = 0.0; - - @Column(name = "text_value", updatable = true, nullable = true, length = TEXT_VALUE_LENGTH) - private String textValue; - - @Column(name = "metric_id", updatable = false, nullable = false) - private Integer metricId; - - @Column(name = "snapshot_id", updatable = true, nullable = true) - private Integer snapshotId; - - @Column(name = "project_id", updatable = true, nullable = true) - private Integer projectId; - - @Column(name = "description", updatable = true, nullable = true, length = 4000) - private String description; - - @Column(name = "rule_id", updatable = true, nullable = true) - private Integer ruleId; - - @Column(name = "alert_status", updatable = true, nullable = true, length = 5) - private String alertStatus; - - @Column(name = "alert_text", updatable = true, nullable = true, length = 4000) - private String alertText; - - @Column(name = "variation_value_1", updatable = true, nullable = true) - private Double variationValue1; - - @Column(name = "variation_value_2", updatable = true, nullable = true) - private Double variationValue2; - - @Column(name = "variation_value_3", updatable = true, nullable = true) - private Double variationValue3; - - @Column(name = "variation_value_4", updatable = true, nullable = true) - private Double variationValue4; - - @Column(name = "variation_value_5", updatable = true, nullable = true) - private Double variationValue5; - - @Column(name = "url", updatable = true, nullable = true, length = 2000) - private String url; - - @Column(name = "characteristic_id", nullable = true) - private Integer characteristicId; - - @Column(name = "person_id", updatable = true, nullable = true) - private Integer personId; - - @Column(name = "measure_data", updatable = true, nullable = true, length = 167772150) - private byte[] data; - - /** - * Creates a measure based on a metric and a double value - */ - public MeasureModel(int metricId, Double val) { - if (val.isNaN() || val.isInfinite()) { - throw new IllegalArgumentException("Measure value is NaN. Metric=" + metricId); - } - this.metricId = metricId; - this.value = val; - } - - /** - * Creates a measure based on a metric and an alert level - */ - public MeasureModel(int metricId, Metric.Level level) { - this.metricId = metricId; - if (level != null) { - this.textValue = level.toString(); - } - } - - /** - * Creates a measure based on a metric and a string value - */ - public MeasureModel(int metricId, String val) { - this.metricId = metricId; - setData(val); - } - - /** - * Creates an empty measure - */ - public MeasureModel() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - /** - * @return the measure double value - */ - public Double getValue() { - return value; - } - - /** - * Sets the measure value - * - * @throws IllegalArgumentException in case value is not a valid double - */ - public MeasureModel setValue(Double value) { - if (value != null && (value.isNaN() || value.isInfinite())) { - throw new IllegalArgumentException(); - } - this.value = value; - return this; - } - - /** - * @return the measure description - */ - public String getDescription() { - return description; - } - - /** - * Sets the measure description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the measure alert level - */ - public Metric.Level getLevelValue() { - if (textValue != null) { - return Metric.Level.valueOf(textValue); - } - return null; - } - - /** - * Use getData() instead - */ - public String getTextValue() { - return textValue; - } - - /** - * Use setData() instead - */ - public void setTextValue(String textValue) { - this.textValue = textValue; - } - - /** - * Concept of measure trend is dropped. This method always returns {@code null} since version 5.2. - * @deprecated since 5.2. See https://jira.sonarsource.com/browse/SONAR-6392 - * @return null - */ - @CheckForNull - @Deprecated - public Integer getTendency() { - return null; - } - - /** - * Concept of measure trend is dropped. This method does nothing. - * @deprecated since 5.2. See https://jira.sonarsource.com/browse/SONAR-6392 - */ - @Deprecated - public MeasureModel setTendency(Integer tendency) { - return this; - } - - /** - * @return whether the measure is about rule - */ - public boolean isRuleMeasure() { - return ruleId != null; - } - - public Integer getMetricId() { - return metricId; - } - - public void setMetricId(Integer metricId) { - this.metricId = metricId; - } - - /** - * @return the snapshot id the measure is attached to - */ - public Integer getSnapshotId() { - return snapshotId; - } - - /** - * Sets the snapshot id - * - * @return the current object - */ - public MeasureModel setSnapshotId(Integer snapshotId) { - this.snapshotId = snapshotId; - return this; - } - - public Integer getRuleId() { - return ruleId; - } - - /** - * Sets the rule for the measure - * - * @return the current object - */ - public MeasureModel setRuleId(Integer ruleId) { - this.ruleId = ruleId; - return this; - } - - /** - * @return the project id - */ - public Integer getProjectId() { - return projectId; - } - - /** - * Sets the project id - */ - public void setProjectId(Integer projectId) { - this.projectId = projectId; - } - - /** - * @return the alert status if there is one, null otherwise - */ - public Metric.Level getAlertStatus() { - if (alertStatus == null) { - return null; - } - return Metric.Level.valueOf(alertStatus); - } - - /** - * Sets the measure alert status - * - * @return the current object - */ - public MeasureModel setAlertStatus(Metric.Level level) { - if (level != null) { - this.alertStatus = level.toString(); - } else { - this.alertStatus = null; - } - return this; - } - - /** - * @return the measure data - */ - public String getData(Metric metric) { - if (this.textValue != null) { - return this.textValue; - } - if (metric.isDataType() && data != null) { - try { - return new String(data, StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - // how is it possible to not support UTF-8 ? - Throwables.propagate(e); - } - } - return null; - } - - /** - * Sets the measure data - */ - public final void setData(String data) { - if (data == null) { - this.textValue = null; - this.data = null; - - } else { - if (data.length() > TEXT_VALUE_LENGTH) { - this.textValue = null; - this.data = data.getBytes(StandardCharsets.UTF_8); - } else { - this.textValue = data; - this.data = null; - } - } - } - - /** - * @return the text of the alert - */ - public String getAlertText() { - return alertText; - } - - /** - * Sets the text for the alert - */ - public void setAlertText(String alertText) { - this.alertText = alertText; - } - - /** - * @return the measure URL - */ - public String getUrl() { - return url; - } - - /** - * Sets the measure URL - */ - public void setUrl(String url) { - this.url = url; - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); - } - - public Double getVariationValue1() { - return variationValue1; - } - - public void setVariationValue1(Double d) { - this.variationValue1 = d; - } - - public Double getVariationValue2() { - return variationValue2; - } - - public void setVariationValue2(Double d) { - this.variationValue2 = d; - } - - public Double getVariationValue3() { - return variationValue3; - } - - public void setVariationValue3(Double d) { - this.variationValue3 = d; - } - - public Double getVariationValue4() { - return variationValue4; - } - - public void setVariationValue4(Double d) { - this.variationValue4 = d; - } - - public Double getVariationValue5() { - return variationValue5; - } - - public void setVariationValue5(Double d) { - this.variationValue5 = d; - } - - /** - * Saves the current object to database - * - * @return the current object - */ - public MeasureModel save(DatabaseSession session) { - session.save(this); - return this; - } - - public Integer getCharacteristicId() { - return characteristicId; - } - - public MeasureModel setCharacteristicId(Integer characteristicId) { - this.characteristicId = characteristicId; - return this; - } - - public Integer getPersonId() { - return personId; - } - - public MeasureModel setPersonId(Integer i) { - this.personId = i; - return this; - } - - @Override - public Object clone() { - MeasureModel clone = new MeasureModel(); - clone.setMetricId(getMetricId()); - clone.setDescription(getDescription()); - clone.setTextValue(getTextValue()); - clone.setAlertStatus(getAlertStatus()); - clone.setAlertText(getAlertText()); - clone.setVariationValue1(getVariationValue1()); - clone.setVariationValue2(getVariationValue2()); - clone.setVariationValue3(getVariationValue3()); - clone.setVariationValue4(getVariationValue4()); - clone.setVariationValue5(getVariationValue5()); - clone.setValue(getValue()); - clone.setRuleId(getRuleId()); - clone.setSnapshotId(getSnapshotId()); - clone.setUrl(getUrl()); - clone.setCharacteristicId(getCharacteristicId()); - clone.setPersonId(getPersonId()); - return clone; - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java index 832885dfc8a..3d849817425 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java @@ -368,42 +368,4 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable, Serial .toString(); } - @Override - public Object clone() { - ResourceModel clone = new ResourceModel(getScope(), getKey(), getQualifier(), getRootId(), getPath(), getName()); - clone.setDescription(getDescription()); - clone.setDeprecatedKey(getDeprecatedKey()); - clone.setEnabled(getEnabled()); - clone.setLanguageKey(getLanguageKey()); - clone.setCopyResourceId(getCopyResourceId()); - clone.setLongName(getLongName()); - clone.setPersonId(getPersonId()); - clone.setCreatedAt(getCreatedAt()); - return clone; - } - - /** - * Maps a resource to a resource model and returns the resource - */ - public static ResourceModel build(Resource resource) { - ResourceModel model = new ResourceModel(); - model.setEnabled(Boolean.TRUE); - model.setDescription(resource.getDescription()); - model.setKey(resource.getEffectiveKey()); - model.setPath(resource.getPath()); - Language lang = resource.getLanguage(); - if (lang != null) { - model.setLanguageKey(lang.getKey()); - } - if (StringUtils.isNotBlank(resource.getName())) { - model.setName(resource.getName()); - } else { - model.setName(resource.getKey()); - } - model.setLongName(resource.getLongName()); - model.setQualifier(resource.getQualifier()); - model.setScope(resource.getScope()); - return model; - } - } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java index 063e927ecc2..3faf0a24764 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java @@ -29,7 +29,6 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.database.BaseIdentifiable; -import org.sonar.api.database.DatabaseSession; import static org.sonar.api.utils.DateUtils.dateToLong; import static org.sonar.api.utils.DateUtils.longToDate; @@ -142,75 +141,6 @@ public class Snapshot extends BaseIdentifiable implements Serializable } - public Snapshot(ResourceModel resource, Snapshot parent) { - this.resourceId = resource.getId(); - this.qualifier = resource.getQualifier(); - this.scope = resource.getScope(); - - if (parent == null) { - path = ""; - depth = 0; - this.createdAt = System.currentTimeMillis(); - - } else { - this.parentId = parent.getId(); - this.rootId = (parent.getRootId() == null ? parent.getId() : parent.getRootId()); - this.createdAt = parent.getCreatedAtMs(); - this.depth = parent.getDepth() + 1; - this.path = new StringBuilder() - .append(parent.getPath()) - .append(parent.getId()) - .append(".") - .toString(); - } - this.rootProjectId = guessRootProjectId(resource, parent); - } - - public Snapshot(ResourceModel resource, boolean last, String status, Date date) { - this(); - setResource(resource); - this.status = status; - this.last = last; - this.createdAt = date.getTime(); - } - - private static Integer guessRootProjectId(ResourceModel resource, Snapshot parent) { - Integer result; - if (parent == null) { - result = resource.getId(); - } else { - result = (parent.getRootProjectId() == null ? parent.getResourceId() : parent.getRootProjectId()); - } - return result; - } - - public Snapshot save(DatabaseSession session) { - return session.save(this); - } - - /** - * Insertion date (technical) - * - * @since 2.14 - */ - public Date getBuildDate() { - return longToDate(buildDate); - } - - /** - * Insertion date (technical) - * - * @since 2.14 - */ - public Snapshot setBuildDate(Date date) { - this.buildDate = dateToLong(date); - return this; - } - - public Long getBuildDateMs() { - return buildDate; - } - public Snapshot setBuildDateMs(Long d) { this.buildDate = d; return this; @@ -286,21 +216,6 @@ public class Snapshot extends BaseIdentifiable implements Serializable return this; } - /** - * @since 2.14 - */ - public Integer getPurgeStatus() { - return purgeStatus; - } - - /** - * @since 2.14 - */ - public Snapshot setPurgeStatus(Integer i) { - this.purgeStatus = i; - return this; - } - public String getScope() { return scope; } @@ -362,289 +277,6 @@ public class Snapshot extends BaseIdentifiable implements Serializable return this; } - public String getPeriod1Mode() { - return period1Mode; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod1Mode(String s) { - this.period1Mode = s; - return this; - } - - public String getPeriod2Mode() { - return period2Mode; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod2Mode(String s) { - this.period2Mode = s; - return this; - } - - public String getPeriod3Mode() { - return period3Mode; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod3Mode(String s) { - this.period3Mode = s; - return this; - } - - public String getPeriod4Mode() { - return period4Mode; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod4Mode(String s) { - this.period4Mode = s; - return this; - } - - public String getPeriod5Mode() { - return period5Mode; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod5Mode(String s) { - this.period5Mode = s; - return this; - } - - public String getPeriod1Param() { - return period1Param; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod1Param(String s) { - this.period1Param = s; - return this; - } - - public String getPeriod2Param() { - return period2Param; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod2Param(String s) { - this.period2Param = s; - return this; - } - - public String getPeriod3Param() { - return period3Param; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod3Param(String s) { - this.period3Param = s; - return this; - } - - public String getPeriod4Param() { - return period4Param; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod4Param(String s) { - this.period4Param = s; - return this; - } - - public String getPeriod5Param() { - return period5Param; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod5Param(String s) { - this.period5Param = s; - return this; - } - - public Date getPeriod1Date() { - return longToDate(period1Date); - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod1Date(Date period1Date) { - this.period1Date = dateToLong(period1Date); - return this; - } - - public Long getPeriod1DateMs() { - return period1Date; - } - - public Snapshot setPeriod1DateMs(Long period1Date) { - this.period1Date = period1Date; - return this; - } - - public Date getPeriod2Date() { - return longToDate(period2Date); - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod2Date(Date period2Date) { - this.period2Date = dateToLong(period2Date); - return this; - } - - public Long getPeriod2DateMs() { - return period2Date; - } - - public Snapshot setPeriod2DateMs(Long period2Date) { - this.period2Date = period2Date; - return this; - } - - public Date getPeriod3Date() { - return longToDate(period3Date); - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod3Date(Date period3Date) { - this.period3Date = dateToLong(period3Date); - return this; - } - - public Long getPeriod3DateMs() { - return period3Date; - } - - public Snapshot setPeriod3DateMs(Long period3Date) { - this.period3Date = period3Date; - return this; - } - - public Date getPeriod4Date() { - return longToDate(period4Date); - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod4Date(Date period4Date) { - this.period4Date = dateToLong(period4Date); - return this; - } - - public Long getPeriod4DateMs() { - return period4Date; - } - - public Snapshot setPeriod4DateMs(Long period4Date) { - this.period4Date = period4Date; - return this; - } - - public Date getPeriod5Date() { - return longToDate(period5Date); - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriod5Date(Date period5Date) { - this.period5Date = dateToLong(period5Date); - return this; - } - - public Long getPeriod5DateMs() { - return period5Date; - } - - public Snapshot setPeriod5DateMs(Long period5Date) { - this.period5Date = period5Date; - return this; - } - - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriodMode(int periodIndex, String s) { - switch (periodIndex) { - case 1: - period1Mode = s; - break; - case 2: - period2Mode = s; - break; - case 3: - period3Mode = s; - break; - case 4: - period4Mode = s; - break; - case 5: - period5Mode = s; - break; - default: - throw newPeriodIndexOutOfBoundsException("periodMode"); - } - return this; - } - public String getPeriodMode(int index) { switch (index) { case 1: @@ -662,34 +294,6 @@ public class Snapshot extends BaseIdentifiable implements Serializable } } - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriodModeParameter(int periodIndex, String s) { - switch (periodIndex) { - case 1: - period1Param = s; - break; - case 2: - period2Param = s; - break; - case 3: - period3Param = s; - break; - case 4: - period4Param = s; - break; - case 5: - period5Param = s; - break; - default: - throw newPeriodIndexOutOfBoundsException("periodParameter"); - } - return this; - } - public String getPeriodModeParameter(int periodIndex) { switch (periodIndex) { case 1: @@ -707,75 +311,6 @@ public class Snapshot extends BaseIdentifiable implements Serializable } } - /** - * For internal use. - * - * @since 2.5 - */ - public Snapshot setPeriodDate(int periodIndex, Date date) { - Long time = dateToLong(date); - switch (periodIndex) { - case 1: - period1Date = time; - break; - case 2: - period2Date = time; - break; - case 3: - period3Date = time; - break; - case 4: - period4Date = time; - break; - case 5: - period5Date = time; - break; - default: - throw newPeriodIndexOutOfBoundsException("periodDate"); - } - return this; - } - - public Snapshot setPeriodDateMs(int periodIndex, Long date) { - switch (periodIndex) { - case 1: - period1Date = date; - break; - case 2: - period2Date = date; - break; - case 3: - period3Date = date; - break; - case 4: - period4Date = date; - break; - case 5: - period5Date = date; - break; - default: - throw newPeriodIndexOutOfBoundsException("periodDate"); - } - return this; - } - - public Date getPeriodDate(int periodIndex) { - switch (periodIndex) { - case 1: - return longToDate(period1Date); - case 2: - return longToDate(period2Date); - case 3: - return longToDate(period3Date); - case 4: - return longToDate(period4Date); - case 5: - return longToDate(period5Date); - default: - throw newPeriodIndexOutOfBoundsException("periodDate"); - } - } - public Long getPeriodDateMs(int periodIndex) { switch (periodIndex) { case 1: diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureModelTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureModelTest.java deleted file mode 100644 index b78feea7328..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureModelTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.api.database.model; - -import org.junit.Test; -import org.sonar.api.measures.CoreMetrics; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MeasureModelTest { - @Test - public void text_is_utf8() { - String s = "accents éà and special characters ç€"; - - MeasureModel measure = new MeasureModel(); - measure.setData(s); - - assertThat(measure.getData(CoreMetrics.DUPLICATIONS_DATA)).isEqualTo(s); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java index 148572c83fb..adcbe3466a3 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java @@ -21,8 +21,9 @@ package org.sonar.api.database.model; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class SnapshotTest { @@ -59,28 +60,4 @@ public class SnapshotTest { assertEquals(Boolean.FALSE, snapshot.getLast()); } - @Test - public void testRootProjectIdOfProjects() { - ResourceModel resource = new ResourceModel(); - resource.setQualifier("TRK"); - resource.setId(3); - - Snapshot snapshot = new Snapshot(resource, null); - assertThat(snapshot.getRootProjectId(), is(3)); - } - - @Test - public void testRootProjectIdOfModules() { - ResourceModel parentResource = new ResourceModel(); - parentResource.setId(3); - parentResource.setQualifier("TRK"); - Snapshot parentSnapshot = new Snapshot(parentResource, null); - - ResourceModel resource = new ResourceModel(); - resource.setId(4); - resource.setQualifier("BRC"); - Snapshot snapshot = new Snapshot(resource, parentSnapshot); - assertThat(snapshot.getRootProjectId(), is(3)); - } - } -- 2.39.5