41
41
import org .jboss .pnc .dto .BuildConfigurationRevisionRef ;
42
42
import org .jboss .pnc .dto .BuildRef ;
43
43
import org .jboss .pnc .dto .User ;
44
- import org .jboss .pnc .dto .requests .BuildPushParameters ;
44
+ import org .jboss .pnc .dto .response .Edge ;
45
+ import org .jboss .pnc .dto .response .Graph ;
45
46
import org .jboss .pnc .enums .ArtifactQuality ;
46
47
import org .jboss .pnc .enums .BuildCategory ;
47
48
import org .jboss .pnc .enums .BuildStatus ;
102
103
public class BuildEndpointTest {
103
104
104
105
private static final Logger logger = LoggerFactory .getLogger (BuildEndpointTest .class );
105
- private static String buildId ;
106
- private static String build2Id ;
107
- private static String build3Id ;
106
+ private static String buildId ; // buildRecord1
107
+ private static String build2Id ; // tempRecord1
108
+ private static String build3Id ; // buildRecord2
109
+ private static String build5Id ; // buildRecord3
110
+ private static String build6Id ; // buildRecord4
108
111
109
112
@ Deployment
110
113
public static EnterpriseArchive deploy () {
@@ -126,6 +129,9 @@ public static void prepareData() throws Exception {
126
129
buildId = it .next ().getId ();
127
130
build2Id = it .next ().getId ();
128
131
build3Id = it .next ().getId ();
132
+ it .next ().getId ();
133
+ build5Id = it .next ().getId ();
134
+ build6Id = it .next ().getId ();
129
135
}
130
136
131
137
@ Test
@@ -736,6 +742,53 @@ public void shouldReportLeafTempBuildThatDependsOnItself() throws RemoteResource
736
742
assertThat (attributes ).containsEntry (org .jboss .pnc .api .constants .Attributes .BUILD_BREW_VERSION , "1.2.4" );
737
743
}
738
744
745
+ @ Test
746
+ @ InSequence (1 )
747
+ public void testGetBuildArtifactDependencyGraph () throws ClientException {
748
+ // arrange
749
+ BuildClient client = new BuildClient (RestClientConfiguration .asAnonymous ());
750
+
751
+ Set <String > expectedVerticesKeys = Set .of (build6Id , buildId , build2Id , build5Id );
752
+ List <Edge <Build >> expectedEdges = List .of (
753
+ Edge .<Build > builder ().source (build6Id ).target (buildId ).cost (1 ).build (), // importedArtifact1 (set to be
754
+ // part of buildId Build in
755
+ // shouldSetBuiltArtifacts)
756
+ Edge .<Build > builder ().source (buildId ).target (build2Id ).cost (1 ).build (), // builtArtifact3 (set as a
757
+ // dependency of buildId Build
758
+ // in
759
+ // shouldSetDependentArtifacts)
760
+ Edge .<Build > builder ().source (build6Id ).target (build2Id ).cost (2 ).build (), // builtArtifact3,
761
+ // builtArtifact4
762
+ Edge .<Build > builder ().source (build6Id ).target (build5Id ).cost (1 ).build ()); // builtArtifact10
763
+
764
+ // act
765
+ Graph <Build > actualGraph = client .getBuildArtifactDependencyGraph (build6Id , null );
766
+
767
+ // assert
768
+ assertThat (actualGraph .getVertices ().keySet ()).containsExactlyInAnyOrderElementsOf (expectedVerticesKeys );
769
+ assertThat (actualGraph .getEdges ()).containsExactlyInAnyOrderElementsOf (expectedEdges );
770
+ }
771
+
772
+ @ Test
773
+ @ InSequence (2 )
774
+ public void testGetBuildArtifactDependencyGraphWithDependants () throws ClientException {
775
+ // arrange
776
+ BuildClient client = new BuildClient (RestClientConfiguration .asAnonymous ());
777
+
778
+ Set <String > expectedVerticesKeys = Set .of (build6Id , buildId , build2Id , build3Id );
779
+ List <Edge <Build >> expectedEdges = List .of (
780
+ Edge .<Build > builder ().source (build6Id ).target (buildId ).cost (1 ).build (), // importedArtifact1
781
+ Edge .<Build > builder ().source (build3Id ).target (buildId ).cost (1 ).build (), // importedArtifact1
782
+ Edge .<Build > builder ().source (buildId ).target (build2Id ).cost (1 ).build ()); // builtArtifact3
783
+
784
+ // act
785
+ Graph <Build > actualGraph = client .getBuildArtifactDependencyGraph (buildId , null );
786
+
787
+ // assert
788
+ assertThat (actualGraph .getVertices ().keySet ()).containsExactlyInAnyOrderElementsOf (expectedVerticesKeys );
789
+ assertThat (actualGraph .getEdges ()).containsExactlyInAnyOrderElementsOf (expectedEdges );
790
+ }
791
+
739
792
private Set <Integer > artifactIds (RemoteCollection <Artifact > artifacts ) {
740
793
Set <Integer > artifactIds = new HashSet <>();
741
794
for (Artifact a : artifacts ) {
0 commit comments