Search in sources :

Example 1 with Artifact

use of org.archifacts.core.model.Artifact in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_containers_are_added_to_the_c4_model.

@Test
void assert_that_containers_are_added_to_the_c4_model() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(defaultContainerDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().map(Artifact::getContainer).filter(Optional::isPresent).map(Optional::get).distinct().forEach(c4ModelBuilder::container);
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Set<Component> components = containers.iterator().next().getComponents();
    assertThat(components).isEmpty();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Optional(java.util.Optional) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 2 with Artifact

use of org.archifacts.core.model.Artifact in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_relationship.

@Test
void assert_that_computation_rule_is_applied_to_relationship() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).descriptor(referenceDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().forEach(c4ModelBuilder::artifact);
    application.getRelationships().stream().forEach(c4ModelBuilder::relationship);
    final BuildingBlock source = application.getBuildingBlocksOfType(buildingBlockType1).iterator().next();
    final Artifact target = application.getArtifacts().stream().filter(MiscArtifact.class::isInstance).findFirst().get();
    c4ModelBuilder.relartionshipRule().predicate(a -> true).computation((relationship, lookup) -> Set.of(lookup.component(source).uses(lookup.component(target), "uses"), lookup.component(target).uses(lookup.component(source), "is used by")));
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Container container = containers.iterator().next();
    final Component class1ForBuildingBlockType1 = container.getComponentWithName("Class1ForBuildingBlockType1");
    assertThat(class1ForBuildingBlockType1).isNotNull();
    final Component miscArtifact1 = container.getComponentWithName("MiscArtifact1");
    assertThat(miscArtifact1).isNotNull();
    assertThat(container.getComponents()).flatMap(Component::getRelationships).hasSize(2).extracting(Relationship::getDescription, Relationship::getSource, Relationship::getDestination).containsExactlyInAnyOrder(tuple("uses", class1ForBuildingBlockType1, miscArtifact1), tuple("is used by", miscArtifact1, class1ForBuildingBlockType1));
}
Also used : ArtifactContainer(org.archifacts.core.model.ArtifactContainer) ArtifactContainerType(org.archifacts.core.model.ArtifactContainerType) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArtifactContainerDescriptor(org.archifacts.core.descriptor.ArtifactContainerDescriptor) Component(com.structurizr.model.Component) JavaField(com.tngtech.archunit.core.domain.JavaField) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Artifact(org.archifacts.core.model.Artifact) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) SourceBasedArtifactRelationshipDescriptor(org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Assertions.tuple(org.assertj.core.api.Assertions.tuple) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test) Application(org.archifacts.core.model.Application) Stream(java.util.stream.Stream) ArtifactRelationshipRole(org.archifacts.core.model.ArtifactRelationshipRole) Relationship(com.structurizr.model.Relationship) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) BuildingBlock(org.archifacts.core.model.BuildingBlock) Optional(java.util.Optional) BuildingBlockType(org.archifacts.core.model.BuildingBlockType) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) BuildingBlock(org.archifacts.core.model.BuildingBlock) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 3 with Artifact

use of org.archifacts.core.model.Artifact in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_artifact.

@Test
void assert_that_computation_rule_is_applied_to_artifact() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    final Set<ArtifactContainer> artifactContainers = application.getContainersOfType(containerType1);
    assertThat(artifactContainers).hasSize(1);
    final ArtifactContainer defaultContainer = artifactContainers.iterator().next();
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    c4ModelBuilder.artifactRule().predicate(artifact -> artifact.getName().equals("Class1ForBuildingBlockType1")).computation((artifact, lookup) -> Set.of(lookup.container(defaultContainer).addComponent("CustomName1", null, "CustomTechnology1"), lookup.container(defaultContainer).addComponent("CustomName2", null, "CustomTechnology2")));
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Set<Component> components = containers.iterator().next().getComponents();
    assertThat(components).hasSize(2).extracting(Component::getName, Component::getTechnology).containsExactlyInAnyOrder(tuple("CustomName1", "CustomTechnology1"), tuple("CustomName2", "CustomTechnology2"));
}
Also used : ArtifactContainer(org.archifacts.core.model.ArtifactContainer) ArtifactContainerType(org.archifacts.core.model.ArtifactContainerType) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArtifactContainerDescriptor(org.archifacts.core.descriptor.ArtifactContainerDescriptor) Component(com.structurizr.model.Component) JavaField(com.tngtech.archunit.core.domain.JavaField) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Artifact(org.archifacts.core.model.Artifact) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) SourceBasedArtifactRelationshipDescriptor(org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Assertions.tuple(org.assertj.core.api.Assertions.tuple) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test) Application(org.archifacts.core.model.Application) Stream(java.util.stream.Stream) ArtifactRelationshipRole(org.archifacts.core.model.ArtifactRelationshipRole) Relationship(com.structurizr.model.Relationship) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) BuildingBlock(org.archifacts.core.model.BuildingBlock) Optional(java.util.Optional) BuildingBlockType(org.archifacts.core.model.BuildingBlockType) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 4 with Artifact

use of org.archifacts.core.model.Artifact in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_container.

