diff --git a/graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java b/graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java index dee9197..addee7a 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/UserAccount.java @@ -47,6 +47,7 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso public static final String KEY_OWNER_SPECIAL_AUTHORITY = "owner_special_authority"; public static final String KEY_ACTIVE_SPECIAL_AUTHORITY = "active_special_authority"; public static final String KEY_N_CONTROL_FLAGS = "top_n_control_flags"; + public static final String LIFETIME_EXPIRATION_DATE = "1969-12-31T23:59:59"; @Expose private String name; @@ -84,6 +85,7 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso @Expose private long referrerRewardsPercentage; + private boolean isLifeTime; /** @@ -248,6 +250,14 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso this.statistics = statistics; } + public boolean isLifeTime() { + return isLifeTime; + } + + public void setLifeTime(boolean lifeTime) { + isLifeTime = lifeTime; + } + /** * Deserializer used to build a UserAccount instance from the full JSON-formatted response obtained * by the 'get_objects' API call. @@ -274,8 +284,10 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso // Handling the deserialization and assignation of the membership date, which internally // is stored as a long POSIX time value try{ - Date date = dateFormat.parse(jsonAccount.get(KEY_MEMBERSHIP_EXPIRATION_DATE).getAsString()); + String expirationDate = jsonAccount.get(KEY_MEMBERSHIP_EXPIRATION_DATE).getAsString(); + Date date = dateFormat.parse(expirationDate); userAccount.setMembershipExpirationDate(date.getTime()); + userAccount.setLifeTime(expirationDate.equals(LIFETIME_EXPIRATION_DATE)); } catch (ParseException e) { System.out.println("ParseException. Msg: "+e.getMessage()); } diff --git a/graphenej/src/test/java/cy/agorise/graphenej/api/GetAccountsTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetAccountsTest.java new file mode 100644 index 0000000..ef836a1 --- /dev/null +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetAccountsTest.java @@ -0,0 +1,67 @@ +package cy.agorise.graphenej.api; + +import com.neovisionaries.ws.client.WebSocketException; + +import junit.framework.Assert; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.AccountProperties; +import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.WitnessResponse; + +public class GetAccountsTest extends BaseApiTest { + private UserAccount ltmAccount = new UserAccount("1.2.99700"); + private UserAccount nonLtmAccount = new UserAccount("1.2.140994"); + + @Test + public void testGetAccount(){ + ArrayList userAccounts = new ArrayList<>(); + userAccounts.add(ltmAccount); + userAccounts.add(nonLtmAccount); + mWebSocket.addListener(new GetAccounts(userAccounts, true, new WitnessResponseListener(){ + + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess."); + List accounts = (List) response.result; + System.out.println(String.format("Got %d accounts", accounts.size())); + for(AccountProperties accountProperties : accounts){ + System.out.println("account name....: "+accountProperties.name); + System.out.println("expiration date.: "+accountProperties.membership_expiration_date); + } + AccountProperties ltmAccountProperties = accounts.get(0); + AccountProperties nonLtmAccountProperties = accounts.get(1); + Assert.assertEquals(ltmAccountProperties.membership_expiration_date, UserAccount.LIFETIME_EXPIRATION_DATE); + Assert.assertFalse(nonLtmAccountProperties.membership_expiration_date.equals(UserAccount.LIFETIME_EXPIRATION_DATE)); + synchronized (GetAccountsTest.this){ + GetAccountsTest.this.notifyAll(); + } + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError. Msg: "+error.message); + synchronized (GetAccountsTest.this){ + GetAccountsTest.this.notifyAll(); + } + } + })); + + try{ + mWebSocket.connect(); + synchronized (this){ + wait(); + } + }catch (WebSocketException e) { + System.out.println("WebSocketException. Msg: " + e.getMessage()); + } catch (InterruptedException e) { + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } +} diff --git a/graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java index 439c9d6..cd7bab8 100644 --- a/graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/GetObjectsTest.java @@ -27,6 +27,7 @@ public class GetObjectsTest extends BaseApiTest{ private final Asset asset = new Asset("1.3.0", "BTS", 5); private final UserAccount account = new UserAccount("1.2.116354"); private final UserAccount bilthon_25 = new UserAccount("1.2.151069"); + private UserAccount ltmAccount = new UserAccount("1.2.99700"); private final String[] bitAssetIds = new String[]{"2.4.21", "2.4.83"}; @Test @@ -109,6 +110,50 @@ public class GetObjectsTest extends BaseApiTest{ } } + @Test + public void testGetLtmAccount(){ + ArrayList ids = new ArrayList<>(); + ids.add(ltmAccount.getObjectId()); + mWebSocket.addListener(new GetObjects(ids, new WitnessResponseListener() { + + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess"); + List result = (List) response.result; + UserAccount userAccount = (UserAccount) result.get(0); + System.out.println("Account name.....: "+userAccount.getName()); + System.out.println("Is LTM...........: "+userAccount.isLifeTime()); + System.out.println("json string......: "+userAccount.toJsonString()); + System.out.println("owner............: "+userAccount.getOwner().getKeyAuthList().get(0).getAddress()); + System.out.println("active key.......: "+userAccount.getActive().getKeyAuthList().get(0).getAddress()); + System.out.println("memo: "+userAccount.getOptions().getMemoKey().getAddress()); + Assert.assertEquals("We expect this account to be LTM",true, userAccount.isLifeTime()); + synchronized (GetObjectsTest.this){ + GetObjectsTest.this.notifyAll(); + } + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError"); + synchronized (GetObjectsTest.this){ + GetObjectsTest.this.notifyAll(); + } + } + })); + + try { + mWebSocket.connect(); + synchronized (this){ + wait(); + } + }catch (WebSocketException e) { + System.out.println("WebSocketException. Msg: " + e.getMessage()); + } catch (InterruptedException e) { + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } + @Test public void testBitAssetData(){ try{