Search in sources :

Example 1 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class LogicalFlowServiceTest method findUpstreamFlowsForEntityReferences.

@Test
public void findUpstreamFlowsForEntityReferences() {
    helper.clearAllFlows();
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    EntityReference c = appHelper.createNewApp("c", ouIds.b);
    EntityReference d = appHelper.createNewApp("d", ouIds.b);
    helper.createLogicalFlow(a, b);
    helper.createLogicalFlow(c, b);
    helper.createLogicalFlow(b, c);
    helper.createLogicalFlow(b, d);
    Collection<LogicalFlow> upstreamFlowsForEmptyList = lfSvc.findUpstreamFlowsForEntityReferences(emptyList());
    assertTrue(isEmpty(upstreamFlowsForEmptyList), "No upstreams when no ref provided");
    Collection<LogicalFlow> upstreamsWhereOnlySource = lfSvc.findUpstreamFlowsForEntityReferences(asList(a));
    assertEquals(0, upstreamsWhereOnlySource.size(), "No upstreams when all refs are only targets");
    Collection<LogicalFlow> allUpstreams = lfSvc.findUpstreamFlowsForEntityReferences(asList(b, c));
    assertEquals(3, allUpstreams.size(), "Returns all upstreams but not downstreams");
}
Also used : 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 2 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalSpecificationServiceTest method create.

@Test
public void create() {
    String username = mkName("create");
    assertThrows(IllegalArgumentException.class, () -> psSvc.create(null), "Should throw exception if create command is null");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    String name = mkName("create");
    ImmutablePhysicalSpecification createCommand = ImmutablePhysicalSpecification.builder().externalId(name).owningEntity(a).name(name).description("desc").format(DataFormatKind.UNKNOWN).lastUpdatedBy(username).isRemoved(false).created(UserTimestamp.mkForUser(username, DateTimeUtilities.nowUtcTimestamp())).build();
    Long specId = psSvc.create(createCommand);
    PhysicalSpecification spec = psSvc.getById(specId);
    assertEquals(specId, spec.id().get(), "Spec id should be created");
    assertEquals(name, spec.name(), "Spec id should be have the same externalId");
    assertThrows(IllegalArgumentException.class, () -> psSvc.create(ImmutablePhysicalSpecification.copyOf(spec)), "Cannot create a specification with an id that exists");
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalSpecificationServiceTest method markRemovedIfUnused.

@Test
public void markRemovedIfUnused() {
    String username = mkName("markRemovedIfUnused");
    assertThrows(IllegalArgumentException.class, () -> psSvc.markRemovedIfUnused(null, username), "Throws exception if entity reference is null");
    ImmutablePhysicalSpecificationDeleteCommand noSpecCmd = ImmutablePhysicalSpecificationDeleteCommand.builder().specificationId(-1L).build();
    CommandResponse<PhysicalSpecificationDeleteCommand> responseNoSpec = psSvc.markRemovedIfUnused(noSpecCmd, username);
    assertEquals(CommandOutcome.FAILURE, responseNoSpec.outcome(), "Fails to mark removed if spec not found");
    assertEquals("Specification not found", responseNoSpec.message().get(), "Should inform of reason for failure");
    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");
    PhysicalFlowCreateCommandResponse physicalFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("markRemovedIfUnused"));
    ImmutablePhysicalSpecificationDeleteCommand deleteCmd = ImmutablePhysicalSpecificationDeleteCommand.builder().specificationId(specId).build();
    CommandResponse<PhysicalSpecificationDeleteCommand> responseWithUnderlyingFlows = psSvc.markRemovedIfUnused(deleteCmd, username);
    assertEquals(CommandOutcome.FAILURE, responseWithUnderlyingFlows.outcome(), "Should not remove spec if underlying flows");
    assertEquals("This specification cannot be deleted as it is being referenced by one or more physical flows", responseWithUnderlyingFlows.message().get(), "Should inform of reason for failure");
    pfHelper.deletePhysicalFlow(physicalFlow.entityReference().id());
    CommandResponse<PhysicalSpecificationDeleteCommand> responseWithNoUnderlyingFlows = psSvc.markRemovedIfUnused(deleteCmd, username);
    assertEquals(CommandOutcome.SUCCESS, responseWithNoUnderlyingFlows.outcome(), "Should not remove spec if underlying flows");
}
Also used : 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 4 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class BookmarkServiceTest method bookmarkCanBeCreated.

@Test
public void bookmarkCanBeCreated() {
    EntityReference bookmarkedEntity = mkAppRef();
    Bookmark bookmark = createBookmark(bookmarkedEntity, "test bookmark");
    List<Bookmark> bookmarks = svc.findByReference(bookmarkedEntity);
    assertEquals(1, bookmarks.size());
    assertEquals(bookmark, first(bookmarks));
}
Also used : Bookmark(org.finos.waltz.model.bookmark.Bookmark) ImmutableBookmark(org.finos.waltz.model.bookmark.ImmutableBookmark) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class DataTypeDecoratorServiceTest method findByEntityIdSelector.

@Test
public void findByEntityIdSelector() {
    String username = mkName("findByEntityIdSelector");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    IdSelectionOptions appOpts = mkOpts(a);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByEntityIdSelector(EntityKind.APPLICATION, appOpts), "If not logical flow kind or physical spec kind should throw exception");
    List<DataTypeDecorator> selectorForLfWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
    assertEquals(emptyList(), selectorForLfWhereNoDecorators, "If no flows and decorators for selector returns empty list");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    Long dtId = dataTypeHelper.createDataType("findByEntityIdSelector");
    Long dtId2 = dataTypeHelper.createDataType("findByEntityIdSelector2");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
    List<DataTypeDecorator> selectorWithDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
    assertEquals(asSet(dtId, dtId2), map(selectorWithDecorators, DataTypeDecorator::dataTypeId), "Returns all data types for flow selector");
    IdSelectionOptions flowOpts = mkOpts(flow.entityReference());
    List<DataTypeDecorator> selectorForPsWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
    assertEquals(emptyList(), selectorForPsWhereNoDecorators, "If no flows and decorators for selector returns empty list");
    Long psId = psHelper.createPhysicalSpec(a, "findByEntityIdSelector");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    pfHelper.createPhysicalFlow(flow.entityReference().id(), psId, "findByEntityIdSelector");
    dtdSvc.updateDecorators(username, specRef, asSet(dtId, dtId2), emptySet());
    List<DataTypeDecorator> selectorForPs = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
    assertEquals(asSet(dtId, dtId2), map(selectorForPs, DataTypeDecorator::dataTypeId), "Returns all data types for spec selector");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) 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