Search in sources :

Example 1 with GoConfigRevision

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

the class ConfigRepositoryTest method shouldBeAbleToCheckin.

@Test
public void shouldBeAbleToCheckin() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v1 v2", "md5-v2", "user-name", "100.9.8", new TimeProvider()));
    assertThat(configRepo.getRevision("md5-v1").getContent(), is("v1"));
    assertThat(configRepo.getRevision("md5-v2").getContent(), is("v1 v2"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 2 with GoConfigRevision

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

the class ConfigRepositoryTest method shouldRemoveUnwantedDataFromDiff.

@Test
public void shouldRemoveUnwantedDataFromDiff() throws Exception {
    configRepo.checkin(goConfigRevision(ConfigFileFixture.configWithPipeline(ConfigFileFixture.SIMPLE_PIPELINE, 33), "md5-1"));
    String configXml = ConfigFileFixture.configWithPipeline(ConfigFileFixture.SIMPLE_PIPELINE, 60);
    configRepo.checkin(new GoConfigRevision(configXml, "md5-2", "user-2", "13.2", new TimeProvider()));
    String configChangesLine1 = "-<cruise schemaVersion='33'>";
    String configChangesLine2 = "+<cruise schemaVersion='60'>";
    String actual = configRepo.configChangesFor("md5-2", "md5-1");
    assertThat(actual, containsString(configChangesLine1));
    assertThat(actual, containsString(configChangesLine2));
    assertThat(actual, not(containsString("--- a/cruise-config.xml")));
    assertThat(actual, not(containsString("+++ b/cruise-config.xml")));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 3 with GoConfigRevision

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

the class ConfigRepositoryTest method shouldGetCommitsCorrectly.

@Test
public void shouldGetCommitsCorrectly() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v2", "md5-v2", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v3", "md5-v3", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v4", "md5-v4", "user-name", "100.3.9", new TimeProvider()));
    GoConfigRevisions goConfigRevisions = configRepo.getCommits(3, 0);
    assertThat(goConfigRevisions.size(), is(3));
    assertThat(goConfigRevisions.get(0).getContent(), is(nullValue()));
    assertThat(goConfigRevisions.get(0).getMd5(), is("md5-v4"));
    assertThat(goConfigRevisions.get(1).getMd5(), is("md5-v3"));
    assertThat(goConfigRevisions.get(2).getMd5(), is("md5-v2"));
    goConfigRevisions = configRepo.getCommits(3, 3);
    assertThat(goConfigRevisions.size(), is(1));
    assertThat(goConfigRevisions.get(0).getMd5(), is("md5-v1"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) GoConfigRevisions(com.thoughtworks.go.GoConfigRevisions) Test(org.junit.Test)

Example 4 with GoConfigRevision

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

the class ConfigRepositoryTest method shouldNotCommitWhenNothingChanged.

@Test
public void shouldNotCommitWhenNothingChanged() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    // md5 is solely trusted
    configRepo.checkin(new GoConfigRevision("v1 v2", "md5-v1", "loser-name", "501.9.8", new TimeProvider()));
    Iterator<RevCommit> commitIterator = configRepo.revisions().iterator();
    int size = 0;
    while (commitIterator.hasNext()) {
        size++;
        commitIterator.next();
    }
    assertThat(size, is(1));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 5 with GoConfigRevision

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

the class GoFileConfigDataSourceTest method shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven.

@Test
public void shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven() throws GitAPIException, IOException {
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
    goConfigDao.updateMailHost(getMailHost("mailhost.local"));
    CruiseConfig cruiseConfig = goConfigDao.load();
    GoConfigRevision revision = configRepository.getRevision(cruiseConfig.getMd5());
    assertThat(revision.getUsername(), is("loser_boozer"));
}
Also used : User(org.springframework.security.userdetails.User) SecurityContext(org.springframework.security.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) 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