use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class StageServiceIntegrationTest method checkin.
private Modification checkin(Material material, String rev, String comment, String user, String email, Date checkinTime) {
Modification commit = checkinWithComment(rev, comment, user, email, checkinTime);
// saved now, used later
dbHelper.addRevisionsWithModifications(material, commit);
return commit;
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class ScheduleTestUtil method pass.
private String pass(final AddedPipeline pipeline, final Date mduAt, final Pipeline instance) {
dbHelper.pass(instance);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
for (Stage stage : instance.getStages()) {
final String dmrRevStr = new StageIdentifier(new PipelineIdentifier(instance.getName(), instance.getCounter(), instance.getName() + instance.getCounter()), stage.getName(), "1").getStageLocator();
Modification modification = new Modification(mduAt, dmrRevStr, instance.getLabel(), instance.getId());
materialRepository.saveMaterialRevision(new MaterialRevision(pipeline.material, modification));
}
}
});
return new StageIdentifier(new PipelineIdentifier(instance.getName(), instance.getCounter(), instance.getName() + instance.getCounter()), pipeline.material.getStageName().toString(), "1").getStageLocator();
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class ScheduleTestUtil method scheduleWith.
private Pipeline scheduleWith(AddedPipeline pipeline, RevisionsForMaterial... revisions) {
Pipeline oldInstance = triggeredPipelines.get(pipeline.config.name());
Map<Material, List<Modification>> modMap = new HashMap<>();
Map<Modification, Modification> identityMap = new HashMap<>();
MaterialRevisions buildCause = new MaterialRevisions();
int i = 0;
for (Material material : new MaterialConfigConverter().toMaterials(pipeline.config.materialConfigs())) {
List<Modification> modifications = new ArrayList<>();
for (Modification modification : modForRev(revisions[i++])) {
if (!identityMap.containsKey(modification)) {
identityMap.put(modification, modification);
}
modifications.add(identityMap.get(modification));
}
MaterialInstance modificationsMaterialInstance = modifications.get(0).getMaterialInstance();
if (modMap.containsKey(material)) {
modifications = modMap.get(material);
} else {
modMap.put(material, modifications);
}
MaterialInstance configuredMaterialInstance = materialRepository.findOrCreateFrom(material);
if (!configuredMaterialInstance.equals(modificationsMaterialInstance)) {
throw new RuntimeException("Please fix the revision order to match material configuration order. Revision given for: " + modificationsMaterialInstance + " against configured material: " + configuredMaterialInstance);
}
if (oldInstance == null) {
buildCause.addRevision(new MaterialRevision(material, modifications));
} else {
MaterialRevision oldRev = oldInstance.getBuildCause().getMaterialRevisions().findRevisionFor(material);
List<Modification> modificationsSince = materialRepository.findModificationsSince(material, oldRev);
List<Modification> newRange = new ArrayList<>();
for (Modification newMod : modificationsSince) {
newRange.add(0, newMod);
if (newMod.equals(modifications)) {
break;
}
}
buildCause.addRevision(new MaterialRevision(material, newRange));
}
}
return dbHelper.schedulePipelineWithAllStages(pipeline.config, BuildCause.createWithModifications(buildCause, "loser"));
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class ScheduleTestUtil method modForRev.
private Modification modForRev(final String revision) {
return (Modification) materialRepository.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.createQuery("from Modification where revision = ?");
q.setParameter(0, revision);
List list = q.list();
if (list.isEmpty()) {
throw new RuntimeException("you are trying to load revision " + revision + " which doesn't exist");
}
return list.get(0);
}
});
}
use of com.thoughtworks.go.domain.materials.Modification in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldCreateEntriesForCompletedPipelines.
@Test
public void shouldCreateEntriesForCompletedPipelines() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
stubStageServiceGetHistory(null, stages(9));
updater.updateMaterial(dependencyMaterial);
List<Modification> modification = materialRepository.findLatestModification(dependencyMaterial).getMaterialRevision(0).getModifications();
assertThat(modification.size(), is(1));
assertThat(modification.get(0).getRevision(), is("pipeline-name/9/stage-name/0"));
assertThat(modification.get(0).getPipelineLabel(), is("LABEL-9"));
}
Aggregations