-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declare immutable types for XStream only when writing files
Add the immutable types only when writing the file because there are files out in the wild that still have referenced objects (probably due to bugs in previous version and/or manual manipulation of files) Issue: #4117
- Loading branch information
Showing
5 changed files
with
289 additions
and
113 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
name.abuchen.portfolio.tests/src/fileversions/XStreamReferencesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fileversions; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.Test; | ||
|
||
import name.abuchen.portfolio.model.Client; | ||
import name.abuchen.portfolio.model.ClientFactory; | ||
import name.abuchen.portfolio.model.ClientTestUtilities; | ||
|
||
@SuppressWarnings("nls") | ||
public class XStreamReferencesTest | ||
{ | ||
@Test | ||
public void testReadingWithReferencesAndWritingWithoutReferences() throws IOException | ||
{ | ||
Client withReferences = ClientFactory | ||
.load(XStreamReferencesTest.class.getResourceAsStream("client_with_relative_references.xml")); | ||
|
||
// check that the first two securities have the same latest price object | ||
// (is a reference in the XML file) | ||
|
||
assertThat(withReferences.getSecurities().get(0).getLatest() == withReferences.getSecurities().get(1) | ||
.getLatest(), is(true)); | ||
|
||
String xml = ClientTestUtilities.toString(withReferences); | ||
Client without = ClientFactory.load(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); | ||
assertThat(without.getSecurities().get(0).getLatest() == without.getSecurities().get(1).getLatest(), is(false)); | ||
} | ||
|
||
@Test | ||
public void testReadingWithIdReferencesAndWritingWithoutIdReferences() throws IOException | ||
{ | ||
Client withReferences = ClientFactory | ||
.load(XStreamReferencesTest.class.getResourceAsStream("client_with_id_references.xml"), true); | ||
|
||
// check that the first two securities have the same latest price object | ||
// (is a reference with "id" attribute in the XML file) | ||
|
||
assertThat(withReferences.getSecurities().get(0).getLatest() == withReferences.getSecurities().get(1) | ||
.getLatest(), is(true)); | ||
|
||
String xml = ClientTestUtilities.toString(withReferences, true); | ||
Client without = ClientFactory.load(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); | ||
assertThat(without.getSecurities().get(0).getLatest() == without.getSecurities().get(1).getLatest(), is(false)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
name.abuchen.portfolio.tests/src/fileversions/client_with_id_references.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<client id="1"> | ||
<version>63</version> | ||
<baseCurrency>EUR</baseCurrency> | ||
<securities> | ||
<security id="2"> | ||
<uuid>987f74dd-2308-4b6b-a5b8-4918e3a73d95</uuid> | ||
<currencyCode>EUR</currencyCode> | ||
<prices/> | ||
<latest id="3" t="2024-08-05" v="10"> | ||
<high>0</high> | ||
<low>0</low> | ||
<volume>0</volume> | ||
</latest> | ||
<attributes> | ||
<map/> | ||
</attributes> | ||
<isRetired>false</isRetired> | ||
</security> | ||
<security id="4"> | ||
<uuid>35b3ba7d-20f4-45be-8804-9d5778f40b52</uuid> | ||
<currencyCode>EUR</currencyCode> | ||
<prices/> | ||
<latest reference="3"/> | ||
<attributes> | ||
<map/> | ||
</attributes> | ||
<isRetired>false</isRetired> | ||
</security> | ||
</securities> | ||
<watchlists/> | ||
<accounts/> | ||
<portfolios/> | ||
<plans/> | ||
<taxonomies/> | ||
<dashboards/> | ||
<properties/> | ||
<settings> | ||
<bookmarks/> | ||
<attributeTypes>Ï | ||
</attributeTypes> | ||
<configurationSets/> | ||
</settings> | ||
</client> |
43 changes: 43 additions & 0 deletions
43
name.abuchen.portfolio.tests/src/fileversions/client_with_relative_references.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<client> | ||
<version>63</version> | ||
<baseCurrency>EUR</baseCurrency> | ||
<securities> | ||
<security> | ||
<uuid>987f74dd-2308-4b6b-a5b8-4918e3a73d95</uuid> | ||
<currencyCode>EUR</currencyCode> | ||
<prices/> | ||
<latest t="2024-08-05" v="10"> | ||
<high>0</high> | ||
<low>0</low> | ||
<volume>0</volume> | ||
</latest> | ||
<attributes> | ||
<map/> | ||
</attributes> | ||
<isRetired>false</isRetired> | ||
</security> | ||
<security> | ||
<uuid>35b3ba7d-20f4-45be-8804-9d5778f40b52</uuid> | ||
<currencyCode>EUR</currencyCode> | ||
<prices/> | ||
<latest reference="../../security/latest"/> | ||
<attributes> | ||
<map/> | ||
</attributes> | ||
<isRetired>false</isRetired> | ||
</security> | ||
</securities> | ||
<watchlists/> | ||
<accounts/> | ||
<portfolios/> | ||
<plans/> | ||
<taxonomies/> | ||
<dashboards/> | ||
<properties/> | ||
<settings> | ||
<bookmarks/> | ||
<attributeTypes>Ï | ||
</attributeTypes> | ||
<configurationSets/> | ||
</settings> | ||
</client> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.