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");
}
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));
}
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"));
}
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"));
}
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"));
}
Aggregations