Search in sources :

Example 1 with IdGeneratorService

use of org.eclipse.kapua.service.generator.id.IdGeneratorService 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 2 with IdGeneratorService

use of org.eclipse.kapua.service.generator.id.IdGeneratorService in project kapua by eclipse.

the class AbstractKapuaEntity method prePersistsAction.

@PrePersist
protected void prePersistsAction() throws KapuaException {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGenerator = locator.getService(IdGeneratorService.class);
    this.id = new KapuaEid(idGenerator.generate().getId());
    this.createdBy = new KapuaEid(KapuaSecurityUtils.getSession().getUserId().getId());
    this.createdOn = new Date();
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaEid(org.eclipse.kapua.commons.model.id.KapuaEid) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Example 3 with IdGeneratorService

use of org.eclipse.kapua.service.generator.id.IdGeneratorService in project kapua by eclipse.

the class IdGeneratorServiceImplTest method testIdGeneration.

@Test
public void testIdGeneration() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    KapuaId id = idGeneratorService.generate();
    assertNotNull(id);
    assertNotNull(id.getShortId());
    assertTrue(!id.getShortId().isEmpty());
    assertNotNull(id.getId());
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Test(org.junit.Test)

Example 4 with IdGeneratorService

use of org.eclipse.kapua.service.generator.id.IdGeneratorService in project kapua by eclipse.

the class IdGeneratorServiceImplTest method testBulkIdGeneration.

@Test
public void testBulkIdGeneration() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    Set<KapuaId> generatedIds = new HashSet<>();
    for (int i = 0; i < 1000; i++) {
        KapuaId id = idGeneratorService.generate();
        assertFalse(generatedIds.contains(id));
        generatedIds.add(id);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with IdGeneratorService

use of org.eclipse.kapua.service.generator.id.IdGeneratorService in project kapua by eclipse.

the class IdGeneratorServiceImplTest method testIdGeneration.

@Test
public void testIdGeneration() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    KapuaId id = idGeneratorService.generate();
    assertNotNull(id);
    assertNotNull(id.getShortId());
    assertTrue(!id.getShortId().isEmpty());
    assertNotNull(id.getId());
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Test(org.junit.Test)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)9 IdGeneratorService (org.eclipse.kapua.service.generator.id.IdGeneratorService)9 KapuaId (org.eclipse.kapua.model.id.KapuaId)8 Date (java.util.Date)5 Test (org.junit.Test)5 AuthorizationService (org.eclipse.kapua.service.authorization.AuthorizationService)3 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)3 DeviceCallExecutor (org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor)3 PackageRequestChannel (org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestChannel)3 PackageRequestMessage (org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestMessage)3 PackageRequestPayload (org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestPayload)3 PackageResponseMessage (org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage)3 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)3 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)3 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)3 HashSet (java.util.HashSet)2 PrePersist (javax.persistence.PrePersist)1 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)1 User (org.eclipse.kapua.service.user.User)1 UserCreator (org.eclipse.kapua.service.user.UserCreator)1