Search in sources :

Example 6 with Application

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

the class JMoleculesDescriptorsTest method assertThat_source_based_artifact_relationship_descriptor_are_recognized.

@ParameterizedTest
@MethodSource("getSourceBasedArtifactRelationshipDescriptors")
void assertThat_source_based_artifact_relationship_descriptor_are_recognized(final ArtifactRelationshipDescriptor artifactRelationshipDescriptor, final RelationshipPair... expectedRelationshipPairs) {
    final Application application = Application.builder().descriptor(JMoleculesDescriptors.BuildingBlockDescriptors.AggregateRootDescriptor).descriptor(JMoleculesDescriptors.BuildingBlockDescriptors.RepositoryDescriptor).descriptor(artifactRelationshipDescriptor).buildApplication(DOMAIN);
    final Set<RelationshipPair> actualRelationshipPairs = application.getRelationshipsOfRole(artifactRelationshipDescriptor.role()).stream().map(r -> new RelationshipPair(r.getSource().getJavaClass().reflect(), r.getTarget().getJavaClass().reflect())).collect(Collectors.toSet());
    assertThat(actualRelationshipPairs).containsExactlyInAnyOrder(expectedRelationshipPairs);
}
Also used : Arrays(java.util.Arrays) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArgumentsAccessor(org.junit.jupiter.params.aggregator.ArgumentsAccessor) ArtifactRelationshipDescriptor(org.archifacts.core.descriptor.ArtifactRelationshipDescriptor) AggregateWith(org.junit.jupiter.params.aggregator.AggregateWith) MyRepository(org.archifacts.integration.jmolecules.domain.MyRepository) MyEventHandler(org.archifacts.integration.jmolecules.domain.MyEventHandler) JavaClass(com.tngtech.archunit.core.domain.JavaClass) MethodSource(org.junit.jupiter.params.provider.MethodSource) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArgumentsAggregationException(org.junit.jupiter.params.aggregator.ArgumentsAggregationException) ArgumentsAggregator(org.junit.jupiter.params.aggregator.ArgumentsAggregator) MyAggregateRootId(org.archifacts.integration.jmolecules.domain.MyAggregateRootId) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) MyAggregateRoot(org.archifacts.integration.jmolecules.domain.MyAggregateRoot) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) MyEntity(org.archifacts.integration.jmolecules.domain.MyEntity) Objects(java.util.Objects) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) Application(org.archifacts.core.model.Application) MyService(org.archifacts.integration.jmolecules.domain.MyService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) BuildingBlock(org.archifacts.core.model.BuildingBlock) MyEvent(org.archifacts.integration.jmolecules.domain.MyEvent) Application(org.archifacts.core.model.Application) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with Application

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

the class JMoleculesDescriptorsTest method assertThat_building_blocks_are_recognized.

@ParameterizedTest
@MethodSource("getBuildingBlocks")
void assertThat_building_blocks_are_recognized(final BuildingBlockDescriptor buildingBlockDescriptor, @AggregateWith(VarargsAggregator.class) final Class<?>... matchingClasses) {
    final Application application = Application.builder().descriptor(buildingBlockDescriptor).buildApplication(DOMAIN);
    final Set<String> expectedClasses = Arrays.stream(matchingClasses).map(Class::getName).collect(Collectors.toSet());
    assertThat(application.getBuildingBlocksOfType(buildingBlockDescriptor.type())).map(BuildingBlock::getJavaClass).map(JavaClass::getName).containsExactlyInAnyOrderElementsOf(expectedClasses);
}
Also used : BuildingBlock(org.archifacts.core.model.BuildingBlock) Application(org.archifacts.core.model.Application) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with Application

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

the class SpringDescriptorTest method assertThat_building_blocks_are_recognized.

@ParameterizedTest
@MethodSource("getBuildingBlocks")
void assertThat_building_blocks_are_recognized(final BuildingBlockDescriptor buildingBlockDescriptor, final Class<?>... matchingClasses) {
    final Application application = Application.builder().descriptor(buildingBlockDescriptor).buildApplication(DOMAIN);
    final Set<String> expectedClassNames = Arrays.stream(matchingClasses).map(Class::getName).collect(Collectors.toSet());
    assertThat(application.getBuildingBlocksOfType(buildingBlockDescriptor.type())).map(b -> b.getJavaClass().getName()).allMatch(name -> expectedClassNames.contains(name));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Arrays(java.util.Arrays) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) MyRepository(org.archifacts.integration.spring.domain.MyRepository) MyComponent(org.archifacts.integration.spring.domain.MyComponent) MyService(org.archifacts.integration.spring.domain.MyService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) Application(org.archifacts.core.model.Application) MyConfiguration(org.archifacts.integration.spring.domain.MyConfiguration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) MyController(org.archifacts.integration.spring.domain.MyController) MethodSource(org.junit.jupiter.params.provider.MethodSource) Application(org.archifacts.core.model.Application) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with Application

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

