Search in sources :

Example 6 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId 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 7 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId 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 8 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class UserServiceTest method testCreate.

/**
 * We should ignore this test until we have build fixed.
 */
@Test
public void testCreate() throws Exception {
    // prepare the UserCreator
    long now = (new Date()).getTime();
    String username = MessageFormat.format("aaa_test_username_{0,number,#}", now);
    String userEmail = MessageFormat.format("testuser_{0,number,#}@organization.com", now);
    String displayName = MessageFormat.format("User Display Name {0}", now);
    // KapuaPeid accountPeid = KapuaEidGenerator.generate();//
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    KapuaId scopeId = idGeneratorService.generate();
    KapuaLocator serviceLocator = KapuaLocator.getInstance();
    UserFactory kapuaEntityCreatorFactory = serviceLocator.getFactory(UserFactory.class);
    UserCreator userCreator = kapuaEntityCreatorFactory.newCreator(scopeId, username);
    userCreator.setDisplayName(displayName);
    userCreator.setEmail(userEmail);
    userCreator.setPhoneNumber("+1 555 123 4567");
    // create the User
    UserService userService = serviceLocator.getService(UserService.class);
    User user = userService.create(userCreator);
    user = userService.find(user.getScopeId(), user.getId());
    // 
    // User asserts
    assertNotNull(user.getId());
    assertNotNull(user.getId().getId());
    assertTrue(user.getOptlock() >= 0);
    assertEquals(scopeId, user.getScopeId());
    assertEquals(userCreator.getName(), user.getName());
    assertNotNull(user.getCreatedOn());
    assertNotNull(user.getCreatedBy());
    assertNotNull(user.getModifiedOn());
    assertNotNull(user.getModifiedBy());
    assertEquals(userCreator.getDisplayName(), user.getDisplayName());
    assertEquals(userCreator.getEmail(), user.getEmail());
    assertEquals(userCreator.getPhoneNumber(), user.getPhoneNumber());
    assertEquals(UserStatus.ENABLED, user.getStatus());
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) User(org.eclipse.kapua.service.user.User) UserService(org.eclipse.kapua.service.user.UserService) UserFactory(org.eclipse.kapua.service.user.UserFactory) KapuaId(org.eclipse.kapua.model.id.KapuaId) UserCreator(org.eclipse.kapua.service.user.UserCreator) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Date(java.util.Date) Test(org.junit.Test)

Example 9 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class PermissionFactoryImpl method parseString.

@Override
public Permission parseString(String stringPermission) throws KapuaException {
    StringTokenizer st = new StringTokenizer(stringPermission, ":");
    int iTokensCount = st.countTokens();
    if (iTokensCount < 1 || iTokensCount > 3) {
        throw new KapuaAuthorizationException(KapuaAuthorizationErrorCodes.INVALID_STRING_PERMISSION, null, stringPermission);
    }
    // 
    // Build the new Permission
    String domain = st.nextToken();
    Actions action = null;
    if (iTokensCount > 1) {
        action = Actions.valueOf(st.nextToken());
    }
    KapuaId scopeTargetId = null;
    if (iTokensCount > 2) {
        try {
            BigInteger kapuaId = new BigInteger(st.nextToken());
            scopeTargetId = new KapuaEid(kapuaId);
        } catch (IllegalArgumentException iae) {
            throw new KapuaAuthorizationException(KapuaAuthorizationErrorCodes.INVALID_STRING_PERMISSION, iae, stringPermission);
        }
    }
    return new PermissionImpl(domain, action, scopeTargetId);
}
Also used : StringTokenizer(java.util.StringTokenizer) KapuaAuthorizationException(org.eclipse.kapua.service.authorization.shiro.KapuaAuthorizationException) Actions(org.eclipse.kapua.service.authorization.permission.Actions) RolePermissionImpl(org.eclipse.kapua.service.authorization.role.shiro.RolePermissionImpl) BigInteger(java.math.BigInteger) KapuaId(org.eclipse.kapua.model.id.KapuaId) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid)

Example 10 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId 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)

Aggregations

KapuaId (org.eclipse.kapua.model.id.KapuaId)75 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)54 Account (org.eclipse.kapua.service.account.Account)14 AccountService (org.eclipse.kapua.service.account.AccountService)14 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 Device (org.eclipse.kapua.service.device.registry.Device)11 Test (org.junit.Test)11 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)10 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)9 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)9 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)9 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)8 IdGeneratorService (org.eclipse.kapua.service.generator.id.IdGeneratorService)8 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)7 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)7 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)7 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)7 User (org.eclipse.kapua.service.user.User)7 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)6