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