11package io .cryptolens ;
22
3+ import com .google .gson .Gson ;
4+ import com .google .gson .reflect .TypeToken ;
35import io .cryptolens .methods .Helpers ;
46import io .cryptolens .methods .Key ;
5- import io .cryptolens .models .APIError ;
6- import io .cryptolens .models .ActivateModel ;
7- import io .cryptolens .models .DeactivateModel ;
8- import io .cryptolens .models .LicenseKey ;
7+ import io .cryptolens .models .*;
98import junit .framework .Test ;
109import junit .framework .TestCase ;
1110import junit .framework .TestSuite ;
1211
12+ import java .lang .reflect .Type ;
13+ import java .nio .file .Files ;
14+ import java .nio .file .Paths ;
15+ import java .util .HashMap ;
16+
1317/**
1418 * Unit test for simple App.
1519 */
1620public class KeyTest
17- extends TestCase
18- {
21+ extends TestCase {
22+
23+ HashMap <String , String > APIKey = null ;
24+
25+
1926 /**
2027 * Create the test case
2128 *
2229 * @param testName name of the test case
2330 */
24- public KeyTest (String testName )
25- {
26- super ( testName );
31+ public KeyTest (String testName ) {
32+ super (testName );
2733 }
2834
2935 /**
3036 * @return the suite of tests being tested
3137 */
32- public static Test suite ()
33- {
34- return new TestSuite ( KeyTest .class );
38+ public static Test suite () {
39+ return new TestSuite (KeyTest .class );
40+ }
41+
42+ public void init () throws Exception {
43+ String api_content = new String (Files .readAllBytes (Paths .get ("apikeys.json" )), "UTF-8" );
44+ Type type = new TypeToken <HashMap <String , String >>(){}.getType ();
45+ APIKey = new Gson ().fromJson (api_content , type );
46+
47+ assertTrue ( true );
48+
3549 }
3650
51+
3752 /**
3853 * Rigourous Test :-)
3954 */
4055 public void testApp () throws Exception {
4156
57+ init ();
58+
4259 String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>" ;
43- String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd" ;
60+ String auth = APIKey . get ( "getkeyactivate" ) ;
4461
4562 APIError error = new APIError ();
4663
@@ -65,7 +82,32 @@ public void testApp() throws Exception {
6582 //Key.Deactivate("", new DeactivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()));
6683 System .out .println (Helpers .GetMachineCode ());
6784
68- assertTrue ( true );
85+ assertTrue (true );
6986
7087 }
88+
89+
90+ public void testGetKey () throws Exception {
91+
92+ init ();
93+
94+ String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>" ;
95+ String auth = APIKey .get ("getkeyactivate" );
96+
97+ APIError error = new APIError ();
98+
99+ LicenseKey license = Key .GetKey (auth , RSAPubKey , new GetKeyModel (3349 , "ICVLD-VVSZR-ZTICT-YKGXL" ), error );
100+
101+ if (license == null ) {
102+ System .out .println ("The license does not work." );
103+ System .out .println ("Error: " + error .message );
104+ } else {
105+ System .out .println ("The license is valid!" );
106+ System .out .println ("It will expire: " + license .Expires );
107+ }
108+
109+ assertTrue (true );
110+
111+ }
112+
71113}
0 commit comments