Add extra test and refactor some BigDecimals to BigIntegers.

This commit is contained in:
Mark Nellemann 2019-12-12 15:12:59 +01:00
parent 5698fa766b
commit f76299c4f8
5 changed files with 119 additions and 10 deletions

View File

@ -1,7 +1,7 @@
id = libcvrapi id = libcvrapi
group = biz.nellemann.libs group = biz.nellemann.libs
version = 1.0.4 version = 1.0.6
licenses = ['APACHE-2.0'] // or something else licenses = ['APACHE-2.0'] // or something else
groovyVersion = 2.5.8 groovyVersion = 2.5.8
slf4jVersion = 1.7.28 slf4jVersion = 1.7.28
spockVersion = 1.3-groovy-2.5 spockVersion = 1.3-groovy-2.5

View File

@ -94,7 +94,7 @@ public class CvrApi {
*/ */
protected String getCompanyJson(String vatNumber) throws Exception { protected String getCompanyJson(String vatNumber) throws Exception {
String response = get(BASE_URL + "/company/" + vatNumber); String response = get(BASE_URL + "/company/" + vatNumber);
log.debug("getCompanyJson() response: {}", response); log.info("getCompanyJson() response: {}", response);
return response; return response;
} }

View File

@ -20,18 +20,24 @@
package biz.nellemann.libcvrapi.pojo; package biz.nellemann.libcvrapi.pojo;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger;
public class AccountingDocumentSummary { public class AccountingDocumentSummary {
String start; String start;
String end; String end;
BigDecimal revenue; BigInteger revenue;
BigDecimal grossprofitloss; BigInteger grossprofitloss;
BigDecimal profitloss; BigInteger profitloss;
BigDecimal equity; BigInteger equity;
BigDecimal averagenumberofemployees; BigInteger averagenumberofemployees;
BigInteger profitlossfromordinaryactivitiesbeforetax;
BigInteger assets;
BigDecimal liquidityratio;
BigDecimal solvencyratio;
BigDecimal equityreturn;
/* TODO: Add fields if needed /* TODO: Add fields if needed
"employeebenefitsexpense": "-27446000", "employeebenefitsexpense": "-27446000",
"depreciationamortisationexpenseprofitorloss": null, "depreciationamortisationexpenseprofitorloss": null,
"profitlossfromordinaryoperatingactivities": null, "profitlossfromordinaryoperatingactivities": null,
@ -62,7 +68,7 @@ public class AccountingDocumentSummary {
"liquidityratio": null, "liquidityratio": null,
"solvencyratio": 7.389193752638244, "solvencyratio": 7.389193752638244,
"equityreturn": null, "equityreturn": null,
*/ */
} }

View File

@ -180,6 +180,23 @@ class CvrApiSpec extends Specification {
Exception ex = thrown() Exception ex = thrown()
} }
void "test we can HTTP GET company with CVR 39895692 deserialized into Company"() {
setup:
def testFile = new File(getClass().getResource('/39895692.json').toURI())
def testJson = testFile.getText('UTF-8')
mockServer.enqueue(new MockResponse().setBody(testJson));
HttpUrl baseUrl = mockServer.url("/v1/dk/");
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
when:
def company = api.getCompanyByVatNumber("39895692")
then:
company != null
company.vat == 39895692
}
// TODO: Test 401, 404, timeouts, gson deserialization errors // TODO: Test 401, 404, timeouts, gson deserialization errors
} }

View File

@ -0,0 +1,86 @@
{
"vat": "39895692",
"address": {
"street": "Stamholmen",
"streetcode": "7527",
"numberfrom": "193",
"numberto": null,
"letterfrom": "A",
"letterto": null,
"floor": "1",
"door": "tv",
"zipcode": "2650",
"cityname": "Hvidovre",
"altcityname": null,
"countrycode": "DK",
"coname": "Cabcon A\\/S",
"freetext": null,
"municode": "167",
"muniname": "HVIDOVRE",
"mailbox": null,
"start": "2019-06-16",
"end": null,
"timestamp": "2019-06-17"
},
"companyform": {"code": "210", "description": "UDL", "longdescription": "Anden udenlandsk virksomhed", "holding": false},
"companystatus": {"text": "AKTIV", "start": "2018-10-01"},
"contact": {"email": "jag@cabcon.dk", "www": "http:\\/\\/www.cabcon.dk", "phone": "38760324", "fax": null},
"status": {"code": null, "creditcode": null, "start": null, "end": null, "bankrupt": false},
"industrycode": {"code": "465210", "text": "Engroshandel med elektronisk udstyr"},
"life": {"start": "2018-10-01", "end": null, "name": "Cabcon AS", "adprotected": true},
"accounting": {
"period": {"start": null, "end": null},
"first": {"start": null, "end": null},
"restructuring_period": {"start": null, "end": null},
"revision": true, "documents": [], "tax": []
},
"capital": {"capital": null, "currency": null, "partial": false, "ipo": false},
"shareholder": {"below_5_percent": false, "public": false},
"info": {
"articles_of_association": null,
"purpose": null,
"bind": null,
"modes": {"legislation_money_laundering": false, "social_economic": false, "government": false},
"attributes": [],
"demerges": null,
"merges": null,
"lei": {"id": null},
"ean": []
},
"secondarynames": [],
"industrycodes": [],
"subsidiaries": ["1024011204"],
"employment": [],
"participants": [
{
"participantnumber": "4007803560",
"address": {
"street": null,
"streetcode": null,
"numberfrom": null,
"numberto": null,
"letterfrom": null,
"letterto": null,
"floor": null,
"door": null,
"zipcode": null,
"cityname": null,
"altcityname": null,
"countrycode": "NO",
"coname": null,
"freetext": "Troll\\u00e5sveien 4",
"municode": null,
"muniname": null,
"mailbox": null,
"start": null,
"end": null,
"timestamp": null,
"unlisted": false
},
"life": {"name": "Cabcon AS", "profession": null, "deceased": false},
"participant": true,
"roles": [{"type": "fully_responsible_participant", "life": {"start": "2018-10-01", "end": null, "title": null}}]
}
],
"participations": []
}