use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method replaceOrAddObject.
@Test
public void replaceOrAddObject() throws JsonProcessingException {
// Entity
Branch branch = do_create_branch();
// Adds some data
String name = uid("T");
EntityDataStoreRecord record = store.addObject(branch, CATEGORY, name, Signature.of(TEST_USER), null, 15);
// Checks
assertTrue(record.getId() > 0);
assertEquals(CATEGORY, record.getCategory());
assertJsonEquals(new IntNode(15), record.getData());
// Updates the same name
EntityDataStoreRecord secondRecord = store.replaceOrAddObject(branch, CATEGORY, name, Signature.of(TEST_USER), null, 16);
// Checks
assertEquals(record.getId(), secondRecord.getId());
assertJsonEquals(new IntNode(16), secondRecord.getData());
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method replaveOrAddForNewRecord.
@Test
public void replaveOrAddForNewRecord() throws JsonProcessingException {
// Entity
Branch branch = do_create_branch();
// Adds some data
String name = uid("T");
EntityDataStoreRecord record = store.add(branch, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(15));
// Checks
assertTrue(record.getId() > 0);
assertEquals(CATEGORY, record.getCategory());
assertJsonEquals(new IntNode(15), record.getData());
// Updates with a different same name
EntityDataStoreRecord secondRecord = store.replaceOrAdd(branch, CATEGORY, name + "2", Signature.of(TEST_USER), null, new IntNode(16));
// Checks
assertNotEquals(record.getId(), secondRecord.getId());
assertJsonEquals(new IntNode(16), secondRecord.getData());
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method delete_by_category.
@Test
public void delete_by_category() {
// Entities
Branch branch1 = do_create_branch();
Branch branch2 = do_create_branch();
// Adds some data with same name for different entities
String name = uid("T");
int id1 = store.add(branch1, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(10)).getId();
int id2 = store.add(branch2, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(10)).getId();
// Gets by ID
assertTrue(store.getById(branch1, id1).isPresent());
assertTrue(store.getById(branch2, id2).isPresent());
// Deletes by category
store.deleteByCategoryBefore(CATEGORY, Time.now());
// Gets by ID ot possible any longer
assertFalse(store.getById(branch1, id1).isPresent());
assertFalse(store.getById(branch2, id2).isPresent());
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method getByCategory.
@Test
public void getByCategory() {
// Entity
Branch branch = do_create_branch();
// Adds some data
// offset: 4
store.addObject(branch, "C1", "N1", Signature.of(TEST_USER), null, 1);
// offset: 3
store.addObject(branch, "C1", "N1", Signature.of(TEST_USER), null, 2);
// offset: 2
store.addObject(branch, "C1", "N1", Signature.of(TEST_USER), null, 3);
// offset: 1
store.addObject(branch, "C1", "N1", Signature.of(TEST_USER), null, 4);
// offset: 0
store.addObject(branch, "C1", "N2", Signature.of(TEST_USER), null, 5);
store.addObject(branch, "C2", "N3", Signature.of(TEST_USER), null, 6);
// Query with pagination
List<EntityDataStoreRecord> records = store.getByCategory(branch, "C1", 2, 1);
// Checks the results
assertEquals(1, records.size());
assertEquals(3, records.get(0).getData().asInt());
// Count
assertEquals(5, store.getCountByCategory(branch, "C1"));
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method last_by_category_and_group_and_name.
@Test
public void last_by_category_and_group_and_name() throws JsonProcessingException {
// Entity
Branch branch = do_create_branch();
// Adds some data, twice, for the same name, and several names, but for a same group
String group = uid("G");
String name1 = uid("T");
String name2 = uid("T");
@SuppressWarnings("unused") int id11 = store.add(branch, CATEGORY, name1, Signature.of(TEST_USER), group, new IntNode(11)).getId();
int id12 = store.add(branch, CATEGORY, name1, Signature.of(TEST_USER), group, new IntNode(12)).getId();
@SuppressWarnings("unused") int id21 = store.add(branch, CATEGORY, name2, Signature.of(TEST_USER), group, new IntNode(21)).getId();
@SuppressWarnings("unused") int id22 = store.add(branch, CATEGORY, name2, Signature.of(TEST_USER), group, new IntNode(22)).getId();
// Gets last by category / name / group
EntityDataStoreRecord record = store.findLastByCategoryAndGroupAndName(branch, CATEGORY, group, name1).orElse(null);
// Checks
assertNotNull(record);
assertEquals(record.getId(), id12);
assertJsonEquals(new IntNode(12), record.getData());
}
Aggregations