use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class SCMServiceDetectorImplTest method provider.
@Test
public void provider() {
Branch branch = Branch.of(Project.of(NameDescription.nd("P", "")), NameDescription.nd("B", ""));
SCMService service = mock(SCMService.class);
SCMServiceProvider provider = mock(SCMServiceProvider.class);
when(provider.getScmService(branch)).thenReturn(Optional.of(service));
SCMServiceDetectorImpl detector = new SCMServiceDetectorImpl(Collections.singletonList(provider));
Optional<SCMService> scmService = detector.getScmService(branch);
assertNotNull(scmService);
assertTrue(scmService.isPresent());
assertSame(service, scmService.orElse(null));
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method last_by_category.
@Test
public void last_by_category() 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 name1 = uid("T");
String name2 = uid("T");
String name3 = uid("T");
@SuppressWarnings("unused") int id11 = store.add(branch, CATEGORY, name1, Signature.of(TEST_USER), null, new IntNode(11)).getId();
int id12 = store.add(branch, CATEGORY, name1, Signature.of(TEST_USER), null, new IntNode(12)).getId();
@SuppressWarnings("unused") int id21 = store.add(branch, CATEGORY, name2, Signature.of(TEST_USER), null, new IntNode(21)).getId();
int id22 = store.add(branch, CATEGORY, name2, Signature.of(TEST_USER), null, new IntNode(22)).getId();
@SuppressWarnings("unused") int id31 = store.add(branch, CATEGORY, name3, Signature.of(TEST_USER), null, new IntNode(31)).getId();
@SuppressWarnings("unused") int id32 = store.add(branch, CATEGORY, name3, Signature.of(TEST_USER), null, new IntNode(32)).getId();
int id33 = store.add(branch, CATEGORY, name3, Signature.of(TEST_USER), null, new IntNode(33)).getId();
// Gets last by name in category
List<EntityDataStoreRecord> records = store.findLastRecordsByNameInCategory(branch, CATEGORY);
assertEquals(3, records.size());
// Checks
assertEquals(id33, records.get(0).getId());
assertEquals(id22, records.get(1).getId());
assertEquals(id12, records.get(2).getId());
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method deleteByBranchByFilter.
@Test
public void deleteByBranchByFilter() {
// Entities
Branch branch1 = do_create_branch();
Branch branch2 = do_create_branch();
// Adds some data
store.deleteAll();
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 1);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 2);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 3);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 4);
store.addObject(branch1, "C1", "N2", Signature.of(TEST_USER), null, 5);
store.addObject(branch1, "C2", "N3", Signature.of(TEST_USER), null, 6);
store.addObject(branch2, "C1", "N1", Signature.of(TEST_USER), null, 7);
store.addObject(branch2, "C1", "N2", Signature.of(TEST_USER), null, 8);
store.addObject(branch2, "C2", "N3", Signature.of(TEST_USER), null, 9);
// Checks
assertEquals(6, store.deleteByFilter(new EntityDataStoreFilter().withEntity(branch1)));
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method countByFilter.
@Test
public void countByFilter() {
// Entities
Branch branch1 = do_create_branch();
Branch branch2 = do_create_branch();
// Adds some data
store.deleteAll();
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 1);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 2);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 3);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 4);
store.addObject(branch1, "C1", "N2", Signature.of(TEST_USER), null, 5);
store.addObject(branch1, "C2", "N3", Signature.of(TEST_USER), null, 6);
store.addObject(branch2, "C1", "N1", Signature.of(TEST_USER), null, 7);
store.addObject(branch2, "C1", "N2", Signature.of(TEST_USER), null, 8);
store.addObject(branch2, "C2", "N3", Signature.of(TEST_USER), null, 9);
// Checks
assertEquals(9, store.getCountByFilter(new EntityDataStoreFilter()));
assertEquals(6, store.getCountByFilter(new EntityDataStoreFilter().withEntity(branch1)));
assertEquals(5, store.getCountByFilter(new EntityDataStoreFilter().withEntity(branch1).withCategory("C1")));
assertEquals(4, store.getCountByFilter(new EntityDataStoreFilter().withEntity(branch1).withCategory("C1").withName("N1")));
// Combinations
assertEquals(7, store.getCountByFilter(new EntityDataStoreFilter().withCategory("C1")));
assertEquals(2, store.getCountByFilter(new EntityDataStoreFilter().withName("N3")));
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method delete_by_group.
@Test
public void delete_by_group() {
// Entity
Branch branch = do_create_branch();
// Adds some data for the group
String group = uid("G");
String name = uid("T");
int id1 = store.add(branch, CATEGORY, name + 1, Signature.of(TEST_USER), group, new IntNode(10)).getId();
int id2 = store.add(branch, CATEGORY, name + 2, Signature.of(TEST_USER), group, new IntNode(10)).getId();
// Gets by ID
assertTrue(store.getById(branch, id1).isPresent());
assertTrue(store.getById(branch, id2).isPresent());
// Deletes by group
store.deleteByGroup(branch, CATEGORY, group);
// Gets by ID ot possible any longer
assertFalse(store.getById(branch, id1).isPresent());
assertFalse(store.getById(branch, id2).isPresent());
}
Aggregations