Search in sources :

Example 1 with AccountCreator

use of org.eclipse.kapua.service.account.AccountCreator in project kapua by eclipse.

the class AccountServiceTest method testCreate.

@Test
public void testCreate() throws Exception {
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.create(accountCreator);
    // 
    // Account asserts
    assertNotNull(account);
    assertNotNull(account.getId());
    assertNotNull(account.getId().getId());
    assertTrue(account.getOptlock() >= 0);
    assertTrue(account.getScopeId().equals(scopeId));
    assertTrue(account.getName().equals(accountCreator.getOrganizationName()));
    assertNotNull(account.getOrganization());
    assertTrue(account.getOrganization().getEmail().equals(accountCreator.getOrganizationEmail()));
    assertNotNull(account.getCreatedOn());
    assertNotNull(account.getCreatedBy());
    assertNotNull(account.getModifiedOn());
    assertNotNull(account.getModifiedBy());
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date) Test(org.junit.Test)

Example 2 with AccountCreator

use of org.eclipse.kapua.service.account.AccountCreator in project kapua by eclipse.

the class AccountServiceTest method getTestAccountCreator.

private AccountCreator getTestAccountCreator(KapuaId scopeId, long random) {
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    String testAccount = String.format("test-%d", accountSerial);
    AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
    AccountCreator accountCreator = accountFactory.newAccountCreator(scopeId, testAccount);
    accountCreator.setAccountPassword("!aA1234567890");
    accountCreator.setOrganizationName(testAccount);
    accountCreator.setOrganizationEmail(String.format("theuser@%s.com", testAccount));
    return accountCreator;
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AccountFactory(org.eclipse.kapua.service.account.AccountFactory) Date(java.util.Date)

Example 3 with AccountCreator

use of org.eclipse.kapua.service.account.AccountCreator in project kapua by eclipse.

the class AccountServiceTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    KapuaLocator locator = KapuaLocator.getInstance();
    long accountSerial = (new Date()).getTime();
    AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.create(accountCreator);
    account = accountService.find(account.getScopeId(), account.getId());
    Organization org = account.getOrganization();
    org.setAddressLine1("5th evenue, NY");
    account.setOrganization(org);
    Account accountUpd = accountService.update(account);
    // 
    // Account asserts
    assertNotNull(accountUpd);
    assertNotNull(accountUpd.getId());
    assertNotNull(accountUpd.getId().getId());
    assertTrue(accountUpd.getOptlock() >= 0);
    assertTrue(accountUpd.getId().equals(account.getId()));
    assertTrue(accountUpd.getScopeId().equals(account.getScopeId()));
    assertTrue(accountUpd.getName().equals(account.getName()));
    assertNotNull(accountUpd.getOrganization());
    assertTrue(accountUpd.getOrganization().getAddressLine1().equals(org.getAddressLine1()));
    assertNotNull(accountUpd.getCreatedOn().equals(account.getCreatedOn()));
    assertNotNull(accountUpd.getCreatedBy().equals(account.getCreatedBy()));
    assertNotNull(account.getModifiedOn());
    assertNotNull(account.getModifiedBy());
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Organization(org.eclipse.kapua.service.account.Organization) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date) Test(org.junit.Test)

Example 4 with AccountCreator

use of org.eclipse.kapua.service.account.AccountCreator in project kapua by eclipse.

the class MessageStoreServiceTest method testStore.

