use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class PluggableSCMMaterialUpdaterTest method shouldUpdateToNewMaterialInstanceWhenConfigHas_Changed.
@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);
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class MaterialServiceTest method shouldGetModificationSince_PluggableSCMMaterial.
@Test
public void shouldGetModificationSince_PluggableSCMMaterial() {
PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
MaterialInstance materialInstance = pluggableSCMMaterial.createMaterialInstance();
when(materialRepository.findMaterialInstance(any(Material.class))).thenReturn(materialInstance);
MaterialPollResult materialPollResult = new MaterialPollResult(null, asList(new SCMRevision("new-revision-456", new Date(), "user", "comment", null, null)));
when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(materialPollResult);
PluggableSCMMaterialRevision previouslyKnownRevision = new PluggableSCMMaterialRevision("revision-124", new Date());
List<Modification> modifications = materialService.modificationsSince(pluggableSCMMaterial, new File("/tmp/flyweight"), previouslyKnownRevision, null);
assertThat(modifications.get(0).getRevision(), is("new-revision-456"));
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class MaterialServiceTest method shouldGetLatestModification_PluggableSCMMaterial.
@Test
public void shouldGetLatestModification_PluggableSCMMaterial() {
PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
MaterialInstance materialInstance = pluggableSCMMaterial.createMaterialInstance();
when(materialRepository.findMaterialInstance(any(Material.class))).thenReturn(materialInstance);
MaterialPollResult materialPollResult = new MaterialPollResult(null, new SCMRevision("blah-123", new Date(), "user", "comment", null, null));
when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(materialPollResult);
List<Modification> modifications = materialService.latestModification(pluggableSCMMaterial, new File("/tmp/flyweight"), null);
assertThat(modifications.get(0).getRevision(), is("blah-123"));
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class MagicalMaterialAndMaterialConfigConversionTest method shouldBeSameObject_WhenConversionIsDoneFromMaterialToMaterialInstanceAndBack.
@Theory
public void shouldBeSameObject_WhenConversionIsDoneFromMaterialToMaterialInstanceAndBack(MaterialConfig materialConfig) throws Exception {
Material material = materialConfigConverter.toMaterial(materialConfig);
MaterialInstance materialInstance = material.createMaterialInstance();
Material materialConvertedBackFromInstance = materialInstance.toOldMaterial(materialConfig.getName().toString(), materialConfig.getFolder(), "pass");
assertTrue(message("Material <-> MaterialInstance conversion failed.", material, materialConvertedBackFromInstance), reflectionEquals(material, materialConvertedBackFromInstance, fieldsWhichShouldBeIgnoredWhenSavedInDbAndGotBack.get(materialConfig.getClass())));
assertThat(materialInstance.getFingerprint(), is(material.getFingerprint()));
assertThat(materialConvertedBackFromInstance.getFingerprint(), is(materialInstance.getFingerprint()));
assertPasswordIsCorrect(material);
assertPasswordIsCorrect(materialConvertedBackFromInstance);
}
use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.
the class ValueStreamMapService method getValueStreamMap.
public ValueStreamMapPresentationModel getValueStreamMap(String materialFingerprint, String revision, Username username, LocalizedOperationResult result) {
try {
MaterialConfig materialConfig = null;
boolean hasViewPermissionForMaterial = false;
List<PipelineConfig> downstreamPipelines = new ArrayList<>();
for (PipelineConfigs pipelineGroup : goConfigService.groups()) {
boolean hasViewPermissionForGroup = securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), pipelineGroup.getGroup());
for (PipelineConfig pipelineConfig : pipelineGroup) {
for (MaterialConfig currentMaterialConfig : pipelineConfig.materialConfigs()) {
if (currentMaterialConfig.getFingerprint().equals(materialFingerprint)) {
materialConfig = currentMaterialConfig;
if (hasViewPermissionForGroup) {
hasViewPermissionForMaterial = true;
}
downstreamPipelines.add(pipelineConfig);
}
}
}
}
if (materialConfig == null) {
result.notFound(LocalizedMessage.string("MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.GLOBAL));
return null;
}
if (!hasViewPermissionForMaterial) {
result.unauthorized(LocalizedMessage.cannotViewMaterial(materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
return null;
}
MaterialInstance materialInstance = materialRepository.findMaterialInstance(materialConfig);
if (materialInstance == null) {
result.notFound(LocalizedMessage.string("MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
return null;
}
Material material = new MaterialConfigConverter().toMaterial(materialConfig);
Modification modification = materialRepository.findModificationWithRevision(material, revision);
if (modification == null) {
result.notFound(LocalizedMessage.string("MATERIAL_MODIFICATION_NOT_FOUND", materialFingerprint, revision), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
return null;
}
ValueStreamMap valueStreamMap = buildValueStreamMap(material, materialInstance, modification, downstreamPipelines, username);
if (valueStreamMap == null) {
return null;
}
return valueStreamMap.presentationModel();
} catch (Exception e) {
result.internalServerError(LocalizedMessage.string("VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL", materialFingerprint, revision));
LOGGER.error("[Value Stream Map] Material {} with revision {} could not be rendered.", materialFingerprint, revision, e);
return null;
}
}
Aggregations