comparison test/org/tmatesoft/hg/test/TestStorePath.java @ 490:b3c16d1aede0

Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 16 Aug 2012 17:08:34 +0200
parents 12f668401613
children 4a0bab2c6da1
comparison
equal deleted inserted replaced
489:9c0138cda59a 490:b3c16d1aede0
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import static org.tmatesoft.hg.internal.RequiresFile.*;
20
19 import java.util.HashMap; 21 import java.util.HashMap;
20 import java.util.Map; 22 import java.util.Map;
21 23
22 import junit.framework.Assert; 24 import junit.framework.Assert;
23 25
24 import org.hamcrest.CoreMatchers; 26 import org.hamcrest.CoreMatchers;
25 import org.junit.Before; 27 import org.junit.Before;
26 import org.junit.Rule; 28 import org.junit.Rule;
27 import org.junit.Test; 29 import org.junit.Test;
30 import org.tmatesoft.hg.core.SessionContext;
28 import org.tmatesoft.hg.internal.BasicSessionContext; 31 import org.tmatesoft.hg.internal.BasicSessionContext;
29 import org.tmatesoft.hg.internal.Internals; 32 import org.tmatesoft.hg.internal.Internals;
33 import org.tmatesoft.hg.internal.RepoInitializer;
30 import org.tmatesoft.hg.util.PathRewrite; 34 import org.tmatesoft.hg.util.PathRewrite;
31 35
32 /** 36 /**
33 * 37 *
34 * @author Artem Tikhomirov 38 * @author Artem Tikhomirov
40 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); 44 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
41 45
42 private PathRewrite storePathHelper; 46 private PathRewrite storePathHelper;
43 private final Map<String, Object> propertyOverrides = new HashMap<String, Object>(); 47 private final Map<String, Object> propertyOverrides = new HashMap<String, Object>();
44 48
45 private Internals internals; 49 private final SessionContext sessionCtx;
50 private final RepoInitializer repoInit;
46 51
47 public static void main(String[] args) throws Throwable { 52 public static void main(String[] args) throws Throwable {
48 final TestStorePath test = new TestStorePath(); 53 final TestStorePath test = new TestStorePath();
49 test.testWindowsFilenames(); 54 test.testWindowsFilenames();
50 test.testHashLongPath(); 55 test.testHashLongPath();
52 test.errorCollector.verify(); 57 test.errorCollector.verify();
53 } 58 }
54 59
55 public TestStorePath() { 60 public TestStorePath() {
56 propertyOverrides.put("hg.consolelog.debug", true); 61 propertyOverrides.put("hg.consolelog.debug", true);
57 internals = new Internals(new BasicSessionContext(propertyOverrides, null)); 62 sessionCtx = new BasicSessionContext(propertyOverrides, null);
58 internals.setStorageConfig(1, 0x7); 63 repoInit = new RepoInitializer().setRequires(STORE + FNCACHE + DOTENCODE);
59 storePathHelper = internals.buildDataFilesHelper(); 64 storePathHelper = repoInit.buildDataFilesHelper(sessionCtx);
60 } 65 }
61 66
62 @Before 67 @Before
63 public void setup() { 68 public void setup() {
64 // just in case there are leftovers from #testNationalChars() and another test builds a helper 69 // just in case there are leftovers from #testNationalChars() and another test builds a helper
118 @Test 123 @Test
119 public void testNationalChars() { 124 public void testNationalChars() {
120 String s = "Привет.txt"; 125 String s = "Привет.txt";
121 // 126 //
122 propertyOverrides.put(Internals.CFG_PROPERTY_FS_FILENAME_ENCODING, "cp1251"); 127 propertyOverrides.put(Internals.CFG_PROPERTY_FS_FILENAME_ENCODING, "cp1251");
123 PathRewrite sph = internals.buildDataFilesHelper(); 128 PathRewrite sph = repoInit.buildDataFilesHelper(sessionCtx);
124 errorCollector.checkThat(sph.rewrite(s), CoreMatchers.<CharSequence>equalTo("store/data/~cf~f0~e8~e2~e5~f2.txt.i")); 129 errorCollector.checkThat(sph.rewrite(s), CoreMatchers.<CharSequence>equalTo("store/data/~cf~f0~e8~e2~e5~f2.txt.i"));
125 // 130 //
126 propertyOverrides.put(Internals.CFG_PROPERTY_FS_FILENAME_ENCODING, "UTF8"); 131 propertyOverrides.put(Internals.CFG_PROPERTY_FS_FILENAME_ENCODING, "UTF8");
127 sph = internals.buildDataFilesHelper(); 132 sph = repoInit.buildDataFilesHelper(sessionCtx);
128 errorCollector.checkThat(sph.rewrite(s), CoreMatchers.<CharSequence>equalTo("store/data/~d0~9f~d1~80~d0~b8~d0~b2~d0~b5~d1~82.txt.i")); 133 errorCollector.checkThat(sph.rewrite(s), CoreMatchers.<CharSequence>equalTo("store/data/~d0~9f~d1~80~d0~b8~d0~b2~d0~b5~d1~82.txt.i"));
129 } 134 }
130 } 135 }