diff options
Diffstat (limited to 'vid-app-common')
23 files changed, 210 insertions, 269 deletions
diff --git a/vid-app-common/.classpath b/vid-app-common/.classpath deleted file mode 100755 index 6d66a1410..000000000 --- a/vid-app-common/.classpath +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" output="target/classes" path="target/generated-sources">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/vid-app-common/.gitignore b/vid-app-common/.gitignore new file mode 100644 index 000000000..675c1faed --- /dev/null +++ b/vid-app-common/.gitignore @@ -0,0 +1,8 @@ +.settings/ +overlays/ +logs/ +debug-logs/ +target/ +.idea/ +.classpath +.project
\ No newline at end of file diff --git a/vid-app-common/.project b/vid-app-common/.project deleted file mode 100755 index f0b63c382..000000000 --- a/vid-app-common/.project +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>vid-app-common</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
- <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- </natures>
-</projectDescription>
diff --git a/vid-app-common/.settings/.jsdtscope b/vid-app-common/.settings/.jsdtscope deleted file mode 100755 index c34a33690..000000000 --- a/vid-app-common/.settings/.jsdtscope +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="src/main/webapp"/>
- <classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
- <attributes>
- <attribute name="hide" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
- <classpathentry kind="output" path=""/>
-</classpath>
diff --git a/vid-app-common/.settings/org.eclipse.core.resources.prefs b/vid-app-common/.settings/org.eclipse.core.resources.prefs deleted file mode 100755 index a54705a11..000000000 --- a/vid-app-common/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,7 +0,0 @@ -eclipse.preferences.version=1
-encoding//src/main/java=UTF-8
-encoding//src/main/resources=UTF-8
-encoding//src/test/java=UTF-8
-encoding//src/test/resources=UTF-8
-encoding//target/generated-sources=UTF-8
-encoding/<project>=UTF-8
diff --git a/vid-app-common/.settings/org.eclipse.jdt.core.prefs b/vid-app-common/.settings/org.eclipse.jdt.core.prefs deleted file mode 100755 index 1ab2bb53a..000000000 --- a/vid-app-common/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/vid-app-common/.settings/org.eclipse.m2e.core.prefs b/vid-app-common/.settings/org.eclipse.m2e.core.prefs deleted file mode 100755 index 14b697b7b..000000000 --- a/vid-app-common/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
diff --git a/vid-app-common/.settings/org.eclipse.wst.common.component b/vid-app-common/.settings/org.eclipse.wst.common.component deleted file mode 100755 index 40a2cb3cc..000000000 --- a/vid-app-common/.settings/org.eclipse.wst.common.component +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
- <wb-module deploy-name="vid-app-common">
- <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
- <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
- <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
- <wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources"/>
- <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
- <dependent-module deploy-path="/" handle="module:/overlay/var/M2_REPO/org/openecomp/ecompsdkos/epsdk-app-overlay/1.1.0-SNAPSHOT/epsdk-app-overlay-1.1.0-SNAPSHOT.war?unpackFolder=target/m2e-wtp/overlays&includes=**/**&excludes=META-INF/MANIFEST.MF">
- <dependency-type>consumes</dependency-type>
- </dependent-module>
- <dependent-module deploy-path="/" handle="module:/overlay/slf/?includes=**/**&excludes=META-INF/MANIFEST.MF">
- <dependency-type>consumes</dependency-type>
- </dependent-module>
- <property name="java-output-path" value="/vid-app-common/target/classes"/>
- <property name="component.exclusion.patterns" value="WEB-INF/lib/*.jar"/>
- <property name="context-root" value="vid-common"/>
- </wb-module>
-</project-modules>
diff --git a/vid-app-common/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/vid-app-common/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml deleted file mode 100755 index b01fdb78f..000000000 --- a/vid-app-common/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml +++ /dev/null @@ -1,7 +0,0 @@ -<root>
- <facet id="jst.jaxrs">
- <node name="libprov">
- <attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
- </node>
- </facet>
-</root>
diff --git a/vid-app-common/.settings/org.eclipse.wst.common.project.facet.core.xml b/vid-app-common/.settings/org.eclipse.wst.common.project.facet.core.xml deleted file mode 100755 index 91e8c54be..000000000 --- a/vid-app-common/.settings/org.eclipse.wst.common.project.facet.core.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<faceted-project>
- <fixed facet="wst.jsdt.web"/>
- <installed facet="java" version="1.8"/>
- <installed facet="jst.web" version="3.1"/>
- <installed facet="jst.jaxrs" version="2.0"/>
- <installed facet="wst.jsdt.web" version="1.0"/>
-</faceted-project>
diff --git a/vid-app-common/.settings/org.eclipse.wst.jsdt.ui.superType.container b/vid-app-common/.settings/org.eclipse.wst.jsdt.ui.superType.container deleted file mode 100755 index 3bd5d0a48..000000000 --- a/vid-app-common/.settings/org.eclipse.wst.jsdt.ui.superType.container +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file diff --git a/vid-app-common/.settings/org.eclipse.wst.jsdt.ui.superType.name b/vid-app-common/.settings/org.eclipse.wst.jsdt.ui.superType.name deleted file mode 100755 index 05bd71b6e..000000000 --- a/vid-app-common/.settings/org.eclipse.wst.jsdt.ui.superType.name +++ /dev/null @@ -1 +0,0 @@ -Window
\ No newline at end of file diff --git a/vid-app-common/.settings/org.eclipse.wst.validation.prefs b/vid-app-common/.settings/org.eclipse.wst.validation.prefs deleted file mode 100755 index 6f1cba68d..000000000 --- a/vid-app-common/.settings/org.eclipse.wst.validation.prefs +++ /dev/null @@ -1,2 +0,0 @@ -disabled=06target
-eclipse.preferences.version=1
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java index 17fb29b59..57d80ce9d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java @@ -1,7 +1,6 @@ package org.onap.vid.asdc.parser; -import org.onap.vid.asdc.beans.Service; -import org.onap.vid.model.*; +import org.apache.commons.lang3.StringUtils; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.FilterType; @@ -11,6 +10,8 @@ import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.*; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.toscaparser.api.parameters.Input; +import org.onap.vid.asdc.beans.Service; +import org.onap.vid.model.*; import java.nio.file.Path; import java.util.*; @@ -417,7 +418,22 @@ public class ToscaParserImpl2 { private boolean isInputMatchesToGroup(List<Property> annotationProperties, org.onap.vid.model.Group group){ for(Property property: annotationProperties){ if(property.getName().equals(VF_MODULE_LABEL)){ - return getPropertyValueAsString(property).equals(group.getProperties().getVfModuleLabel()); + final Object values = property.getValue(); + final String vfModuleLabel = group.getProperties().getVfModuleLabel(); + if (values instanceof List) { + if (listContainsAsString((List) values, vfModuleLabel)) return true; + } else { + return getPropertyValueAsString(property).equals(vfModuleLabel); + } + } + } + return false; + } + + private boolean listContainsAsString(List list, String value) { + for (Object v : list) { + if (StringUtils.equals(v.toString(), value)) { + return true; } } return false; @@ -428,7 +444,7 @@ public class ToscaParserImpl2 { } private String removeSquareBrackets(String stringWithSquareBrackets){ - return stringWithSquareBrackets.substring(1, stringWithSquareBrackets.length()-1); + return stringWithSquareBrackets.replaceAll("(^\\[|\\]$)", ""); } private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper){ @@ -507,7 +523,10 @@ public class ToscaParserImpl2 { for (Property property : properties) { //special handling to necessary sub-property "ecomp_generated_naming" if(property.getName().equals("nf_naming")){ - propertiesMap.put(removeSquareBrackets(((LinkedHashMap)(property.getValue())).keySet().toString()) ,((LinkedHashMap)(property.getValue())).get("ecomp_generated_naming").toString()); + final Object ecompGeneratedNaming = ((Map) (property.getValue())).get("ecomp_generated_naming"); + if (ecompGeneratedNaming != null) { + propertiesMap.put("ecomp_generated_naming", ecompGeneratedNaming.toString()); + } } propertiesMap.put(property.getName(), property.getValue().toString()); } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java b/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java index 91617ff42..85caac424 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java @@ -22,6 +22,7 @@ package org.onap.vid.model; * ============LICENSE_END========================================================= */ +import java.util.Collections; import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -82,7 +83,7 @@ public class CategoryParameter extends VidBaseEntity { @OneToMany(fetch = FetchType.EAGER, mappedBy = "categoryParameter") public Set<CategoryParameterOption> getOptions() { - return options; + return Collections.unmodifiableSet(options); } public void setOptions(Set<CategoryParameterOption> options) { diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index c5bee2448..acdf0afb5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -235,8 +235,7 @@ public class AaiServiceImpl implements AaiService { resultList.add(getServicesByProjectNames(projects, roleValidator)); } if (!resultList.isEmpty()) { - Intersection<ServiceInstanceSearchResult> intersection = new Intersection<>(); - serviceInstancesSearchResults.serviceInstances = intersection.intersectMultipileArray(resultList); + serviceInstancesSearchResults.serviceInstances = Intersection.of(resultList); } return new AaiResponse<>(serviceInstancesSearchResults, null, HttpStatus.SC_OK); diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java b/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java index 6e0d1fc25..ed1be5c76 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java @@ -1,31 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 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.onap.vid.utils; -import java.util.List; -import java.util.stream.Collectors; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; -/** - * Created by moriya1 on 10/10/2017. - */ -public class Intersection<T> { - public List<T> intersectMultipileArray(List<List<T>> lists) { - if (lists.size() == 1) { - return lists.get(0); - } else { - List<T> intersectResult = intersectTwoArrays(lists.get(0),lists.get(1)); +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; - lists.remove(0); - lists.remove(0); - lists.add(0,intersectResult); - return intersectMultipileArray(lists); - } +public class Intersection { + private Intersection() { } - public List<T> intersectTwoArrays(List<T> list1, List<T> list2) { - - List<T> intersect = list1.stream() - .filter(list2::contains) - .collect(Collectors.toList()); - return intersect; + /** + * Returns intersection of given lists. Treats those lists as sets, ignores repetitions. + */ + public static <T> List<T> of(Collection<List<T>> lists) { + return lists + .stream() + .map(elements -> (Set<T>) Sets.newHashSet(elements)) + .reduce(Sets::intersection) + .map(set -> (List<T>) Lists.newArrayList(set)) + .orElse(Collections.emptyList()); } } diff --git a/vid-app-common/src/main/resources/1712_ADIOD.zip b/vid-app-common/src/main/resources/1712_ADIOD.zip Binary files differnew file mode 100644 index 000000000..281ee8aa3 --- /dev/null +++ b/vid-app-common/src/main/resources/1712_ADIOD.zip diff --git a/vid-app-common/src/main/resources/sdcservices.json b/vid-app-common/src/main/resources/sdcservices.json index 1d9d160e3..e300597e5 100644 --- a/vid-app-common/src/main/resources/sdcservices.json +++ b/vid-app-common/src/main/resources/sdcservices.json @@ -71,6 +71,20 @@ "resources": null }, { + "uuid": "90fe6842-aa76-4b68-8329-5c86ff564407", + "invariantUUID": "0311f998-9268-4fd6-bbba-afff15087b72", + "name": "4-27_vMME_Service", + "version": "1.0", + "toscaModelURL": "./1712_ADIOD.zip", + "category": "Mobility", + "lifecycleState": "CERTIFIED", + "lastUpdaterUserId": "rg276b", + "lastUpdaterFullName": null, + "distributionStatus": "DISTRIBUTED", + "artifacts": null, + "resources": null + }, + { "uuid": "73e1322a-8a9a-49dc-9558-b0c5c5770e4a", "invariantUUID": "f430728a-4530-42be-a577-1206b9484cef", "name": "4-27_vMME_Service", diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java index 1282a6f78..e1c5e923b 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java @@ -15,8 +15,8 @@ import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.asdc.AsdcClient; import org.onap.vid.asdc.local.LocalAsdcClient; -import org.onap.vid.model.*; import org.onap.vid.controllers.ToscaParserMockHelper; +import org.onap.vid.model.*; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -196,6 +196,28 @@ public class ToscaParserImpl2Test { JsonAssert.assertJsonEquals(expectedConfigurations, actualConfigurations); } + @Test + public void modelWithAnnotatedInputWithTwoProperties_vfModuleGetsTheInput() throws Exception { + final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json"); + final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())); + + assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1: { inputs: { 201712488_adiodvpe10_availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel)); + } + + @Test + public void modelWithNfNamingWithToValues_ecompGeneratedNamingIsExtracted() throws Exception { + final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json"); + final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())); + + assertJsonStringEqualsIgnoreNulls("" + + "{ vnfs: " + + " { \"201712-488_ADIOD-vPE-1 0\": " + + " { properties: { " + + " ecomp_generated_naming: \"true\", " + + " nf_naming: \"{naming_policy=SDNC_Policy.Config_MS_1806SRIOV_VPE_ADIoDJson, ecomp_generated_naming=true}\" " + + "} } } }", om.writeValueAsString(serviceModel)); + } + private void setPprobeServiceProxy(Map<String, PortMirroringConfig> expectedConfigurations){ //Port Mirroring Configuration By Policy 0 doesn't contains pProbe. // But due to sdc design if pProbe not exists parser expects to get it from other source. diff --git a/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java index 7a4263c7e..3492a7547 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java @@ -95,7 +95,8 @@ public class CategoryParameterServiceImplTest { AddCategoryOptionsRequest optionsRequest = new AddCategoryOptionsRequest(); optionsRequest.options.add(OPTION_NAME); CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true); - categoryParameter.getOptions().add(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter)); + CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true); + categoryParameter.addOption(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter)); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); String expectedError = String.format(CategoryParameterServiceImpl.OPTION_ALREADY_EXIST_FOR_CATEGORY @@ -155,9 +156,10 @@ public class CategoryParameterServiceImplTest { @Test public void deleteCategoryOption_happyPath() { CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true); + CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true); CategoryParameterOption categoryParameterOption = - new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter); - categoryParameter.getOptions().add(categoryParameterOption); + new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter); + categoryParameter.addOption(categoryParameterOption); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); doReturn(aList).when(dataAccessService).getList(any(), anyString(), any(), any()); @@ -171,9 +173,10 @@ public class CategoryParameterServiceImplTest { @Test public void getCategoryParametersTest() { CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true); + CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true); CategoryParameterOption categoryParameterOption = - new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter); - categoryParameter.getOptions().add(categoryParameterOption); + new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter); + categoryParameter.addOption(categoryParameterOption); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); doReturn(aList).when(dataAccessService).getList(any(), anyString(), any(), any()); @@ -191,8 +194,9 @@ public class CategoryParameterServiceImplTest { public void updateCategoryParameterOption_domainObjectGetsSavedSuccessfully() { CategoryParameterOptionRep optionRepExisting = new CategoryParameterOptionRep(APP_ID_VID, OPTION_NAME); CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true); - categoryParameter.getOptions().add( - new CategoryParameterOption(APP_ID_VID, UNIQUE_OPTION_NAME, categoryParameter)); + CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true); + categoryParameter.addOption( + new CategoryParameterOption(APP_ID_VID, UNIQUE_OPTION_NAME, anotherCategoryParameter)); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); doReturn(aList).when(dataAccessService).getList(CategoryParameter.class, QUERY_STRING_FOR_CATEGORY_NAME, null, null); @@ -207,7 +211,8 @@ public class CategoryParameterServiceImplTest { public void updateCategoryParameterOption_shouldFailUpdateForbidden() { CategoryParameterOptionRep optionRep = new CategoryParameterOptionRep("1", CATEGORY_NAME); CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, false); - categoryParameter.getOptions().add(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter)); + CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, false); + categoryParameter.addOption(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter)); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); doReturn(aList).when(dataAccessService).getList(CategoryParameter.class, QUERY_STRING_FOR_CATEGORY_NAME, null, null); @@ -222,7 +227,8 @@ public class CategoryParameterServiceImplTest { CategoryParameterOptionRep optionRep = new CategoryParameterOptionRep("SOME_UNRELATED_ID", CATEGORY_NAME); CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true); - categoryParameter.getOptions().add(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, categoryParameter)); + CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true); + categoryParameter.addOption(new CategoryParameterOption(APP_ID_VID, OPTION_NAME, anotherCategoryParameter)); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); doReturn(aList).when(dataAccessService).getList(CategoryParameter.class, QUERY_STRING_FOR_CATEGORY_NAME, null, null); @@ -238,9 +244,9 @@ public class CategoryParameterServiceImplTest { CategoryParameter categoryParameter = createCategoryParameter(CATEGORY_NAME, true); CategoryParameter anotherCategoryParameter = createCategoryParameter(CATEGORY_NAME, true); - categoryParameter.getOptions().add( + categoryParameter.addOption( new CategoryParameterOption(APP_ID_VID, UNIQUE_OPTION_NAME, anotherCategoryParameter)); - categoryParameter.getOptions().add( + categoryParameter.addOption( new CategoryParameterOption(APP_ID_SDC, OPTION_NAME, anotherCategoryParameter)); List<CategoryParameter> aList = createCategoryParametersList(categoryParameter); diff --git a/vid-app-common/src/test/java/org/onap/vid/testUtils/IntersectionTest.java b/vid-app-common/src/test/java/org/onap/vid/testUtils/IntersectionTest.java index c766d26f3..dcccab008 100644 --- a/vid-app-common/src/test/java/org/onap/vid/testUtils/IntersectionTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/testUtils/IntersectionTest.java @@ -1,101 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 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.onap.vid.testUtils; -import org.junit.Assert; import org.junit.Test; import org.onap.vid.utils.Intersection; -import java.util.ArrayList; import java.util.List; -/** - * Created by moriya1 on 10/10/2017. - */ +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.util.Lists.emptyList; +import static org.assertj.core.util.Lists.list; + public class IntersectionTest { @Test - public void testFourArrays(){ - List<String> l1 = new ArrayList<String>(); - l1.add("1"); - l1.add("2"); - - List<String> l2 = new ArrayList<String>(); - l2.add("2"); - l2.add("3"); - - List<String> l3 = new ArrayList<String>(); - l3.add("2"); - l3.add("4"); - - List<String> l4 = new ArrayList<String>(); - l4.add("2"); - l4.add("5"); - - List<List<String>> all = new ArrayList<>(); - all.add(l1); - all.add(l2); - all.add(l3); - all.add(l4); - Intersection<String> m = new Intersection<>(); - List<String> ans = m.intersectMultipileArray(all); - Assert.assertEquals(1,ans.size()); - Assert.assertEquals(ans.get(0),"2"); + public void testFourArrays() { + // given + List<List<String>> input = list( + list("1", "2"), + list("2", "3"), + list("2", "4"), + list("2", "5") + ); + // when + List<String> output = Intersection.of(input); + // then + assertThat(output).containsExactlyInAnyOrder("2"); } - - @Test - public void testTwoArrays(){ - List<String> l1 = new ArrayList<String>(); - l1.add("1"); - l1.add("2"); - - List<String> l2 = new ArrayList<String>(); - l2.add("2"); - l2.add("3"); - - List<List<String>> all = new ArrayList<>(); - all.add(l1); - all.add(l2); - Intersection<String> m = new Intersection<>(); - List<String> l3 = m.intersectMultipileArray(all); - Assert.assertEquals(l3.size(),1); - Assert.assertEquals(l3.get(0),"2"); + public void testTwoArrays() { + // given + List<List<String>> input = list( + list("1", "2"), + list("2", "3") + ); + // when + List<String> output = Intersection.of(input); + // then + assertThat(output).containsExactlyInAnyOrder("2"); } @Test - public void testNoIntersection(){ - List<String> l1 = new ArrayList<String>(); - l1.add("1"); - l1.add("2"); - - List<String> l2 = new ArrayList<String>(); - l2.add("3"); - l2.add("4"); + public void testNoIntersection() { + // given + List<List<String>> input = list( + list("1", "2"), + list("3", "4") + ); + // when + List<String> output = Intersection.of(input); + // then + assertThat(output).isEmpty(); - List<List<String>> all = new ArrayList<>(); - all.add(l1); - all.add(l2); - Intersection<String> m = new Intersection<>(); - List<String> l3 = m.intersectMultipileArray(all); - Assert.assertEquals(l3.size(),0); + } + @Test + public void testOneArray() { + // given + List<List<String>> input = list(list("1", "2")); + // when + List<String> output = Intersection.of(input); + // then + assertThat(output).containsExactlyInAnyOrder("1", "2"); } @Test - public void testOneArrays(){ - List<String> l1 = new ArrayList<String>(); - l1.add("1"); - l1.add("2"); - List<List<String>> all = new ArrayList<>(); - all.add(l1); - Intersection<String> m = new Intersection<>(); - List<String> l3 = m.intersectMultipileArray(all); - Assert.assertEquals(l3.size(),2); - Assert.assertEquals(l3.get(0),"1"); - Assert.assertEquals(l3.get(1),"2"); + public void testEmptyInput() { + // when + List<String> output = Intersection.of(emptyList()); + // then + assertThat(output).isEmpty(); + } + @Test + public void shouldIgnoreRepetitions() { + // when + List<String> output = Intersection.of(list( + list("1", "1"), + list("1", "1") + )); + // then + assertThat(output).containsExactly("1"); } } diff --git a/vid-app-common/src/test/resources/empty.json b/vid-app-common/src/test/resources/empty.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/vid-app-common/src/test/resources/empty.json @@ -0,0 +1 @@ +{}
\ No newline at end of file |