Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case to sync etf-data into taxonomy
Issue: #1908
- Loading branch information
Showing
6 changed files
with
221 additions
and
20 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
name.abuchen.portfolio.tests/src/name/abuchen/portfolio/TestUtilities.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,19 @@ | ||
package name.abuchen.portfolio; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Scanner; | ||
|
||
public class TestUtilities | ||
{ | ||
private TestUtilities() | ||
{ | ||
} | ||
|
||
public static String read(Class<?> clazz, String resource) | ||
{ | ||
try (Scanner scanner = new Scanner(clazz.getResourceAsStream(resource), StandardCharsets.UTF_8.name())) | ||
{ | ||
return scanner.useDelimiter("\\A").next(); //$NON-NLS-1$ | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
name.abuchen.portfolio.tests/src/name/abuchen/portfolio/online/impl/ETFDataComTest.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,106 @@ | ||
package name.abuchen.portfolio.online.impl; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.json.simple.JSONValue; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import name.abuchen.portfolio.SecurityBuilder; | ||
import name.abuchen.portfolio.TaxonomyBuilder; | ||
import name.abuchen.portfolio.TestUtilities; | ||
import name.abuchen.portfolio.model.AttributeType; | ||
import name.abuchen.portfolio.model.Classification; | ||
import name.abuchen.portfolio.model.Classification.Assignment; | ||
import name.abuchen.portfolio.model.Client; | ||
import name.abuchen.portfolio.model.ClientSettings; | ||
import name.abuchen.portfolio.model.Security; | ||
import name.abuchen.portfolio.model.Taxonomy; | ||
|
||
@SuppressWarnings("nls") | ||
public class ETFDataComTest | ||
{ | ||
private static ETFDataCom.OnlineItem item; | ||
|
||
@BeforeClass | ||
public static void setup() | ||
{ | ||
JSONObject object = (JSONObject) JSONValue | ||
.parse(TestUtilities.read(ETFDataComTest.class, "etf-data.com.response.txt")); | ||
item = ETFDataCom.OnlineItem.from(object); | ||
} | ||
|
||
@Test | ||
public void testItemAttributes() | ||
{ | ||
assertThat(item.getIsin(), is("DE000A0H0744")); | ||
assertThat(item.getName(), is("iShares Dow Jones Asia Pacific Select Dividend 50 UCITS ETF (DE)")); | ||
|
||
// test creation of security | ||
|
||
ClientSettings settings = new ClientSettings(); | ||
settings.getAttributeTypes().collect(Collectors.toList()).stream().forEach(settings::removeAttributeType); | ||
|
||
Security security = item.create(settings); | ||
|
||
assertThat(security.getIsin(), is(item.getIsin())); | ||
assertThat(security.getName(), is(item.getName())); | ||
|
||
assertThat(settings.getAttributeTypes().count(), is(7L)); | ||
|
||
Function<String, Object> attribute2value = name -> { | ||
AttributeType type = settings.getAttributeTypes().filter(a -> name.equals(a.getSource())).findFirst() | ||
.orElseThrow(IllegalArgumentException::new); | ||
return security.getAttributes().get(type); | ||
}; | ||
|
||
assertThat(attribute2value.apply("etf-data.com$distributionType"), is("DISTRIBUTING")); | ||
assertThat(attribute2value.apply("etf-data.com$distributionFrequency"), is(nullValue())); | ||
assertThat(attribute2value.apply("etf-data.com$domicile"), is("DEU")); | ||
} | ||
|
||
@Test | ||
public void testUpdateOfTaxonomy() | ||
{ | ||
final String someIdentifier = "SOMETHING"; | ||
|
||
Client client = new Client(); | ||
Security security = new SecurityBuilder().addTo(client); | ||
Taxonomy taxonomy = new TaxonomyBuilder().addClassification(someIdentifier).addTo(client); | ||
|
||
boolean hasModifications = item.updateCountryAllocation(taxonomy, security); | ||
assertThat(hasModifications, is(true)); | ||
|
||
// second update does not modify the taxonomy | ||
hasModifications = item.updateCountryAllocation(taxonomy, security); | ||
assertThat(hasModifications, is(false)); | ||
|
||
List<Classification> classifications = taxonomy.getClassifications(security); | ||
assertThat(classifications.size(), is(6)); | ||
Assignment assignment = classifications.stream().filter(c -> c.getName().equals("CHN")).findAny() | ||
.orElseThrow(IllegalArgumentException::new).getAssignments().get(0); | ||
assertThat(assignment.getWeight(), is(451)); | ||
|
||
// modify taxonomy | ||
|
||
assignment.setWeight(111); | ||
|
||
classifications.stream().filter(c -> c.getName().equals("NZL")).findAny() | ||
.orElseThrow(IllegalArgumentException::new).clearAssignments(); | ||
|
||
taxonomy.getClassificationById(someIdentifier).addAssignment(new Assignment(security)); | ||
|
||
hasModifications = item.updateCountryAllocation(taxonomy, security); | ||
assertThat(hasModifications, is(true)); | ||
assertThat(assignment.getWeight(), is(451)); | ||
assertThat(taxonomy.getClassificationById(someIdentifier).getAssignments().isEmpty(), is(true)); | ||
|
||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
....abuchen.portfolio.tests/src/name/abuchen/portfolio/online/impl/etf-data.com.response.txt
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,86 @@ | ||
{ | ||
"assetClass": "EQUITY", | ||
"baseCurrency": "EUR", | ||
"distributionFrequency": null, | ||
"distributionType": "DISTRIBUTING", | ||
"domicile": "DEU", | ||
"indexName": "DJ Asia Pacific Select Dividend 50 Index", | ||
"isin": "DE000A0H0744", | ||
"listings": [ | ||
{ | ||
"bloombergTicker": "APSDEX GY", | ||
"currency": "EUR", | ||
"exchange": "XETRA", | ||
"reutersTicker": "EXXW.DE", | ||
"ticker": "EXXW" | ||
} | ||
], | ||
"name": "iShares Dow Jones Asia Pacific Select Dividend 50 UCITS ETF (DE)", | ||
"provider": "iShares", | ||
"regions": [ | ||
{ | ||
"country": "HKG", | ||
"percentage": 39.49 | ||
}, | ||
{ | ||
"country": "AUS", | ||
"percentage": 23.47 | ||
}, | ||
{ | ||
"country": "JPN", | ||
"percentage": 18.37 | ||
}, | ||
{ | ||
"country": "SGP", | ||
"percentage": 11.69 | ||
}, | ||
{ | ||
"country": "CHN", | ||
"percentage": 4.51 | ||
}, | ||
{ | ||
"country": "NZL", | ||
"percentage": 2.27 | ||
} | ||
], | ||
"replicationMethod": "PHYSICAL", | ||
"sectors": [ | ||
{ | ||
"percentage": 31.71, | ||
"sector": "FINANCIALS" | ||
}, | ||
{ | ||
"percentage": 20.78, | ||
"sector": "REAL_ESTATE" | ||
}, | ||
{ | ||
"percentage": 15.6, | ||
"sector": "INDUSTRIALS" | ||
}, | ||
{ | ||
"percentage": 8.47, | ||
"sector": "COMMUNICATION_SERVICES" | ||
}, | ||
{ | ||
"percentage": 8.35, | ||
"sector": "MATERIALS" | ||
}, | ||
{ | ||
"percentage": 5.71, | ||
"sector": "UTILITIES" | ||
}, | ||
{ | ||
"percentage": 4.08, | ||
"sector": "ENERGY" | ||
}, | ||
{ | ||
"percentage": 3.44, | ||
"sector": "INFORMATION_TECHNOLOGY" | ||
}, | ||
{ | ||
"percentage": 1.66, | ||
"sector": "CONSUMER_DISCRETIONARY" | ||
} | ||
], | ||
"totalFee": 0.31 | ||
} |
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
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