Search in sources :

Example 6 with Branch

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

Example 7 with Branch

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

Example 8 with Branch

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

Example 9 with Branch

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

Example 10 with Branch

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());
}
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