Search in sources :

Example 81 with EntityReference

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");
}
Also used : IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) EntitySearchOptions.mkForEntity(org.finos.waltz.model.entity_search.EntitySearchOptions.mkForEntity) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) org.finos.waltz.model.physical_specification(org.finos.waltz.model.physical_specification) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) CommandResponse(org.finos.waltz.model.command.CommandResponse) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) Set(java.util.Set) UserTimestamp(org.finos.waltz.model.UserTimestamp) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 82 with EntityReference

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");
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 83 with EntityReference

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");
}
Also used : IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) EntitySearchOptions.mkForEntity(org.finos.waltz.model.entity_search.EntitySearchOptions.mkForEntity) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) org.finos.waltz.model.physical_specification(org.finos.waltz.model.physical_specification) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) CommandResponse(org.finos.waltz.model.command.CommandResponse) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) Set(java.util.Set) UserTimestamp(org.finos.waltz.model.UserTimestamp) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 84 with EntityReference

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");
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 85 with EntityReference

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");
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)114 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)55 Test (org.junit.jupiter.api.Test)55 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)40 EntityKind (org.finos.waltz.model.EntityKind)23 List (java.util.List)21 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)19 Autowired (org.springframework.beans.factory.annotation.Autowired)17 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)16 Set (java.util.Set)14 Collection (java.util.Collection)13 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)9 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)8 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)8 Bookmark (org.finos.waltz.model.bookmark.Bookmark)8 Collections.emptyList (java.util.Collections.emptyList)7 Collectors (java.util.stream.Collectors)7 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)7