Switch jgit library to the EDL (3-clause BSD)
[egit/zawir.git] / org.spearce.jgit.test / tst / org / spearce / jgit / lib / RepositoryConfigTest.java
blob8c55fe87c03f451aede80a4b9b70c60d26166641
1 /*
2 * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
4 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the following
10 * conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
20 * - Neither the name of the Git Development Community nor the
21 * names of its contributors may be used to endorse or promote
22 * products derived from this software without specific prior
23 * written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 package org.spearce.jgit.lib;
42 import java.io.File;
43 import java.io.IOException;
45 /**
46 * Test reading of git config
48 public class RepositoryConfigTest extends RepositoryTestCase {
49 /**
50 * Read config item with no value from a section without a subsection.
52 * @throws IOException
54 public void test001_ReadBareKey() throws IOException {
55 final File path = writeTrashFile("config_001", "[foo]\nbar\n");
56 RepositoryConfig repositoryConfig = new RepositoryConfig(null, path);
57 System.out.println(repositoryConfig.getString("foo", null, "bar"));
58 assertEquals(true, repositoryConfig.getBoolean("foo", null, "bar", false));
59 assertEquals("", repositoryConfig.getString("foo", null, "bar"));
62 /**
63 * Read various data from a subsection.
65 * @throws IOException
67 public void test002_ReadWithSubsection() throws IOException {
68 final File path = writeTrashFile("config_002", "[foo \"zip\"]\nbar\n[foo \"zap\"]\nbar=false\nn=3\n");
69 RepositoryConfig repositoryConfig = new RepositoryConfig(null, path);
70 assertEquals(true, repositoryConfig.getBoolean("foo", "zip", "bar", false));
71 assertEquals("", repositoryConfig.getString("foo","zip", "bar"));
72 assertEquals(false, repositoryConfig.getBoolean("foo", "zap", "bar", true));
73 assertEquals("false", repositoryConfig.getString("foo", "zap", "bar"));
74 assertEquals(3, repositoryConfig.getInt("foo", "zap", "n", 4));
75 assertEquals(4, repositoryConfig.getInt("foo", "zap","m", 4));
78 public void test003_PutRemote() throws IOException {
79 File cfgFile = writeTrashFile("config_003", "");
80 RepositoryConfig repositoryConfig = new RepositoryConfig(null, cfgFile);
81 repositoryConfig.setString("sec", "ext", "name", "value");
82 repositoryConfig.setString("sec", "ext", "name2", "value2");
83 repositoryConfig.save();
84 checkFile(cfgFile, "[sec \"ext\"]\n\tname = value\n\tname2 = value2\n");
87 public void test004_PutSimple() throws IOException {
88 File cfgFile = writeTrashFile("config_004", "");
89 RepositoryConfig repositoryConfig = new RepositoryConfig(null, cfgFile);
90 repositoryConfig.setString("my", null, "somename", "false");
91 repositoryConfig.save();
92 checkFile(cfgFile, "[my]\n\tsomename = false\n");