Search in sources :

Example 6 with ModifiedFile

use of com.thoughtworks.go.domain.materials.ModifiedFile in project gocd by gocd.

the class P4OutputParserTest method shouldRetrieveModificationFromDescription.

@Test
void shouldRetrieveModificationFromDescription() throws P4OutputParseException, ParseException {
    String output = "Change 2 by cce123user@connect4_10.18.2.31 on 2008/08/19 15:04:43\n" + "\n" + "\tAdded config file\n" + "\n" + "Affected files ...\n" + "\n" + "... //depot/cruise-config.xml#1 add\n" + "... //depot/README.txt#2 edit\n" + "... //depot/cruise-output/log.xml#1 delete\n" + "";
    Modification mod = parser.modificationFromDescription(output, new ConsoleResult(0, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
    assertThat(mod.getRevision()).isEqualTo("2");
    assertThat(mod.getUserName()).isEqualTo("cce123user@connect4_10.18.2.31");
    assertThat(mod.getModifiedTime()).isEqualTo(DESCRIPTION_FORMAT.parse("2008/08/19 15:04:43"));
    assertThat(mod.getComment()).isEqualTo("Added config file");
    List<ModifiedFile> files = mod.getModifiedFiles();
    assertThat(files.size()).isEqualTo(3);
    assertThat(files.get(0).getAction()).isEqualTo(ModifiedAction.added);
    assertThat(files.get(0).getFileName()).isEqualTo("cruise-config.xml");
    assertThat(files.get(1).getAction()).isEqualTo(ModifiedAction.modified);
    assertThat(files.get(2).getAction()).isEqualTo(ModifiedAction.deleted);
    assertThat(files.get(2).getFileName()).isEqualTo("cruise-output/log.xml");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) ArrayList(java.util.ArrayList) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) Test(org.junit.jupiter.api.Test)

Example 7 with ModifiedFile

use of com.thoughtworks.go.domain.materials.ModifiedFile in project gocd by gocd.

the class GitCommandTest method shouldRetrieveLatestModification.

@Test
public void shouldRetrieveLatestModification() throws Exception {
    Modification mod = git.latestModification().get(0);
    assertThat(mod.getUserName(), is("Chris Turner <cturner@thoughtworks.com>"));
    assertThat(mod.getComment(), is("Added 'run-till-file-exists' ant target"));
    assertThat(mod.getModifiedTime(), is(parseRFC822("Fri, 12 Feb 2010 16:12:04 -0800")));
    assertThat(mod.getRevision(), is("5def073a425dfe239aabd4bf8039ffe3b0e8856b"));
    List<ModifiedFile> files = mod.getModifiedFiles();
    assertThat(files.size(), is(1));
    assertThat(files.get(0).getFileName(), is("build.xml"));
    assertThat(files.get(0).getAction(), Matchers.is(ModifiedAction.modified));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) Test(org.junit.Test)

Example 8 with ModifiedFile

use of com.thoughtworks.go.domain.materials.ModifiedFile in project gocd by gocd.

the class SCMXmlViewModelTest method shouldPopulateModificationDetailsForPluggableSCMMaterial.

@Test
public void shouldPopulateModificationDetailsForPluggableSCMMaterial() {
    String userName = "user";
    String comment = "comment-1";
    Date checkinDate = new Date(System.currentTimeMillis());
    String revision = "revision-1";
    Modification modification = new Modification(userName, comment, null, checkinDate, revision);
    modification.setModifiedFiles(new ArrayList<>(asList(new ModifiedFile("f1", null, ModifiedAction.added), new ModifiedFile("f2", null, ModifiedAction.deleted))));
    Modifications modifications = new Modifications(modification);
    XmlWriterContext writerContext = mock(XmlWriterContext.class);
    when(writerContext.getBaseUrl()).thenReturn("http://someurl:8153/go");
    Element modificationsTag = DocumentHelper.createDocument().addElement("modifications");
    new PipelineXmlViewModel.ScmXmlViewModel(MaterialsMother.pluggableSCMMaterial()).populateXmlForModifications(modifications, writerContext, modificationsTag);
    Element changeSet = modificationsTag.element("changeset");
    assertThat(changeSet, is(not(nullValue())));
    assertThat(changeSet.attributeValue("changesetUri"), is("http://someurl:8153/go/api/materials/1/changeset/revision-1.xml"));
    assertThat(changeSet.element("user").getText(), is(userName));
    assertThat(changeSet.element("revision").getText(), is(revision));
    assertThat(changeSet.element("checkinTime").getText(), is(DateUtils.formatISO8601(checkinDate)));
    assertThat(changeSet.element("message").getText(), is(comment));
    Element file1 = (Element) changeSet.elements("file").get(0);
    assertThat(file1.attributeValue("name"), is("f1"));
    assertThat(file1.attributeValue("action"), is("added"));
    Element file2 = (Element) changeSet.elements("file").get(1);
    assertThat(file2.attributeValue("name"), is("f2"));
    assertThat(file2.attributeValue("action"), is("deleted"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.dom4j.Element) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 9 with ModifiedFile

use of com.thoughtworks.go.domain.materials.ModifiedFile in project gocd by gocd.

the class PipelineSqlMapDaoIntegrationTest method shouldRetrieveModificationsSortedBySavedOrder.

@Test
public void shouldRetrieveModificationsSortedBySavedOrder() throws SQLException {
    GitMaterial gitMaterial = new GitMaterial("url");
    PipelineConfig pipelineConfig = PipelineMother.twoBuildPlansWithResourcesAndMaterials("mingle", "dev");
    pipelineConfig.setMaterialConfigs(new MaterialConfigs(gitMaterial.config()));
    Modification firstModification = new Modification(new Date(), "1", "MOCK_LABEL-12", null);
    Modification secondModification = new Modification(new Date(), "2", "MOCK_LABEL-12", null);
    ArrayList<ModifiedFile> modifiedFiles = new ArrayList<ModifiedFile>() {

        {
            add(new ModifiedFile("filename", "foldername", ModifiedAction.modified));
        }
    };
    secondModification.setModifiedFiles(modifiedFiles);
    MaterialRevisions materialRevisions = new MaterialRevisions();
    materialRevisions.addRevision(gitMaterial, firstModification, secondModification);
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
    assertNotInserted(pipeline.getId());
    save(pipeline);
    Pipeline pipelineFromDB = pipelineDao.mostRecentPipeline(pipeline.getName());
    List<MaterialRevision> revisionsFromDB = pipelineFromDB.getMaterialRevisions().getRevisions();
    List<Modification> modificationsFromDB = revisionsFromDB.get(0).getModifications();
    assertThat(modificationsFromDB.size(), is(2));
    assertThat(modificationsFromDB.get(0).getRevision(), is("1"));
    assertThat(modificationsFromDB.get(1).getRevision(), is("2"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) TimeProvider(com.thoughtworks.go.util.TimeProvider) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) Test(org.junit.jupiter.api.Test)

Example 10 with ModifiedFile

use of com.thoughtworks.go.domain.materials.ModifiedFile in project gocd by gocd.

the class TransactionCacheInterceptorTest method shouldOptOutOfCacheServing_forUpdateOnItemsInCollection.

@Test
public void shouldOptOutOfCacheServing_forUpdateOnItemsInCollection() {
    final MaterialInstance materialInstance = savedHg();
    final Modification mod = new Modification("loser", "loser commiting a winner stroke", "foo@bar.com", new Date(), "123");
    mod.setMaterialInstance(materialInstance);
    ModifiedFile foo_c = mod.createModifiedFile("foo.c", "src", ModifiedAction.added);
    hibernateDaoSupport.getHibernateTemplate().save(mod);
    ReflectionUtil.setField(foo_c, "fileName", "foo_generated.c");
    assertionUtil.assertCacheBehaviourInTxn(new TransactionCacheAssertionUtil.DoInTxn() {

        @Override
        public void invoke() {
            hibernateDaoSupport.getHibernateTemplate().update(mod);
            hibernateDaoSupport.getHibernateTemplate().flush();
        }
    });
    assertThat(hibernateDaoSupport.getHibernateTemplate().load(ModifiedFile.class, foo_c.getId()).getFileName(), is("foo_generated.c"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)12 Modification (com.thoughtworks.go.domain.materials.Modification)10 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SAXBuilder (org.jdom2.input.SAXBuilder)3 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)2 Test (org.junit.Test)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)1 Modifications (com.thoughtworks.go.domain.materials.Modifications)1 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)1 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 ConsoleResult (com.thoughtworks.go.util.command.ConsoleResult)1 Element (org.dom4j.Element)1