Skip to content

Commit 5e4a464

Browse files
author
BramBear
authored
Merge pull request #54 from avanaur/master
#49 Unit tests for Statuses API Wrapper
2 parents 8db2bb1 + 2d7748c commit 5e4a464

File tree

8 files changed

+66
-110
lines changed

8 files changed

+66
-110
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.authenteq.api;
2+
3+
import com.authenteq.AbstractTest;
4+
import com.authenteq.builders.BigchainDbConfigBuilder;
5+
import org.junit.BeforeClass;
6+
7+
public class AbstractApiTest extends AbstractTest{
8+
9+
/**
10+
* Inits the.
11+
*/
12+
@BeforeClass
13+
public static void init() {
14+
BigchainDbConfigBuilder
15+
.baseUrl(get( "test.api.url", "https://test.ipdb.io" ))
16+
.addToken("app_id", get("test.app.id", ""))
17+
.addToken("app_key", get("test.app.key", ""))
18+
.setup();
19+
}
20+
21+
}

src/test/java/com/authenteq/api/AssetsApiTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,9 @@
2222
/**
2323
* The Class AssetsApiTest.
2424
*/
25-
public class AssetsApiTest extends AbstractTest
25+
public class AssetsApiTest extends AbstractApiTest
2626
{
2727

28-
/**
29-
* Inits the.
30-
*/
31-
@BeforeClass
32-
public static void init() {
33-
BigchainDbConfigBuilder
34-
.baseUrl( get( "test.api.url", "https://test.ipdb.io" ))
35-
.addToken("app_id", "2bbaf3ff")
36-
.addToken("app_key", "c929b708177dcc8b9d58180082029b8d")
37-
.setup();
38-
}
39-
4028
/**
4129
* Test asset search.
4230
*/

src/test/java/com/authenteq/api/BlocksApiTest.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,11 @@
2626
/**
2727
* The Class BlocksApiTest.
2828
*/
29-
public class BlocksApiTest extends AbstractTest
29+
public class BlocksApiTest extends AbstractApiTest
3030
{
3131
private String publicKey = "302a300506032b657003210033c43dc2180936a2a9138a05f06c892d2fb1cfda4562cbc35373bf13cd8ed373";
3232
private String privateKey = "302e020100300506032b6570042204206f6b0cd095f1e83fc5f08bffb79c7c8a30e77a3ab65f4bc659026b76394fcea8";
3333

34-
/**
35-
* Inits the.
36-
*/
37-
@BeforeClass
38-
public static void init() {
39-
BigchainDbConfigBuilder
40-
.baseUrl( get( "test.api.url", "https://test.ipdb.io" ) )
41-
.addToken("app_id", "2bbaf3ff")
42-
.addToken("app_key", "c929b708177dcc8b9d58180082029b8d").setup();
43-
}
44-
4534
/**
4635
* Test asset search.
4736
* @throws InterruptedException

src/test/java/com/authenteq/api/OutputsApiTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,9 @@
2424
/**
2525
* The Class OutputsApiTest.
2626
*/
27-
public class OutputsApiTest extends AbstractTest
27+
public class OutputsApiTest extends AbstractApiTest
2828
{
2929

30-
/**
31-
* Inits the.
32-
*/
33-
@BeforeClass
34-
public static void init() {
35-
BigchainDbConfigBuilder
36-
.baseUrl(get( "test.api.url", "https://test.ipdb.io" ) )
37-
.addToken("app_id", "2bbaf3ff")
38-
.addToken("app_key", "c929b708177dcc8b9d58180082029b8d")
39-
.setup();
40-
}
41-
4230
/**
4331
* Test.
4432
* @throws InvalidKeySpecException

src/test/java/com/authenteq/api/StatusesApiTest.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@
33
import java.io.IOException;
44

55
import com.authenteq.AbstractTest;
6+
import com.authenteq.model.StatusCode;
67
import org.junit.BeforeClass;
78
import org.junit.Test;
89

910
import com.authenteq.builders.BigchainDbConfigBuilder;
1011

12+
import static org.hamcrest.CoreMatchers.is;
13+
import static org.junit.Assert.assertThat;
14+
1115
/**
1216
* The Class StatusesApiTest.
1317
*/
14-
public class StatusesApiTest extends AbstractTest
18+
public class StatusesApiTest extends AbstractApiTest
1519
{
1620

17-
/**
18-
* Inits the.
19-
*/
20-
@BeforeClass
21-
public static void init() {
22-
BigchainDbConfigBuilder
23-
.baseUrl( get( "test.api.url", "https://test.ipdb.io" ) )
24-
.addToken("app_id", "2bbaf3ff")
25-
.addToken("app_key", "c929b708177dcc8b9d58180082029b8d")
26-
.setup();
21+
@Test(expected = StatusException.class)
22+
public void failWhenTransactionStatusNotFound() throws IOException, StatusException {
23+
StatusesApi.getTransactionStatus("437ce30de5cf1c3ad199fa983aded47d0db43567befa92e3a36b38a5784e4d3a").getStatus();
2724
}
28-
29-
/**
30-
* Test status transaction.
31-
*/
25+
3226
@Test
33-
public void testStatusTransaction() {
34-
try {
35-
System.out.println(StatusesApi.getTransactionStatus("437ce30de5cf1c3ad199fa983aded47d0db43567befa92e3a36b38a5784e4d3a").getStatus());
36-
} catch (IOException | StatusException e) {
37-
// TODO Auto-generated catch block
38-
e.printStackTrace();
39-
}
27+
public void getTransactionStatusSuccessfully() throws IOException, StatusException {
28+
StatusCode status = StatusesApi.getTransactionStatus("829752491efa070476431d7cb77ddd53eeb7916e8f01ef5bd7580bf731f799e3").getStatus();
29+
30+
assertThat(status.statusCode(), is("valid"));
31+
}
32+
33+
@Test(expected = StatusException.class)
34+
public void failWhenBlockStatusNotFound() throws IOException, StatusException {
35+
StatusesApi.getBlockStatus("437ce30de5cf1c3ad199fa983aded47d0db43567befa92e3a36b38a5784e4d3a").getStatus();
36+
}
37+
38+
@Test
39+
public void getBlockStatusSuccessfully() throws IOException, StatusException {
40+
StatusCode status = StatusesApi.getBlockStatus("1929586867cb7d531d9de001de0370ecfab72c84f5a157cc51fa288445cb5605").getStatus();
41+
42+
assertThat(status.statusCode(), is("valid"));
4043
}
4144
}

src/test/java/com/authenteq/api/TransactionApiTest.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
11
package com.authenteq.api;
22

3-
import static org.junit.Assert.assertNotNull;
4-
import static org.junit.Assert.assertTrue;
5-
6-
import java.io.IOException;
7-
import java.security.KeyPair;
8-
import java.security.spec.InvalidKeySpecException;
9-
103
import com.authenteq.AbstractTest;
11-
import com.authenteq.constants.Operations;
12-
import org.junit.BeforeClass;
13-
import org.junit.Test;
14-
import com.authenteq.builders.BigchainDbConfigBuilder;
154
import com.authenteq.builders.BigchainDbTransactionBuilder;
16-
import com.authenteq.model.Transaction;
17-
18-
import com.authenteq.util.JsonUtils;
5+
import com.authenteq.constants.Operations;
196
import com.authenteq.model.Account;
207
import com.authenteq.model.DataModel;
218
import com.authenteq.model.GenericCallback;
9+
import com.authenteq.model.Transaction;
10+
import com.authenteq.util.JsonUtils;
2211
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
2312
import net.i2p.crypto.eddsa.EdDSAPublicKey;
24-
import net.i2p.crypto.eddsa.Utils;
2513
import okhttp3.Response;
14+
import org.junit.Test;
15+
16+
import java.io.IOException;
17+
import java.security.KeyPair;
18+
import java.security.spec.InvalidKeySpecException;
19+
20+
import static org.junit.Assert.assertNotNull;
2621

2722
/**
2823
* The Class BigchaindbTransactionTest.
2924
*/
30-
public class TransactionApiTest extends AbstractTest
25+
public class TransactionApiTest extends AbstractApiTest
3126
{
3227

33-
private String publicKey = "302a300506032b657003210033c43dc2180936a2a9138a05f06c892d2fb1cfda4562cbc35373bf13cd8ed373";
34-
private String privateKey = "302e020100300506032b6570042204206f6b0cd095f1e83fc5f08bffb79c7c8a30e77a3ab65f4bc659026b76394fcea8";
35-
36-
/**
37-
* Inits the.
38-
*/
39-
@BeforeClass
40-
public static void init() {
41-
BigchainDbConfigBuilder
42-
.baseUrl( get( "test.api.url", "https://test.ipdb.io" ) )
43-
.addToken("app_id", "2bbaf3ff")
44-
.addToken("app_key", "c929b708177dcc8b9d58180082029b8d")
45-
.setup();
46-
}
28+
private static final String publicKey = "302a300506032b657003210033c43dc2180936a2a9138a05f06c892d2fb1cfda4562cbc35373bf13cd8ed373";
29+
private static final String privateKey = "302e020100300506032b6570042204206f6b0cd095f1e83fc5f08bffb79c7c8a30e77a3ab65f4bc659026b76394fcea8";
4730

4831
/**
4932
* Test post transaction using builder.

src/test/java/com/authenteq/api/VotesApiTest.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
package com.authenteq.api;
22

3-
import java.io.IOException;
4-
5-
import com.authenteq.AbstractTest;
6-
import org.junit.Before;
7-
import org.junit.BeforeClass;
83
import org.junit.Test;
94

10-
import com.authenteq.api.AssetsApi;
11-
import com.authenteq.builders.BigchainDbConfigBuilder;
5+
import java.io.IOException;
126

137

148
/**
159
* The Class VotesApiTest.
1610
*/
17-
public class VotesApiTest extends AbstractTest
11+
public class VotesApiTest extends AbstractApiTest
1812
{
1913

20-
/**
21-
* Inits the.
22-
*/
23-
@BeforeClass
24-
public static void init() {
25-
BigchainDbConfigBuilder
26-
.baseUrl( get( "test.api.url", "https://test.ipdb.io" ))
27-
.addToken("app_id", "2bbaf3ff")
28-
.addToken("app_key", "c929b708177dcc8b9d58180082029b8d")
29-
.setup();
30-
}
31-
3214
/**
3315
* Test asset search.
3416
*/

src/test/resources/test.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
test.api.url=https://test.ipdb.io
2+
test.app.id=2bbaf3ff
3+
test.app.key=c929b708177dcc8b9d58180082029b8d

0 commit comments

Comments
 (0)