X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fmodel-loader.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fentity%2Fmodel%2FModelSorterTest.java;h=8f4bf8df6c260bec3f6b31362e67600a5931342a;hp=d1d54b7b8a01a00d6a253c170108685534482d7a;hb=c5aea4a8bc398fc1c6220875e55b9520fd7f7524;hpb=ce332032dd208c5c769a2297409d8aca3f780fa8 diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java index d1d54b7..8f4bf8d 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java @@ -1,5 +1,5 @@ /** - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. @@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.isEmptyString; import static org.junit.Assert.assertThat; import java.util.ArrayList; @@ -40,17 +41,18 @@ public class ModelSorterTest { ModelArtifact model = buildTestModel(); ModelSorter.Node nodeA = new ModelSorter.Node(model); ModelSorter.Node nodeB = new ModelSorter.Node(model); - ModelSorter.Node nodeC = new ModelSorter.Node(model); ModelSorter.Edge edgeA = new ModelSorter.Edge(nodeA, nodeB); - ModelSorter.Edge edgeB = new ModelSorter.Edge(nodeA, nodeB); - ModelSorter.Edge edgeC = new ModelSorter.Edge(nodeB, nodeA); - ModelSorter.Edge edgeD = new ModelSorter.Edge(nodeA, nodeC); assertThat(edgeA, is(equalTo(edgeA))); assertThat(edgeA, is(not(equalTo(null)))); assertThat(edgeA, is(not(equalTo(model)))); + ModelSorter.Edge edgeB = new ModelSorter.Edge(nodeA, nodeB); + ModelSorter.Edge edgeC = new ModelSorter.Edge(nodeB, nodeA); + + ModelSorter.Node nodeC = new ModelSorter.Node(model); + ModelSorter.Edge edgeD = new ModelSorter.Edge(nodeA, nodeC); assertThat(edgeA, is(equalTo(edgeB))); assertThat(edgeA, is(not(equalTo(edgeC)))); assertThat(edgeA, is(not(equalTo(edgeD)))); @@ -60,17 +62,31 @@ public class ModelSorterTest { public void nodeEquality() throws BabelArtifactParsingException { ModelArtifact model = buildTestModel(); ModelSorter.Node nodeA = new ModelSorter.Node(model); - ModelSorter.Node nodeB = new ModelSorter.Node(model); assertThat(nodeA, is(equalTo(nodeA))); assertThat(nodeA, is(not(equalTo(null)))); assertThat(nodeA, is(not(equalTo(model)))); + ModelSorter.Node nodeB = new ModelSorter.Node(model); assertThat(nodeA, is(equalTo(nodeB))); assertThat(nodeA.toString(), is(equalTo(nodeB.toString()))); assertThat(nodeA, is(not(equalTo(new ModelSorter.Node(new ModelArtifact()))))); } + @Test + public void testToString() throws BabelArtifactParsingException { + ModelArtifact model = buildTestModel(); + + ModelSorter.Node nodeA = new ModelSorter.Node(model); + assertThat(nodeA.toString(), not(isEmptyString())); + + ModelSorter.Node nodeB = new ModelSorter.Node(model); + nodeA.addEdge(nodeB); + assertThat(nodeA.toString(), not(isEmptyString())); + assertThat(nodeB.toString(), not(isEmptyString())); + + } + @Test public void noModels() throws BabelArtifactParsingException { assertThat(new ModelSorter().sort(null), is(nullValue())); @@ -84,20 +100,32 @@ public class ModelSorterTest { @Test public void multipleModels() throws BabelArtifactParsingException { - Artifact a = buildTestModel("aaaa", "mvaaaa", "cccc|mvcccc"); - Artifact b = buildTestModel("bbbb", "mvbbbb", "aaaa|mvaaaa"); - Artifact c = buildTestModel("cccc", "mvcccc"); - List expected = Arrays.asList(c, a, b); - assertThat(new ModelSorter().sort(Arrays.asList(a, b, c)), is(expected)); + Artifact artA = buildTestModel("aaaa", "mvaaaa", "cccc|mvcccc"); + Artifact artB = buildTestModel("bbbb", "mvbbbb", "aaaa|mvaaaa"); + Artifact artC = buildTestModel("cccc", "mvcccc"); + List expected = Arrays.asList(artC, artA, artB); + assertThat(new ModelSorter().sort(Arrays.asList(artA, artB, artC)), is(expected)); + } + + + @Test + public void multipleModelsWithMultipleIncomingEdges() throws BabelArtifactParsingException { + ModelArtifact artA = buildTestModel("aaaa", "mvaaaa", "cccc|mvcccc"); + Artifact artB = buildTestModel("bbbb", "mvbbbb", "aaaa|mvaaaa"); + Artifact artC = buildTestModel("cccc", "mvcccc"); + Artifact artD = buildTestModel("dddd", "mvdddd", "cccc|mvcccc"); + artA.addDependentModelId("dddd|mvdddd"); + List expected = Arrays.asList(artC, artD, artA, artB); + assertThat(new ModelSorter().sort(Arrays.asList(artA, artB, artC, artD)), is(expected)); } @Test public void multipleModelsAndNamedQueries() throws BabelArtifactParsingException { - Artifact a = buildTestModel("aaaa", "1111", "cccc|2222"); + Artifact artifact = buildTestModel("aaaa", "1111", "cccc|2222"); Artifact nq1 = buildTestNamedQuery("nq1", "aaaa|1111"); Artifact nq2 = buildTestNamedQuery("nqw", "existing-model"); - List expected = Arrays.asList(a, nq2, nq1); - assertThat(new ModelSorter().sort(Arrays.asList(nq1, nq2, a)), is(expected)); + List expected = Arrays.asList(artifact, nq2, nq1); + assertThat(new ModelSorter().sort(Arrays.asList(nq1, nq2, artifact)), is(expected)); } @Test(expected = BabelArtifactParsingException.class)