Search in sources :

Example 1 with NameDescription

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

the class ResourceHttpMessageConverterIT method branch.

@Test
public void branch() throws IOException {
    // 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
    converter.writeInternal(b, message);
    // Content
    String json = new String(output.toByteArray(), "UTF-8");
    // Parsing
    JsonNode node = ObjectMapperFactory.create().readTree(json);
    // Check
    TestUtils.assertJsonEquals(object().with("id", 1).with("name", "B").with("description", "Branch").with("disabled", false).with("type", "CLASSIC").with("project", object().with("id", 1).with("name", "P").with("description", "Projet créé").with("disabled", false).with("signature", SIGNATURE_OBJECT).with("_self", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectController#getProject:1").with("_branches", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranchListForProject:1").with("_branchStatusViews", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectController#getBranchStatusViews:1").with("_buildSearch", "urn:test:net.nemerosa.ontrack.boot.ui.BuildController#buildSearchForm:1").with("_buildDiffActions", "urn:test:net.nemerosa.ontrack.boot.ui.BuildController#buildDiffActions:1").with("_properties", "urn:test:net.nemerosa.ontrack.boot.ui.PropertyController#getProperties:PROJECT,1").with("_extra", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectEntityExtensionController#getInformation:PROJECT,1").with("_actions", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectEntityExtensionController#getActions:PROJECT,1").with("_decorations", "urn:test:net.nemerosa.ontrack.boot.ui.DecorationsController#getDecorations:PROJECT,1").with("_events", "urn:test:net.nemerosa.ontrack.boot.ui.EventController#getEvents:PROJECT,1,0,10").with("_page", "urn:test:#:entity:PROJECT:1").end()).with("signature", SIGNATURE_OBJECT).with("_self", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranch:1").with("_project", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectController#getProject:1").with("_promotionLevels", "urn:test:net.nemerosa.ontrack.boot.ui.PromotionLevelController#getPromotionLevelListForBranch:1").with("_validationStamps", "urn:test:net.nemerosa.ontrack.boot.ui.ValidationStampController#getValidationStampListForBranch:1").with("_validationStampViews", "urn:test:net.nemerosa.ontrack.boot.ui.ValidationStampController#getValidationStampViewListForBranch:1").with("_allValidationStampFilters", "urn:test:net.nemerosa.ontrack.boot.ui.ValidationStampFilterController#getAllBranchValidationStampFilters:1").with("_branches", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranchListForProject:1").with("_properties", "urn:test:net.nemerosa.ontrack.boot.ui.PropertyController#getProperties:BRANCH,1").with("_actions", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectEntityExtensionController#getActions:BRANCH,1").with("_status", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranchStatusView:1").with("_view", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#buildView:1").with("_decorations", "urn:test:net.nemerosa.ontrack.boot.ui.DecorationsController#getDecorations:BRANCH,1").with("_buildFilterResources", "urn:test:net.nemerosa.ontrack.boot.ui.BuildFilterController#buildFilters:1").with("_buildFilterForms", "urn:test:net.nemerosa.ontrack.boot.ui.BuildFilterController#buildFilterForms:1").with("_buildFilterSave", "urn:test:net.nemerosa.ontrack.boot.ui.BuildFilterController#createFilter:1,").with("_events", "urn:test:net.nemerosa.ontrack.boot.ui.EventController#getEvents:BRANCH,1,0,10").with("_page", "urn:test:#:entity:BRANCH:1").end(), node);
}
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) Test(org.junit.Test)

Example 2 with NameDescription

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

the class ResourceHttpMessageConverterIT method branch_enable_granted_for_automation.

@Test
public void branch_enable_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)).withDisabled(true).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);
    // Enable link
    assertEquals("urn:test:net.nemerosa.ontrack.boot.ui.BranchController#enableBranch:1", node.path("_enable").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 3 with NameDescription

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

the class ResourcesTest method resource_collection_with_filtering.

@Test
public void resource_collection_with_filtering() throws JsonProcessingException {
    Project project = Project.of(new NameDescription("PRJ", "Project"));
    List<Branch> branches = Arrays.asList(Branch.of(project, new NameDescription("B1", "Branch 1")).withSignature(SIGNATURE), Branch.of(project, new NameDescription("B2", "Branch 2")).withSignature(SIGNATURE));
    Resources<Branch> resourceCollection = Resources.of(branches, URI.create("urn:branch"));
    assertResourceJson(mapper, object().with("_self", "urn:branch").with("resources", array().with(object().with("id", 0).with("name", "B1").with("description", "Branch 1").with("disabled", false).with("type", "CLASSIC").with("signature", SIGNATURE_OBJECT).end()).with(object().with("id", 0).with("name", "B2").with("description", "Branch 2").with("disabled", false).with("type", "CLASSIC").with("signature", SIGNATURE_OBJECT).end()).end()).end(), resourceCollection, Resources.class);
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) NameDescription(net.nemerosa.ontrack.model.structure.NameDescription) Branch(net.nemerosa.ontrack.model.structure.Branch) Test(org.junit.Test)

Example 4 with NameDescription

use of net.nemerosa.ontrack.model.structure.NameDescription 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)

Aggregations

Branch (net.nemerosa.ontrack.model.structure.Branch)4 NameDescription (net.nemerosa.ontrack.model.structure.NameDescription)4 Project (net.nemerosa.ontrack.model.structure.Project)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HttpOutputMessage (org.springframework.http.HttpOutputMessage)3 IOException (java.io.IOException)2