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());
}
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();
}
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());
}
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);
}
}
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());
}
Aggregations