Search in sources :

Example 6 with Project

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

use of net.nemerosa.ontrack.model.structure.Project 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 8 with Project

use of net.nemerosa.ontrack.model.structure.Project 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 9 with Project

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

the class AccountServiceIT method admin_can_delete_promotion_run.

/**
 * Regression test for #427
 */
@Test
public void admin_can_delete_promotion_run() throws Exception {
    // Creates an account
    ID id = account().getId();
    // Assigns the Administrator role to this account
    asUser().with(AccountManagement.class).call(() -> accountService.saveGlobalPermission(PermissionTargetType.ACCOUNT, id.get(), new PermissionInput("ADMINISTRATOR")));
    // Gets the ACL of the account
    Account account = asUser().with(AccountManagement.class).call(() -> accountService.withACL(AuthenticatedAccount.of(accountService.getAccount(id))));
    // Creates any project
    Project project = doCreateProject();
    // Checks the account can delete a promotion run
    assertTrue("An administrator must be granted the promotion run deletion", account.isGranted(project.id(), PromotionRunDelete.class));
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) ID(net.nemerosa.ontrack.model.structure.ID) Test(org.junit.Test)

Example 10 with Project

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

the class SCMController method createChangeLogFileFilter.

/**
 * Adding a change log file filter
 */
@RequestMapping(value = "changeLog/fileFilter/{projectId}/create", method = RequestMethod.POST)
public Resource<SCMFileChangeFilter> createChangeLogFileFilter(@PathVariable ID projectId, @RequestBody SCMFileChangeFilter filter) {
    securityService.checkProjectFunction(projectId.get(), ProjectConfig.class);
    return securityService.asAdmin(() -> {
        // Loads the project
        Project project = structureService.getProject(projectId);
        // Gets the store
        SCMFileChangeFilters config = entityDataService.retrieve(project, SCMFileChangeFilters.class.getName(), SCMFileChangeFilters.class).orElse(SCMFileChangeFilters.create());
        // Updates the store
        config = config.save(filter);
        // Saves the store back
        entityDataService.store(project, SCMFileChangeFilters.class.getName(), config);
        // OK
        return getChangeLogFileFilter(projectId, filter.getName());
    });
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) SCMFileChangeFilters(net.nemerosa.ontrack.extension.scm.model.SCMFileChangeFilters)

Aggregations

Project (net.nemerosa.ontrack.model.structure.Project)16 Test (org.junit.Test)13 Branch (net.nemerosa.ontrack.model.structure.Branch)5 NameDescription (net.nemerosa.ontrack.model.structure.NameDescription)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HttpOutputMessage (org.springframework.http.HttpOutputMessage)3 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 IOException (java.io.IOException)2 LocalDateTime (java.time.LocalDateTime)2 Account (net.nemerosa.ontrack.model.security.Account)2 ID (net.nemerosa.ontrack.model.structure.ID)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 GraphQLInt (graphql.Scalars.GraphQLInt)1 GraphQLString (graphql.Scalars.GraphQLString)1 DataFetcher (graphql.schema.DataFetcher)1 GraphQLArgument.newArgument (graphql.schema.GraphQLArgument.newArgument)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1