forked from portfolio-performance/portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadingHistoricClientFilesTest.java
More file actions
93 lines (76 loc) · 3.65 KB
/
ReadingHistoricClientFilesTest.java
File metadata and controls
93 lines (76 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fileversions;
import static fileversions.FileHelper.find;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.ClientTestUtilities;
@RunWith(Parameterized.class)
@SuppressWarnings("nls")
public class ReadingHistoricClientFilesTest
{
@Parameters(name = "{index}: {0}")
public static Collection<Object[]> getFiles()
{
return Arrays.asList(new Object[][] { // NOSONAR
{ "client52", 52 }, { "client53", 53 }, { "client69", 69 } });
}
private String file;
private int versionOnDisk;
public ReadingHistoricClientFilesTest(String file, int versionOnDisk)
{
this.file = file;
this.versionOnDisk = versionOnDisk;
}
@Test
public void compare() throws IOException
{
Client xmlClient = ClientFactory.load(find(file + ".xml"), null, new NullProgressMonitor());
String xml = ClientTestUtilities.toString(xmlClient);
assertThat(xmlClient.getFileVersionAfterRead(), is(versionOnDisk));
Client binaryClient = ClientFactory.load(find(file + ".binary.portfolio"), null, new NullProgressMonitor());
String binary = ClientTestUtilities.toString(binaryClient);
assertThat(binaryClient.getFileVersionAfterRead(), is(versionOnDisk));
Client binaryEncryptedClient = ClientFactory.load(find(file + ".binary+pwd.portfolio"), "123456".toCharArray(),
new NullProgressMonitor());
String binaryEncrypted = ClientTestUtilities.toString(binaryEncryptedClient);
assertThat(binaryEncryptedClient.getFileVersionAfterRead(), is(versionOnDisk));
String xmlEncrpyted = null;
if (versionOnDisk < 60)
{
Client xmlEncrpytedClient = ClientFactory.load(find(file + ".xml+pwd.portfolio"), "123456".toCharArray(),
new NullProgressMonitor());
xmlEncrpyted = ClientTestUtilities.toString(xmlEncrpytedClient);
assertThat(xmlEncrpytedClient.getFileVersionAfterRead(), is(versionOnDisk));
}
if (!xml.equals(binary))
{
int pos = ClientTestUtilities.indexOfDifference(xml, binary);
assertThat("binary version is not identical to xml " + pos,
binary.substring(pos, Math.min(pos + 100, binary.length())),
is(xml.substring(pos, Math.min(pos + 100, xml.length()))));
}
if (!xml.equals(binaryEncrypted))
{
int pos = ClientTestUtilities.indexOfDifference(xml, binaryEncrypted);
assertThat("encrypted binary version is not identicdal to xml " + pos,
binaryEncrypted.substring(pos, Math.min(pos + 100, binaryEncrypted.length())),
is(xml.substring(pos, Math.min(pos + 100, xml.length()))));
}
if (xmlEncrpyted != null && !xml.equals(xmlEncrpyted))
{
int pos = ClientTestUtilities.indexOfDifference(xml, xmlEncrpyted);
assertThat("encrypted xml is not identical to xml " + pos,
xmlEncrpyted.substring(pos, Math.min(pos + 100, xmlEncrpyted.length())),
is(xml.substring(pos, Math.min(pos + 100, xml.length()))));
}
}
}