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