From 41ce69ec659d4fe1568bb7cfa0fd353e0469dfd4 Mon Sep 17 00:00:00 2001 From: Tomasz Golabek Date: Thu, 22 Aug 2019 13:05:23 +0200 Subject: [PATCH] unit tests - catalog-be Additional junit tests Change-Id: Ief7f445521f7821e47715a44c423fd11a17568e1 Issue-ID: SDC-2326 Signed-off-by: Tomasz Golabek --- .../sdc/be/types/ServiceConsumptionDataTest.java | 32 ++++++++++++++ .../sdc/be/types/ServiceConsumptionSourceTest.java | 39 +++++++++++++++++ .../openecomp/sdc/be/dao/neo4j/BatchBuilder.java | 31 +------------ .../org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java | 4 ++ .../openecomp/sdc/be/dao/neo4j/NodeRelation.java | 5 +++ .../sdc/be/dao/neo4j/BatchBuilderTest.java | 37 ++++++++++++++++ .../sdc/be/dao/neo4j/GraphNeighbourTableTest.java | 51 ++++++++++++++++++++++ .../openecomp/sdc/be/dao/neo4j/Neo4jEdgeTest.java | 32 ++++++++++++++ .../sdc/be/dao/neo4j/Neo4jOperationStatusTest.java | 34 +++++++++++++++ .../sdc/be/dao/neo4j/NodeRelationTest.java | 32 ++++++++++++++ 10 files changed, 267 insertions(+), 30 deletions(-) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionDataTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionSourceTest.java create mode 100644 catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilderTest.java create mode 100644 catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTableTest.java create mode 100644 catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdgeTest.java create mode 100644 catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatusTest.java create mode 100644 catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/NodeRelationTest.java diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionDataTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionDataTest.java new file mode 100644 index 0000000000..17a5d720ad --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionDataTest.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.types; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class ServiceConsumptionDataTest { + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(ServiceConsumptionData.class, hasValidGettersAndSetters()); + } +} \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionSourceTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionSourceTest.java new file mode 100644 index 0000000000..9949151f7a --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/types/ServiceConsumptionSourceTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.types; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ServiceConsumptionSourceTest { + + @Test + public void shouldReturnSourceValue() { + ServiceConsumptionSource serviceInput = ServiceConsumptionSource.getSourceValue("ServiceInput"); + assertEquals(serviceInput, ServiceConsumptionSource.SERVICE_INPUT); + } + + @Test + public void shouldReturnSource() { + String serviceInput = ServiceConsumptionSource.SERVICE_INPUT.getSource(); + assertEquals(serviceInput, "ServiceInput"); + } +} \ No newline at end of file diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java index 9d30c20683..a13c23140e 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java @@ -26,16 +26,10 @@ import java.util.ArrayList; import java.util.List; public class BatchBuilder { - // private Map> nodes; - // private List relations; - // - private List elements; - // TODO add filter + private List elements; protected BatchBuilder() { - // nodes = new HashMap>(); - // relations = new ArrayList(); elements = new ArrayList<>(); } @@ -52,28 +46,5 @@ public class BatchBuilder { return elements; } - // public BatchBuilder add( Neo4jNode element ){ - // String label = element.getLabel(); - // List list = nodes.get(label); - // if ( list == null ){ - // list = new ArrayList(); - // } - // list.add(element); - // nodes.put(label, list); - - // return this; - // } - // public BatchBuilder add( Neo4jRelation relation ){ - // relations.add(relation); - // return this; - // } - // - // public Map> getNodes() { - // return nodes; - // } - // - // public List getRelations() { - // return relations; - // } } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java index bdd17b6512..3e2cf9c8d4 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.be.dao.neo4j; +import com.google.common.annotations.VisibleForTesting; import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum; import java.util.Map; @@ -30,6 +31,9 @@ public class Neo4jEdge { private Map properties; private ActionEnum action; + @VisibleForTesting + Neo4jEdge() {} + public Neo4jEdge(GraphEdgeLabels edgeType, Map properties, ActionEnum actionEnum) { super(); this.edgeType = edgeType; diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java index c1402f402f..089bbdbba3 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java @@ -20,12 +20,17 @@ package org.openecomp.sdc.be.dao.neo4j; +import com.google.common.annotations.VisibleForTesting; + public class NodeRelation { private int fromIndex; private int toIndex; private Neo4jEdge edge; + @VisibleForTesting + NodeRelation() {} + public NodeRelation(int fromIndex, int toIndex, Neo4jEdge edge) { super(); this.fromIndex = fromIndex; diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilderTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilderTest.java new file mode 100644 index 0000000000..65ce29b946 --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilderTest.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.dao.neo4j; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; + +public class BatchBuilderTest { + + private GraphRelation graphElement = new GraphRelation(); + + @Test + public void shouldAddAndGetElement() { + BatchBuilder builder = BatchBuilder.getBuilder(); + builder.add(graphElement); + assertEquals(graphElement, builder.getElements().get(0)); + } +} \ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTableTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTableTest.java new file mode 100644 index 0000000000..14d3f3aeb0 --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTableTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.dao.neo4j; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.openecomp.sdc.be.resources.data.ArtifactData; + +public class GraphNeighbourTableTest { + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(GraphNeighbourTable.class, hasValidGettersAndSetters()); + } + + @Test + public void shouldAddEdge() { + GraphNeighbourTable graphNeighbourTable = new GraphNeighbourTable(); + NodeRelation directedEdge = new NodeRelation(1, 1, null); + graphNeighbourTable.addEdge(directedEdge); + assertEquals(directedEdge, graphNeighbourTable.getDirectedEdges().get(0)); + } + + @Test + public void shouldAddNode() { + GraphNeighbourTable graphNeighbourTable = new GraphNeighbourTable(); + ArtifactData node = new ArtifactData(); + int index = graphNeighbourTable.addNode(node); + assertEquals(node, graphNeighbourTable.getNodes().get(0)); + assertEquals(index, 0); + } +} \ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdgeTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdgeTest.java new file mode 100644 index 0000000000..664fed070f --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdgeTest.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.dao.neo4j; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class Neo4jEdgeTest { + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(Neo4jEdge.class, hasValidGettersAndSetters()); + } +} \ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatusTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatusTest.java new file mode 100644 index 0000000000..837cf0baee --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatusTest.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.dao.neo4j; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class Neo4jOperationStatusTest { + + @Test + public void shouldPrintStatusInCorrectFormat() { + String status = Neo4jOperationStatus.BAD_REQUEST + .setMessage("A").setHelpErrorMsg("B").setOriginError("C").printError(); + assertEquals(status, "[BAD_REQUEST-C-B-A]"); + } +} \ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/NodeRelationTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/NodeRelationTest.java new file mode 100644 index 0000000000..523c519617 --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/NodeRelationTest.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.dao.neo4j; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class NodeRelationTest { + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(NodeRelation.class, hasValidGettersAndSetters()); + } +} \ No newline at end of file -- 2.16.6