Search in sources :

Example 26 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class EntityDataStoreIT method replaceOrAdd.

@Test
public void replaceOrAdd() 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 the same name
    EntityDataStoreRecord secondRecord = store.replaceOrAdd(branch, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(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 27 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class EntityDataStoreIT method addObject.

@Test
public void addObject() 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
    assertNotNull(record);
    assertTrue(record.getId() > 0);
    assertEquals(CATEGORY, record.getCategory());
    assertNotNull(record.getSignature());
    assertEquals(name, record.getName());
    assertNull(record.getGroupName());
    assertEquals(branch.getProjectEntityType(), record.getEntity().getProjectEntityType());
    assertEquals(branch.getId(), record.getEntity().getId());
    assertJsonEquals(new IntNode(15), record.getData());
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 28 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class EntityDataStoreIT method last_by_category_and_name.

@Test
public void last_by_category_and_name() throws JsonProcessingException {
    // Entity
    Branch branch = do_create_branch();
    // Adds some data, twice, for the same name
    String name = uid("T");
    @SuppressWarnings("unused") int id1 = store.add(branch, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(15)).getId();
    int id2 = store.add(branch, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(16)).getId();
    // Gets last by category / name
    EntityDataStoreRecord record = store.findLastByCategoryAndName(branch, CATEGORY, name, Time.now()).orElse(null);
    // Checks
    assertNotNull(record);
    assertEquals(record.getId(), id2);
    assertJsonEquals(new IntNode(16), record.getData());
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 29 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class ResourceHttpMessageConverterIT method branch_disable_granted_for_automation.

@Test
public void branch_disable_granted_for_automation() throws Exception {
    // Objects
    Project p = Project.of(new NameDescription("P", "Projet créé")).withId(ID.of(1)).withSignature(SIGNATURE);
    Branch b = Branch.of(p, new NameDescription("B", "Branch")).withId(ID.of(1)).withSignature(SIGNATURE);
    // Message
    HttpOutputMessage message = mock(HttpOutputMessage.class);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    when(message.getBody()).thenReturn(output);
    // Serialization
    asGlobalRole("AUTOMATION").execute(() -> {
        try {
            converter.writeInternal(b, message);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    // Content
    String json = new String(output.toByteArray(), "UTF-8");
    // Parsing
    JsonNode node = ObjectMapperFactory.create().readTree(json);
    // Disable link
    assertEquals("urn:test:net.nemerosa.ontrack.boot.ui.BranchController#disableBranch:1", node.path("_disable").asText());
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) NameDescription(net.nemerosa.ontrack.model.structure.NameDescription) Branch(net.nemerosa.ontrack.model.structure.Branch) HttpOutputMessage(org.springframework.http.HttpOutputMessage) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class BuildFilterServiceIT method saveFilter_predefined.

@Test
public void saveFilter_predefined() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a predefined filter for this account
    Ack filterCreated = asAccount(account).call(() -> buildFilterService.saveFilter(branch.getId(), false, "MyFilter", PromotionLevelBuildFilterProvider.class.getName(), JsonUtils.object().end()));
    assertFalse("A predefined filter cannot be saved", filterCreated.isSuccess());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) Ack(net.nemerosa.ontrack.model.Ack) 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