Search in sources :

Example 11 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class FullConfigSaveMergeFlowTest method shouldCheckinGeneratedConfigXMLToConfigRepo.

@Test
public void shouldCheckinGeneratedConfigXMLToConfigRepo() throws Exception {
    String mergedConfig = "merged_config";
    Date currentTime = mock(Date.class);
    ArgumentCaptor<GoConfigRevision> revisionArgumentCaptor = ArgumentCaptor.forClass(GoConfigRevision.class);
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(configRepository.getConfigMergedWithLatestRevision(any(GoConfigRevision.class), any(String.class))).thenReturn(mergedConfig);
    when(writer.toString(document)).thenReturn("cruise_config");
    when(serverVersion.version()).thenReturn("16.13.0");
    when(timeProvider.currentTime()).thenReturn(currentTime);
    when(loader.loadConfigHolder(any(String.class), any(MagicalGoConfigXmlLoader.Callback.class))).thenReturn(new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig()));
    doNothing().when(configRepository).checkin(revisionArgumentCaptor.capture());
    flow.execute(updateConfigCommand, partials, "test_user");
    GoConfigRevision goConfigRevision = revisionArgumentCaptor.getValue();
    assertThat(goConfigRevision.getContent(), is(mergedConfig));
    assertThat(goConfigRevision.getUsername(), is("test_user"));
    assertThat(goConfigRevision.getMd5(), is(updateConfigCommand.configForEdit().getMd5()));
    assertThat(goConfigRevision.getGoVersion(), is("16.13.0"));
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Date(java.util.Date) Test(org.junit.Test)

Example 12 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class FullConfigSaveMergeFlowTest method shouldMergeConfigWithLatestRevision.

@Test
public void shouldMergeConfigWithLatestRevision() throws Exception {
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(writer.toString(document)).thenReturn("cruise_config");
    when(loader.loadConfigHolder(any(String.class), any(MagicalGoConfigXmlLoader.Callback.class))).thenReturn(new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig()));
    flow.execute(updateConfigCommand, partials, null);
    verify(configRepository).getConfigMergedWithLatestRevision(new GoConfigRevision("config", "temporary-md5-for-branch", "user", "version", new TimeProvider()), "md5");
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 13 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class FullConfigSaveNormalFlowTest method shouldCheckinGeneratedConfigXMLToConfigRepo.

@Test
public void shouldCheckinGeneratedConfigXMLToConfigRepo() throws Exception {
    String configAsXml = "cruise config as xml";
    Date currentTime = mock(Date.class);
    ArgumentCaptor<GoConfigRevision> revisionArgumentCaptor = ArgumentCaptor.forClass(GoConfigRevision.class);
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(writer.toString(document)).thenReturn(configAsXml);
    when(loader.preprocessAndValidate(configForEdit)).thenReturn(new BasicCruiseConfig());
    when(serverVersion.version()).thenReturn("16.13.0");
    when(timeProvider.currentTime()).thenReturn(currentTime);
    doNothing().when(configRepository).checkin(revisionArgumentCaptor.capture());
    flow.execute(updateConfigCommand, partials, "test_user");
    GoConfigRevision goConfigRevision = revisionArgumentCaptor.getValue();
    assertThat(goConfigRevision.getContent(), is(configAsXml));
    assertThat(goConfigRevision.getUsername(), is("test_user"));
    assertThat(goConfigRevision.getMd5(), is(updateConfigCommand.configForEdit().getMd5()));
    assertThat(goConfigRevision.getGoVersion(), is("16.13.0"));
    assertThat(goConfigRevision.getTime(), is(currentTime));
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Date(java.util.Date) Test(org.junit.Test)

Example 14 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class ConfigRepositoryTest method shouldFailWhenDoesNotFindARev.

@Test
public void shouldFailWhenDoesNotFindARev() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    try {
        configRepo.getRevision("some-random-revision");
        fail("should have failed as revision does not exist");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), is("There is no config version corresponding to md5: 'some-random-revision'"));
    }
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 15 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class ConfigRepositoryTest method shouldCommitIntoGivenBranch.

@Test
public void shouldCommitIntoGivenBranch() throws Exception {
    configRepo.checkin(goConfigRevision("something", "md5-1"));
    RevCommit revCommitOnMaster = configRepo.getCurrentRevCommit();
    String branchName = "branch1";
    configRepo.createBranch(branchName, revCommitOnMaster);
    String newConfigXML = "config-xml";
    GoConfigRevision configRevision = new GoConfigRevision(newConfigXML, "md5", "user", "version", new TimeProvider());
    RevCommit branchRevCommit = configRepo.checkinToBranch(branchName, configRevision);
    assertThat(branchRevCommit, is(notNullValue()));
    assertThat(getLatestConfigAt(branchName), is(newConfigXML));
    assertThat(configRepo.getCurrentRevCommit(), is(revCommitOnMaster));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)28 Test (org.junit.Test)22 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 GoConfigRevisions (com.thoughtworks.go.GoConfigRevisions)2 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 FileOutputStream (java.io.FileOutputStream)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 DateTime (org.joda.time.DateTime)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 SecurityContext (org.springframework.security.context.SecurityContext)1