Skip to content

Commit 88fade3

Browse files
committed
Fix to the previous commit
1 parent c38c753 commit 88fade3

File tree

3 files changed

+94
-5
lines changed

3 files changed

+94
-5
lines changed

src/main/java/io/cryptolens/methods/Message.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ public class Message {
2121
* on the time and the channel.
2222
* @param token The access token with 'GetMessages' permission.
2323
* @param model Method parameters.
24-
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
25-
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
26-
* <code>error</code> into this parameter.
2724
*/
28-
public GetMessagesResult GetMessages (String token, GetMessagesModel model) {
25+
public static GetMessagesResult GetMessages (String token, GetMessagesModel model) {
2926
return GetMessages(token, model, null);
3027
}
3128

@@ -40,7 +37,7 @@ public GetMessagesResult GetMessages (String token, GetMessagesModel model) {
4037
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
4138
* <code>error</code> into this parameter.
4239
*/
43-
public GetMessagesResult GetMessages (String token, GetMessagesModel model, APIError error) {
40+
public static GetMessagesResult GetMessages (String token, GetMessagesModel model, APIError error) {
4441

4542

4643
Map<String,String> extraParams = new HashMap<>();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package io.cryptolens.models;
22

3+
import com.google.gson.annotations.SerializedName;
4+
35
public class MessageObject {
46

7+
@SerializedName(value = "id", alternate = {"Id"})
58
public int Id;
9+
10+
@SerializedName(value = "content", alternate = {"Content"})
611
public String Content;
12+
13+
@SerializedName(value = "created", alternate = {"Created"})
714
public long Created;
15+
16+
@SerializedName(value = "channel", alternate = {"Channel"})
817
public String Channel;
918
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.cryptolens;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.reflect.TypeToken;
5+
import io.cryptolens.methods.Helpers;
6+
import io.cryptolens.methods.Message;
7+
import io.cryptolens.methods.ProductMethods;
8+
import io.cryptolens.models.GetMessagesModel;
9+
import io.cryptolens.models.GetMessagesResult;
10+
import io.cryptolens.models.GetProductsResult;
11+
import io.cryptolens.models.LicenseKey;
12+
import junit.framework.Test;
13+
import junit.framework.TestCase;
14+
import junit.framework.TestSuite;
15+
16+
import java.lang.reflect.Type;
17+
import java.nio.file.Files;
18+
import java.nio.file.Paths;
19+
import java.util.HashMap;
20+
21+
22+
/**
23+
* Unit test for simple App.
24+
*/
25+
public class MessageTest
26+
extends TestCase
27+
{
28+
29+
HashMap<String, String> APIKey = null;
30+
LicenseKey license = null;
31+
String machineCode = "2FE620C9C62F6A8BBD17F2AF49E12434B7C2CFC67FD2F48C2CB090893C4B4694";
32+
33+
/**
34+
* Create the test case
35+
*
36+
* @param testName name of the test case
37+
*/
38+
public MessageTest(String testName )
39+
{
40+
super( testName );
41+
}
42+
43+
/**
44+
* @return the suite of tests being tested
45+
*/
46+
public static Test suite()
47+
{
48+
return new TestSuite( MessageTest.class );
49+
}
50+
51+
public void init() throws Exception{
52+
String api_content = new String(Files.readAllBytes(Paths.get("apikeys.json")), "UTF-8");
53+
Type type = new TypeToken<HashMap<String, String>>(){}.getType();
54+
APIKey = new Gson().fromJson(api_content, type);
55+
56+
assertTrue( true );
57+
58+
}
59+
/**
60+
* Rigourous Test :-)
61+
*/
62+
public void testApp() throws Exception {
63+
64+
65+
}
66+
67+
public void testGetMessages() throws Exception{
68+
69+
init();
70+
71+
GetMessagesResult getMessages = Message.GetMessages(APIKey.get("getmessages"), new GetMessagesModel());
72+
73+
if(!Helpers.IsSuccessful(getMessages)) {
74+
fail("Could not obtain a list of messages.");
75+
}
76+
77+
for (int i = 0; i < getMessages.Messages.size(); i++) {
78+
System.out.println(getMessages.Messages.get(i).Content);
79+
80+
}
81+
82+
}
83+
}

0 commit comments

Comments
 (0)