|
| 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