Delete user does not work consistently in Maven SDK tests

35 views
Skip to first unread message

Mano Swerts

unread,
Dec 7, 2012, 9:22:51 AM12/7/12
to alfresco-techn...@googlegroups.com
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.

Gabriele Columbro

unread,
Dec 7, 2012, 12:34:15 PM12/7/12
to alfresco-techn...@googlegroups.com, maven-a...@googlegroups.com
Hi,

cc-ing the Maven Alfresco List as the question might be more appropriate there.

Do you get any exception when the deletion fail or it fails silently? Could it be somehow related to the transaction not being committed? Is the @AfterClass method always called?

Sorry for the quite simple questions, but I have no clue right now on why it shouldn't work.

Thanks,

Gab

--
You received this message because you are subscribed to the Google Groups "Alfresco Technical Discussion" group.
To view this discussion on the web visit https://groups.google.com/d/msg/alfresco-technical-discussion/-/7M_6syxhOYEJ.
To post to this group, send email to alfresco-techn...@googlegroups.com.
To unsubscribe from this group, send email to alfresco-technical-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/alfresco-technical-discussion?hl=en.



--
Gabriele Columbro
Principal Architect, 
Consulting Services
Mobile: +31627565103


Mano Swerts

unread,
Dec 11, 2012, 4:23:53 AM12/11/12
to alfresco-techn...@googlegroups.com, maven-a...@googlegroups.com
Hi Gabriele,

The deletion fails silently. It could be a transactional issue, but we do no manage transactions manually. The @AfterClass is always called and the deletes are called as well. We do a check whether the person still exists after the delete and it returns false. So it should be deleted, but apparently when we run the build a second time they do not seem to be deleted. So it seems to be a transaction that has not been committed, but like I said before, we do not handle transactions ourselves.

What I noticed however, is that the teardown only fails in the last test of the build. The teardown for all tests run fine, except for the last one. I verified that this behaviour is consistent.

Kind regards,

Mano
To unsubscribe from this group, send email to alfresco-technical-discussion+unsub...@googlegroups.com.

Mano Swerts

unread,
Dec 12, 2012, 2:33:27 AM12/12/12
to alfresco-techn...@googlegroups.com, maven-a...@googlegroups.com
Hi Gabriele,

The problem occurs with the deletion of other nodes as well. So probably you are right that it has to do with the transaction in the teardown not being committed. Do you have any clue how the transactions are implemented in the SDK? We already tried to set the Spring @Transactional and @Rollback annotations, but without any success. We also tried to manually start and commit a transaction using the Alfresco TransactionService, but also without result.

Mano Swerts

unread,
Jan 16, 2013, 2:08:36 AM1/16/13
to maven-a...@googlegroups.com, alfresco-techn...@googlegroups.com
Hi all,

Does nobody have the same issue? Is there somebody looking into this?

Kind regards,

Mano Swerts

Gabriele Columbro

unread,
Jan 17, 2013, 5:41:01 AM1/17/13
to alfresco-techn...@googlegroups.com, maven-a...@googlegroups.com
Sorry Mano,

I have been quite caught up lately and not able to give any TLC to the SDK.

I'll try to have a look at this this week, unless someone else in the list has some spare cycle to look into this / share experiences?

Thanks,

Gab


To post to this group, send email to alfresco-techn...@googlegroups.com.
To unsubscribe from this group, send email to alfresco-technical-d...@googlegroups.com.



--
Gabriele Columbro
Principal Architect, 
Consulting Services

Reply all
Reply to author
Forward
0 new messages