use of org.archifacts.core.model.Application 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();
}
use of org.archifacts.core.model.Application in project archifacts by archifacts.
the class C4ModelBuilderTest method assert_that_misc_artifacts_are_added_to_the_c4_model.
@Test
void assert_that_misc_artifacts_are_added_to_the_c4_model() {
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().filter(MiscArtifact.class::isInstance).forEach(c4ModelBuilder::artifact);
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(1).extracting(Component::getName, Component::getTechnology).containsExactly(tuple("MiscArtifact1", "Misc"));
}
use of org.archifacts.core.model.Application 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));
}
use of org.archifacts.core.model.Application in project archifacts by archifacts.
the class C4ModelBuilderTest method assert_that_referenced_artifacts_are_not_added_automatically.
@Test
void assert_that_referenced_artifacts_are_not_added_automatically() {
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.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
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(1).extracting(Component::getName, Component::getTechnology).containsExactly(tuple("Class1ForBuildingBlockType1", "BuildingBlockType1"));
}
use of org.archifacts.core.model.Application 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"));
}
Aggregations