Search in sources :

Example 11 with Project

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

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

the class GitHubEngineConfigurationMigrationActionIT method migration.

/**
 * Test of the migration.
 * <p>
 * An old GitHub configuration is created with name "OntrackTest"
 * (see {@link TestGitHubEngineConfigurationMigrationPreparationAction})
 * <p>
 * A project P is created, using this configuration.
 * <p>
 * The test must check that the old configuration has been migrated and that the project
 * is now using a configuration including the repository, the indexation interval.
 */
@Test
public void migration() throws Exception {
    // Gets the project
    Project project = asUser().with(ProjectList.class).call(() -> structureService.findProjectByName("GitHubEngineConfigurationMigrationAction")).orElseThrow(() -> new ProjectNotFoundException("GitHubEngineConfigurationMigrationAction"));
    // Gets the migrated configuration
    GitHubEngineConfiguration gitHubEngineConfiguration = configurationRepository.find(GitHubEngineConfiguration.class, "OntrackTest").orElseThrow(() -> new RuntimeException("Cannot find \"OntrackTest\" configuration"));
    assertEquals("OntrackTest", gitHubEngineConfiguration.getName());
    assertEquals("https://github.com", gitHubEngineConfiguration.getUrl());
    assertEquals("user", gitHubEngineConfiguration.getUser());
    assertEquals("password", encryptionService.decrypt(gitHubEngineConfiguration.getPassword()));
    assertEquals("token", gitHubEngineConfiguration.getOauth2Token());
    // Gets the GitHub project property
    GitHubProjectConfigurationProperty configurationProperty = asUser().withView(project).call(() -> propertyService.getProperty(project, GitHubProjectConfigurationPropertyType.class).option()).orElseThrow(() -> new RuntimeException("Missing GitHub property on project"));
    assertEquals("OntrackTest", configurationProperty.getConfiguration().getName());
    assertEquals("nemerosa/ontrack", configurationProperty.getRepository());
    assertEquals(30, configurationProperty.getIndexationInterval());
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) ProjectNotFoundException(net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException) GitHubProjectConfigurationProperty(net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationProperty) GitHubProjectConfigurationPropertyType(net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationPropertyType) GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration) Test(org.junit.Test)

Example 13 with Project

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

the class GitController method changeLog.

/**
 * Change log export
 */
@RequestMapping(value = "changelog/export", method = RequestMethod.GET)
public ResponseEntity<String> changeLog(IssueChangeLogExportRequest request) {
    // Gets the change log
    GitChangeLog changeLog = gitService.changeLog(request);
    // Gets the associated project
    Project project = changeLog.getProject();
    // Gets the configuration for the project
    GitConfiguration gitConfiguration = gitService.getProjectConfiguration(project).orElseThrow(() -> new GitProjectNotConfiguredException(project.getId()));
    // Gets the issue service
    Optional<ConfiguredIssueService> optConfiguredIssueService = gitConfiguration.getConfiguredIssueService();
    if (!optConfiguredIssueService.isPresent()) {
        return new ResponseEntity<>("The branch is not configured for issues", HttpStatus.NO_CONTENT);
    }
    ConfiguredIssueService configuredIssueService = optConfiguredIssueService.get();
    // Gets the issue change log
    GitChangeLogIssues changeLogIssues = gitService.getChangeLogIssues(changeLog);
    // List of issues
    List<Issue> issues = changeLogIssues.getList().stream().map(SCMChangeLogIssue::getIssue).collect(Collectors.toList());
    // Exports the change log using the given format
    ExportedIssues exportedChangeLogIssues = configuredIssueService.getIssueServiceExtension().exportIssues(configuredIssueService.getIssueServiceConfiguration(), issues, request);
    // Content type
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Content-Type", exportedChangeLogIssues.getFormat() + "; charset=utf-8");
    // Body and headers
    return new ResponseEntity<>(exportedChangeLogIssues.getContent(), responseHeaders, HttpStatus.OK);
}
Also used : ExportedIssues(net.nemerosa.ontrack.extension.issues.export.ExportedIssues) Project(net.nemerosa.ontrack.model.structure.Project) HttpHeaders(org.springframework.http.HttpHeaders) ConfiguredIssueService(net.nemerosa.ontrack.extension.issues.model.ConfiguredIssueService) ResponseEntity(org.springframework.http.ResponseEntity) Issue(net.nemerosa.ontrack.extension.issues.model.Issue) SCMChangeLogIssue(net.nemerosa.ontrack.extension.scm.model.SCMChangeLogIssue)

Example 14 with Project

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

the class EntityDataServiceIT method retrieve_authorized_for_view.

@Test
public void retrieve_authorized_for_view() throws Exception {
    // Creates an entity
    Project project = doCreateProject();
    // Key
    String key = uid("K");
    // Stores some data
    asAdmin().execute(() -> entityDataService.store(project, key, "Value 1"));
    // Retrieves it using view right only
    String value = asUser().withView(project).call(() -> entityDataService.retrieve(project, key).orElse(null));
    // Cheks
    assertEquals("Value 1", value);
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) Test(org.junit.Test)

Example 15 with Project

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

the class EntityDataStoreRecordTest method compare_on_id_needed.

@Test
public void compare_on_id_needed() {
    Project project = Project.of(NameDescription.nd("P", ""));
    LocalDateTime now = Time.now();
    List<EntityDataStoreRecord> records = Arrays.asList(new EntityDataStoreRecord(1, project, "TEST", "N1", null, Signature.of(now, "test"), new IntNode(10)), new EntityDataStoreRecord(2, project, "TEST", "N1", null, Signature.of(now, "test"), new IntNode(10)));
    records.sort(Comparator.naturalOrder());
    assertTrue("Newest record is first by ID if dates are equal", records.get(0).getId() == 2);
}
Also used : LocalDateTime(java.time.LocalDateTime) Project(net.nemerosa.ontrack.model.structure.Project) IntNode(com.fasterxml.jackson.databind.node.IntNode) Test(org.junit.Test)

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