diff options
author | ys9693 <ys9693@att.com> | 2019-07-31 13:42:32 +0300 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-07-31 13:13:08 +0000 |
commit | 3bc744e849fff5f599746f9035449b1940bdcdc7 (patch) | |
tree | 9c50ec0d28d52e93b14ac6e8cc20c3e8a3e13edc | |
parent | ad353e729ad380cb669886af11d347eebda92ac4 (diff) |
fix GetEntity API method returning a map rather than a list1.6.0
Issue-ID: SDC-2481
Change-Id: I710ed80a7e1b0e4d23176b0a3b33910b28a83bbf
Signed-off-by: Yuli Shlosberg <ys9693@att.com>
5 files changed, 88 insertions, 23 deletions
diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java index c5f98d8..ac160e0 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java +++ b/src/main/java/org/onap/sdc/tosca/parser/api/IEntityDetails.java @@ -87,13 +87,13 @@ public interface IEntityDetails { * Retrieves map of requirements of the entity instance * @return map of entity requirement names and corresponding {@link RequirementAssignment} object instances */ - Map<String, RequirementAssignment> getRequirements(); + List<RequirementAssignment> getRequirements(); /** * Retrieves map of capabilities of the entity instance * @return map of entity capability names and corresponding {@link CapabilityAssignment} object instances */ - Map<String, CapabilityAssignment> getCapabilities(); + List<CapabilityAssignment> getCapabilities(); /** * Retrieves list of policy target names diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java b/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java index f6f961c..57559c6 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/EntityDetails.java @@ -67,19 +67,15 @@ public abstract class EntityDetails implements IEntityDetails { } @Override - public Map<String, RequirementAssignment> getRequirements() { + public List<RequirementAssignment> getRequirements() { return entityTemplate.getRequirements() - .getAll() - .stream() - .collect(Collectors.toMap(RequirementAssignment::getName, ra->ra)); + .getAll(); } @Override - public Map<String, CapabilityAssignment> getCapabilities() { + public List<CapabilityAssignment> getCapabilities() { return entityTemplate.getCapabilities() - .getAll() - .stream() - .collect(Collectors.toMap(CapabilityAssignment::getName, ca->ca)); + .getAll(); } @Override diff --git a/src/test/java/org/onap/sdc/impl/CapReqWithSameNamesTest.java b/src/test/java/org/onap/sdc/impl/CapReqWithSameNamesTest.java new file mode 100644 index 0000000..4203293 --- /dev/null +++ b/src/test/java/org/onap/sdc/impl/CapReqWithSameNamesTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-tosca + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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.onap.sdc.impl; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.enums.SdcTypes; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.RequirementAssignment; + +import java.net.URL; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class CapReqWithSameNamesTest { + + private static ISdcCsarHelper helper = null; + + @BeforeClass + public static void setUpClass() { + try { + URL resource = GetEntityPortMirroringTest.class.getClassLoader() + .getResource("csars/service-VdbePx-csar.csar"); + if (resource != null) { + helper = SdcToscaParserFactory.getInstance().getSdcCsarHelper(resource.getFile()); + } + + } catch (SdcToscaParserException e) { + e.printStackTrace(); + } + } + + @Test + public void verify2reqWithSameName() { + EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.CONFIGURATION) + .build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE) + .build(); + + List<IEntityDetails> entities = helper.getEntity(entityQuery, topologyTemplateQuery, false); + long count = entities.stream() + .flatMap(f -> f.getRequirements().stream()) + .map(RequirementAssignment::getName) + .filter("vlan_assignment"::equals).count(); + assertEquals(2L, count); + + } + +} diff --git a/src/test/java/org/onap/sdc/impl/GetEntityPortMirroringTest.java b/src/test/java/org/onap/sdc/impl/GetEntityPortMirroringTest.java index 8aa08b7..33e130e 100644 --- a/src/test/java/org/onap/sdc/impl/GetEntityPortMirroringTest.java +++ b/src/test/java/org/onap/sdc/impl/GetEntityPortMirroringTest.java @@ -115,21 +115,17 @@ public class GetEntityPortMirroringTest { assertEquals(2, proxyNodes.size()); assertEquals(1, configurationNodes.size()); - Map<String, RequirementAssignment> reqMap = configurationNodes.get(0).getRequirements(); - assertEquals(cap0, reqMap.get("source").getCapabilityName()); - assertEquals(cap1, reqMap.get("collector").getCapabilityName()); + List<RequirementAssignment> reqMap = configurationNodes.get(0).getRequirements(); + assertEquals(cap0, reqMap.stream().filter(f -> f.getName().equals("source")).findAny().get().getCapabilityName()); + assertEquals(cap1, reqMap.stream().filter(f -> f.getName().equals("collector")).findAny().get().getCapabilityName()); assertTrue(isCapabilityFound(proxyNodes.get(0), cap0)); assertTrue(isCapabilityFound(proxyNodes.get(1), cap1)); } private boolean isCapabilityFound(IEntityDetails nodeDetails, String capName) { - List<CapabilityAssignment> assignments = nodeDetails.getCapabilities() - .values() - .stream() - .filter(ca->capName.equals(ca.getDefinition() - .getName())) - .collect(Collectors.toList()); - return assignments.size() == 1; + List<CapabilityAssignment> assignments = nodeDetails.getCapabilities(); + CapabilityAssignment capabilityAssignment = assignments.stream().filter(f -> f.getDefinition().getName().equals(capName)).findAny().orElse(null); + return capabilityAssignment != null; } } diff --git a/src/test/java/org/onap/sdc/impl/GetEntityTest.java b/src/test/java/org/onap/sdc/impl/GetEntityTest.java index 7d37d67..f1fcf2f 100644 --- a/src/test/java/org/onap/sdc/impl/GetEntityTest.java +++ b/src/test/java/org/onap/sdc/impl/GetEntityTest.java @@ -88,9 +88,9 @@ public class GetEntityTest { assertEquals("ssc_ssc_avpn_port_0", entities.get(0).getName()); assertEquals(18, entities.get(0).getProperties().size()); assertEquals(1, entities.get(0).getRequirements().size()); - assertEquals(13, entities.get(0).getCapabilities().entrySet().size()); - Map<String, CapabilityAssignment> capAssignments = entities.get(0).getCapabilities(); - CapabilityAssignment capabilityAssignment = capAssignments.get("network.outgoing.packets.rate"); + assertEquals(13, entities.get(0).getCapabilities().size()); + List<CapabilityAssignment> capAssignments = entities.get(0).getCapabilities(); + CapabilityAssignment capabilityAssignment = capAssignments.stream().filter(p -> p.getName().equals("network.outgoing.packets.rate")).findAny().orElse(null); assertEquals("org.openecomp.capabilities.metric.Ceilometer", capabilityAssignment.getDefinition().getType()); } |