Hi all,
We are using the new Alfresco Maven SDK, but we are running into problems creating and removing test users for our tests.
Take the following example:
public class AlfrescoTest {
protected static PersonService personService;
@BeforeClass
public static void initAppContext() {
ApplicationContextHelper.setUseLazyLoading(false);
ApplicationContextHelper.setNoAutoStart(true);
applicationContext = ApplicationContextHelper.getApplicationContext(new String[] { "classpath:alfresco/application-context.xml" });
personService = (PersonService) applicationContext.getBean("PersonService");
AuthenticationUtil.setFullyAuthenticatedUser("admin");
personService.deletePerson("John"); // always works, but not the place to do it
createUser("John");
}
@Test
public void aSimpleTest() {
// ...
}
@AfterClass
public static void teardown() {
AuthenticationUtil.setFullyAuthenticatedUser("admin");
personService.deletePerson("John"); // mostly doesn't work
}
private static void createUser(String userName) {
Map<QName, Serializable> properties = new HashMap<>();
properties.put(ContentModel.PROP_USERNAME, userName);
personService.createPerson(properties);
}
}
As you can see in the code, we want to create some test users in the @BeforeClass of our test. This works fine. Then we want to delete these users at the end of the tests, so in the @AfterClass. This does not work reliably. Most of the time the users aren't deleted. When we delete them in the @BeforeClass it always works, but that's not the place we want to clear our users.
Does anybody have a clue why this isn't working?
Any help is greatly appreciated.