@Test
void assert_that_computation_rule_is_applied_to_container() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(defaultContainerDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().map(Artifact::getContainer).filter(Optional::isPresent).map(Optional::get).distinct().forEach(c4ModelBuilder::container);
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    c4ModelBuilder.containerRule().predicate(a -> true).computation((container, lookup) -> Set.of(lookup.softwareSystem().addContainer("CustomName1", null, "CustomTechnology1"), lookup.softwareSystem().addContainer("CustomName2", null, "CustomTechnology2")));
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(2).extracting(Container::getName, Container::getTechnology).containsExactlyInAnyOrder(tuple("CustomName1", "CustomTechnology1"), tuple("CustomName2", "CustomTechnology2"));
}
Also used : ArtifactContainer(org.archifacts.core.model.ArtifactContainer) ArtifactContainerType(org.archifacts.core.model.ArtifactContainerType) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArtifactContainerDescriptor(org.archifacts.core.descriptor.ArtifactContainerDescriptor) Component(com.structurizr.model.Component) JavaField(com.tngtech.archunit.core.domain.JavaField) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Artifact(org.archifacts.core.model.Artifact) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) SourceBasedArtifactRelationshipDescriptor(org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor) Container(com.structurizr.model.Container) MiscArtifact(org.archifacts.core.model.MiscArtifact) Assertions.tuple(org.assertj.core.api.Assertions.tuple) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test) Application(org.archifacts.core.model.Application) Stream(java.util.stream.Stream) ArtifactRelationshipRole(org.archifacts.core.model.ArtifactRelationshipRole) Relationship(com.structurizr.model.Relationship) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) BuildingBlock(org.archifacts.core.model.BuildingBlock) Optional(java.util.Optional) BuildingBlockType(org.archifacts.core.model.BuildingBlockType) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Optional(java.util.Optional) Application(org.archifacts.core.model.Application) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 5 with Artifact

use of org.archifacts.core.model.Artifact in project archifacts by archifacts.

the class C4ModelBuilderTest method assert_that_an_IllegalStateException_is_thrown_if_an_Archifact_is_not_mapped_to_the_expected_type.

@Test
void assert_that_an_IllegalStateException_is_thrown_if_an_Archifact_is_not_mapped_to_the_expected_type() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
    final C4Model c4Model = c4ModelBuilder.build();
    final Artifact miscArtifact1 = application.getArtifacts().stream().filter(artifact -> artifact.getName().equals("MiscArtifact1")).findFirst().get();
    final Artifact class1ForBuildingBlockType1 = application.getArtifacts().stream().filter(artifact -> artifact.getName().equals("Class1ForBuildingBlockType1")).findFirst().get();
    assertThatIllegalStateException().isThrownBy(() -> c4Model.component(miscArtifact1)).withMessage("<MiscArtifact> org.archifacts.integration.c4.model.domain.MiscArtifact1 is not mapped to a C4 model item of type com.structurizr.model.Component");
    assertThatIllegalStateException().isThrownBy(() -> c4Model.relationship(miscArtifact1)).withMessage("<MiscArtifact> org.archifacts.integration.c4.model.domain.MiscArtifact1 is not mapped to a C4 model item of type com.structurizr.model.Relationship");
    assertThatIllegalStateException().isThrownBy(() -> c4Model.container(miscArtifact1)).withMessage("<MiscArtifact> org.archifacts.integration.c4.model.domain.MiscArtifact1 is not mapped to a C4 model item of type com.structurizr.model.Container");
    assertThatNoException().isThrownBy(() -> c4Model.component(class1ForBuildingBlockType1));
    assertThatIllegalStateException().isThrownBy(() -> c4Model.relationship(class1ForBuildingBlockType1)).withMessage("<BuildingBlockType1> org.archifacts.integration.c4.model.domain.Class1ForBuildingBlockType1 is not mapped to a C4 model item of type com.structurizr.model.Relationship");
    assertThatIllegalStateException().isThrownBy(() -> c4Model.container(class1ForBuildingBlockType1)).withMessage("<BuildingBlockType1> org.archifacts.integration.c4.model.domain.Class1ForBuildingBlockType1 is not mapped to a C4 model item of type com.structurizr.model.Container");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Application(org.archifacts.core.model.Application) Artifact(org.archifacts.core.model.Artifact) MiscArtifact(org.archifacts.core.model.MiscArtifact) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Aggregations

Workspace (com.structurizr.Workspace)5 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)5 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)5 Application (org.archifacts.core.model.Application)5 Artifact (org.archifacts.core.model.Artifact)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5 Test (org.junit.jupiter.api.Test)5 Component (com.structurizr.model.Component)4 Container (com.structurizr.model.Container)4 Optional (java.util.Optional)4 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)4 Relationship (com.structurizr.model.Relationship)3 JavaClass (com.tngtech.archunit.core.domain.JavaClass)3 JavaField (com.tngtech.archunit.core.domain.JavaField)3 Set (java.util.Set)3 Stream (java.util.stream.Stream)3 ArtifactContainerDescriptor (org.archifacts.core.descriptor.ArtifactContainerDescriptor)3 BuildingBlockDescriptor (org.archifacts.core.descriptor.BuildingBlockDescriptor)3 SourceBasedArtifactRelationshipDescriptor (org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor)3 ArtifactContainerType (org.archifacts.core.model.ArtifactContainerType)3