use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class SvnPostCommitHookImplementerTest method shouldPruneListToGiveOutOnlySvnMaterialsWhichMatchTheRepositoryUUID.
@Test
public void shouldPruneListToGiveOutOnlySvnMaterialsWhichMatchTheRepositoryUUID() {
final SvnMaterial svnMaterial1 = mock(SvnMaterial.class);
final SvnMaterial svnMaterial2 = mock(SvnMaterial.class);
final SvnMaterial svnMaterial3 = mock(SvnMaterial.class);
final HashSet<Material> allMaterials = new HashSet<>(Arrays.asList(svnMaterial1, svnMaterial2, svnMaterial3));
final HashMap<Object, Object> params = new HashMap<>();
final String uuid = "12345";
params.put(SvnPostCommitHookImplementer.UUID, uuid);
final SvnPostCommitHookImplementer spy = spy(implementer);
final HashMap<String, String> map = new HashMap<>();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
map.put("url1", "12345");
map.put("url2", "54321");
return map;
}
}).when(spy).createUrlToRemoteUUIDMap(allMaterials);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return Boolean.FALSE;
}
}).when(spy).isQualified(uuid, svnMaterial1, map);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return Boolean.TRUE;
}
}).when(spy).isQualified(uuid, svnMaterial2, map);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return Boolean.FALSE;
}
}).when(spy).isQualified(uuid, svnMaterial3, map);
final Set<Material> prunedList = spy.prune(allMaterials, params);
assertThat(prunedList.size(), is(1));
verify(spy, times(1)).createUrlToRemoteUUIDMap(allMaterials);
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldUpdateOnlyOnceIfThereAreTwoMaterialsWithSameFingerPrintButDifferentDest.
@Test
public void shouldUpdateOnlyOnceIfThereAreTwoMaterialsWithSameFingerPrintButDifferentDest() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterial material2 = new HgMaterial("url", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
HgMaterialConfig materialConfig2 = new HgMaterialConfig("url", null);
material1.setFolder("folder1");
material2.setFolder("folder2");
assertThat(material1.getFingerprint(), is(material2.getFingerprint()));
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.addMaterialConfig(materialConfig2);
Material[] materials = new Material[] { material1, material2 };
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(material2);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
verify(mockMaterialUpdateService, times(1)).updateMaterial(any(Material.class));
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateFailedMessage(materials[0], 0, new Exception("Cannot connect to repo")));
verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldAllowRetriggeringIfThePreviousTriggerFailed.
@Test
public void shouldAllowRetriggeringIfThePreviousTriggerFailed() throws Exception {
GitMaterialConfig materialConfig = MaterialConfigsMother.gitMaterialConfig();
PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs(materialConfig));
Material material = new MaterialConfigConverter().toMaterial(materialConfig);
buildCauseProducerService.manualSchedulePipeline(Username.CRUISE_TIMER, pipelineConfig.name(), new ScheduleOptions(), errorResult());
HttpOperationResult result = new HttpOperationResult();
when(materialConfigConverter.toMaterial(materialConfig)).thenReturn(material);
when(materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs())).thenReturn(pipelineConfig.materialConfigs());
when(materialConfigConverter.toMaterials(pipelineConfig.materialConfigs())).thenReturn(new Materials(material));
when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
buildCauseProducerService.manualSchedulePipeline(Username.CRUISE_TIMER, pipelineConfig.name(), new ScheduleOptions(), result);
assertThat(result.httpCode(), is(202));
assertThat(result.fullMessage(), is("Request to schedule pipeline pipeline accepted"));
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class MagicalMaterialAndMaterialConfigConversionTest method shouldBeSameObject_WhenConversionIsDoneFromMaterialConfigToMaterialAndBack.
@Theory
public void shouldBeSameObject_WhenConversionIsDoneFromMaterialConfigToMaterialAndBack(MaterialConfig materialConfig) throws Exception {
Material materialFromConfig = materialConfigConverter.toMaterial(materialConfig);
MaterialConfig materialConfigConvertedBackFromMaterial = materialFromConfig.config();
assertThat(materialConfigConvertedBackFromMaterial, is(materialConfig));
assertTrue(message("Material <-> MaterialConfig conversion failed.", materialConfigConvertedBackFromMaterial, materialConfig), reflectionEquals(materialConfigConvertedBackFromMaterial, materialConfig));
assertThat(materialFromConfig.getFingerprint(), is(materialConfig.getFingerprint()));
assertThat(materialFromConfig.isAutoUpdate(), is(materialConfig.isAutoUpdate()));
assertThat(materialConfigConvertedBackFromMaterial.getFingerprint(), is(materialConfig.getFingerprint()));
assertPasswordIsCorrect(materialConfig);
assertPasswordIsCorrect(materialFromConfig);
assertPasswordIsCorrect(materialConfigConvertedBackFromMaterial);
}
use of com.thoughtworks.go.domain.materials.Material 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);
}
Aggregations