use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method findByIds.
@Test
public void findByIds() {
assertEquals(emptyList(), psSvc.findByIds(null), "Returns empty list if id list is null");
assertEquals(emptyList(), psSvc.findByIds(emptyList()), "Returns empty list if empty list provided");
assertEquals(emptyList(), psSvc.findByIds(asList(-1L)), "Returns empty set if empty ids cannot be found");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
Long specId2 = psHelper.createPhysicalSpec(b, "findByEntityReference");
Collection<PhysicalSpecification> specs = psSvc.findByIds(asList(specId, specId2));
assertEquals(asSet(specId, specId2), map(specs, d -> d.entityReference().id()), "Returns correct list of ids");
psHelper.removeSpec(specId2);
Collection<PhysicalSpecification> specsAfterRemoval = psSvc.findByIds(asList(specId, specId2));
assertEquals(asSet(specId, specId2), map(specsAfterRemoval, d -> d.entityReference().id()), "Returns all specs by id, even if removed");
Collection<PhysicalSpecification> withNullInList = psSvc.findByIds(asList(specId, null));
assertEquals(asSet(specId), map(withNullInList, d -> d.entityReference().id()), "Returns specs for all ids that are not null");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method updateExternalId.
@Test
public void updateExternalId() {
assertThrows(IllegalArgumentException.class, () -> psSvc.updateExternalId(null, null), "Should throw exception if spec id is null");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
assertThrows(IllegalArgumentException.class, () -> psSvc.updateExternalId(specId, null), "Throws exception if new external id is null");
int unknownSpec = psSvc.updateExternalId(-1L, "UPDATED");
assertEquals(0, unknownSpec, "Should be no updates where unknown spec");
int updatedSpecCount = psSvc.updateExternalId(specId, "UPDATED");
assertEquals(1, updatedSpecCount, "Should be one update where spec exists");
PhysicalSpecification updatedSpec = psSvc.getById(specId);
assertEquals("UPDATED", updatedSpec.externalId().get(), "Spec id should be updated");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method findByEntityReference.
@Test
public void findByEntityReference() {
assertThrows(IllegalArgumentException.class, () -> psSvc.findByEntityReference(null), "Throws exception if entity reference is null");
Set<PhysicalSpecification> whereEntityUnrelated = psSvc.findByEntityReference(mkRef(EntityKind.COST_KIND, -1));
assertEquals(emptySet(), whereEntityUnrelated, "Returns an empty set where entity is not related");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
Set<PhysicalSpecification> returnsAsSetEvenIfMultipleLinksToSpec = psSvc.findByEntityReference(a);
assertEquals(asSet(a.id()), map(returnsAsSetEvenIfMultipleLinksToSpec, d -> d.owningEntity().id()), "Should return if no flows but is owning entity");
Set<PhysicalSpecification> noFlows = psSvc.findByEntityReference(b);
assertEquals(emptySet(), noFlows, "Should return empty set for an application if not owner or linked by flow");
PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findByEntityReference"));
Set<PhysicalSpecification> linkedByPhysFlow = psSvc.findByEntityReference(b);
assertEquals(asSet(specId), map(linkedByPhysFlow, d -> d.entityReference().id()), "Should return specs for an application if linked to a flow");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method getById.
@Test
public void getById() {
PhysicalSpecification unknownId = psSvc.getById(-1);
assertNull(unknownId, "If unknown id returns null");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
Long specId = psHelper.createPhysicalSpec(a, "getById");
PhysicalSpecification spec = psSvc.getById(specId);
assertEquals(a, spec.owningEntity(), "getById returns correct physical specification with correct owning entity");
assertTrue(spec.name().startsWith("getById"), "getById returns correct physical specification");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method makeActive.
@Test
public void makeActive() {
String username = mkName("makeActive");
assertThrows(IllegalArgumentException.class, () -> psSvc.makeActive(null, username), "Should throw exception if spec id is null");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
int active = psSvc.makeActive(specId, username);
assertEquals(1, active, "Will still update even if the spec is already active");
psHelper.removeSpec(specId);
int madeActive = psSvc.makeActive(specId, username);
assertEquals(1, madeActive, "Will update removed flows to active");
assertThrows(IllegalArgumentException.class, () -> psSvc.makeActive(specId, null), "Should throw exception if username is null as cannot be logged");
}
Aggregations