diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-02-04 10:42:21 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-02-04 10:42:21 +0100 |
commit | a14a0644c2a27ddec22f23925578a40aa6fa8302 (patch) | |
tree | aa5c078cc8ec7c4e2020960ad9a343fb7e79a16c /sonar-core | |
parent | 0f44a42b85093a3dcef64b52f6e15337b119ec88 (diff) | |
download | sonarqube-a14a0644c2a27ddec22f23925578a40aa6fa8302.tar.gz sonarqube-a14a0644c2a27ddec22f23925578a40aa6fa8302.zip |
Upgrade copyright headers
Diffstat (limited to 'sonar-core')
77 files changed, 1122 insertions, 1122 deletions
diff --git a/sonar-core/src/main/java/org/sonar/api/database/configuration/DatabaseConfiguration.java b/sonar-core/src/main/java/org/sonar/api/database/configuration/DatabaseConfiguration.java index cd945c5425b..70b49625d69 100644 --- a/sonar-core/src/main/java/org/sonar/api/database/configuration/DatabaseConfiguration.java +++ b/sonar-core/src/main/java/org/sonar/api/database/configuration/DatabaseConfiguration.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/api/database/configuration/Property.java b/sonar-core/src/main/java/org/sonar/api/database/configuration/Property.java index efafbcc508d..f464c73adb6 100644 --- a/sonar-core/src/main/java/org/sonar/api/database/configuration/Property.java +++ b/sonar-core/src/main/java/org/sonar/api/database/configuration/Property.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/api/database/configuration/ResourceDatabaseConfiguration.java b/sonar-core/src/main/java/org/sonar/api/database/configuration/ResourceDatabaseConfiguration.java index 4cead063e31..d53ea7f6f61 100644 --- a/sonar-core/src/main/java/org/sonar/api/database/configuration/ResourceDatabaseConfiguration.java +++ b/sonar-core/src/main/java/org/sonar/api/database/configuration/ResourceDatabaseConfiguration.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java b/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java index ac3b0f6afab..9df43699ec8 100644 --- a/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java +++ b/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java b/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java index 2944b8547e5..8e871d084c2 100644 --- a/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java +++ b/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java b/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java index 7b42df06bb7..6e2ab843b58 100644 --- a/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/components/CacheMetricFinder.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java index 1e0b747bb61..cf31ad3a525 100644 --- a/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/components/DefaultMetricFinder.java b/sonar-core/src/main/java/org/sonar/core/components/DefaultMetricFinder.java index 12eaf9c68c5..e3165f32915 100644 --- a/sonar-core/src/main/java/org/sonar/core/components/DefaultMetricFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/components/DefaultMetricFinder.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java b/sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java index a7a04c7cf24..cbddb421088 100644 --- a/sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/components/DefaultModelFinder.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java index 3c0d50e7bcd..2b0318c14b0 100644 --- a/sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/components/DefaultRuleFinder.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java b/sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java index a1e51e95d9a..0d4f65e89f4 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java +++ b/sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java index 22b6772d874..a842173f3a2 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java +++ b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginDao.java b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginDao.java index 1fe44ab9e7b..2f7f241cf5f 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginDao.java +++ b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginDao.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginFile.java b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginFile.java index 03c4934e4aa..4deef0f3c64 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginFile.java +++ b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPluginFile.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java index 4c8c71b0b72..5f09d281a97 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresDao.java @@ -1,196 +1,196 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.AsyncMeasureSnapshot;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import java.util.Date;
-import java.util.List;
-
-public class AsyncMeasuresDao extends BaseDao {
-
- public AsyncMeasuresDao(DatabaseSession session) {
- super(session);
- }
-
- public MeasureModel getAsyncMeasure(Long asyncMeasureId) {
- return getSession().getEntityManager().find(MeasureModel.class, asyncMeasureId);
- }
-
- public void deleteAsyncMeasure(MeasureModel asyncMeasure) {
- deleteAsyncMeasureSnapshots(asyncMeasure.getId());
- getSession().remove(asyncMeasure);
- }
-
- public Snapshot getPreviousSnapshot(Snapshot s) {
- try {
- return (Snapshot) getSession().createQuery(
- "SELECT s FROM Snapshot s " +
- "WHERE s.createdAt<:date " +
- "AND s.scope=:scope " +
- "AND s.resourceId=:resourceId " +
- "ORDER BY s.createdAt DESC")
- .setParameter("date", s.getCreatedAt())
- .setParameter("scope", s.getScope())
- .setParameter("resourceId", s.getResourceId())
- .setMaxResults(1)
- .getSingleResult();
- } catch (NoResultException ex) {
- return null;
- }
- }
-
- public List<Snapshot> getNextSnapshotsUntilDate(MeasureModel measure, Date date) {
- Query query = getSession().createQuery(
- "SELECT s FROM Snapshot s " +
- "WHERE s.resourceId=:projectId " +
- "AND s.createdAt>=:beginDate " +
- (date != null ? "AND s.createdAt<:endDate " : "") +
- "AND s.scope=:scope " +
- "ORDER BY s.createdAt ASC ")
- .setParameter("projectId", measure.getProjectId())
- .setParameter("beginDate", measure.getMeasureDate())
- .setParameter("scope", ResourceModel.SCOPE_PROJECT);
- if (date != null) {
- query.setParameter("endDate", date);
- }
- return query.getResultList();
- }
-
- public AsyncMeasureSnapshot createAsyncMeasureSnapshot(Long asyncMeasureId, Integer snapshotId, Date AsyncMeasureDate, Date snapshotDate, Integer metricId, Integer projectId) {
- AsyncMeasureSnapshot asyncMeasureSnapshot = new AsyncMeasureSnapshot(asyncMeasureId, snapshotId, AsyncMeasureDate, snapshotDate, metricId, projectId);
- getSession().save(asyncMeasureSnapshot);
- return asyncMeasureSnapshot;
- }
-
- public void updateAsyncMeasureSnapshot(AsyncMeasureSnapshot asyncMeasureSnapshot, Snapshot snapshot) {
- if (snapshot != null) {
- asyncMeasureSnapshot.setSnapshotId(snapshot.getId());
- asyncMeasureSnapshot.setSnapshotDate(snapshot.getCreatedAt());
- } else {
- asyncMeasureSnapshot.setSnapshotId(null);
- asyncMeasureSnapshot.setSnapshotDate(null);
- }
- getSession().merge(asyncMeasureSnapshot);
- }
-
- public void removeSnapshotFromAsyncMeasureSnapshot(AsyncMeasureSnapshot asyncMeasureSnapshot) {
- asyncMeasureSnapshot.setSnapshotId(null);
- asyncMeasureSnapshot.setSnapshotDate(null);
- getSession().merge(asyncMeasureSnapshot);
- }
-
-
- public AsyncMeasureSnapshot getNextAsyncMeasureSnapshot(Integer projetcId, Integer metricId, Date date) {
- try {
- return (AsyncMeasureSnapshot) getSession().createQuery(
- "SELECT ams FROM AsyncMeasureSnapshot ams " +
- "WHERE ams.projectId=:projectId " +
- "AND ams.metricId=:metricId " +
- "AND ams.measureDate>:date " +
- "ORDER BY ams.measureDate ASC")
- .setParameter("projectId", projetcId)
- .setParameter("metricId", metricId)
- .setParameter("date", date)
- .setMaxResults(1)
- .getSingleResult();
- } catch (NoResultException ex) {
- return null;
- }
- }
-
- public List<AsyncMeasureSnapshot> getNextAsyncMeasureSnapshotsUntilDate(MeasureModel asyncMeasure, Date endDate) {
- Query query = getSession().createQuery(
- "SELECT ams FROM AsyncMeasureSnapshot ams " +
- "WHERE ams.projectId=:projectId " +
- "AND ams.metricId=:metricId " +
- (endDate != null ? "AND ams.measureDate<:endDate " : "") +
- "AND ams.snapshotDate>=:measureDate " +
- "ORDER BY ams.snapshotDate ASC ")
- .setParameter("projectId", asyncMeasure.getProjectId())
- .setParameter("metricId", asyncMeasure.getMetricId())
- .setParameter("measureDate", asyncMeasure.getMeasureDate());
- if (endDate != null) {
- query.setParameter("endDate", endDate);
- }
- return query.getResultList();
- }
-
- public List<AsyncMeasureSnapshot> getPreviousAsyncMeasureSnapshots(Integer projectId, Date beginDate, Date endDate) {
- Query query = getSession().createQuery(
- "SELECT ams FROM AsyncMeasureSnapshot ams " +
- "WHERE ams.projectId=:projectId " +
- "AND ams.measureDate<=:endDate " +
- (beginDate != null ? "AND ams.measureDate>:beginDate " : "") +
- "AND ams.snapshotId IS NULL " +
- "ORDER BY ams.measureDate ASC")
- .setParameter("projectId", projectId)
- .setParameter("endDate", endDate);
- if (beginDate != null) {
- query.setParameter("beginDate", beginDate);
- }
- return query.getResultList();
- }
-
- public List<AsyncMeasureSnapshot> getAsyncMeasureSnapshotsFromSnapshotId(Integer snapshotId, List<Integer> metricIdsToExclude) {
- Query query = getSession().createQuery(
- "SELECT ams FROM AsyncMeasureSnapshot ams " +
- "WHERE ams.snapshotId=:snapshotId " +
- (!metricIdsToExclude.isEmpty() ? "AND ams.metricId NOT IN (:metricIdsToExclude) " : "") +
- "ORDER BY ams.measureDate ASC")
- .setParameter("snapshotId", snapshotId);
- if (!metricIdsToExclude.isEmpty()) {
- query.setParameter("metricIdsToExclude", metricIdsToExclude);
- }
- return query.getResultList();
- }
-
- public AsyncMeasureSnapshot getLastAsyncMeasureSnapshot(Integer projetcId, Integer metricId, Date date) {
- try {
- return (AsyncMeasureSnapshot) getSession().createQuery(
- "SELECT ams FROM AsyncMeasureSnapshot ams " +
- "WHERE ams.projectId=:projectId " +
- "AND ams.metricId=:metricId " +
- "AND ams.measureDate<:date " +
- "ORDER BY ams.measureDate DESC")
- .setParameter("projectId", projetcId)
- .setParameter("metricId", metricId)
- .setParameter("date", date)
- .setMaxResults(1)
- .getSingleResult();
- } catch (NoResultException ex) {
- return null;
- }
- }
-
- public void deleteAsyncMeasureSnapshots(Long asyncMeasureId) {
- getSession().createQuery(
- "DELETE FROM AsyncMeasureSnapshot ams WHERE ams.measureId=:measureId")
- .setParameter("measureId", asyncMeasureId)
- .executeUpdate();
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.sonar.api.database.DatabaseSession; +import org.sonar.api.database.model.AsyncMeasureSnapshot; +import org.sonar.api.database.model.MeasureModel; +import org.sonar.api.database.model.ResourceModel; +import org.sonar.api.database.model.Snapshot; + +import javax.persistence.NoResultException; +import javax.persistence.Query; +import java.util.Date; +import java.util.List; + +public class AsyncMeasuresDao extends BaseDao { + + public AsyncMeasuresDao(DatabaseSession session) { + super(session); + } + + public MeasureModel getAsyncMeasure(Long asyncMeasureId) { + return getSession().getEntityManager().find(MeasureModel.class, asyncMeasureId); + } + + public void deleteAsyncMeasure(MeasureModel asyncMeasure) { + deleteAsyncMeasureSnapshots(asyncMeasure.getId()); + getSession().remove(asyncMeasure); + } + + public Snapshot getPreviousSnapshot(Snapshot s) { + try { + return (Snapshot) getSession().createQuery( + "SELECT s FROM Snapshot s " + + "WHERE s.createdAt<:date " + + "AND s.scope=:scope " + + "AND s.resourceId=:resourceId " + + "ORDER BY s.createdAt DESC") + .setParameter("date", s.getCreatedAt()) + .setParameter("scope", s.getScope()) + .setParameter("resourceId", s.getResourceId()) + .setMaxResults(1) + .getSingleResult(); + } catch (NoResultException ex) { + return null; + } + } + + public List<Snapshot> getNextSnapshotsUntilDate(MeasureModel measure, Date date) { + Query query = getSession().createQuery( + "SELECT s FROM Snapshot s " + + "WHERE s.resourceId=:projectId " + + "AND s.createdAt>=:beginDate " + + (date != null ? "AND s.createdAt<:endDate " : "") + + "AND s.scope=:scope " + + "ORDER BY s.createdAt ASC ") + .setParameter("projectId", measure.getProjectId()) + .setParameter("beginDate", measure.getMeasureDate()) + .setParameter("scope", ResourceModel.SCOPE_PROJECT); + if (date != null) { + query.setParameter("endDate", date); + } + return query.getResultList(); + } + + public AsyncMeasureSnapshot createAsyncMeasureSnapshot(Long asyncMeasureId, Integer snapshotId, Date AsyncMeasureDate, Date snapshotDate, Integer metricId, Integer projectId) { + AsyncMeasureSnapshot asyncMeasureSnapshot = new AsyncMeasureSnapshot(asyncMeasureId, snapshotId, AsyncMeasureDate, snapshotDate, metricId, projectId); + getSession().save(asyncMeasureSnapshot); + return asyncMeasureSnapshot; + } + + public void updateAsyncMeasureSnapshot(AsyncMeasureSnapshot asyncMeasureSnapshot, Snapshot snapshot) { + if (snapshot != null) { + asyncMeasureSnapshot.setSnapshotId(snapshot.getId()); + asyncMeasureSnapshot.setSnapshotDate(snapshot.getCreatedAt()); + } else { + asyncMeasureSnapshot.setSnapshotId(null); + asyncMeasureSnapshot.setSnapshotDate(null); + } + getSession().merge(asyncMeasureSnapshot); + } + + public void removeSnapshotFromAsyncMeasureSnapshot(AsyncMeasureSnapshot asyncMeasureSnapshot) { + asyncMeasureSnapshot.setSnapshotId(null); + asyncMeasureSnapshot.setSnapshotDate(null); + getSession().merge(asyncMeasureSnapshot); + } + + + public AsyncMeasureSnapshot getNextAsyncMeasureSnapshot(Integer projetcId, Integer metricId, Date date) { + try { + return (AsyncMeasureSnapshot) getSession().createQuery( + "SELECT ams FROM AsyncMeasureSnapshot ams " + + "WHERE ams.projectId=:projectId " + + "AND ams.metricId=:metricId " + + "AND ams.measureDate>:date " + + "ORDER BY ams.measureDate ASC") + .setParameter("projectId", projetcId) + .setParameter("metricId", metricId) + .setParameter("date", date) + .setMaxResults(1) + .getSingleResult(); + } catch (NoResultException ex) { + return null; + } + } + + public List<AsyncMeasureSnapshot> getNextAsyncMeasureSnapshotsUntilDate(MeasureModel asyncMeasure, Date endDate) { + Query query = getSession().createQuery( + "SELECT ams FROM AsyncMeasureSnapshot ams " + + "WHERE ams.projectId=:projectId " + + "AND ams.metricId=:metricId " + + (endDate != null ? "AND ams.measureDate<:endDate " : "") + + "AND ams.snapshotDate>=:measureDate " + + "ORDER BY ams.snapshotDate ASC ") + .setParameter("projectId", asyncMeasure.getProjectId()) + .setParameter("metricId", asyncMeasure.getMetricId()) + .setParameter("measureDate", asyncMeasure.getMeasureDate()); + if (endDate != null) { + query.setParameter("endDate", endDate); + } + return query.getResultList(); + } + + public List<AsyncMeasureSnapshot> getPreviousAsyncMeasureSnapshots(Integer projectId, Date beginDate, Date endDate) { + Query query = getSession().createQuery( + "SELECT ams FROM AsyncMeasureSnapshot ams " + + "WHERE ams.projectId=:projectId " + + "AND ams.measureDate<=:endDate " + + (beginDate != null ? "AND ams.measureDate>:beginDate " : "") + + "AND ams.snapshotId IS NULL " + + "ORDER BY ams.measureDate ASC") + .setParameter("projectId", projectId) + .setParameter("endDate", endDate); + if (beginDate != null) { + query.setParameter("beginDate", beginDate); + } + return query.getResultList(); + } + + public List<AsyncMeasureSnapshot> getAsyncMeasureSnapshotsFromSnapshotId(Integer snapshotId, List<Integer> metricIdsToExclude) { + Query query = getSession().createQuery( + "SELECT ams FROM AsyncMeasureSnapshot ams " + + "WHERE ams.snapshotId=:snapshotId " + + (!metricIdsToExclude.isEmpty() ? "AND ams.metricId NOT IN (:metricIdsToExclude) " : "") + + "ORDER BY ams.measureDate ASC") + .setParameter("snapshotId", snapshotId); + if (!metricIdsToExclude.isEmpty()) { + query.setParameter("metricIdsToExclude", metricIdsToExclude); + } + return query.getResultList(); + } + + public AsyncMeasureSnapshot getLastAsyncMeasureSnapshot(Integer projetcId, Integer metricId, Date date) { + try { + return (AsyncMeasureSnapshot) getSession().createQuery( + "SELECT ams FROM AsyncMeasureSnapshot ams " + + "WHERE ams.projectId=:projectId " + + "AND ams.metricId=:metricId " + + "AND ams.measureDate<:date " + + "ORDER BY ams.measureDate DESC") + .setParameter("projectId", projetcId) + .setParameter("metricId", metricId) + .setParameter("date", date) + .setMaxResults(1) + .getSingleResult(); + } catch (NoResultException ex) { + return null; + } + } + + public void deleteAsyncMeasureSnapshots(Long asyncMeasureId) { + getSession().createQuery( + "DELETE FROM AsyncMeasureSnapshot ams WHERE ams.measureId=:measureId") + .setParameter("measureId", asyncMeasureId) + .executeUpdate(); + } + +} diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java index 26b1926b901..e985ee3c614 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/AsyncMeasuresService.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/BaseDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/BaseDao.java index 3c5f441bf43..f493c31795a 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/BaseDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/BaseDao.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java b/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java index 078b5c65396..fad86b13ce3 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/DaoFacade.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java index 77303c1c9ba..6501e981a32 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java @@ -1,120 +1,120 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.Predicate;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.measures.Metric;
-
-import java.util.*;
-
-public class MeasuresDao extends BaseDao {
-
- private final Map<String, Metric> metricsByName = new HashMap<String, Metric>();
-
- public MeasuresDao(DatabaseSession session) {
- super(session);
- }
-
- public Metric getMetric(Metric metric) {
- return getMetricsByName().get(metric.getKey());
- }
-
- public List<Metric> getMetrics(List<Metric> metrics) {
- List<Metric> result = new ArrayList<Metric>();
- for (Metric metric : metrics) {
- result.add(getMetric(metric));
- }
- return result;
- }
-
- public Metric getMetric(String metricName) {
- return getMetricsByName().get(metricName);
- }
-
- public Collection<Metric> getMetrics() {
- return getMetricsByName().values();
- }
-
- public Collection<Metric> getEnabledMetrics() {
- return CollectionUtils.select(getMetricsByName().values(), new Predicate() {
- public boolean evaluate(Object o) {
- return ((Metric) o).getEnabled();
- }
- });
- }
-
- public Collection<Metric> getUserDefinedMetrics() {
- return CollectionUtils.select(getMetricsByName().values(), new Predicate() {
- public boolean evaluate(Object o) {
- Metric m = (Metric) o;
- return (m.getEnabled() && m.getOrigin() != Metric.Origin.JAV);
- }
- });
- }
-
- public void disableAutomaticMetrics() {
- getSession().createQuery("update " + Metric.class.getSimpleName() + " m set m.enabled=false where m.userManaged=false").executeUpdate();
- getSession().commit();
- metricsByName.clear();
- }
-
- public void registerMetrics(Collection<Metric> metrics) {
- if (metrics != null) {
- for (Metric metric : metrics) {
- metric.setEnabled(Boolean.TRUE);
- persistMetric(metric);
- }
- getSession().commit();
- }
- }
-
- public void persistMetric(Metric metric) {
- Metric dbMetric = getMetric(metric);
- if (dbMetric != null) {
- dbMetric.merge(metric);
- getSession().getEntityManager().merge(dbMetric);
-
- } else {
- getSession().getEntityManager().persist(metric);
- }
-
- metricsByName.clear();
- }
-
- public void disabledMetrics(Collection<Metric> metrics) {
- for (Metric metric : metrics) {
- metric.setEnabled(Boolean.FALSE);
- getSession().getEntityManager().persist(metric);
- metricsByName.put(metric.getName(), metric);
- }
- }
-
- private Map<String, Metric> getMetricsByName() {
- if (metricsByName.isEmpty()) {
- List<Metric> metrics = getSession().getResults(Metric.class);
- for (Metric metric : metrics) {
- metricsByName.put(metric.getKey(), metric);
- }
- }
- return metricsByName;
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import org.sonar.api.database.DatabaseSession; +import org.sonar.api.measures.Metric; + +import java.util.*; + +public class MeasuresDao extends BaseDao { + + private final Map<String, Metric> metricsByName = new HashMap<String, Metric>(); + + public MeasuresDao(DatabaseSession session) { + super(session); + } + + public Metric getMetric(Metric metric) { + return getMetricsByName().get(metric.getKey()); + } + + public List<Metric> getMetrics(List<Metric> metrics) { + List<Metric> result = new ArrayList<Metric>(); + for (Metric metric : metrics) { + result.add(getMetric(metric)); + } + return result; + } + + public Metric getMetric(String metricName) { + return getMetricsByName().get(metricName); + } + + public Collection<Metric> getMetrics() { + return getMetricsByName().values(); + } + + public Collection<Metric> getEnabledMetrics() { + return CollectionUtils.select(getMetricsByName().values(), new Predicate() { + public boolean evaluate(Object o) { + return ((Metric) o).getEnabled(); + } + }); + } + + public Collection<Metric> getUserDefinedMetrics() { + return CollectionUtils.select(getMetricsByName().values(), new Predicate() { + public boolean evaluate(Object o) { + Metric m = (Metric) o; + return (m.getEnabled() && m.getOrigin() != Metric.Origin.JAV); + } + }); + } + + public void disableAutomaticMetrics() { + getSession().createQuery("update " + Metric.class.getSimpleName() + " m set m.enabled=false where m.userManaged=false").executeUpdate(); + getSession().commit(); + metricsByName.clear(); + } + + public void registerMetrics(Collection<Metric> metrics) { + if (metrics != null) { + for (Metric metric : metrics) { + metric.setEnabled(Boolean.TRUE); + persistMetric(metric); + } + getSession().commit(); + } + } + + public void persistMetric(Metric metric) { + Metric dbMetric = getMetric(metric); + if (dbMetric != null) { + dbMetric.merge(metric); + getSession().getEntityManager().merge(dbMetric); + + } else { + getSession().getEntityManager().persist(metric); + } + + metricsByName.clear(); + } + + public void disabledMetrics(Collection<Metric> metrics) { + for (Metric metric : metrics) { + metric.setEnabled(Boolean.FALSE); + getSession().getEntityManager().persist(metric); + metricsByName.put(metric.getName(), metric); + } + } + + private Map<String, Metric> getMetricsByName() { + if (metricsByName.isEmpty()) { + List<Metric> metrics = getSession().getResults(Metric.class); + for (Metric metric : metrics) { + metricsByName.put(metric.getKey(), metric); + } + } + return metricsByName; + } +} diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java index ba1eb21cf80..86ea45a7aa9 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/ProfilesDao.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java index b90e8afe852..4870ad168e7 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/RulesDao.java @@ -1,65 +1,65 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.RuleFailureModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleParam;
-
-import java.util.Iterator;
-import java.util.List;
-
-public class RulesDao extends BaseDao {
-
- public RulesDao(DatabaseSession session) {
- super(session);
- }
-
- public List<Rule> getRules() {
- return getSession().getResults(Rule.class, "enabled", true);
- }
-
- public List<Rule> getRulesByRepository(String repositoryKey) {
- return getSession().getResults(Rule.class, "pluginName", repositoryKey, "enabled", true);
- }
-
- /**
- * @deprecated since 2.5 use {@link #getRulesByRepository(String)} instead.
- */
- @Deprecated
- public List<Rule> getRulesByPlugin(String pluginKey) {
- return getRulesByRepository(pluginKey);
- }
-
- public Rule getRuleByKey(String repositoryKey, String ruleKey) {
- return getSession().getSingleResult(Rule.class, "key", ruleKey, "pluginName", repositoryKey, "enabled", true);
- }
-
-
- public RuleParam getRuleParam(Rule rule, String paramKey) {
- return getSession().getSingleResult(RuleParam.class, "rule", rule, "key", paramKey);
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.sonar.api.database.DatabaseSession; +import org.sonar.api.database.model.RuleFailureModel; +import org.sonar.api.database.model.Snapshot; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.ActiveRule; +import org.sonar.api.rules.ActiveRuleParam; +import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RuleParam; + +import java.util.Iterator; +import java.util.List; + +public class RulesDao extends BaseDao { + + public RulesDao(DatabaseSession session) { + super(session); + } + + public List<Rule> getRules() { + return getSession().getResults(Rule.class, "enabled", true); + } + + public List<Rule> getRulesByRepository(String repositoryKey) { + return getSession().getResults(Rule.class, "pluginName", repositoryKey, "enabled", true); + } + + /** + * @deprecated since 2.5 use {@link #getRulesByRepository(String)} instead. + */ + @Deprecated + public List<Rule> getRulesByPlugin(String pluginKey) { + return getRulesByRepository(pluginKey); + } + + public Rule getRuleByKey(String repositoryKey, String ruleKey) { + return getSession().getSingleResult(Rule.class, "key", ruleKey, "pluginName", repositoryKey, "enabled", true); + } + + + public RuleParam getRuleParam(Rule rule, String paramKey) { + return getSession().getSingleResult(RuleParam.class, "rule", rule, "key", paramKey); + } + +} diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java index ec54f8f059a..b0c0ec5614d 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java index 0f860ae4e32..8a265b59430 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/Dialect.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/DialectRepository.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/DialectRepository.java index e05c3b92329..48d06331084 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/DialectRepository.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/DialectRepository.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java index b6bb3a68392..b8440a7efa3 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/HsqlDb.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java index f59c2ee4240..8e480719c2a 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/MsSql.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java index 180dec0b1ee..694e1335793 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/MySql.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java index ebec6753619..990e617e1d0 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/Oracle.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/OracleSequenceGenerator.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/OracleSequenceGenerator.java index 7fa1abfa2d1..b62af9d9b45 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/OracleSequenceGenerator.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/OracleSequenceGenerator.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSQLSequenceGenerator.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSQLSequenceGenerator.java index 12094ba0745..a04390c2b3e 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSQLSequenceGenerator.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSQLSequenceGenerator.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java b/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java index 7d7318e51eb..b7741722b9d 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dialect/PostgreSql.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index 921cbcab6d3..f4c958a1452 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseBatch.java b/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseBatch.java index 6f90114d5a8..28dd8140c9b 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseBatch.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseBatch.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java b/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java index 9ea59cd7b89..3dcc9908278 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/AbstractDatabaseConnector.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseBatch.java b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseBatch.java index 8612b5c3f03..d2298d8d8ab 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseBatch.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseBatch.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseConnector.java b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseConnector.java index 93aa1191504..72abcf6755a 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseConnector.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseConnector.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseException.java b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseException.java index 46ec6d5cf26..e8ae03ef336 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseException.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseException.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionFactory.java b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionFactory.java index 8257f4c5cb2..06feec22d5e 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionFactory.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionFactory.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java index 8ea912e1b79..8236ca120d2 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DatabaseSessionProvider.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java b/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java index 151284a4d67..d30892f14b4 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/DriverDatabaseConnector.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java index 5a350117670..b407bacfe2a 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/MemoryDatabaseConnector.java b/sonar-core/src/main/java/org/sonar/jpa/session/MemoryDatabaseConnector.java index 5d00ddb02df..5e9cfa2f09f 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/MemoryDatabaseConnector.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/MemoryDatabaseConnector.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java b/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java index 8bd845565b2..66a0581b319 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactory.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/api/database/configuration/DatabaseConfigurationTest.java b/sonar-core/src/test/java/org/sonar/api/database/configuration/DatabaseConfigurationTest.java index 26a54faedff..74c8b41a491 100644 --- a/sonar-core/src/test/java/org/sonar/api/database/configuration/DatabaseConfigurationTest.java +++ b/sonar-core/src/test/java/org/sonar/api/database/configuration/DatabaseConfigurationTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/api/database/configuration/ResourceDatabaseConfigurationTest.java b/sonar-core/src/test/java/org/sonar/api/database/configuration/ResourceDatabaseConfigurationTest.java index a856d0729fd..c7739d0a278 100644 --- a/sonar-core/src/test/java/org/sonar/api/database/configuration/ResourceDatabaseConfigurationTest.java +++ b/sonar-core/src/test/java/org/sonar/api/database/configuration/ResourceDatabaseConfigurationTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/classloaders/ClassLoadersCollectionTest.java b/sonar-core/src/test/java/org/sonar/core/classloaders/ClassLoadersCollectionTest.java index bf5876dec33..0f69e2624b0 100644 --- a/sonar-core/src/test/java/org/sonar/core/classloaders/ClassLoadersCollectionTest.java +++ b/sonar-core/src/test/java/org/sonar/core/classloaders/ClassLoadersCollectionTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/classloaders/ResourcesClassLoaderTest.java b/sonar-core/src/test/java/org/sonar/core/classloaders/ResourcesClassLoaderTest.java index 001ca44f690..675567e85b7 100644 --- a/sonar-core/src/test/java/org/sonar/core/classloaders/ResourcesClassLoaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/classloaders/ResourcesClassLoaderTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java index a67fd0cf713..813740c7e6c 100644 --- a/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/components/CacheMetricFinderTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java index 0eb9d239161..33d76615ad0 100644 --- a/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/components/CacheRuleFinderTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/components/DefaultMetricFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/DefaultMetricFinderTest.java index 9a6cec853c5..cfb615d5da5 100644 --- a/sonar-core/src/test/java/org/sonar/core/components/DefaultMetricFinderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/components/DefaultMetricFinderTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java index 222bf4053ed..0b96ed82e26 100644 --- a/sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/components/DefaultModelFinderTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java b/sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java index 7d2c2b8176a..0d5ce6b71b9 100644 --- a/sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/components/DefaultRuleFinderTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/components/ModelTest.java b/sonar-core/src/test/java/org/sonar/core/components/ModelTest.java index b614dfbe8d2..5e45216c2ca 100644 --- a/sonar-core/src/test/java/org/sonar/core/components/ModelTest.java +++ b/sonar-core/src/test/java/org/sonar/core/components/ModelTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java b/sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java index 6e1aa0d93de..475e469851e 100644 --- a/sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java +++ b/sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginDaoTest.java b/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginDaoTest.java index 878c492c89b..48492ca30fe 100644 --- a/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginDaoTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginTest.java b/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginTest.java index 6a6d3cad2ca..0698e5c9bd1 100644 --- a/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginTest.java +++ b/sonar-core/src/test/java/org/sonar/core/plugin/JpaPluginTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresDaoTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresDaoTest.java index 3c70c3fd62c..ea86260a583 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresDaoTest.java @@ -1,165 +1,165 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.junit.Test;
-import org.sonar.api.database.model.AsyncMeasureSnapshot;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class AsyncMeasuresDaoTest extends AbstractDbUnitTestCase {
-
- private static final int PROJECT_ID = 1;
- private static final int METRIC_ID = 1;
-
- @Test
- public void testGetNextAsyncMeasureSnapshot() {
- setupData("sharedFixture", "testGetNextAsyncMeasureSnapshot");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- AsyncMeasureSnapshot asyncMeasure = asyncMeasuresDao.getNextAsyncMeasureSnapshot(
- PROJECT_ID, METRIC_ID, stringToDate("2008-12-04 08:00:00.00"));
-
- assertThat(asyncMeasure.getId(), is(3));
- }
-
- @Test
- public void testGetNextSnapshotsUntilDate() {
- setupData("sharedFixture", "testGetNextSnapshotsUntilDate");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- MeasureModel asyncMeasure = getSession().getEntityManager().find(MeasureModel.class, 1l);
- List<Snapshot> snapshotIds = asyncMeasuresDao.getNextSnapshotsUntilDate(
- asyncMeasure, stringToDate("2008-12-06 12:00:00.00"));
-
- assertThat(snapshotIds.size(), is(2));
- assertThat(snapshotIds.get(0).getId(), is(2));
- assertThat(snapshotIds.get(1).getId(), is(4));
- }
-
- @Test
- public void testGetPreviousSnapshot() {
- setupData("sharedFixture", "testGetPreviousSnapshot");
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- Snapshot s = new Snapshot();
- s.setCreatedAt(stringToDate("2008-12-04 08:00:00.00"));
- s.setScope(ResourceModel.SCOPE_PROJECT);
- ResourceModel resource1 = getSession().getEntity(ResourceModel.class, 1);
- ResourceModel resource2 = getSession().getEntity(ResourceModel.class, 2);
-
- s.setResource(resource1);
- assertThat(asyncMeasuresDao.getPreviousSnapshot(s).getId(), is(1));
-
- s.setResource(resource2);
- assertThat(asyncMeasuresDao.getPreviousSnapshot(s).getId(), is(5));
- }
-
- @Test
- public void testGetNextAsyncMeasureSnapshotsUntilDate() {
- setupData("sharedFixture", "testGetNextAsyncMeasureSnapshotsUntilDate");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- MeasureModel asyncMeasure = getSession().getEntityManager().find(MeasureModel.class, 3l);
- List<AsyncMeasureSnapshot> asyncMeasureSnapshots = asyncMeasuresDao.getNextAsyncMeasureSnapshotsUntilDate(
- asyncMeasure, stringToDate("2008-12-06 08:00:00.00"));
-
- assertThat(asyncMeasureSnapshots.size(), is(2));
- assertThat(asyncMeasureSnapshots.get(0).getId(), is(2));
- assertThat(asyncMeasureSnapshots.get(1).getId(), is(3));
- }
-
- @Test
- public void testDeleteAsyncMeasure() {
- setupData("sharedFixture", "testDeleteAsyncMeasure");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- MeasureModel asyncMeasure = getSession().getEntityManager().find(MeasureModel.class, 1l);
- asyncMeasuresDao.deleteAsyncMeasure(asyncMeasure);
-
- getSession().commit();
- checkTables("testDeleteAsyncMeasure", "project_measures", "async_measure_snapshots");
- }
-
- @Test
- public void testGetAsyncMeasureSnapshotsFromSnapshotId() {
- setupData("sharedFixture", "testGetAsyncMeasureSnapshotsFromSnapshotId");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- Integer snapshotId = 1;
- List<AsyncMeasureSnapshot> asyncMeasureSnapshots = asyncMeasuresDao.getAsyncMeasureSnapshotsFromSnapshotId(
- snapshotId, Arrays.asList(1));
- assertThat(asyncMeasureSnapshots.size(), is(1));
- assertThat(asyncMeasureSnapshots.get(0).getId(), is(2));
- }
-
- @Test
- public void testGetLastAsyncMeasureSnapshot() {
- setupData("sharedFixture", "testGetLastAsyncMeasureSnapshot");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- AsyncMeasureSnapshot asyncMeasureSnapshot = asyncMeasuresDao.getLastAsyncMeasureSnapshot(
- PROJECT_ID, METRIC_ID, stringToDate("2008-12-04 12:00:00.00"));
- assertThat(asyncMeasureSnapshot.getId(), is(2));
- }
-
- @Test
- public void testDeleteAsyncMeasureSnapshots() {
- setupData("sharedFixture", "testDeleteAsyncMeasureSnapshots");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- asyncMeasuresDao.deleteAsyncMeasureSnapshots(1l);
-
- checkTables("testDeleteAsyncMeasureSnapshots", "async_measure_snapshots");
- }
-
- @Test
- public void testGetPreviousAsyncMeasureSnapshots() {
- setupData("sharedFixture", "testGetPreviousAsyncMeasureSnapshots");
-
- AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession());
- List<AsyncMeasureSnapshot> asyncMeasureSnapshots = asyncMeasuresDao.getPreviousAsyncMeasureSnapshots(
- PROJECT_ID, stringToDate("2008-12-04 08:00:00.00"), stringToDate("2008-12-08 08:00:00.00"));
- assertThat(asyncMeasureSnapshots.size(), is(2));
- assertThat(asyncMeasureSnapshots.get(0).getId(), is(5));
- assertThat(asyncMeasureSnapshots.get(1).getId(), is(6));
- }
-
-
- private static Date stringToDate(String sDate) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
- try {
- return sdf.parse(sDate);
- } catch (ParseException e) {
- throw new RuntimeException("Bad date format.");
- }
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.junit.Test; +import org.sonar.api.database.model.AsyncMeasureSnapshot; +import org.sonar.api.database.model.MeasureModel; +import org.sonar.api.database.model.ResourceModel; +import org.sonar.api.database.model.Snapshot; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class AsyncMeasuresDaoTest extends AbstractDbUnitTestCase { + + private static final int PROJECT_ID = 1; + private static final int METRIC_ID = 1; + + @Test + public void testGetNextAsyncMeasureSnapshot() { + setupData("sharedFixture", "testGetNextAsyncMeasureSnapshot"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + AsyncMeasureSnapshot asyncMeasure = asyncMeasuresDao.getNextAsyncMeasureSnapshot( + PROJECT_ID, METRIC_ID, stringToDate("2008-12-04 08:00:00.00")); + + assertThat(asyncMeasure.getId(), is(3)); + } + + @Test + public void testGetNextSnapshotsUntilDate() { + setupData("sharedFixture", "testGetNextSnapshotsUntilDate"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + MeasureModel asyncMeasure = getSession().getEntityManager().find(MeasureModel.class, 1l); + List<Snapshot> snapshotIds = asyncMeasuresDao.getNextSnapshotsUntilDate( + asyncMeasure, stringToDate("2008-12-06 12:00:00.00")); + + assertThat(snapshotIds.size(), is(2)); + assertThat(snapshotIds.get(0).getId(), is(2)); + assertThat(snapshotIds.get(1).getId(), is(4)); + } + + @Test + public void testGetPreviousSnapshot() { + setupData("sharedFixture", "testGetPreviousSnapshot"); + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + Snapshot s = new Snapshot(); + s.setCreatedAt(stringToDate("2008-12-04 08:00:00.00")); + s.setScope(ResourceModel.SCOPE_PROJECT); + ResourceModel resource1 = getSession().getEntity(ResourceModel.class, 1); + ResourceModel resource2 = getSession().getEntity(ResourceModel.class, 2); + + s.setResource(resource1); + assertThat(asyncMeasuresDao.getPreviousSnapshot(s).getId(), is(1)); + + s.setResource(resource2); + assertThat(asyncMeasuresDao.getPreviousSnapshot(s).getId(), is(5)); + } + + @Test + public void testGetNextAsyncMeasureSnapshotsUntilDate() { + setupData("sharedFixture", "testGetNextAsyncMeasureSnapshotsUntilDate"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + MeasureModel asyncMeasure = getSession().getEntityManager().find(MeasureModel.class, 3l); + List<AsyncMeasureSnapshot> asyncMeasureSnapshots = asyncMeasuresDao.getNextAsyncMeasureSnapshotsUntilDate( + asyncMeasure, stringToDate("2008-12-06 08:00:00.00")); + + assertThat(asyncMeasureSnapshots.size(), is(2)); + assertThat(asyncMeasureSnapshots.get(0).getId(), is(2)); + assertThat(asyncMeasureSnapshots.get(1).getId(), is(3)); + } + + @Test + public void testDeleteAsyncMeasure() { + setupData("sharedFixture", "testDeleteAsyncMeasure"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + MeasureModel asyncMeasure = getSession().getEntityManager().find(MeasureModel.class, 1l); + asyncMeasuresDao.deleteAsyncMeasure(asyncMeasure); + + getSession().commit(); + checkTables("testDeleteAsyncMeasure", "project_measures", "async_measure_snapshots"); + } + + @Test + public void testGetAsyncMeasureSnapshotsFromSnapshotId() { + setupData("sharedFixture", "testGetAsyncMeasureSnapshotsFromSnapshotId"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + Integer snapshotId = 1; + List<AsyncMeasureSnapshot> asyncMeasureSnapshots = asyncMeasuresDao.getAsyncMeasureSnapshotsFromSnapshotId( + snapshotId, Arrays.asList(1)); + assertThat(asyncMeasureSnapshots.size(), is(1)); + assertThat(asyncMeasureSnapshots.get(0).getId(), is(2)); + } + + @Test + public void testGetLastAsyncMeasureSnapshot() { + setupData("sharedFixture", "testGetLastAsyncMeasureSnapshot"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + AsyncMeasureSnapshot asyncMeasureSnapshot = asyncMeasuresDao.getLastAsyncMeasureSnapshot( + PROJECT_ID, METRIC_ID, stringToDate("2008-12-04 12:00:00.00")); + assertThat(asyncMeasureSnapshot.getId(), is(2)); + } + + @Test + public void testDeleteAsyncMeasureSnapshots() { + setupData("sharedFixture", "testDeleteAsyncMeasureSnapshots"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + asyncMeasuresDao.deleteAsyncMeasureSnapshots(1l); + + checkTables("testDeleteAsyncMeasureSnapshots", "async_measure_snapshots"); + } + + @Test + public void testGetPreviousAsyncMeasureSnapshots() { + setupData("sharedFixture", "testGetPreviousAsyncMeasureSnapshots"); + + AsyncMeasuresDao asyncMeasuresDao = new AsyncMeasuresDao(getSession()); + List<AsyncMeasureSnapshot> asyncMeasureSnapshots = asyncMeasuresDao.getPreviousAsyncMeasureSnapshots( + PROJECT_ID, stringToDate("2008-12-04 08:00:00.00"), stringToDate("2008-12-08 08:00:00.00")); + assertThat(asyncMeasureSnapshots.size(), is(2)); + assertThat(asyncMeasureSnapshots.get(0).getId(), is(5)); + assertThat(asyncMeasureSnapshots.get(1).getId(), is(6)); + } + + + private static Date stringToDate(String sDate) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS"); + try { + return sdf.parse(sDate); + } catch (ParseException e) { + throw new RuntimeException("Bad date format."); + } + } + +} diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresServiceTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresServiceTest.java index 9ef3ad41034..7b936b5ee9f 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresServiceTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dao/AsyncMeasuresServiceTest.java @@ -1,153 +1,153 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-public class AsyncMeasuresServiceTest extends AbstractDbUnitTestCase {
-
- @Test
- public void assignLatestMeasuresToLastSnapshot() {
- setupData("sharedFixture", "assignLatestMeasuresToLastSnapshot");
-
- AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession());
- Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 2);
- asyncMeasuresService.refresh(snapshot);
-
- checkTables("assignLatestMeasuresToLastSnapshot", "async_measure_snapshots");
- }
-
- @Test
- public void assignNewMeasuresToLastSnapshot() {
- setupData("sharedFixture", "assignNewMeasuresToLastSnapshot");
-
- AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession());
- Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 2);
- asyncMeasuresService.refresh(snapshot);
-
- checkTables("assignNewMeasuresToLastSnapshot", "async_measure_snapshots");
- }
-
- @Test
- public void assignMeasuresWhenNoPreviousSnapshot() {
- setupData("sharedFixture", "assignMeasuresWhenNoPreviousSnapshot");
-
- AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession());
- Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 1);
- asyncMeasuresService.refresh(snapshot);
-
- checkTables("assignMeasuresWhenNoPreviousSnapshot", "async_measure_snapshots");
- }
-
- @Test
- public void assignLatestMeasuresWhenNoPreviousSnapshot() {
- setupData("sharedFixture", "assignLatestMeasuresWhenNoPreviousSnapshot");
-
- AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession());
- Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 1);
- asyncMeasuresService.refresh(snapshot);
-
- checkTables("assignLatestMeasuresWhenNoPreviousSnapshot", "async_measure_snapshots");
- }
-
- @Test
- public void assignPastMeasuresToPastSnapshot() {
- setupData("sharedFixture", "assignPastMeasuresToPastSnapshot");
-
- AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession());
- Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 3);
- asyncMeasuresService.refresh(snapshot);
-
- checkTables("assignPastMeasuresToPastSnapshot", "async_measure_snapshots");
- }
-
- @Test
- public void assignNewMeasureToFutureSnapshots() {
- setupData("sharedFixture", "assignNewMeasureToFutureSnapshots");
-
- AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession());
- asyncMeasuresService.registerMeasure(2l);
-
- checkTables("assignNewMeasureToFutureSnapshots", "async_measure_snapshots");
- }
-
- @Test
- public void assignMeasureToFutureSnapshotsWithDifferentMetric() {
- setupData("sharedFixture", "assignMeasureToFutureSnapshotsWithDifferentMetric");
-
- AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession());
- asyncMeasureService.registerMeasure(3l);
-
- checkTables("assignMeasureToFutureSnapshotsWithDifferentMetric", "async_measure_snapshots");
- }
-
- @Test
- public void assignAPastMeasureToNextSnapshotsWithDifferentMetric() {
- setupData("sharedFixture", "assignAPastMeasureToNextSnapshotsWithDifferentMetric");
-
- AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession());
- asyncMeasureService.registerMeasure(2l);
-
- checkTables("assignAPastMeasureToNextSnapshotsWithDifferentMetric", "async_measure_snapshots");
- }
-
- @Test
- public void addFutureSnapshot() {
- setupData("sharedFixture", "addFutureSnapshot");
-
- AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession());
- asyncMeasureService.registerMeasure(2l);
-
- checkTables("addFutureSnapshot", "async_measure_snapshots");
- }
-
- @Test
- public void addInvisibleMeasure() {
- setupData("sharedFixture", "addInvisibleMeasure");
-
- AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession());
- asyncMeasureService.registerMeasure(2l);
-
- checkTables("addInvisibleMeasure", "async_measure_snapshots");
- }
-
- @Test
- public void deleteMeasure() {
- setupData("sharedFixture", "deleteMeasure");
-
- AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession());
- asyncMeasureService.deleteMeasure(2l);
-
- checkTables("deleteMeasure", "async_measure_snapshots");
- }
-
- @Test
- public void deleteLastMeasure() {
- setupData("sharedFixture", "deleteLastMeasure");
-
- AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession());
- asyncMeasureService.deleteMeasure(1l);
-
- checkTables("deleteLastMeasure", "async_measure_snapshots");
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.junit.Test; +import org.sonar.api.database.model.Snapshot; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +public class AsyncMeasuresServiceTest extends AbstractDbUnitTestCase { + + @Test + public void assignLatestMeasuresToLastSnapshot() { + setupData("sharedFixture", "assignLatestMeasuresToLastSnapshot"); + + AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession()); + Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 2); + asyncMeasuresService.refresh(snapshot); + + checkTables("assignLatestMeasuresToLastSnapshot", "async_measure_snapshots"); + } + + @Test + public void assignNewMeasuresToLastSnapshot() { + setupData("sharedFixture", "assignNewMeasuresToLastSnapshot"); + + AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession()); + Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 2); + asyncMeasuresService.refresh(snapshot); + + checkTables("assignNewMeasuresToLastSnapshot", "async_measure_snapshots"); + } + + @Test + public void assignMeasuresWhenNoPreviousSnapshot() { + setupData("sharedFixture", "assignMeasuresWhenNoPreviousSnapshot"); + + AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession()); + Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 1); + asyncMeasuresService.refresh(snapshot); + + checkTables("assignMeasuresWhenNoPreviousSnapshot", "async_measure_snapshots"); + } + + @Test + public void assignLatestMeasuresWhenNoPreviousSnapshot() { + setupData("sharedFixture", "assignLatestMeasuresWhenNoPreviousSnapshot"); + + AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession()); + Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 1); + asyncMeasuresService.refresh(snapshot); + + checkTables("assignLatestMeasuresWhenNoPreviousSnapshot", "async_measure_snapshots"); + } + + @Test + public void assignPastMeasuresToPastSnapshot() { + setupData("sharedFixture", "assignPastMeasuresToPastSnapshot"); + + AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession()); + Snapshot snapshot = getSession().getEntityManager().find(Snapshot.class, 3); + asyncMeasuresService.refresh(snapshot); + + checkTables("assignPastMeasuresToPastSnapshot", "async_measure_snapshots"); + } + + @Test + public void assignNewMeasureToFutureSnapshots() { + setupData("sharedFixture", "assignNewMeasureToFutureSnapshots"); + + AsyncMeasuresService asyncMeasuresService = new AsyncMeasuresService(getSession()); + asyncMeasuresService.registerMeasure(2l); + + checkTables("assignNewMeasureToFutureSnapshots", "async_measure_snapshots"); + } + + @Test + public void assignMeasureToFutureSnapshotsWithDifferentMetric() { + setupData("sharedFixture", "assignMeasureToFutureSnapshotsWithDifferentMetric"); + + AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession()); + asyncMeasureService.registerMeasure(3l); + + checkTables("assignMeasureToFutureSnapshotsWithDifferentMetric", "async_measure_snapshots"); + } + + @Test + public void assignAPastMeasureToNextSnapshotsWithDifferentMetric() { + setupData("sharedFixture", "assignAPastMeasureToNextSnapshotsWithDifferentMetric"); + + AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession()); + asyncMeasureService.registerMeasure(2l); + + checkTables("assignAPastMeasureToNextSnapshotsWithDifferentMetric", "async_measure_snapshots"); + } + + @Test + public void addFutureSnapshot() { + setupData("sharedFixture", "addFutureSnapshot"); + + AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession()); + asyncMeasureService.registerMeasure(2l); + + checkTables("addFutureSnapshot", "async_measure_snapshots"); + } + + @Test + public void addInvisibleMeasure() { + setupData("sharedFixture", "addInvisibleMeasure"); + + AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession()); + asyncMeasureService.registerMeasure(2l); + + checkTables("addInvisibleMeasure", "async_measure_snapshots"); + } + + @Test + public void deleteMeasure() { + setupData("sharedFixture", "deleteMeasure"); + + AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession()); + asyncMeasureService.deleteMeasure(2l); + + checkTables("deleteMeasure", "async_measure_snapshots"); + } + + @Test + public void deleteLastMeasure() { + setupData("sharedFixture", "deleteLastMeasure"); + + AsyncMeasuresService asyncMeasureService = new AsyncMeasuresService(getSession()); + asyncMeasureService.deleteMeasure(1l); + + checkTables("deleteLastMeasure", "async_measure_snapshots"); + } + +} diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/MeasuresDaoTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/MeasuresDaoTest.java index 5502905e5e6..e0a98be7b7c 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dao/MeasuresDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dao/MeasuresDaoTest.java @@ -1,107 +1,107 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.measures.Metric;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-
-public class MeasuresDaoTest extends AbstractDbUnitTestCase {
-
- private MeasuresDao service;
- private ResourceModel project;
-
- @Before
- public void before() throws Exception {
- service = new MeasuresDao(getSession());
- project = new ResourceModel(ResourceModel.SCOPE_PROJECT, "foo:bar", ResourceModel.QUALIFIER_PROJECT_TRUNK, null, "Foo");
- project.setName("project name");
- getSession().save(project);
- }
-
- @Test
- public void shouldReturnUserDefinedMetrics() {
- for (Metric metric : createMetrics()) {
- getSession().save(metric);
- }
-
- Collection<Metric> metrics = service.getUserDefinedMetrics();
- assertThat(metrics.size(), is(2));
- for (Metric metric : metrics) {
- assertThat(metric.getOrigin(), not(Metric.Origin.JAV));
- }
- }
-
- @Test
- public void shouldRegisterMetrics() {
- Collection<Metric> newMetrics = createMetrics();
- service.registerMetrics(newMetrics);
-
- Collection<Metric> metrics = service.getEnabledMetrics();
- assertThat(metrics.size(), is(newMetrics.size()));
- }
-
- @Test
- public void shouldDisabledMetrics() {
- Collection<Metric> newMetrics = createMetrics();
-
- service.disabledMetrics(newMetrics);
-
- Collection<Metric> allMetrics = service.getMetrics();
- assertThat(allMetrics.size(), is(newMetrics.size()));
-
- Collection<Metric> disabledMetrics = service.getEnabledMetrics();
- assertThat(disabledMetrics.size(), is(0));
- }
-
-
- private Collection<Metric> createMetrics() {
- Metric m1 = new Metric("metric1");
- m1.setEnabled(false);
- m1.setOrigin(Metric.Origin.JAV);
-
- Metric m2 = new Metric("metric2");
- m2.setEnabled(true);
- m2.setOrigin(Metric.Origin.JAV);
-
- Metric m3 = new Metric("metric3");
- m3.setEnabled(false);
- m3.setOrigin(Metric.Origin.GUI);
-
- Metric m4 = new Metric("metric4");
- m4.setEnabled(true);
- m4.setOrigin(Metric.Origin.GUI);
-
- Metric m5 = new Metric("metric5");
- m5.setEnabled(true);
- m5.setOrigin(Metric.Origin.WS);
-
- return Arrays.asList(m1, m2, m3, m4, m5);
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.database.model.ResourceModel; +import org.sonar.api.measures.Metric; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +import java.util.Arrays; +import java.util.Collection; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +public class MeasuresDaoTest extends AbstractDbUnitTestCase { + + private MeasuresDao service; + private ResourceModel project; + + @Before + public void before() throws Exception { + service = new MeasuresDao(getSession()); + project = new ResourceModel(ResourceModel.SCOPE_PROJECT, "foo:bar", ResourceModel.QUALIFIER_PROJECT_TRUNK, null, "Foo"); + project.setName("project name"); + getSession().save(project); + } + + @Test + public void shouldReturnUserDefinedMetrics() { + for (Metric metric : createMetrics()) { + getSession().save(metric); + } + + Collection<Metric> metrics = service.getUserDefinedMetrics(); + assertThat(metrics.size(), is(2)); + for (Metric metric : metrics) { + assertThat(metric.getOrigin(), not(Metric.Origin.JAV)); + } + } + + @Test + public void shouldRegisterMetrics() { + Collection<Metric> newMetrics = createMetrics(); + service.registerMetrics(newMetrics); + + Collection<Metric> metrics = service.getEnabledMetrics(); + assertThat(metrics.size(), is(newMetrics.size())); + } + + @Test + public void shouldDisabledMetrics() { + Collection<Metric> newMetrics = createMetrics(); + + service.disabledMetrics(newMetrics); + + Collection<Metric> allMetrics = service.getMetrics(); + assertThat(allMetrics.size(), is(newMetrics.size())); + + Collection<Metric> disabledMetrics = service.getEnabledMetrics(); + assertThat(disabledMetrics.size(), is(0)); + } + + + private Collection<Metric> createMetrics() { + Metric m1 = new Metric("metric1"); + m1.setEnabled(false); + m1.setOrigin(Metric.Origin.JAV); + + Metric m2 = new Metric("metric2"); + m2.setEnabled(true); + m2.setOrigin(Metric.Origin.JAV); + + Metric m3 = new Metric("metric3"); + m3.setEnabled(false); + m3.setOrigin(Metric.Origin.GUI); + + Metric m4 = new Metric("metric4"); + m4.setEnabled(true); + m4.setOrigin(Metric.Origin.GUI); + + Metric m5 = new Metric("metric5"); + m5.setEnabled(true); + m5.setOrigin(Metric.Origin.WS); + + return Arrays.asList(m1, m2, m3, m4, m5); + } +} diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java index 0b821d51dc2..38049f3416c 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dao/ProfilesDaoTest.java @@ -1,58 +1,58 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-public class ProfilesDaoTest extends AbstractDbUnitTestCase {
-
- private ProfilesDao profilesDao;
-
- @Before
- public void setup() {
- profilesDao = new ProfilesDao(getSession());
- }
-
-
- @Test
- public void testGetActiveProfile() {
- RulesProfile testDefaultProfile = new RulesProfile("default", "java", true, true);
- RulesProfile testProfile = new RulesProfile("not default", "java", false, false);
- getSession().save(testDefaultProfile, testProfile);
-
- ResourceModel testResourceWithProfile = new ResourceModel(ResourceModel.SCOPE_PROJECT, "withProfile", "qual", null, "test");
- testResourceWithProfile.setRulesProfile(testProfile);
- ResourceModel testResourceWithNoProfile = new ResourceModel(ResourceModel.SCOPE_PROJECT, "withoutProfile", "qual", null, "test");
- getSession().save(testResourceWithProfile, testResourceWithNoProfile);
-
- assertNull(profilesDao.getActiveProfile("wrongLanguage", "withoutProfile"));
- assertEquals(testDefaultProfile.getId(), profilesDao.getActiveProfile("java", "wrongKey").getId());
- assertEquals(testDefaultProfile.getId(), profilesDao.getActiveProfile("java", "withoutProfile").getId());
- assertEquals(testProfile.getId(), profilesDao.getActiveProfile("java", "withProfile").getId());
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.database.model.ResourceModel; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class ProfilesDaoTest extends AbstractDbUnitTestCase { + + private ProfilesDao profilesDao; + + @Before + public void setup() { + profilesDao = new ProfilesDao(getSession()); + } + + + @Test + public void testGetActiveProfile() { + RulesProfile testDefaultProfile = new RulesProfile("default", "java", true, true); + RulesProfile testProfile = new RulesProfile("not default", "java", false, false); + getSession().save(testDefaultProfile, testProfile); + + ResourceModel testResourceWithProfile = new ResourceModel(ResourceModel.SCOPE_PROJECT, "withProfile", "qual", null, "test"); + testResourceWithProfile.setRulesProfile(testProfile); + ResourceModel testResourceWithNoProfile = new ResourceModel(ResourceModel.SCOPE_PROJECT, "withoutProfile", "qual", null, "test"); + getSession().save(testResourceWithProfile, testResourceWithNoProfile); + + assertNull(profilesDao.getActiveProfile("wrongLanguage", "withoutProfile")); + assertEquals(testDefaultProfile.getId(), profilesDao.getActiveProfile("java", "wrongKey").getId()); + assertEquals(testDefaultProfile.getId(), profilesDao.getActiveProfile("java", "withoutProfile").getId()); + assertEquals(testProfile.getId(), profilesDao.getActiveProfile("java", "withProfile").getId()); + } + +} diff --git a/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java b/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java index 7d1b0e97a64..f17496a6d55 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dao/RulesDaoTest.java @@ -1,68 +1,68 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.dao;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.*;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-public class RulesDaoTest extends AbstractDbUnitTestCase {
-
- private RulesDao rulesDao;
-
- @Before
- public void setup() {
- rulesDao = new RulesDao(getSession());
- }
-
- @Test
- public void shouldGetRules() {
- setupData("shouldGetRules");
-
- List<Rule> rules = rulesDao.getRules();
- assertThat(rules, notNullValue());
- assertThat(rules.size(), is(2));
-
- assertEquals("rule_one", rules.get(0).getKey());
- assertEquals(1, rules.get(0).getParams().size());
- }
-
- @Test
- public void shouldGetRuleWithRuleKeyAndPluginKey() {
- setupData("shouldGetRuleWithRuleKeyAndPluginKey");
-
- Rule rule = rulesDao.getRuleByKey("plugin", "checkstyle.rule1");
- assertThat(rule, notNullValue());
- assertThat(rule.getId(), notNullValue());
-
- Rule rule2 = rulesDao.getRuleByKey("plugin", "key not found");
- assertThat(rule2, nullValue());
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.dao; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.*; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +public class RulesDaoTest extends AbstractDbUnitTestCase { + + private RulesDao rulesDao; + + @Before + public void setup() { + rulesDao = new RulesDao(getSession()); + } + + @Test + public void shouldGetRules() { + setupData("shouldGetRules"); + + List<Rule> rules = rulesDao.getRules(); + assertThat(rules, notNullValue()); + assertThat(rules.size(), is(2)); + + assertEquals("rule_one", rules.get(0).getKey()); + assertEquals(1, rules.get(0).getParams().size()); + } + + @Test + public void shouldGetRuleWithRuleKeyAndPluginKey() { + setupData("shouldGetRuleWithRuleKeyAndPluginKey"); + + Rule rule = rulesDao.getRuleByKey("plugin", "checkstyle.rule1"); + assertThat(rule, notNullValue()); + assertThat(rule.getId(), notNullValue()); + + Rule rule2 = rulesDao.getRuleByKey("plugin", "key not found"); + assertThat(rule2, nullValue()); + } + +} diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/DerbyTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/DerbyTest.java index 298f4775765..7da394f4fce 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/DerbyTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/DerbyTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/DialectRepositoryTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/DialectRepositoryTest.java index 0f7db36bd7a..4a67f441d2f 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/DialectRepositoryTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/DialectRepositoryTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/HsqlDbTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/HsqlDbTest.java index 20cebfd9eb7..440500dae08 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/HsqlDbTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/HsqlDbTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/MsSqlTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/MsSqlTest.java index 5d2a9a53043..5554eba67da 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/MsSqlTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/MsSqlTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/MySqlTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/MySqlTest.java index ad60fa7e0a1..a0717686535 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/MySqlTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/MySqlTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleSequenceGeneratorTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleSequenceGeneratorTest.java index ba15aa47854..05d963f9323 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleSequenceGeneratorTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleSequenceGeneratorTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleTest.java index 89145bf7305..23e3116e518 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/OracleTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSQLSequenceGeneratorTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSQLSequenceGeneratorTest.java index 3738d30f56c..b7ed6cee924 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSQLSequenceGeneratorTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSQLSequenceGeneratorTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSqlTest.java b/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSqlTest.java index b16d92c5e4d..6af5a72b609 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSqlTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/dialect/PostgreSqlTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/entity/PropertyTest.java b/sonar-core/src/test/java/org/sonar/jpa/entity/PropertyTest.java index c948023d82a..f57f58f3d86 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/entity/PropertyTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/entity/PropertyTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/entity/SchemaMigrationTest.java b/sonar-core/src/test/java/org/sonar/jpa/entity/SchemaMigrationTest.java index 8be589fb5b2..21a2268f48b 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/entity/SchemaMigrationTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/entity/SchemaMigrationTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/session/AbstractDatabaseConnectorTest.java b/sonar-core/src/test/java/org/sonar/jpa/session/AbstractDatabaseConnectorTest.java index 5d5cc9cfc83..f584eb4b72b 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/session/AbstractDatabaseConnectorTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/session/AbstractDatabaseConnectorTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or 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 4094cca55c2..014a7054f6b 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 @@ -1,122 +1,122 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.session;
-
-import org.hamcrest.Matchers;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.internal.matchers.IsCollectionContaining;
-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.*;
-
-public class DatabaseSessionTest extends AbstractDbUnitTestCase {
- private static final Long NB_INSERTS = 20000l;
-
- private ResourceModel project1;
- private ResourceModel project2;
-
- @Before
- public void setup() {
- project1 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact", "JAV", null, "my name");
- project2 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact1", "JAV", null, "my name 2");
- }
-
- @Test
- public void performaceTestOnBatchInserts() throws Exception {
-
- Snapshot snapshot = new Snapshot(project1, true, "", new Date(1));
- getSession().save(project1, 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"));
- }
-
- @Test
- public void testGetSingleResultWithNoCriterias() {
- try {
- assertNull(getSession().getSingleResult(ResourceModel.class, (Object[]) null));
- fail("No IllegalStateException raised");
- } catch (IllegalStateException ex) {
- // error raised correctly
- }
- }
-
- @Test
- public void testGetSingleResultWithOneResult() {
- getSession().save(project1);
- ResourceModel hit = getSession().getSingleResult(ResourceModel.class, "name", "my name");
- assertNotNull(hit);
- assertEquals(project1, hit);
- }
-
- @Test
- public void testGetSingleResultWithTwoResults() {
- getSession().save(project1, project2);
- try {
- getSession().getSingleResult(ResourceModel.class, "qualifier", "JAV");
- fail("No NonUniqueResultException raised");
- } catch (NonUniqueResultException ex) {
- // error raised correctly
- }
- }
-
- @Test
- public void testGetResultsWithNoResults() {
- List<ResourceModel> hits = getSession().getResults(ResourceModel.class, "name", "foo");
- assertTrue(hits.isEmpty());
- }
-
- @Test
- public void testGetResultsWithMultipleResults() {
- ResourceModel project3 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact3", "TEST", null, "my name 3");
- getSession().save(project1, project2, project3);
-
- List<ResourceModel> hits = getSession().getResults(ResourceModel.class, "qualifier", "JAV");
- assertFalse(hits.isEmpty());
- assertThat(hits, IsCollectionContaining.hasItems(project1, project2));
- assertThat(hits, Matchers.not(IsCollectionContaining.hasItem(project3)));
- }
-
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.jpa.session; + +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.internal.matchers.IsCollectionContaining; +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.*; + +public class DatabaseSessionTest extends AbstractDbUnitTestCase { + private static final Long NB_INSERTS = 20000l; + + private ResourceModel project1; + private ResourceModel project2; + + @Before + public void setup() { + project1 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact", "JAV", null, "my name"); + project2 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact1", "JAV", null, "my name 2"); + } + + @Test + public void performaceTestOnBatchInserts() throws Exception { + + Snapshot snapshot = new Snapshot(project1, true, "", new Date(1)); + getSession().save(project1, 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")); + } + + @Test + public void testGetSingleResultWithNoCriterias() { + try { + assertNull(getSession().getSingleResult(ResourceModel.class, (Object[]) null)); + fail("No IllegalStateException raised"); + } catch (IllegalStateException ex) { + // error raised correctly + } + } + + @Test + public void testGetSingleResultWithOneResult() { + getSession().save(project1); + ResourceModel hit = getSession().getSingleResult(ResourceModel.class, "name", "my name"); + assertNotNull(hit); + assertEquals(project1, hit); + } + + @Test + public void testGetSingleResultWithTwoResults() { + getSession().save(project1, project2); + try { + getSession().getSingleResult(ResourceModel.class, "qualifier", "JAV"); + fail("No NonUniqueResultException raised"); + } catch (NonUniqueResultException ex) { + // error raised correctly + } + } + + @Test + public void testGetResultsWithNoResults() { + List<ResourceModel> hits = getSession().getResults(ResourceModel.class, "name", "foo"); + assertTrue(hits.isEmpty()); + } + + @Test + public void testGetResultsWithMultipleResults() { + ResourceModel project3 = new ResourceModel(ResourceModel.SCOPE_PROJECT, "mygroup:myartifact3", "TEST", null, "my name 3"); + getSession().save(project1, project2, project3); + + List<ResourceModel> hits = getSession().getResults(ResourceModel.class, "qualifier", "JAV"); + assertFalse(hits.isEmpty()); + assertThat(hits, IsCollectionContaining.hasItems(project1, project2)); + assertThat(hits, Matchers.not(IsCollectionContaining.hasItem(project3))); + } + +} diff --git a/sonar-core/src/test/java/org/sonar/jpa/session/DriverDatabaseConnectorTest.java b/sonar-core/src/test/java/org/sonar/jpa/session/DriverDatabaseConnectorTest.java index f133296d10f..dfc0716eb0d 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/session/DriverDatabaseConnectorTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/session/DriverDatabaseConnectorTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactoryTest.java b/sonar-core/src/test/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactoryTest.java index 7f1c2eb5c3b..ee374066c75 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactoryTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/session/ThreadLocalDatabaseSessionFactoryTest.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java b/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java index 0f4eb82793d..6e9aa22013a 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java +++ b/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or |