Example #1
0
  @Test
  public void shouldDelegateToMaterialRepository_getTotalModificationsFor() {
    GitMaterialConfig materialConfig = new GitMaterialConfig("http://test.com");
    GitMaterialInstance gitMaterialInstance =
        new GitMaterialInstance("http://test.com", null, null, "flyweight");

    when(materialRepository.findMaterialInstance(materialConfig)).thenReturn(gitMaterialInstance);

    when(materialRepository.getTotalModificationsFor(gitMaterialInstance)).thenReturn(1L);

    Long totalCount = materialService.getTotalModificationsFor(materialConfig);

    assertThat(totalCount, is(1L));
  }
Example #2
0
  @Test
  public void shouldReturnTheRevisionsThatMatchTheGivenSearchString() {
    when(securityService.hasViewPermissionForPipeline("pavan", "pipeline")).thenReturn(true);
    LocalizedOperationResult operationResult = mock(LocalizedOperationResult.class);
    MaterialConfig materialConfig = mock(MaterialConfig.class);
    when(goConfigService.materialForPipelineWithFingerprint("pipeline", "sha"))
        .thenReturn(materialConfig);

    List<MatchedRevision> expected =
        Arrays.asList(
            new MatchedRevision(
                "23",
                "revision",
                "revision",
                "user",
                new DateTime(2009, 10, 10, 12, 0, 0, 0).toDate(),
                "comment"));
    when(materialRepository.findRevisionsMatching(materialConfig, "23")).thenReturn(expected);
    assertThat(
        materialService.searchRevisions(
            "pipeline",
            "sha",
            "23",
            new Username(new CaseInsensitiveString("pavan")),
            operationResult),
        is(expected));
  }
Example #3
0
  @Test
  public void shouldDelegateToMaterialRepository_getModificationsFor() {
    GitMaterialConfig materialConfig = new GitMaterialConfig("http://test.com");
    GitMaterialInstance gitMaterialInstance =
        new GitMaterialInstance("http://test.com", null, null, "flyweight");
    Pagination pagination = Pagination.pageStartingAt(0, 10, 10);
    Modifications modifications = new Modifications();
    modifications.add(new Modification("user", "comment", "email", new Date(), "revision"));

    when(materialRepository.findMaterialInstance(materialConfig)).thenReturn(gitMaterialInstance);

    when(materialRepository.getModificationsFor(gitMaterialInstance, pagination))
        .thenReturn(modifications);

    Modifications gotModifications =
        materialService.getModificationsFor(materialConfig, pagination);

    assertThat(gotModifications, is(modifications));
  }
Example #4
0
  public void insertLatestOrNewModifications(
      Material material, MaterialInstance materialInstance, File folder, Modifications list) {
    List<Modification> newChanges =
        list.isEmpty()
            ? materialChecker.findLatestModification(folder, material, subprocessExecutionContext)
            : materialService.modificationsSince(
                material, folder, list.latestRevision(material), subprocessExecutionContext);
    if (newChanges.isEmpty()) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
            String.format(
                "[Material Update] Did not find any new modifications for material '%s' with flyweight '%s' using working directory '%s'",
                material, material.getFingerprint(), folder.getAbsolutePath()));
      }
    } else {
      LOGGER.info(
          String.format(
              "[Material Update] Found '%s' modifications for material '%s' with flyweight '%s' using working directory '%s'",
              newChanges.size(), material, material.getFingerprint(), folder.getAbsolutePath()));

      materialRepository.saveModifications(materialInstance, newChanges);
    }
  }
  @Test
  public void shouldUpdateToNewMaterialInstanceWhenConfigHas_Changed() throws Exception {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = material.createMaterialInstance();
    materialInstance.setId(1);

    material
        .getScmConfig()
        .getConfiguration()
        .add(ConfigurationPropertyMother.create("key2", false, "value2"));
    MaterialInstance newMaterialInstance = material.createMaterialInstance();
    newMaterialInstance.setId(1);
    File file = new File("random");

    Modifications modifications = new Modifications();
    when(materialRepository.find(anyLong())).thenReturn(materialInstance);

    materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);

    verify(materialRepository).saveOrUpdate(newMaterialInstance);
    verify(scmMaterialUpdater)
        .insertLatestOrNewModifications(material, materialInstance, file, modifications);
  }
Example #6
0
 public void addNewMaterialWithModifications(Material material, File folder) {
   MaterialRevisions materialRevisions = materialRepository.findLatestModification(material);
   Modifications list = materialRevisions.getModifications(material);
   insertLatestOrNewModifications(
       material, materialRepository.findOrCreateFrom(material), folder, list);
 }
 private MaterialRevisions checkinFile(
     SvnMaterial svn, String checkinFile, final SvnTestRepo svnRepository) throws Exception {
   svnRepository.checkInOneFile(checkinFile);
   materialDatabaseUpdater.updateMaterial(svn);
   return materialRepository.findLatestModification(svn);
 }
Example #8
0
 private void assertHasModifcation(MaterialRevisions materialRevisions, boolean b) {
   HgMaterial hgMaterial = new HgMaterial("foo.com", null);
   when(materialRepository.findLatestModification(hgMaterial)).thenReturn(materialRevisions);
   assertThat(materialService.hasModificationFor(hgMaterial), is(b));
 }