@Test
public void testStore() throws Exception {
    KapuaId scopeId = new KapuaEid(BigInteger.valueOf(1));
    long accountSerial = (new Date()).getTime();
    AccountCreator accountCreator = this.getTestAccountCreator(scopeId, accountSerial);
    MessageStoreService messageStoreService = locator.getService(MessageStoreService.class);
    DatastoreObjectFactory dsObjectFactory = locator.getFactory(DatastoreObjectFactory.class);
    MessageCreator messageCreator = dsObjectFactory.newMessageCreator();
    Payload messagePayload = dsObjectFactory.newPayload();
    Position messagePosition = dsObjectFactory.newPosition();
    Map<String, Object> metrics = new HashMap<String, Object>();
    Date now = new Date();
    messageCreator.setTimestamp(now);
    messageCreator.setReceivedOn(now);
    String topicName = String.format("%s/CLIENT001/APP01", accountCreator.getName());
    messageCreator.setTopic(topicName);
    metrics.put("metric_long", 1L);
    metrics.put("metric_string", "pippo");
    messagePayload.setMetrics(metrics);
    messagePayload.setCollectedOn(now);
    messagePosition.setAltitude(1.0);
    messagePosition.setTimestamp(now);
    messagePayload.setPosition(messagePosition);
    messagePayload.setMetrics(metrics);
    messageCreator.setPayload(messagePayload);
// FIXME store fails fix it !!
// StorableId messageId = messageStoreService.store(scopeId, messageCreator);
// 
// Message asserts
// assertNotNull(messageId);
// assertTrue(!messageId.toString().isEmpty());
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) DatastoreObjectFactory(org.eclipse.kapua.service.datastore.DatastoreObjectFactory) Position(org.eclipse.kapua.service.datastore.model.Position) HashMap(java.util.HashMap) MessageStoreService(org.eclipse.kapua.service.datastore.MessageStoreService) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) Date(java.util.Date) MessageCreator(org.eclipse.kapua.service.datastore.model.MessageCreator) Payload(org.eclipse.kapua.service.datastore.model.Payload) KapuaId(org.eclipse.kapua.model.id.KapuaId) Test(org.junit.Test)

Example 5 with AccountCreator

use of org.eclipse.kapua.service.account.AccountCreator in project kapua by eclipse.

the class DeviceCommandManagementServiceTest method setUpClass.

// @BeforeClass
public static void setUpClass() {
    try {
        // 
        // Login
        String username = "kapua-sys";
        String password = "kapua-password";
        AuthenticationService authenticationService = locator.getService(AuthenticationService.class);
        UsernamePasswordTokenFactory credentialsFactory = locator.getFactory(UsernamePasswordTokenFactory.class);
        authenticationService.login(credentialsFactory.newInstance(username, password.toCharArray()));
        // 
        // Get current user Id
        adminUserId = KapuaSecurityUtils.getSession().getUserId();
        adminScopeId = KapuaSecurityUtils.getSession().getScopeId();
        // 
        // Create test account
        KapuaLocator locator = KapuaLocator.getInstance();
        // 
        // Account creation
        String accountName = String.format("test-acct-%d", (new Date()).getTime());
        AccountService accountService = locator.getService(AccountService.class);
        AccountFactory accountFactory = locator.getFactory(AccountFactory.class);
        AccountCreator accountCreator = accountFactory.newAccountCreator(adminScopeId, accountName);
        accountCreator.setAccountPassword("!bV0123456789");
        accountCreator.setOrganizationName(accountName);
        accountCreator.setOrganizationEmail(accountName + "@m.com");
        account = accountService.create(accountCreator);
    } catch (KapuaException exc) {
        exc.printStackTrace();
    }
}
Also used : AccountCreator(org.eclipse.kapua.service.account.AccountCreator) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) AccountFactory(org.eclipse.kapua.service.account.AccountFactory) KapuaException(org.eclipse.kapua.KapuaException) UsernamePasswordTokenFactory(org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory) AuthenticationService(org.eclipse.kapua.service.authentication.AuthenticationService) AccountService(org.eclipse.kapua.service.account.AccountService) Date(java.util.Date)

Aggregations

AccountCreator (org.eclipse.kapua.service.account.AccountCreator)9 Date (java.util.Date)8 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)8 KapuaId (org.eclipse.kapua.model.id.KapuaId)6 AccountService (org.eclipse.kapua.service.account.AccountService)6 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)5 Account (org.eclipse.kapua.service.account.Account)5 Test (org.junit.Test)5 AccountFactory (org.eclipse.kapua.service.account.AccountFactory)4 HashMap (java.util.HashMap)1 KapuaEntityNotFoundException (org.eclipse.kapua.KapuaEntityNotFoundException)1 KapuaException (org.eclipse.kapua.KapuaException)1 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)1 GwtAccountCreator (org.eclipse.kapua.app.console.shared.model.GwtAccountCreator)1 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)1 Organization (org.eclipse.kapua.service.account.Organization)1 AuthenticationService (org.eclipse.kapua.service.authentication.AuthenticationService)1 UsernamePasswordTokenFactory (org.eclipse.kapua.service.authentication.UsernamePasswordTokenFactory)1 DatastoreObjectFactory (org.eclipse.kapua.service.datastore.DatastoreObjectFactory)1 MessageStoreService (org.eclipse.kapua.service.datastore.MessageStoreService)1