Created
November 4, 2013 12:52
-
-
Save aVolpe/7302008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @WatcherTest.java 1.0 Nov 4, 2013 Sistema Integral de Gestion Hospitalaria | |
*/ | |
package py.una.med.base.test.test.replication.watchers; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.assertFalse; | |
import static org.junit.Assert.assertThat; | |
import static org.junit.Assert.assertTrue; | |
import liquibase.change.Change; | |
import org.junit.Test; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.support.AnnotationConfigContextLoader; | |
import org.springframework.transaction.annotation.EnableTransactionManagement; | |
import py.una.med.base.test.base.BaseTestWithDatabase; | |
import py.una.med.base.test.configuration.TransactionTestConfiguration; | |
import py.una.med.base.test.test.replication.layers.EntityDao; | |
import py.una.med.base.test.test.replication.layers.ReplicatedEntity; | |
import py.una.med.base.test.test.replication.layers.ReplicatedEntityChild; | |
import py.una.med.base.test.util.TestUtils; | |
/** | |
* | |
* @author Arturo Volpe | |
* @since 2.2.8 | |
* @version 1.0 Nov 4, 2013 | |
* | |
*/ | |
@ContextConfiguration(loader = AnnotationConfigContextLoader.class) | |
public class WatcherTest extends BaseTestWithDatabase { | |
@Configuration | |
@EnableTransactionManagement | |
static class ContextConfiguration extends TransactionTestConfiguration { | |
@Override | |
public Class<?>[] getEntityClasses() { | |
return TestUtils.getReferencedClasses(ReplicatedEntity.class); | |
}; | |
@Bean | |
EntityDao dao() { | |
return new EntityDao(); | |
} | |
} | |
@Autowired | |
private EntityDao dao; | |
@Autowired | |
private Informer informer; | |
@Test | |
public void testLogicalDeletion() throws Exception { | |
assertTrue("New entity (created by SQL) is not active", dao.getById(1L) | |
.isActive()); | |
dao.remove(1L); | |
ReplicatedEntity re = dao.getById(1L); | |
assertFalse("Deleted entity is active", re.isActive()); | |
} | |
@Test | |
public void testEventRegistration() throws Exception { | |
assertThat("SQL created entities are not registered", informer | |
.getChanges(ReplicatedEntity.class, "-1").getItems().size(), | |
is(5)); | |
assertThat("Not shareable entity has changes", | |
informer.getChanges(ReplicatedEntityChild.class, "-1"), is(0L)); | |
String lastId = informer.getChanges(ReplicatedEntity.class, "-1") | |
.getChangeId(); | |
assertThat("Informer#getChanges is not idempotent", informer | |
.getChanges(ReplicatedEntity.class, lastId).getItems().size(), | |
is(0)); | |
dao.remove(1L); | |
assertThat("A logical deletion is ommited", | |
informer.getChanges(ReplicatedEntity.class, lastId).getItems() | |
.size(), is(1)); | |
Change c = informer.getChanges(ReplicatedEntity.class, lastId); | |
ReplicatedEntity re = c.getItems().get(0); | |
assertFalse("Informer produces wrong entities", re.isActive()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment