From 803926af358815abfe9fd27e63fcb0bd40b25784 Mon Sep 17 00:00:00 2001 From: talig Date: Thu, 25 Oct 2018 10:08:32 +0300 Subject: Add UT for zusammen adaptor Change-Id: I80720b3c322b55ae39b363f3042c9f0efb5e1510 Issue-ID: SDC-1822 Signed-off-by: talig --- .../dao/impl/VersionableEntityDaoZusammenImpl.java | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core') diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java index 9e12d0dec9..f90ef79290 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java @@ -1,17 +1,35 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.openecomp.sdc.versioning.dao.impl; import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.ItemVersion; import com.amdocs.zusammen.datatypes.itemversion.Tag; +import java.util.Collection; +import java.util.Comparator; +import java.util.Optional; +import org.apache.commons.collections4.CollectionUtils; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.core.zusammen.api.ZusammenUtil; import org.openecomp.sdc.versioning.dao.VersionableEntityDao; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; -import java.util.Optional; - public class VersionableEntityDaoZusammenImpl implements VersionableEntityDao { private ZusammenAdaptor zusammenAdaptor; @@ -47,9 +65,20 @@ public class VersionableEntityDaoZusammenImpl implements VersionableEntityDao { // TODO: 3/19/2017 move to a common util private Id getItemVersionId(Id itemId, SessionContext context) { - Optional itemVersionOptional = zusammenAdaptor.getFirstVersion(context, itemId); + Optional itemVersionOptional = getFirstVersion(context, itemId); ItemVersion itemVersion = itemVersionOptional.orElseThrow(() -> new RuntimeException(String.format("No version was found for item %s.", itemId))); return itemVersion.getId(); } + + private Optional getFirstVersion(SessionContext context, Id itemId) { + Collection versions = zusammenAdaptor.listPublicVersions(context, itemId); + return CollectionUtils.isEmpty(versions) + ? Optional.empty() + : versions.stream().min(getVersionModificationTimeDescComparator()); + } + + private static Comparator getVersionModificationTimeDescComparator() { + return (o1, o2) -> Integer.compare(o2.getId().getValue().length(), o1.getId().getValue().length()); + } } -- cgit 1.2.3-korg