Search in sources :

Example 6 with GitService

use of io.fabric8.git.GitService in project fabric8 by jboss-fuse.

the class CachingGitDataStoreTest method setUp.

@Before
public void setUp() throws Exception {
    sfb = new ZKServerFactoryBean();
    delete(sfb.getDataDir());
    delete(sfb.getDataLogDir());
    sfb.afterPropertiesSet();
    runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
    EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
    EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
    EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
    EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
    EasyMock.replay(runtimeProperties);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + sfb.getClientPortAddress().getPort()).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
    curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    // setup a local and remote git repo
    basedir = System.getProperty("basedir", ".");
    File root = new File(basedir + "/target/git").getCanonicalFile();
    delete(root);
    new File(root, "remote").mkdirs();
    remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
    remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
    new File(root, "local").mkdirs();
    git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
    git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", remoteUrl);
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.save();
    FabricGitServiceImpl gitService = new FabricGitServiceImpl();
    gitService.bindRuntimeProperties(runtimeProperties);
    gitService.activate();
    gitService.setGitForTesting(git);
    dataStore = new GitDataStoreImpl();
    dataStore.bindCurator(curator);
    dataStore.bindGitService(gitService);
    dataStore.bindRuntimeProperties(runtimeProperties);
    dataStore.bindConfigurer(new Configurer() {

        @Override
        public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
            return null;
        }

        @Override
        public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
            return null;
        }
    });
    Map<String, Object> datastoreProperties = new HashMap<String, Object>();
    // datastoreProperties.put(GitDataStoreImpl.GIT_REMOTE_URL, remoteUrl);
    dataStore.activate(datastoreProperties);
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) HashMap(java.util.HashMap) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) IOException(java.io.IOException) StoredConfig(org.eclipse.jgit.lib.StoredConfig) DataStoreTemplate(io.fabric8.api.DataStoreTemplate) Configurer(io.fabric8.api.scr.Configurer) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) RuntimeProperties(io.fabric8.api.RuntimeProperties) Before(org.junit.Before)

Aggregations

GitService (io.fabric8.git.GitService)4 GitContext (io.fabric8.api.GitContext)3 RuntimeProperties (io.fabric8.api.RuntimeProperties)3 File (java.io.File)3 PushResult (org.eclipse.jgit.transport.PushResult)3 Before (org.junit.Before)3 DataStoreTemplate (io.fabric8.api.DataStoreTemplate)2 FabricException (io.fabric8.api.FabricException)2 GitDataStore (io.fabric8.git.GitDataStore)2 ZKServerFactoryBean (io.fabric8.zookeeper.spring.ZKServerFactoryBean)2 IOException (java.io.IOException)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2 RetryOneTime (org.apache.curator.retry.RetryOneTime)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 DataStore (io.fabric8.api.DataStore)1 Configurer (io.fabric8.api.scr.Configurer)1 ValidatingReference (io.fabric8.api.scr.ValidatingReference)1 ValidationSupport (io.fabric8.api.scr.ValidationSupport)1 GitNode (io.fabric8.git.GitNode)1 PullPushPolicy (io.fabric8.git.PullPushPolicy)1