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>
5 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
21 * - Neither the name of the Git Development Community nor the
22 * names of its contributors may be used to endorse or promote
23 * products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
27 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
38 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 package org
.spearce
.jgit
.lib
;
44 import java
.io
.IOException
;
45 import java
.util
.Arrays
;
46 import java
.util
.LinkedList
;
49 * Test reading of git config
51 public class RepositoryConfigTest
extends RepositoryTestCase
{
53 * Read config item with no value from a section without a subsection.
57 public void test001_ReadBareKey() throws IOException
{
58 final File path
= writeTrashFile("config_001", "[foo]\nbar\n");
59 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, path
);
60 System
.out
.println(repositoryConfig
.getString("foo", null, "bar"));
61 assertEquals(true, repositoryConfig
.getBoolean("foo", null, "bar", false));
62 assertEquals("", repositoryConfig
.getString("foo", null, "bar"));
66 * Read various data from a subsection.
70 public void test002_ReadWithSubsection() throws IOException
{
71 final File path
= writeTrashFile("config_002", "[foo \"zip\"]\nbar\n[foo \"zap\"]\nbar=false\nn=3\n");
72 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, path
);
73 assertEquals(true, repositoryConfig
.getBoolean("foo", "zip", "bar", false));
74 assertEquals("", repositoryConfig
.getString("foo","zip", "bar"));
75 assertEquals(false, repositoryConfig
.getBoolean("foo", "zap", "bar", true));
76 assertEquals("false", repositoryConfig
.getString("foo", "zap", "bar"));
77 assertEquals(3, repositoryConfig
.getInt("foo", "zap", "n", 4));
78 assertEquals(4, repositoryConfig
.getInt("foo", "zap","m", 4));
81 public void test003_PutRemote() throws IOException
{
82 File cfgFile
= writeTrashFile("config_003", "");
83 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, cfgFile
);
84 repositoryConfig
.setString("sec", "ext", "name", "value");
85 repositoryConfig
.setString("sec", "ext", "name2", "value2");
86 repositoryConfig
.save();
87 checkFile(cfgFile
, "[sec \"ext\"]\n\tname = value\n\tname2 = value2\n");
90 public void test004_PutGetSimple() throws IOException
{
91 File cfgFile
= writeTrashFile("config_004", "");
92 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, cfgFile
);
93 repositoryConfig
.setString("my", null, "somename", "false");
94 repositoryConfig
.save();
95 checkFile(cfgFile
, "[my]\n\tsomename = false\n");
96 assertEquals("false", repositoryConfig
97 .getString("my", null, "somename"));
100 public void test005_PutGetStringList() throws IOException
{
101 File cfgFile
= writeTrashFile("config_005", "");
102 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, cfgFile
);
103 final LinkedList
<String
> values
= new LinkedList
<String
>();
104 values
.add("value1");
105 values
.add("value2");
106 repositoryConfig
.setStringList("my", null, "somename", values
);
107 repositoryConfig
.save();
108 assertTrue(Arrays
.equals(values
.toArray(), repositoryConfig
109 .getStringList("my", null, "somename")));
110 checkFile(cfgFile
, "[my]\n\tsomename = value1\n\tsomename = value2\n");