Search in sources :

Example 6 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class MainPreferencePage method updateLabel.

void updateLabel() {
    String msg;
    if (removed || osioCluster.getAccounts().isEmpty()) {
        msg = "No configured accounts";
    } else {
        IAccount account = osioCluster.getAccounts().get(0);
        msg = account.getId() + " account configured valid until " + Date.from(Instant.ofEpochMilli(account.getAccessTokenExpiryTime()));
    }
    label.setText(msg);
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount)

Example 7 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountModelTest method testAddRemoveAccount.

@Test
public void testAddRemoveAccount() {
    IAccountModel m = AccountService.getDefault().getModel();
    assertNotNull(m);
    final Boolean[] checkAdded = new Boolean[] { false };
    final Boolean[] checkRemoved = new Boolean[] { false };
    IAccountModelListener listener = new AccountModelAdapter() {

        @Override
        public void accountAdded(IAccountModel source, IAccount account) {
            checkAdded[0] = true;
        }

        @Override
        public void accountRemoved(IAccountModel source, IAccount account) {
            checkRemoved[0] = true;
        }
    };
    m.addListener(listener);
    try {
        ICluster cluster = m.createCluster("id1");
        m.addCluster(cluster);
        List<ICluster> clusters = m.getClusters();
        assertEquals(2, clusters.size());
        assertEquals(0, cluster.getAccounts().size());
        IAccount account = cluster.createAccount("id2");
        cluster.addAccount(account);
        assertEquals(1, cluster.getAccounts().size());
        cluster.removeAccount(account);
        assertEquals(0, cluster.getAccounts().size());
        m.removeCluster(cluster);
        clusters = m.getClusters();
        assertEquals(1, clusters.size());
        assertTrue(checkAdded[0]);
        assertTrue(checkRemoved[0]);
    } finally {
        m.removeListener(listener);
    }
}
Also used : IAccountModel(org.jboss.tools.openshift.io.core.model.IAccountModel) IAccount(org.jboss.tools.openshift.io.core.model.IAccount) IAccountModelListener(org.jboss.tools.openshift.io.core.model.IAccountModelListener) ICluster(org.jboss.tools.openshift.io.core.model.ICluster) AccountModelAdapter(org.jboss.tools.openshift.io.core.model.AccountModelAdapter) Test(org.junit.Test)

Example 8 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountServiceTest method checkRefreshIsRequiredIfAccessTokenExpired.

@Test
public void checkRefreshIsRequiredIfAccessTokenExpired() {
    IAccount account = cluster.createAccount("myid");
    account.setAccessToken("at");
    account.setRefreshToken("rt");
    account.setAccessTokenExpiryTime(System.currentTimeMillis() - 1000);
    AccountStatus status = service.getStatus(account);
    assertEquals(AccountStatus.NEEDS_REFRESH, status);
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) Test(org.junit.Test)

Example 9 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountServiceTest method checkValidIfAccessedRecentry.

@Test
public void checkValidIfAccessedRecentry() {
    IAccount account = cluster.createAccount("myid");
    account.setAccessToken("at");
    account.setRefreshToken("rt");
    account.setLastRefreshedTime(System.currentTimeMillis());
    AccountStatus status = service.getStatus(account);
    assertEquals(AccountStatus.VALID, status);
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) Test(org.junit.Test)

Aggregations

IAccount (org.jboss.tools.openshift.io.core.model.IAccount)9 Test (org.junit.Test)5 ICluster (org.jboss.tools.openshift.io.core.model.ICluster)3 AccountModelAdapter (org.jboss.tools.openshift.io.core.model.AccountModelAdapter)1 IAccountModel (org.jboss.tools.openshift.io.core.model.IAccountModel)1 IAccountModelListener (org.jboss.tools.openshift.io.core.model.IAccountModelListener)1