Search in sources :

Example 21 with Branch

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));
}
Also used : Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 22 with Branch

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());
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 23 with Branch

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)));
}
Also used : Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 24 with Branch

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")));
}
Also used : Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 25 with Branch

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());
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Aggregations

Branch (net.nemerosa.ontrack.model.structure.Branch)33 Test (org.junit.Test)29 IntNode (com.fasterxml.jackson.databind.node.IntNode)12 Account (net.nemerosa.ontrack.model.security.Account)7 Ack (net.nemerosa.ontrack.model.Ack)6 Project (net.nemerosa.ontrack.model.structure.Project)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 BuildFilterResource (net.nemerosa.ontrack.model.buildfilter.BuildFilterResource)4 NameDescription (net.nemerosa.ontrack.model.structure.NameDescription)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HttpOutputMessage (org.springframework.http.HttpOutputMessage)3 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 BranchFilterMgt (net.nemerosa.ontrack.model.security.BranchFilterMgt)2 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)2 ID (net.nemerosa.ontrack.model.structure.ID)2 StructureService (net.nemerosa.ontrack.model.structure.StructureService)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 GraphQLInt (graphql.Scalars.GraphQLInt)1 GraphQLString (graphql.Scalars.GraphQLString)1