Fix tests.
This commit is contained in:
parent
af74b269e4
commit
ef472a41ee
|
@ -39,12 +39,21 @@ public class CvrApi {
|
||||||
private final String userAgent;
|
private final String userAgent;
|
||||||
private final String authenticationToken;
|
private final String authenticationToken;
|
||||||
|
|
||||||
private static final String BASE_URL = "https://rest.cvrapi.dk/v1/dk";
|
private final String BASE_URL;
|
||||||
|
|
||||||
|
|
||||||
public CvrApi(String userAgent, String authenticationToken) {
|
public CvrApi(String userAgent, String authenticationToken) {
|
||||||
|
this(userAgent, authenticationToken, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CvrApi(String userAgent, String authenticationToken, String baseUrl) {
|
||||||
this.userAgent = userAgent;
|
this.userAgent = userAgent;
|
||||||
this.authenticationToken = authenticationToken;
|
this.authenticationToken = authenticationToken;
|
||||||
|
if(baseUrl == null) {
|
||||||
|
this.BASE_URL = "https://rest.cvrapi.dk/v1/dk";
|
||||||
|
} else {
|
||||||
|
this.BASE_URL = baseUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ class CvrApiSpec extends Specification {
|
||||||
MockWebServer mockServer = new MockWebServer();
|
MockWebServer mockServer = new MockWebServer();
|
||||||
|
|
||||||
def setup() {
|
def setup() {
|
||||||
api = new CvrApi("Test User Agent", "testAuthToken")
|
|
||||||
mockServer.start()
|
mockServer.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +21,7 @@ class CvrApiSpec extends Specification {
|
||||||
|
|
||||||
void "test unsuccessful parsing of JSON"() {
|
void "test unsuccessful parsing of JSON"() {
|
||||||
setup:
|
setup:
|
||||||
|
api = new CvrApi("Test User Agent", "testAuthToken")
|
||||||
def testJson = "{'foo':'bar'}"
|
def testJson = "{'foo':'bar'}"
|
||||||
|
|
||||||
when:
|
when:
|
||||||
|
@ -33,6 +33,7 @@ class CvrApiSpec extends Specification {
|
||||||
|
|
||||||
void "test unsuccessful parsing of JSON w. VAT as text"() {
|
void "test unsuccessful parsing of JSON w. VAT as text"() {
|
||||||
setup:
|
setup:
|
||||||
|
api = new CvrApi("Test User Agent", "testAuthToken")
|
||||||
def testJson = "{'vat':'abcd1234'}"
|
def testJson = "{'vat':'abcd1234'}"
|
||||||
|
|
||||||
when:
|
when:
|
||||||
|
@ -45,6 +46,7 @@ class CvrApiSpec extends Specification {
|
||||||
void "test succesful parsing company with CVR 25063864"() {
|
void "test succesful parsing company with CVR 25063864"() {
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
|
api = new CvrApi("Test User Agent", "testAuthToken")
|
||||||
def testFile = new File(getClass().getResource('/25063864.json').toURI())
|
def testFile = new File(getClass().getResource('/25063864.json').toURI())
|
||||||
def testJson = testFile.getText('UTF-8')
|
def testJson = testFile.getText('UTF-8')
|
||||||
|
|
||||||
|
@ -63,6 +65,7 @@ class CvrApiSpec extends Specification {
|
||||||
void "test succesful parsing of company with CVR 15027800"() {
|
void "test succesful parsing of company with CVR 15027800"() {
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
|
api = new CvrApi("Test User Agent", "testAuthToken")
|
||||||
def testFile = new File(getClass().getResource('/15027800.json').toURI())
|
def testFile = new File(getClass().getResource('/15027800.json').toURI())
|
||||||
def testJson = testFile.getText('UTF-8')
|
def testJson = testFile.getText('UTF-8')
|
||||||
|
|
||||||
|
@ -83,7 +86,7 @@ class CvrApiSpec extends Specification {
|
||||||
setup:
|
setup:
|
||||||
mockServer.enqueue(new MockResponse().setBody("{}"));
|
mockServer.enqueue(new MockResponse().setBody("{}"));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
api.baseUrl = baseUrl.toString()
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def jsonString = api.getCompanyJson("15027800")
|
def jsonString = api.getCompanyJson("15027800")
|
||||||
|
@ -100,7 +103,7 @@ class CvrApiSpec extends Specification {
|
||||||
def testJson = testFile.getText('UTF-8')
|
def testJson = testFile.getText('UTF-8')
|
||||||
mockServer.enqueue(new MockResponse().setBody(testJson));
|
mockServer.enqueue(new MockResponse().setBody(testJson));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
api.baseUrl = baseUrl.toString()
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def company = api.getCompanyByVatNumber("25063864")
|
def company = api.getCompanyByVatNumber("25063864")
|
||||||
|
@ -114,7 +117,7 @@ class CvrApiSpec extends Specification {
|
||||||
setup:
|
setup:
|
||||||
mockServer.enqueue(new MockResponse().setBody("{'foo':'bar'}"));
|
mockServer.enqueue(new MockResponse().setBody("{'foo':'bar'}"));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
api.baseUrl = baseUrl.toString()
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def company = api.getCompanyByVatNumber("15027800")
|
def company = api.getCompanyByVatNumber("15027800")
|
||||||
|
@ -127,7 +130,7 @@ class CvrApiSpec extends Specification {
|
||||||
setup:
|
setup:
|
||||||
mockServer.enqueue(new MockResponse().setBody(''));
|
mockServer.enqueue(new MockResponse().setBody(''));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
api.baseUrl = baseUrl.toString()
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def company = api.getCompanyByVatNumber("15027800")
|
def company = api.getCompanyByVatNumber("15027800")
|
||||||
|
@ -140,6 +143,7 @@ class CvrApiSpec extends Specification {
|
||||||
setup:
|
setup:
|
||||||
mockServer.enqueue(new MockResponse().setResponseCode(404));
|
mockServer.enqueue(new MockResponse().setResponseCode(404));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def company = api.get(baseUrl.toString())
|
def company = api.get(baseUrl.toString())
|
||||||
|
@ -153,7 +157,7 @@ class CvrApiSpec extends Specification {
|
||||||
setup:
|
setup:
|
||||||
mockServer.enqueue(new MockResponse().setResponseCode(401));
|
mockServer.enqueue(new MockResponse().setResponseCode(401));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
api.baseUrl = baseUrl.toString()
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def company = api.get(baseUrl.toString())
|
def company = api.get(baseUrl.toString())
|
||||||
|
@ -167,7 +171,7 @@ class CvrApiSpec extends Specification {
|
||||||
setup:
|
setup:
|
||||||
mockServer.enqueue(new MockResponse().setResponseCode(405));
|
mockServer.enqueue(new MockResponse().setResponseCode(405));
|
||||||
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
HttpUrl baseUrl = mockServer.url("/v1/dk/");
|
||||||
api.baseUrl = baseUrl.toString()
|
api = new CvrApi("Test User Agent", "testAuthToken", baseUrl.toString())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
def company = api.get(baseUrl.toString())
|
def company = api.get(baseUrl.toString())
|
||||||
|
|
Loading…
Reference in a new issue