]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-249 add unit tests
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 26 Nov 2010 08:10:37 +0000 (08:10 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 26 Nov 2010 08:10:37 +0000 (08:10 +0000)
23 files changed:
sonar-batch/src/main/java/org/sonar/batch/Batch.java
sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java
sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java [new file with mode: 0644]
sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shared.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml [deleted file]
sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shared.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shouldSaveSource-result.xml [new file with mode: 0644]

index 847bd08cdeb87a21772a00b572195374486efbab..303d4d099b5bd145c6bcd104b93b723c7da91dec 100644 (file)
@@ -78,7 +78,7 @@ public class Batch {
     batchContainer.as(Characteristics.CACHE).addComponent(EventPersister.class);
     batchContainer.as(Characteristics.CACHE).addComponent(LinkPersister.class);
     batchContainer.as(Characteristics.CACHE).addComponent(MeasurePersister.class);
-    batchContainer.as(Characteristics.CACHE).addComponent(ResourcePersister.class);
+    batchContainer.as(Characteristics.CACHE).addComponent(DefaultResourcePersister.class);
     batchContainer.as(Characteristics.CACHE).addComponent(SourcePersister.class);
     batchContainer.as(Characteristics.CACHE).addComponent(ViolationPersister.class);
     batchContainer.as(Characteristics.CACHE).addComponent(JpaPluginDao.class);
index 83b21a6dd39ff17f6b549f602ec8cac22522971d..d6843c900dd1f9158b3b8fc0d4c5c16cc0b3b522 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.api.rules.DefaultRulesManager;
 import org.sonar.api.utils.IocContainer;
 import org.sonar.api.utils.SonarException;
 import org.sonar.batch.index.DefaultIndex;
-import org.sonar.batch.index.ResourcePersister;
+import org.sonar.batch.index.DefaultResourcePersister;
 import org.sonar.batch.phases.Phases;
 import org.sonar.core.qualitymodel.DefaultModelFinder;
 import org.sonar.core.rule.DefaultRuleFinder;
@@ -78,7 +78,7 @@ public class ProjectBatch {
     batchContainer.as(Characteristics.CACHE).addComponent(RulesDao.class);
 
     // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
-    batchContainer.as(Characteristics.CACHE).addComponent(globalContainer.getComponent(ResourcePersister.class).getSnapshot(project));
+    batchContainer.as(Characteristics.CACHE).addComponent(globalContainer.getComponent(DefaultResourcePersister.class).getSnapshot(project));
 
     batchContainer.as(Characteristics.CACHE).addComponent(org.sonar.api.database.daos.RulesDao.class);
     batchContainer.as(Characteristics.CACHE).addComponent(org.sonar.api.database.daos.MeasuresDao.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
new file mode 100644 (file)
index 0000000..82a3dc0
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * 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.batch.index;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.ResourceModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.utils.SonarException;
+
+import javax.persistence.NonUniqueResultException;
+import javax.persistence.Query;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public final class DefaultResourcePersister implements ResourcePersister {
+
+  private DatabaseSession session;
+
+  private Map<Resource, Snapshot> snapshotsByResource = Maps.newHashMap();
+
+  public DefaultResourcePersister(DatabaseSession session) {
+    this.session = session;
+  }
+
+  public Snapshot saveProject(Project project) {
+    Snapshot snapshot = snapshotsByResource.get(project);
+    if (snapshot == null) {
+      snapshot = doSaveProject(project);
+    }
+    return snapshot;
+  }
+
+  public Snapshot getSnapshot(Resource resource) {
+    if (resource != null) {
+      return snapshotsByResource.get(resource);
+    }
+    return null;
+  }
+
+  /**
+   * just for unit tests
+   */
+  Map<Resource, Snapshot> getSnapshotsByResource() {
+    return snapshotsByResource;
+  }
+
+  private Snapshot doSaveProject(Project project) {
+    ResourceModel model = findOrCreateModel(project, project.getKey());
+    model.setLanguageKey(project.getLanguageKey());// ugly, only for projects
+
+    Snapshot parentSnapshot = null;
+    if (project.getParent() != null) {
+      // assume that the parent project has already been saved
+      parentSnapshot = snapshotsByResource.get(project.getParent());
+      model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
+    }
+    model = session.save(model);
+    project.setId(model.getId()); // TODO to be removed
+
+    Snapshot snapshot = new Snapshot(model, parentSnapshot);
+    snapshot.setVersion(project.getAnalysisVersion());
+    snapshot.setCreatedAt(project.getAnalysisDate());
+    snapshot = session.save(snapshot);
+    session.commit();
+    snapshotsByResource.put(project, snapshot);
+    return snapshot;
+  }
+
+  public Snapshot saveResource(Project project, Resource resource) {
+    if (resource == null) {
+      return null;
+    }
+    Snapshot snapshot = snapshotsByResource.get(resource);
+    if (snapshot == null) {
+      if (resource instanceof Project) {
+        snapshot = doSaveProject((Project) resource);
+
+      } else if (resource instanceof Library) {
+        snapshot = doSaveLibrary(project, (Library) resource);
+
+      } else {
+        snapshot = doSaveResource(project, resource);
+      }
+    }
+    return snapshot;
+  }
+
+  private Snapshot doSaveLibrary(Project project, Library library) {
+    ResourceModel model = findOrCreateModel(library, library.getKey());
+    model = session.save(model);
+    library.setId(model.getId()); // TODO to be removed
+    library.setEffectiveKey(library.getKey());
+
+    Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion());
+    if (snapshot == null) {
+      snapshot = new Snapshot(model, null);
+      snapshot.setCreatedAt(project.getAnalysisDate());
+      snapshot.setVersion(library.getVersion());
+      snapshot.setStatus(Snapshot.STATUS_PROCESSED);
+
+      // see http://jira.codehaus.org/browse/SONAR-1850
+      // The qualifier must be LIB, even if the resource is TRK, because this snapshot has no measures.
+      snapshot.setQualifier(Resource.QUALIFIER_LIB);
+      snapshot = session.save(snapshot);
+    }
+    session.commit();
+    return snapshot;
+  }
+
+  private Snapshot findLibrarySnapshot(Integer resourceId, String version) {
+    Query query = session.createQuery("from " + Snapshot.class.getSimpleName() + " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last");
+    query.setParameter("resourceId", resourceId);
+    query.setParameter("version", version);
+    query.setParameter("scope", Resource.SCOPE_SET);
+    query.setParameter("qualifier", Resource.QUALIFIER_LIB);
+    query.setParameter("last", Boolean.TRUE);
+    List<Snapshot> snapshots = query.getResultList();
+    if (snapshots.isEmpty()) {
+      snapshots = session.getResults(Snapshot.class, "resourceId", resourceId, "version", version, "scope", Resource.SCOPE_SET, "qualifier", Resource.QUALIFIER_LIB);
+    }
+    return (snapshots.isEmpty() ? null : snapshots.get(0));
+  }
+
+  /**
+   * Everything except project and library
+   */
+  private Snapshot doSaveResource(Project project, Resource resource) {
+    String databaseKey = getDatabaseKey(project, resource);
+    ResourceModel model = findOrCreateModel(resource, databaseKey);
+    Snapshot projectSnapshot = snapshotsByResource.get(project);
+    model.setRootId(projectSnapshot.getResourceId());
+    model = session.save(model);
+    resource.setId(model.getId()); // TODO to be removed
+    resource.setEffectiveKey(databaseKey);
+
+    Snapshot parentSnapshot = (Snapshot)ObjectUtils.defaultIfNull(getSnapshot(resource.getParent()), projectSnapshot);
+    Snapshot snapshot = new Snapshot(model, parentSnapshot);
+    snapshot = session.save(snapshot);
+    session.commit();
+    snapshotsByResource.put(resource, snapshot);
+    return snapshot;
+  }
+
+  public void clear() {
+    // we keep cache of projects
+    for (Iterator<Map.Entry<Resource, Snapshot>> it = snapshotsByResource.entrySet().iterator(); it.hasNext();) {
+      Map.Entry<Resource, Snapshot> entry = it.next();
+      if (!ResourceUtils.isSet(entry.getKey())) {
+        it.remove();
+      }
+    }
+  }
+
+
+  private ResourceModel findOrCreateModel(Resource resource, String databaseKey) {
+    ResourceModel model;
+    try {
+      model = session.getSingleResult(ResourceModel.class, "key", databaseKey);
+      if (model == null) {
+        model = createModel(resource, databaseKey);
+
+      } else {
+        mergeModel(model, resource);
+      }
+      return model;
+
+    } catch (NonUniqueResultException e) {
+      throw new SonarException("The resource '" + databaseKey + "' is duplicated in database.");
+    }
+  }
+
+  static ResourceModel createModel(Resource resource, String databaseKey) {
+    ResourceModel model = new ResourceModel();
+    model.setEnabled(Boolean.TRUE);
+    model.setDescription(resource.getDescription());
+    model.setKey(databaseKey);
+    if (resource.getLanguage() != null) {
+      model.setLanguageKey(resource.getLanguage().getKey());
+    }
+    if (StringUtils.isNotBlank(resource.getName())) {
+      model.setName(resource.getName());
+    } else {
+      model.setName(resource.getKey());
+    }
+    model.setLongName(resource.getLongName());
+    model.setScope(resource.getScope());
+    model.setQualifier(resource.getQualifier());
+    return model;
+  }
+
+  static void mergeModel(ResourceModel model, Resource resource) {
+    model.setEnabled(true);
+    if (StringUtils.isNotBlank(resource.getName())) {
+      model.setName(resource.getName());
+    }
+    if (StringUtils.isNotBlank(resource.getLongName())) {
+      model.setLongName(resource.getLongName());
+    }
+    if (StringUtils.isNotBlank(resource.getDescription())) {
+      model.setDescription(resource.getDescription());
+    }
+    if (!ResourceUtils.isLibrary(resource)) {
+      model.setScope(resource.getScope());
+      model.setQualifier(resource.getQualifier());
+    }
+    if (resource.getLanguage() != null) {
+      model.setLanguageKey(resource.getLanguage().getKey());
+    }
+  }
+
+  static String getDatabaseKey(Project project, Resource resource) {
+    if (StringUtils.equals(Resource.SCOPE_SET, resource.getScope())) {
+      // projects + libraries
+      return resource.getKey();
+    }
+    return new StringBuilder(ResourceModel.KEY_SIZE)
+        .append(project.getKey())
+        .append(':')
+        .append(resource.getKey())
+        .toString();
+  }
+}
index f9f77b5ae2d5a800861d73313eae1d98aa5cfdfd..94660c451c4dce569d7400ca434dc2bac54c57a4 100644 (file)
  */
 package org.sonar.batch.index;
 
-import com.google.common.collect.Maps;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.ResourceModel;
 import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Library;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.api.utils.SonarException;
 
-import javax.persistence.NonUniqueResultException;
-import javax.persistence.Query;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+public interface ResourcePersister {
+  Snapshot saveProject(Project project);
 
-public class ResourcePersister {
+  Snapshot getSnapshot(Resource resource);
 
-  private DatabaseSession session;
+  Snapshot saveResource(Project project, Resource resource);
 
-  private Map<Resource, Snapshot> snapshotsByResource = Maps.newHashMap();
-
-  public ResourcePersister(DatabaseSession session) {
-    this.session = session;
-  }
-
-  public Snapshot saveProject(Project project) {
-    Snapshot snapshot = snapshotsByResource.get(project);
-    if (snapshot == null) {
-      snapshot = doSaveProject(project);
-    }
-    return snapshot;
-  }
-
-  public Snapshot getSnapshot(Resource resource) {
-    if (resource != null) {
-      return snapshotsByResource.get(resource);
-    }
-    return null;
-  }
-
-  /**
-   * just for unit tests
-   */
-  Map<Resource, Snapshot> getSnapshotsByResource() {
-    return snapshotsByResource;
-  }
-
-  private Snapshot doSaveProject(Project project) {
-    ResourceModel model = findOrCreateModel(project, project.getKey());
-    model.setLanguageKey(project.getLanguageKey());// ugly, only for projects
-
-    Snapshot parentSnapshot = null;
-    if (project.getParent() != null) {
-      // assume that the parent project has already been saved
-      parentSnapshot = snapshotsByResource.get(project.getParent());
-      model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
-    }
-    model = session.save(model);
-    project.setId(model.getId()); // TODO to be removed
-
-    Snapshot snapshot = new Snapshot(model, parentSnapshot);
-    snapshot.setVersion(project.getAnalysisVersion());
-    snapshot.setCreatedAt(project.getAnalysisDate());
-    snapshot = session.save(snapshot);
-    session.commit();
-    snapshotsByResource.put(project, snapshot);
-    return snapshot;
-  }
-
-  public Snapshot saveResource(Project project, Resource resource) {
-    if (resource == null) {
-      return null;
-    }
-    Snapshot snapshot = snapshotsByResource.get(resource);
-    if (snapshot == null) {
-      if (resource instanceof Project) {
-        snapshot = doSaveProject((Project) resource);
-
-      } else if (resource instanceof Library) {
-        snapshot = doSaveLibrary(project, (Library) resource);
-
-      } else {
-        snapshot = doSaveResource(project, resource);
-      }
-    }
-    return snapshot;
-  }
-
-  private Snapshot doSaveLibrary(Project project, Library library) {
-    ResourceModel model = findOrCreateModel(library, library.getKey());
-    model = session.save(model);
-    library.setId(model.getId()); // TODO to be removed
-    library.setEffectiveKey(library.getKey());
-
-    Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion());
-    if (snapshot == null) {
-      snapshot = new Snapshot(model, null);
-      snapshot.setCreatedAt(project.getAnalysisDate());
-      snapshot.setVersion(library.getVersion());
-      snapshot.setStatus(Snapshot.STATUS_PROCESSED);
-
-      // see http://jira.codehaus.org/browse/SONAR-1850
-      // The qualifier must be LIB, even if the resource is TRK, because this snapshot has no measures.
-      snapshot.setQualifier(Resource.QUALIFIER_LIB);
-      snapshot = session.save(snapshot);
-    }
-    session.commit();
-    return snapshot;
-  }
-
-  private Snapshot findLibrarySnapshot(Integer resourceId, String version) {
-    Query query = session.createQuery("from " + Snapshot.class.getSimpleName() + " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last");
-    query.setParameter("resourceId", resourceId);
-    query.setParameter("version", version);
-    query.setParameter("scope", Resource.SCOPE_SET);
-    query.setParameter("qualifier", Resource.QUALIFIER_LIB);
-    query.setParameter("last", Boolean.TRUE);
-    List<Snapshot> snapshots = query.getResultList();
-    if (snapshots.isEmpty()) {
-      snapshots = session.getResults(Snapshot.class, "resourceId", resourceId, "version", version, "scope", Resource.SCOPE_SET, "qualifier", Resource.QUALIFIER_LIB);
-    }
-    return (snapshots.isEmpty() ? null : snapshots.get(0));
-  }
-
-  /**
-   * Everything except project and library
-   */
-  private Snapshot doSaveResource(Project project, Resource resource) {
-    String databaseKey = getDatabaseKey(project, resource);
-    ResourceModel model = findOrCreateModel(resource, databaseKey);
-    Snapshot projectSnapshot = snapshotsByResource.get(project);
-    model.setRootId(projectSnapshot.getResourceId());
-    model = session.save(model);
-    resource.setId(model.getId()); // TODO to be removed
-    resource.setEffectiveKey(databaseKey);
-
-    Snapshot parentSnapshot = (Snapshot)ObjectUtils.defaultIfNull(getSnapshot(resource.getParent()), projectSnapshot);
-    Snapshot snapshot = new Snapshot(model, parentSnapshot);
-    snapshot = session.save(snapshot);
-    session.commit();
-    snapshotsByResource.put(resource, snapshot);
-    return snapshot;
-  }
-
-  public void clear() {
-    // we keep cache of projects
-    for (Iterator<Map.Entry<Resource, Snapshot>> it = snapshotsByResource.entrySet().iterator(); it.hasNext();) {
-      Map.Entry<Resource, Snapshot> entry = it.next();
-      if (!ResourceUtils.isSet(entry.getKey())) {
-        it.remove();
-      }
-    }
-  }
-
-
-  private ResourceModel findOrCreateModel(Resource resource, String databaseKey) {
-    ResourceModel model;
-    try {
-      model = session.getSingleResult(ResourceModel.class, "key", databaseKey);
-      if (model == null) {
-        model = createModel(resource, databaseKey);
-
-      } else {
-        mergeModel(model, resource);
-      }
-      return model;
-
-    } catch (NonUniqueResultException e) {
-      throw new SonarException("The resource '" + databaseKey + "' is duplicated in database.");
-    }
-  }
-
-  static ResourceModel createModel(Resource resource, String databaseKey) {
-    ResourceModel model = new ResourceModel();
-    model.setEnabled(Boolean.TRUE);
-    model.setDescription(resource.getDescription());
-    model.setKey(databaseKey);
-    if (resource.getLanguage() != null) {
-      model.setLanguageKey(resource.getLanguage().getKey());
-    }
-    if (StringUtils.isNotBlank(resource.getName())) {
-      model.setName(resource.getName());
-    } else {
-      model.setName(resource.getKey());
-    }
-    model.setLongName(resource.getLongName());
-    model.setScope(resource.getScope());
-    model.setQualifier(resource.getQualifier());
-    return model;
-  }
-
-  static void mergeModel(ResourceModel model, Resource resource) {
-    model.setEnabled(true);
-    if (StringUtils.isNotBlank(resource.getName())) {
-      model.setName(resource.getName());
-    }
-    if (StringUtils.isNotBlank(resource.getLongName())) {
-      model.setLongName(resource.getLongName());
-    }
-    if (StringUtils.isNotBlank(resource.getDescription())) {
-      model.setDescription(resource.getDescription());
-    }
-    if (!ResourceUtils.isLibrary(resource)) {
-      model.setScope(resource.getScope());
-      model.setQualifier(resource.getQualifier());
-    }
-    if (resource.getLanguage() != null) {
-      model.setLanguageKey(resource.getLanguage().getKey());
-    }
-  }
-
-  static String getDatabaseKey(Project project, Resource resource) {
-    if (StringUtils.equals(Resource.SCOPE_SET, resource.getScope())) {
-      // projects + libraries
-      return resource.getKey();
-    }
-    return new StringBuilder(ResourceModel.KEY_SIZE)
-        .append(project.getKey())
-        .append(':')
-        .append(resource.getKey())
-        .toString();
-  }
+  void clear();
 }
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
new file mode 100644 (file)
index 0000000..8134742
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * 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.batch.index;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.JavaPackage;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
+
+  private Project singleProject, multiModuleProject, moduleA, moduleB, moduleB1;
+
+  @Before
+  public void before() throws ParseException {
+    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
+    singleProject = new Project("foo");
+    singleProject.setName("Foo").setDescription("some description").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+
+    multiModuleProject = new Project("root");
+    multiModuleProject.setName("Root").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+
+    moduleA = new Project("a");
+    moduleA.setName("A").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+    moduleA.setParent(multiModuleProject);
+
+    moduleB = new Project("b");
+    moduleB.setName("B").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+    moduleB.setParent(multiModuleProject);
+
+    moduleB1 = new Project("b1");
+    moduleB1.setName("B1").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
+    moduleB1.setParent(moduleB);
+  }
+
+
+  @Test
+  public void shouldSaveNewProject() {
+    setupData("shared");
+
+    ResourcePersister persister = new DefaultResourcePersister(getSession());
+    persister.saveProject(singleProject);
+
+    checkTables("shouldSaveNewProject", "projects", "snapshots");
+  }
+
+  @Test
+  public void shouldSaveNewMultiModulesProject() throws ParseException {
+    setupData("shared");
+
+    ResourcePersister persister = new DefaultResourcePersister(getSession());
+    persister.saveProject(multiModuleProject);
+    persister.saveProject(moduleA);
+    persister.saveProject(moduleB);
+    persister.saveProject(moduleB1);
+
+    checkTables("shouldSaveNewMultiModulesProject", "projects", "snapshots");
+  }
+
+  @Test
+  public void shouldSaveNewDirectory() {
+    setupData("shared");
+
+    ResourcePersister persister = new DefaultResourcePersister(getSession());
+    persister.saveProject(singleProject);
+    persister.saveResource(singleProject, new JavaPackage("org.foo"));
+
+    // check that the directory is attached to the project
+    checkTables("shouldSaveNewDirectory", "projects", "snapshots");
+  }
+
+  @Test
+  public void shouldSaveNewLibrary() {
+    setupData("shared");
+
+    ResourcePersister persister = new DefaultResourcePersister(getSession());
+    persister.saveProject(singleProject);
+    persister.saveResource(singleProject, new Library("junit:junit", "4.8.2"));
+    persister.saveResource(singleProject, new Library("junit:junit", "4.8.2"));// do nothing, already saved
+    persister.saveResource(singleProject, new Library("junit:junit", "3.2"));
+
+    checkTables("shouldSaveNewLibrary", "projects", "snapshots");
+  }
+
+  @Test
+  public void shouldClearResourcesExceptProjects() {
+    setupData("shared");
+
+    DefaultResourcePersister persister = new DefaultResourcePersister(getSession());
+    persister.saveProject(multiModuleProject);
+    persister.saveProject(moduleA);
+    persister.saveResource(moduleA, new JavaPackage("org.foo"));
+    persister.saveResource(moduleA, new JavaFile("org.foo.MyClass"));
+    persister.clear();
+
+    assertThat(persister.getSnapshotsByResource().size(), is(2));
+    assertThat(persister.getSnapshotsByResource().get(multiModuleProject), notNullValue());
+    assertThat(persister.getSnapshotsByResource().get(moduleA), notNullValue());
+  }
+
+  @Test
+  public void shouldUpdateExistingResource() {
+    setupData("shouldUpdateExistingResource");
+
+    ResourcePersister persister = new DefaultResourcePersister(getSession());
+    singleProject.setName("new name");
+    singleProject.setDescription("new description");
+    persister.saveProject(singleProject);
+
+    checkTables("shouldUpdateExistingResource", "projects", "snapshots");
+  }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
deleted file mode 100644 (file)
index 88fbb20..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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.batch.index;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.JavaPackage;
-import org.sonar.api.resources.Library;
-import org.sonar.api.resources.Project;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.notNullValue;
-
-public class ResourcePersisterTest extends AbstractDbUnitTestCase {
-
-  private Project singleProject, multiModuleProject, moduleA, moduleB, moduleB1;
-
-  @Before
-  public void before() throws ParseException {
-    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
-    singleProject = new Project("foo");
-    singleProject.setName("Foo").setDescription("some description").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
-
-    multiModuleProject = new Project("root");
-    multiModuleProject.setName("Root").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
-
-    moduleA = new Project("a");
-    moduleA.setName("A").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
-    moduleA.setParent(multiModuleProject);
-
-    moduleB = new Project("b");
-    moduleB.setName("B").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
-    moduleB.setParent(multiModuleProject);
-
-    moduleB1 = new Project("b1");
-    moduleB1.setName("B1").setLanguageKey("java").setAnalysisDate(format.parse("25/12/2010"));
-    moduleB1.setParent(moduleB);
-  }
-
-
-  @Test
-  public void shouldSaveNewProject() {
-    setupData("shared");
-
-    ResourcePersister persister = new ResourcePersister(getSession());
-    persister.saveProject(singleProject);
-
-    checkTables("shouldSaveNewProject", "projects", "snapshots");
-  }
-
-  @Test
-  public void shouldSaveNewMultiModulesProject() throws ParseException {
-    setupData("shared");
-
-    ResourcePersister persister = new ResourcePersister(getSession());
-    persister.saveProject(multiModuleProject);
-    persister.saveProject(moduleA);
-    persister.saveProject(moduleB);
-    persister.saveProject(moduleB1);
-
-    checkTables("shouldSaveNewMultiModulesProject", "projects", "snapshots");
-  }
-
-  @Test
-  public void shouldSaveNewDirectory() {
-    setupData("shared");
-
-    ResourcePersister persister = new ResourcePersister(getSession());
-    persister.saveProject(singleProject);
-    persister.saveResource(singleProject, new JavaPackage("org.foo"));
-
-    // check that the directory is attached to the project
-    checkTables("shouldSaveNewDirectory", "projects", "snapshots");
-  }
-
-  @Test
-  public void shouldSaveNewLibrary() {
-    setupData("shared");
-
-    ResourcePersister persister = new ResourcePersister(getSession());
-    persister.saveProject(singleProject);
-    persister.saveResource(singleProject, new Library("junit:junit", "4.8.2"));
-    persister.saveResource(singleProject, new Library("junit:junit", "4.8.2"));// do nothing, already saved
-    persister.saveResource(singleProject, new Library("junit:junit", "3.2"));
-
-    checkTables("shouldSaveNewLibrary", "projects", "snapshots");
-  }
-
-  @Test
-  public void shouldClearResourcesExceptProjects() {
-    setupData("shared");
-
-    ResourcePersister persister = new ResourcePersister(getSession());
-    persister.saveProject(multiModuleProject);
-    persister.saveProject(moduleA);
-    persister.saveResource(moduleA, new JavaPackage("org.foo"));
-    persister.saveResource(moduleA, new JavaFile("org.foo.MyClass"));
-    persister.clear();
-
-    assertThat(persister.getSnapshotsByResource().size(), is(2));
-    assertThat(persister.getSnapshotsByResource().get(multiModuleProject), notNullValue());
-    assertThat(persister.getSnapshotsByResource().get(moduleA), notNullValue());
-  }
-
-  @Test
-  public void shouldUpdateExistingResource() {
-    setupData("shouldUpdateExistingResource");
-
-    ResourcePersister persister = new ResourcePersister(getSession());
-    singleProject.setName("new name");
-    singleProject.setDescription("new description");
-    persister.saveProject(singleProject);
-
-    checkTables("shouldUpdateExistingResource", "projects", "snapshots");
-  }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
new file mode 100644 (file)
index 0000000..d92fdb8
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.batch.index;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.utils.SonarException;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class SourcePersisterTest extends AbstractDbUnitTestCase {
+
+  private SourcePersister sourcePersister;
+
+  @Before
+  public void before() {
+    setupData("shared");
+    Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
+    ResourcePersister resourcePersister = mock(ResourcePersister.class);
+    when(resourcePersister.saveResource((Project) anyObject(), (Resource) anyObject())).thenReturn(snapshot);
+    sourcePersister = new SourcePersister(getSession(), resourcePersister);
+  }
+
+  @Test
+  public void shouldSaveSource() {
+    sourcePersister.saveSource(new Project(""), new JavaFile("org.foo.Bar"), "this is the file content");
+    checkTables("shouldSaveSource", "snapshot_sources");
+  }
+
+  @Test(expected = SonarException.class)
+  public void shouldFailIfSourceSavedSeveralTimes() {
+    Project project = new Project("project");
+    JavaFile file = new JavaFile("org.foo.Bar");
+    sourcePersister.saveSource(project, file, "this is the file content");
+    sourcePersister.saveSource(project, file, "new content"); // fail
+  }
+}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shared.xml
new file mode 100644 (file)
index 0000000..0c4e4ae
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- other project -->
+  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
+            name="Other project" long_name="Other" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="P" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewDirectory-result.xml
new file mode 100644 (file)
index 0000000..7e82d5b
--- /dev/null
@@ -0,0 +1,30 @@
+<dataset>
+
+  <!-- other project -->
+  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
+            name="Other project" long_name="Other" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="P" islast="false" depth="0"/>
+
+
+  <!-- new project -->
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+            name="Foo" long_name="Foo" description="some description"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001"
+            name="org.foo" long_name="org.foo" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0"/>
+
+  <snapshots id="3002" project_id="1002" parent_snapshot_id="3001" root_project_id="1001" root_snapshot_id="3001"
+             scope="DIR" qualifier="PAC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001."
+             status="U" islast="false" depth="1"/>
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewLibrary-result.xml
new file mode 100644 (file)
index 0000000..f53d742
--- /dev/null
@@ -0,0 +1,34 @@
+<dataset>
+
+  <!-- other project -->
+  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
+            name="Other project" long_name="Other" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="P" islast="false" depth="0" />
+
+
+  <!-- new project -->
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+            name="Foo" long_name="Foo" description="some description"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <projects id="1002" scope="PRJ" qualifier="LIB" kee="junit:junit" root_id="[null]"
+            name="junit:junit" long_name="junit:junit" description="[null]"
+            enabled="true" language="[null]" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+  <snapshots id="3002" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="LIB" created_at="2010-12-25 00:00:00.00" version="4.8.2" path=""
+             status="P" islast="false" depth="0" />
+
+  <snapshots id="3003" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="LIB" created_at="2010-12-25 00:00:00.00" version="3.2" path=""
+             status="P" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml
new file mode 100644 (file)
index 0000000..a83a24b
--- /dev/null
@@ -0,0 +1,48 @@
+<dataset>
+
+  <!-- other project -->
+  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
+            name="Other project" long_name="Other" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="P" islast="false" depth="0" />
+
+
+  <!-- new project -->
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="root" root_id="[null]"
+            name="Root" long_name="Root" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <projects id="1002" scope="PRJ" qualifier="BRC" kee="a" root_id="1001"
+            name="A" long_name="A" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <projects id="1003" scope="PRJ" qualifier="BRC" kee="b" root_id="1001"
+            name="B" long_name="B" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <projects id="1004" scope="PRJ" qualifier="BRC" kee="b1" root_id="1001"
+            name="B1" long_name="B1" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+
+  <snapshots id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]"  root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+  <snapshots id="3002" project_id="1002" root_project_id="1001" parent_snapshot_id="3001" root_snapshot_id="3001"
+             scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001."
+             status="U" islast="false" depth="1" />
+
+  <snapshots id="3003" project_id="1003" root_project_id="1001" parent_snapshot_id="3001" root_snapshot_id="3001"
+             scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001."
+             status="U" islast="false" depth="1" />
+
+  <snapshots id="3004" project_id="1004" root_project_id="1001" parent_snapshot_id="3003" root_snapshot_id="3001"
+             scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001.3003."
+             status="U" islast="false" depth="2" />
+
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldSaveNewProject-result.xml
new file mode 100644 (file)
index 0000000..e69ab9a
--- /dev/null
@@ -0,0 +1,22 @@
+<dataset>
+
+  <!-- other project -->
+  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
+            name="Other project" long_name="Other" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="P" islast="false" depth="0" />
+
+
+  <!-- new project -->
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+            name="Foo" long_name="Foo" description="some description"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource-result.xml
new file mode 100644 (file)
index 0000000..3006cd6
--- /dev/null
@@ -0,0 +1,17 @@
+<dataset>
+
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+            name="new name" long_name="new name" description="new description"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <!-- old snapshot -->
+  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+  <!-- new snapshot -->
+  <snapshots id="3002" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldUpdateExistingResource.xml
new file mode 100644 (file)
index 0000000..1a6997f
--- /dev/null
@@ -0,0 +1,11 @@
+<dataset>
+
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+            name="old name" long_name="old name" description="old description"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shared.xml
deleted file mode 100644 (file)
index 0c4e4ae..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-
-  <!-- other project -->
-  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
-            name="Other project" long_name="Other" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
-             status="P" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml
deleted file mode 100644 (file)
index 7e82d5b..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<dataset>
-
-  <!-- other project -->
-  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
-            name="Other project" long_name="Other" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
-             status="P" islast="false" depth="0"/>
-
-
-  <!-- new project -->
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
-            name="Foo" long_name="Foo" description="some description"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <projects id="1002" scope="DIR" qualifier="PAC" kee="foo:org.foo" root_id="1001"
-            name="org.foo" long_name="org.foo" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0"/>
-
-  <snapshots id="3002" project_id="1002" parent_snapshot_id="3001" root_project_id="1001" root_snapshot_id="3001"
-             scope="DIR" qualifier="PAC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001."
-             status="U" islast="false" depth="1"/>
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml
deleted file mode 100644 (file)
index f53d742..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<dataset>
-
-  <!-- other project -->
-  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
-            name="Other project" long_name="Other" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
-             status="P" islast="false" depth="0" />
-
-
-  <!-- new project -->
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
-            name="Foo" long_name="Foo" description="some description"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <projects id="1002" scope="PRJ" qualifier="LIB" kee="junit:junit" root_id="[null]"
-            name="junit:junit" long_name="junit:junit" description="[null]"
-            enabled="true" language="[null]" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0" />
-
-  <snapshots id="3002" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="LIB" created_at="2010-12-25 00:00:00.00" version="4.8.2" path=""
-             status="P" islast="false" depth="0" />
-
-  <snapshots id="3003" project_id="1002" parent_snapshot_id="[null]" root_project_id="1002" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="LIB" created_at="2010-12-25 00:00:00.00" version="3.2" path=""
-             status="P" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml
deleted file mode 100644 (file)
index a83a24b..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<dataset>
-
-  <!-- other project -->
-  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
-            name="Other project" long_name="Other" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
-             status="P" islast="false" depth="0" />
-
-
-  <!-- new project -->
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="root" root_id="[null]"
-            name="Root" long_name="Root" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <projects id="1002" scope="PRJ" qualifier="BRC" kee="a" root_id="1001"
-            name="A" long_name="A" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <projects id="1003" scope="PRJ" qualifier="BRC" kee="b" root_id="1001"
-            name="B" long_name="B" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <projects id="1004" scope="PRJ" qualifier="BRC" kee="b1" root_id="1001"
-            name="B1" long_name="B1" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-
-  <snapshots id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]"  root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0" />
-
-  <snapshots id="3002" project_id="1002" root_project_id="1001" parent_snapshot_id="3001" root_snapshot_id="3001"
-             scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001."
-             status="U" islast="false" depth="1" />
-
-  <snapshots id="3003" project_id="1003" root_project_id="1001" parent_snapshot_id="3001" root_snapshot_id="3001"
-             scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001."
-             status="U" islast="false" depth="1" />
-
-  <snapshots id="3004" project_id="1004" root_project_id="1001" parent_snapshot_id="3003" root_snapshot_id="3001"
-             scope="PRJ" qualifier="BRC" created_at="2010-12-25 00:00:00.00" version="[null]" path="3001.3003."
-             status="U" islast="false" depth="2" />
-
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml
deleted file mode 100644 (file)
index e69ab9a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<dataset>
-
-  <!-- other project -->
-  <projects id="1000" scope="PRJ" qualifier="TRK" kee="my:key" root_id="[null]"
-            name="Other project" long_name="Other" description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3000" project_id="1000" parent_snapshot_id="[null]" root_project_id="1000" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
-             status="P" islast="false" depth="0" />
-
-
-  <!-- new project -->
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
-            name="Foo" long_name="Foo" description="some description"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml
deleted file mode 100644 (file)
index 3006cd6..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<dataset>
-
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
-            name="new name" long_name="new name" description="new description"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <!-- old snapshot -->
-  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0" />
-
-  <!-- new snapshot -->
-  <snapshots id="3002" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml
deleted file mode 100644 (file)
index 1a6997f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
-            name="old name" long_name="old name" description="old description"
-            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
-  <snapshots id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" version="[null]" path=""
-             status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shared.xml
new file mode 100644 (file)
index 0000000..8290d2e
--- /dev/null
@@ -0,0 +1,11 @@
+<dataset>
+
+  <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
+            name="Bar" long_name="org.foo.Bar" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
+             scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="U" islast="false" depth="3" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shouldSaveSource-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/SourcePersisterTest/shouldSaveSource-result.xml
new file mode 100644 (file)
index 0000000..535d213
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
+            name="Bar" long_name="org.foo.Bar" description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+  <snapshots id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
+             scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+             status="U" islast="false" depth="3" />
+
+  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="1000" DATA="this is the file content"/>
+</dataset>
\ No newline at end of file