Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions teaql-core/src/test/java/io/teaql/core/EntityRootTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.teaql.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class EntityRootTest {

private static final EntityKey ORDER = new EntityKey("Order", 1L);
private static final EntityKey OTHER_ORDER = new EntityKey("Order", 2L);

@Test
public void markAsNewRecordsOnlyRequestedKeyAndIsIdempotent() {
EntityRoot root = new EntityRoot();

root.markAsNew(ORDER);
root.markAsNew(ORDER);

assertTrue(root.isNew(ORDER));
assertFalse(root.isNew(OTHER_ORDER));
assertEquals(1, root.newKeys().size());
}

@Test
public void newKeysViewIsReadOnly() {
EntityRoot root = new EntityRoot();
root.markAsNew(ORDER);

assertThrows(UnsupportedOperationException.class, () -> root.newKeys().add(OTHER_ORDER));
}

@Test
public void markAsDeleteRecordsOnlyRequestedKeyAndIsIdempotent() {
EntityRoot root = new EntityRoot();

root.markAsDelete(ORDER);
root.markAsDelete(ORDER);

assertTrue(root.isMarkedAsDelete(ORDER));
assertFalse(root.isMarkedAsDelete(OTHER_ORDER));
assertEquals(1, root.deletedKeys().size());
}

@Test
public void deletedKeysViewIsReadOnly() {
EntityRoot root = new EntityRoot();
root.markAsDelete(ORDER);

assertThrows(
UnsupportedOperationException.class,
() -> root.deletedKeys().add(OTHER_ORDER));
}

@Test
public void markingEntityDeletedClearsItsChangesFromEveryScopeOnly() {
EntityRoot root = new EntityRoot();
root.set(ORDER, "status", "CREATED");
root.set(OTHER_ORDER, "status", "CREATED");
root.pushChangeSet();
root.set(ORDER, "total", 100L);
root.set(OTHER_ORDER, "total", 200L);

root.markAsDelete(ORDER);

assertTrue(root.changedFieldNames(ORDER).isEmpty());
assertNull(root.get(ORDER, "status"));
assertNull(root.get(ORDER, "total"));
assertEquals("CREATED", root.get(OTHER_ORDER, "status"));
assertEquals(200L, root.get(OTHER_ORDER, "total"));
}
}
Loading