the class AxonDescriptorsTest method assertThat_building_blocks_are_recognized.

@ParameterizedTest
@MethodSource("getBuildingBlocks")
void assertThat_building_blocks_are_recognized(final BuildingBlockDescriptor buildingBlockDescriptor, final Class<?>... matchingClasses) {
    final Application application = Application.builder().descriptor(buildingBlockDescriptor).buildApplication(DOMAIN);
    final Set<String> expectedClassNames = Arrays.stream(matchingClasses).map(Class::getName).collect(Collectors.toSet());
    assertThat(application.getBuildingBlocksOfType(buildingBlockDescriptor.type())).map(b -> b.getJavaClass().getName()).allMatch(name -> expectedClassNames.contains(name));
}
Also used : Arrays(java.util.Arrays) ReplaceUnderscores(org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) MyAggregateRootId(org.archifacts.integration.axon.domain.MyAggregateRootId) MyEvent2(org.archifacts.integration.axon.domain.MyEvent2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MySagaEventHandler(org.archifacts.integration.axon.domain.MySagaEventHandler) MethodSource(org.junit.jupiter.params.provider.MethodSource) MyQuery1(org.archifacts.integration.axon.domain.MyQuery1) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Tuple(org.assertj.core.groups.Tuple) SourceBasedArtifactRelationshipDescriptor(org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor) MyQuery2(org.archifacts.integration.axon.domain.MyQuery2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) DisplayNameGeneration(org.junit.jupiter.api.DisplayNameGeneration) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) MyAggregateMember3(org.archifacts.integration.axon.domain.MyAggregateMember3) Application(org.archifacts.core.model.Application) MyAggregateMember2(org.archifacts.integration.axon.domain.MyAggregateMember2) MyCommand1(org.archifacts.integration.axon.domain.MyCommand1) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) MyAggregateMember1(org.archifacts.integration.axon.domain.MyAggregateMember1) MyCommand2(org.archifacts.integration.axon.domain.MyCommand2) BuildingBlockDescriptor(org.archifacts.core.descriptor.BuildingBlockDescriptor) MyAggregateRoot(org.archifacts.integration.axon.domain.MyAggregateRoot) MyEventHandler(org.archifacts.integration.axon.domain.MyEventHandler) MyEvent1(org.archifacts.integration.axon.domain.MyEvent1) MySaga(org.archifacts.integration.axon.domain.MySaga) MyQueryHandler(org.archifacts.integration.axon.domain.MyQueryHandler) Application(org.archifacts.core.model.Application) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with Application

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

the class C4ModelBuilderTest method assert_that_relationship_source_and_target_is_automatically_added_to_the_c4_model.

@Test
void assert_that_relationship_source_and_target_is_automatically_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.getRelationships().stream().forEach(c4ModelBuilder::relationship);
    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(1).extracting(Relationship::getDescription, Relationship::getSource, Relationship::getDestination).containsExactly(tuple("references", class1ForBuildingBlockType1, miscArtifact1));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Aggregations

Application (org.archifacts.core.model.Application)17 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)16 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)16 Workspace (com.structurizr.Workspace)12 Test (org.junit.jupiter.api.Test)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 Set (java.util.Set)7 Stream (java.util.stream.Stream)7 BuildingBlockDescriptor (org.archifacts.core.descriptor.BuildingBlockDescriptor)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 DisplayNameGeneration (org.junit.jupiter.api.DisplayNameGeneration)7 ReplaceUnderscores (org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores)7 SourceBasedArtifactRelationshipDescriptor (org.archifacts.core.descriptor.SourceBasedArtifactRelationshipDescriptor)5 Artifact (org.archifacts.core.model.Artifact)5 BuildingBlock (org.archifacts.core.model.BuildingBlock)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5 Assertions.tuple (org.assertj.core.api.Assertions.tuple)5 JavaClass (com.tngtech.archunit.core.domain.JavaClass)4