aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java62
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java89
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java73
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java20
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java110
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java170
7 files changed, 276 insertions, 250 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java
index c2f6c4708d..23ffc2549b 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/VersionsImpl.java
@@ -145,21 +145,11 @@ public class VersionsImpl implements Versions {
@Override
public Response listRevisions(String itemId, String versionId, String user) {
- GenericCollectionWrapper<RevisionDto> results = new GenericCollectionWrapper<>();
- MapRevisionToDto mapper = new MapRevisionToDto();
-
List<Revision> revisions = versioningManager.listRevisions(itemId, new Version(versionId));
- /* When creating a new item an initial version is created with invalid data.
- This revision is not an applicable revision. The logic of identifying this revision is:
- 1- only the first version of item has this issue
- 2- only in the first item version there are 2 revisions created
- 3- the second revision is in format "Initial <vlm/vsp>: <name of the vlm/vsp>"
- 4- only if a revision in this format exists we remove the first revision. */
- if (revisions.size() > 1 &&
- revisions.get(revisions.size() - 2).getMessage().matches("Initial .*:.*")) {
- revisions.remove(revisions.size() - 1);
- }
+ filterRevisions(revisions);
+ GenericCollectionWrapper<RevisionDto> results = new GenericCollectionWrapper<>();
+ MapRevisionToDto mapper = new MapRevisionToDto();
revisions.forEach(revision -> results.add(mapper.applyMapping(revision, RevisionDto.class)));
return Response.ok(results).build();
}
@@ -189,13 +179,15 @@ public class VersionsImpl implements Versions {
return Response.ok().build();
}
+ private Version getVersion(String itemId, Version version) {
+ Version retrievedVersion = versioningManager.get(itemId, version);
- private void revert(RevisionRequestDto request, String itemId, String versionId) {
- if (request.getRevisionId() == null) {
- throw new CoreException(new RevisionIdNotFoundErrorBuilder().build());
+ if (retrievedVersion.getState().getSynchronizationState() != SynchronizationState.Merging &&
+ // looks for sdc applicative conflicts
+ conflictsManager.isConflicted(itemId, retrievedVersion)) {
+ retrievedVersion.getState().setSynchronizationState(SynchronizationState.Merging);
}
-
- versioningManager.revert(itemId, new Version(versionId), request.getRevisionId());
+ return retrievedVersion;
}
private void sync(String itemId, Version version) {
@@ -214,6 +206,29 @@ public class VersionsImpl implements Versions {
ActivityType.Commit, user, true, "", message));
}
+ private void revert(RevisionRequestDto request, String itemId, String versionId) {
+ if (request.getRevisionId() == null) {
+ throw new CoreException(new RevisionIdNotFoundErrorBuilder().build());
+ }
+
+ versioningManager.revert(itemId, new Version(versionId), request.getRevisionId());
+ }
+
+ private void filterRevisions(List<Revision> revisions) {
+ /* When creating a new item an initial version is created with invalid data.
+ This revision is not an applicable revision. The logic of identifying this revision is:
+ 1- only the first version of item has this issue
+ 2- only in the first item version there are 2 revisions created
+ 3- the second revision is in format "Initial <vlm/vsp>: <name of the vlm/vsp>"
+ 4- only if a revision in this format exists we remove the first revision. */
+ int numOfRevisions = revisions.size();
+ if (numOfRevisions > 1 &&
+
+ revisions.get(numOfRevisions - 2).getMessage().matches("Initial .*:.*")) {
+ revisions.remove(numOfRevisions - 1);
+ }
+ }
+
private void notifyUsers(String itemId, Version version, String message,
String userName, NotificationEventTypes eventType) {
Map<String, Object> eventProperties = new HashMap<>();
@@ -236,10 +251,10 @@ public class VersionsImpl implements Versions {
}
private class SyncEvent implements Event {
-
private String eventType;
private String originatorId;
private Map<String, Object> attributes;
+
private String entityId;
public SyncEvent(String eventType, String originatorId,
@@ -269,15 +284,6 @@ public class VersionsImpl implements Versions {
public String getEntityId() {
return entityId;
}
- }
- private Version getVersion(String itemId, Version version) {
- version = versioningManager.get(itemId, version);
-
- if (version.getState().getSynchronizationState() != SynchronizationState.Merging &&
- conflictsManager.isConflicted(itemId, version)) { // looks for sdc applicative conflicts
- version.getState().setSynchronizationState(SynchronizationState.Merging);
- }
- return version;
}
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
index 77152c6fbb..e1a60386e4 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
@@ -81,6 +81,7 @@ import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM
import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
+import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit;
@Named
@Service("vendorLicenseModels")
@@ -88,9 +89,12 @@ import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERS
@Validated
public class VendorLicenseModelsImpl implements VendorLicenseModels {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private static final Logger logger = LoggerFactory.getLogger(VendorLicenseModelsImpl.class);
- public static final String SUBMIT_ITEM = "Submit_Item";
+ private static final String VLM_ID = "VLM id";
+ private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
+ private static final String SUBMIT_HEALED_VERSION_ERROR =
+ "VLM Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
+ private static final Logger LOGGER = LoggerFactory.getLogger(VendorLicenseModelsImpl.class);
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
private ItemPermissionsManager permissionsManager = ItemPermissionsManagerFactory.getInstance()
.createInterface();
@@ -107,7 +111,7 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
@Override
public Response listLicenseModels(String versionStatus, String user) {
- mdcDataDebugMessage.debugEntryMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
MdcUtil.initMdc(LoggerServiceName.List_VLM.toString());
Predicate<Item> itemPredicate;
@@ -130,14 +134,14 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
.sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
.forEach(vspItem -> results.add(mapper.applyMapping(vspItem, ItemDto.class)));
- mdcDataDebugMessage.debugExitMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
return Response.ok(results).build();
}
@Override
public Response createLicenseModel(VendorLicenseModelRequestDto request, String user) {
- mdcDataDebugMessage.debugEntryMessage(null);
- logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_VLM + request.getVendorName());
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
+ LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_VLM + request.getVendorName());
MdcUtil.initMdc(LoggerServiceName.Create_VLM.toString());
Item item = new Item();
@@ -169,14 +173,14 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
activityLogManager.logActivity(new ActivityLogEntity(vlm.getId(), version,
ActivityType.Create, user, true, "", ""));
- mdcDataDebugMessage.debugExitMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
return Response.ok(itemCreationDto).build();
}
@Override
public Response updateLicenseModel(VendorLicenseModelRequestDto request, String vlmId,
String versionId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(VLM_ID, vlmId);
MdcUtil.initMdc(LoggerServiceName.Update_VLM.toString());
VendorLicenseModelEntity vlm =
@@ -187,13 +191,13 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
vendorLicenseManager.updateVendorLicenseModel(vlm);
- mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(VLM_ID, vlmId);
return Response.ok().build();
}
@Override
public Response getLicenseModel(String vlmId, String versionId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(VLM_ID, vlmId);
MdcUtil.initMdc(LoggerServiceName.Get_VLM.toString());
Version version = versioningManager.get(vlmId, new Version(versionId));
@@ -203,37 +207,34 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
try {
Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
.healItemVersion(vlmId, version, ItemType.vlm, false);
- healedVersion.ifPresent(vlm::setVersion);
-
- if (healedVersion.isPresent() && version.getStatus() == VersionStatus.Certified) {
- try {
- submit(vlmId, healedVersion.get(), "Submit after heal", user);
- } catch (Exception ex) {
- logger.error("VLM Id {}: Error while submitting version {} " +
- "created based on Certified version {} for healing purpose.",
- vlmId, healedVersion.get().getId(), versionId, ex.getMessage());
+
+ if (healedVersion.isPresent()) {
+ vlm.setVersion(healedVersion.get());
+ if (version.getStatus() == VersionStatus.Certified) {
+ submitHealedVersion(vlmId, healedVersion.get(), versionId, user);
}
}
} catch (Exception e) {
- logger.error(String.format("Error while auto healing VLM with Id %s and version %s: %s",
- vlmId, versionId, e.getMessage()));
+ LOGGER.error(
+ String.format("Error while auto healing VLM with Id %s and version %s", vlmId, versionId),
+ e);
}
VendorLicenseModelEntityDto vlmDto =
new MapVendorLicenseModelEntityToDto().applyMapping(vlm, VendorLicenseModelEntityDto.class);
- mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(VLM_ID, vlmId);
return Response.ok(vlmDto).build();
}
@Override
public Response deleteLicenseModel(String vlmId, String versionId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(VLM_ID, vlmId);
MdcUtil.initMdc(LoggerServiceName.Delete_VLM.toString());
vendorLicenseManager.deleteVendorLicenseModel(vlmId, new Version(versionId));
- mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(VLM_ID, vlmId);
return Response.ok().build();
}
@@ -243,27 +244,24 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
String versionId, String user) {
Version version = new Version(versionId);
- switch (request.getAction()) {
- case Submit:
- if (!permissionsManager.isAllowed(vlmId, user, SUBMIT_ITEM)) {
- return Response.status(Response.Status.FORBIDDEN).entity
- (new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
- }
- String message =
- request.getSubmitRequest() == null ? "" : request.getSubmitRequest().getMessage();
- submit(vlmId, version, message, user);
+ if (request.getAction() == Submit) {
+ if (!permissionsManager.isAllowed(vlmId, user, SUBMIT_ITEM_ACTION)) {
+ return Response.status(Response.Status.FORBIDDEN)
+ .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
+ }
+ String message =
+ request.getSubmitRequest() == null ? "Submit" : request.getSubmitRequest().getMessage();
+ submit(vlmId, version, message, user);
- notifyUsers(vlmId, version, message, user, NotificationEventTypes.SUBMIT);
- break;
- default:
- }
+ notifyUsers(vlmId, version, message, user, NotificationEventTypes.SUBMIT);
+ }
return Response.ok().build();
}
private void submit(String vlmId, Version version, String message, String user) {
MdcUtil.initMdc(LoggerServiceName.Submit_VLM.toString());
- logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.SUBMIT_VLM + vlmId);
+ LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.SUBMIT_VLM + vlmId);
vendorLicenseManager.validate(vlmId, version);
versioningManager.submit(vlmId, version, message);
@@ -272,6 +270,17 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
new ActivityLogEntity(vlmId, version, ActivityType.Submit, user, true, "", message));
}
+ private void submitHealedVersion(String vlmId, Version healedVersion, String baseVersionId,
+ String user) {
+ try {
+ submit(vlmId, healedVersion, "Submit after heal", user);
+ } catch (Exception ex) {
+ LOGGER.error(
+ String.format(SUBMIT_HEALED_VERSION_ERROR, vlmId, healedVersion.getId(), baseVersionId),
+ ex);
+ }
+ }
+
private void notifyUsers(String itemId, Version version, String message,
String userName, NotificationEventTypes eventType) {
Map<String, Object> eventProperties = new HashMap<>();
@@ -289,7 +298,7 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels {
try {
notifier.notifySubscribers(syncEvent, userName);
} catch (Exception e) {
- logger.error("Failed to send sync notification to users subscribed o item '" + itemId);
+ LOGGER.error("Failed to send sync notification to users subscribed o item '" + itemId);
}
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
index b92a431714..3eab416306 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
@@ -107,6 +107,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
+import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
import static org.openecomp.sdc.logging.messages.AuditMessages.SUBMIT_VSP_ERROR;
import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
@@ -122,8 +123,11 @@ import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERS
@Service("vendorSoftwareProducts")
@Scope(value = "prototype")
public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
- private static final String SUBMIT_ITEM = "Submit_Item";
+ private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
+ private static final String ATTACHMENT_FILENAME = "attachment; filename=";
+ private static final String SUBMIT_HEALED_VERSION_ERROR =
+ "VSP Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductsImpl.class);
private static ItemCreationDto validationVsp;
@@ -237,20 +241,17 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
try {
Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
.healItemVersion(vspId, version, ItemType.vsp, false);
- healedVersion.ifPresent(vspDetails::setVersion);
-
- if (healedVersion.isPresent() && version.getStatus() == VersionStatus.Certified) {
- try {
- submitHealedVsp(vspId, healedVersion.get(), user);
- } catch (Exception ex) {
- LOGGER.error("VSP Id {}: Error while submitting version {} " +
- "created based on Certified version {} for healing purpose.",
- vspId, healedVersion.get().getId(), versionId, ex.getMessage());
+
+ if (healedVersion.isPresent()) {
+ vspDetails.setVersion(healedVersion.get());
+ if (version.getStatus() == VersionStatus.Certified) {
+ submitHealedVersion(vspId, healedVersion.get(), versionId, user);
}
}
} catch (Exception e) {
- LOGGER.error(String.format("Error while auto healing VSP with Id %s and version %s: %s",
- vspId, versionId, e.getMessage()));
+ LOGGER.error(
+ String.format("Error while auto healing VSP with Id %s and version %s", vspId, versionId),
+ e);
}
VspDetailsDto vspDetailsDto =
@@ -260,16 +261,22 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
return Response.ok(vspDetailsDto).build();
}
- private void submitHealedVsp(String vspId, Version healedVersion, String user)
- throws IOException {
- Optional<ValidationResponse>
- validationResponse = submit(vspId, healedVersion, "Submit healed Vsp", user);
- if (validationResponse.isPresent()) {
- // TODO: 8/9/2017 before collaboration checkout was done at this scenario (equivalent
- // to new version in collaboration). need to decide what should be done now.
- throw new IllegalStateException("Certified vsp after healing failed on validation");
+ private void submitHealedVersion(String vspId, Version healedVersion, String baseVersionId,
+ String user) {
+ try {
+ Optional<ValidationResponse>
+ validationResponse = submit(vspId, healedVersion, "Submit healed Vsp", user);
+ if (validationResponse.isPresent()) {
+ // TODO: 8/9/2017 before collaboration checkout was done at this scenario (equivalent
+ // to new version in collaboration). need to decide what should be done now.
+ throw new IllegalStateException("Certified vsp after healing failed on validation");
+ }
+ vendorSoftwareProductManager.createPackage(vspId, healedVersion);
+ } catch (Exception ex) {
+ LOGGER.error(
+ String.format(SUBMIT_HEALED_VERSION_ERROR, vspId, healedVersion.getId(), baseVersionId),
+ ex);
}
- vendorSoftwareProductManager.createPackage(vspId, healedVersion);
}
@Override
@@ -302,12 +309,12 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
switch (request.getAction()) {
case Submit:
- if (!permissionsManager.isAllowed(vspId, user, SUBMIT_ITEM)) {
+ if (!permissionsManager.isAllowed(vspId, user, SUBMIT_ITEM_ACTION)) {
return Response.status(Response.Status.FORBIDDEN)
.entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
}
String message =
- request.getSubmitRequest() == null ? "" : request.getSubmitRequest().getMessage();
+ request.getSubmitRequest() == null ? "Submit" : request.getSubmitRequest().getMessage();
Optional<ValidationResponse> validationResponse = submit(vspId, version, message, user);
if (validationResponse.isPresent()) {
@@ -368,7 +375,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
return Response.status(Response.Status.NOT_FOUND).build();
}
Response.ResponseBuilder response = Response.ok(orchestrationTemplateFile);
- response.header("Content-Disposition", "attachment; filename=LatestHeatPackage.zip");
+ response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + "LatestHeatPackage.zip");
return response.build();
}
@@ -428,7 +435,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.IMPORT_FAIL + vspId);
return Response.status(Response.Status.NOT_FOUND).build();
}
- response.header("Content-Disposition", "attachment; filename=" + zipFile.getName());
+ response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + zipFile.getName());
LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.IMPORT_SUCCESS + vspId);
return response.build();
@@ -478,7 +485,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
return Response.status(Response.Status.NOT_FOUND).build();
}
response
- .header("Content-Disposition", "attachment; filename=" + textInformationArtifact.getName());
+ .header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + textInformationArtifact.getName());
return response.build();
}
@@ -621,16 +628,14 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
.getInfo(vspId, version);
//todo - remove after fix missing candidate element
- if(candidateInfo == null){
+ if (candidateInfo == null) {
candidateInfo = new OrchestrationTemplateCandidateData();
candidateInfo.setFileSuffix("zip");
}
- vspDetailsDto
- .setCandidateOnboardingOrigin( candidateInfo.getFileSuffix()
- == null
- ? OnboardingTypesEnum.NONE.toString()
- : candidateInfo.getFileSuffix());
+ vspDetailsDto.setCandidateOnboardingOrigin(candidateInfo.getFileSuffix() == null
+ ? OnboardingTypesEnum.NONE.toString()
+ : candidateInfo.getFileSuffix());
}
private boolean userHasPermission(String itemId, String userId) {
@@ -642,8 +647,8 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
private void printAuditForErrors(List<ErrorMessage> errorList, String vspId, String auditType) {
errorList.forEach(errorMessage -> {
if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) {
- LOGGER.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),
- vspId));
+ LOGGER.audit(
+ AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(), vspId));
}
});
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
index 3e85a53ac2..e46037373f 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
@@ -13,7 +13,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
public class ItemManagerImpl implements ItemManager {
- public static final String CREATE_ITEM = "Create_Item";
+ private static final String CREATE_ITEM = "Create_Item";
private ItemDao itemDao;
private PermissionsServices permissionsServices;
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 7f983477cf..347d328193 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -75,8 +75,9 @@ import java.util.stream.Collectors;
public class VersioningManagerImpl implements VersioningManager {
private static final Logger LOGGER = LoggerFactory.getLogger(VersioningManagerImpl.class);
private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private static Map<String, Set<VersionableEntityMetadata>> versionableEntities = new HashMap<>();
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private static final Map<String, Set<VersionableEntityMetadata>> VERSIONABLE_ENTITIES =
+ new HashMap<>();
private final VersionInfoDao versionInfoDao;
private final VersionInfoDeletedDao versionInfoDeletedDao;
@@ -129,7 +130,7 @@ public class VersioningManagerImpl implements VersioningManager {
VersionableEntityAction action, String user) {
- mdcDataDebugMessage.debugEntryMessage("entity Id", entityId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("entity Id", entityId);
Version activeVersion;
@@ -180,7 +181,7 @@ public class VersioningManagerImpl implements VersioningManager {
}
}
- mdcDataDebugMessage.debugExitMessage("entity Id", entityId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("entity Id", entityId);
return versionInfo;
}
@@ -198,7 +199,7 @@ public class VersioningManagerImpl implements VersioningManager {
@Override
public void register(String entityType, VersionableEntityMetadata entityMetadata) {
Set<VersionableEntityMetadata> entitiesMetadata =
- versionableEntities.computeIfAbsent(entityType, k -> new HashSet<>());
+ VERSIONABLE_ENTITIES.computeIfAbsent(entityType, k -> new HashSet<>());
entitiesMetadata.add(entityMetadata);
}
@@ -518,7 +519,7 @@ public class VersioningManagerImpl implements VersioningManager {
versionDao.create(itemId, version);
itemManager.updateVersionStatus(itemId, VersionStatus.Draft, null);
- publish(itemId, version, String.format("Initial version: %s ", version.getName()));
+ publish(itemId, version, String.format("Create version: %s", version.getName()));
return version;
}
@@ -597,7 +598,6 @@ public class VersioningManagerImpl implements VersioningManager {
@Override
public List<Revision> listRevisions(String itemId, Version version) {
return versionDao.listRevisions(itemId, version);
-
}
private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
@@ -683,7 +683,7 @@ public class VersioningManagerImpl implements VersioningManager {
private void initVersionOnEntity(String entityType, String entityId, Version baseVersion,
Version newVersion) {
- Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
@@ -694,7 +694,7 @@ public class VersioningManagerImpl implements VersioningManager {
private void deleteVersionFromEntity(String entityType, String entityId,
Version versionToDelete, Version backToVersion) {
- Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
@@ -704,7 +704,7 @@ public class VersioningManagerImpl implements VersioningManager {
}
private void closeVersionOnEntity(String entityType, String entityId, Version versionToClose) {
- Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
index afffd47943..6ac2ab30d5 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
@@ -9,11 +9,11 @@ import org.openecomp.sdc.notification.services.SubscriptionService;
import org.openecomp.sdc.versioning.dao.ItemDao;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.Item;
-import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collection;
+import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -21,9 +21,17 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
public class ItemManagerImplTest {
+ private static final String USER = "user1";
+ private static final String ITEM_ID = "item1";
+ private static final String ITEM_NAME = "item 1 name";
+ private static final String ITEM_TYPE_A = "A";
+ private static final String ITEM_TYPE_B = "B";
@Mock
private ItemDao itemDao;
@Mock
@@ -40,116 +48,128 @@ public class ItemManagerImplTest {
@Test
public void testList() throws Exception {
- doReturn(Stream.of(
- createItem("item1", "A"),
- createItem("item2", "B"),
- createItem("item3", "B"),
- createItem("item4", "A"))
- .collect(Collectors.toList())).when(itemDao).list();
-
- Collection<Item> items = itemManager.list(item -> "B".equals(item.getType()));
- Assert.assertEquals(items.size(), 2);
- Assert.assertTrue(items.stream().anyMatch(item -> "item2".equals(item.getName())));
- Assert.assertTrue(items.stream().anyMatch(item -> "item3".equals(item.getName())));
+ List<Item> returnedItems = Stream.of(createItem(ITEM_ID, ITEM_NAME, ITEM_TYPE_A),
+ createItem("item2", "item2 name", ITEM_TYPE_B),
+ createItem("item3", "item3 name", ITEM_TYPE_B),
+ createItem("item4", "item4 name", ITEM_TYPE_A)).collect(Collectors.toList());
+ doReturn(returnedItems).when(itemDao).list();
+
+ Collection<Item> items = itemManager.list(item -> ITEM_TYPE_B.equals(item.getType()));
+
+ assertEquals(items.size(), 2);
+ assertTrue(
+ items.stream().anyMatch(item -> returnedItems.get(1).getName().equals(item.getName())));
+ assertTrue(
+ items.stream().anyMatch(item -> returnedItems.get(2).getName().equals(item.getName())));
}
@Test
public void testGetNotExisting() throws Exception {
- Item item = itemManager.get("item1");
- Assert.assertNull(item);
+ Item item = itemManager.get(ITEM_ID);
+ assertNull(item);
}
@Test
public void testGet() throws Exception {
- Item toBeReturned = new Item();
- toBeReturned.setId("itemId");
+ Item toBeReturned = createItem(ITEM_ID, ITEM_NAME, ITEM_TYPE_A);
doReturn(toBeReturned).when(itemDao).get(any(Item.class));
- Item item = itemManager.get("itemId");
- Assert.assertEquals(item.getId(), "itemId");
+ Item item = itemManager.get(ITEM_ID);
+
+ assertItemEquals(item, toBeReturned);
}
@Test
public void testCreate() throws Exception {
- SessionContextProviderFactory.getInstance().createInterface().create("user1");
+ SessionContextProviderFactory.getInstance().createInterface().create(USER);
+
+ Item returnedItem = createItem(ITEM_ID, ITEM_NAME, ITEM_TYPE_A);
+ doReturn(returnedItem).when(itemDao).create(any(Item.class));
- Item toBeReturned = new Item();
- toBeReturned.setId("itemId");
- doReturn(toBeReturned).when(itemDao).create(any(Item.class));
+ Item inputItem = createItem(null, returnedItem.getName(), returnedItem.getType());
+ Item item = itemManager.create(inputItem);
- Item item = itemManager.create(createItem("item1", "A"));
- Assert.assertEquals(item.getId(), "itemId");
+ assertItemEquals(item, returnedItem);
+ verify(permissionsServices).execute(ITEM_ID, USER, "Create_Item");
+ verify(subscriptionService).subscribe(USER, ITEM_ID);
}
@Test
public void testUpdateNotExistingVersionStatus() throws Exception {
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
+
verify(itemDao, never()).update(any(Item.class));
}
@Test
public void testUpdateVersionStatusWhenNone() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
+
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 1);
- Assert.assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 1);
+ assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
}
@Test
public void testUpdateVersionStatusAddFirst() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Draft, null);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Draft, null);
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().size(), 1);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 1);
+ assertEquals(item.getVersionStatusCounters().size(), 1);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 1);
}
@Test
public void testUpdateVersionStatus() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
item.getVersionStatusCounters().put(VersionStatus.Certified, 2);
item.getVersionStatusCounters().put(VersionStatus.Draft, 3);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().size(), 2);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 2);
+ assertEquals(item.getVersionStatusCounters().size(), 2);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 2);
}
@Test
public void testUpdateVersionStatusRemoveLast() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
item.getVersionStatusCounters().put(VersionStatus.Certified, 2);
item.getVersionStatusCounters().put(VersionStatus.Draft, 1);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().size(), 1);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
- Assert.assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
+ assertEquals(item.getVersionStatusCounters().size(), 1);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
+ assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
}
- private Item createItem(String name, String type) {
+ private Item createItem(String id, String name, String type) {
Item item = new Item();
- item.setId(name);
+ item.setId(id);
item.setName(name);
item.setType(type);
return item;
}
+ private void assertItemEquals(Item actual, Item expected) {
+ assertEquals(actual.getId(), expected.getId());
+ assertEquals(actual.getName(), expected.getName());
+ assertEquals(actual.getType(), expected.getType());
+ }
} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
index 2d1109abe6..4f8c682c5e 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
@@ -39,13 +39,13 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -58,6 +58,9 @@ import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
public class VersioningManagerImplTest {
+ private static final String ITEM_ID = "itemId";
+ private static final String VERSION_ID = "versionId";
+
@Mock
private VersionDao versionDaoMock;
@Mock
@@ -73,85 +76,83 @@ public class VersioningManagerImplTest {
}
@Test
- public void testList() throws Exception {
- String itemId = "itemId";
+ public void testListWhenNone() throws Exception {
+ doReturn(new ArrayList<>()).when(versionDaoMock).list(ITEM_ID);
+ List<Version> versions = versioningManager.list(ITEM_ID);
+
+ Assert.assertTrue(versions.isEmpty());
+ }
+
+ @Test
+ public void testList() throws Exception {
List<Version> returnedVersions = Stream.of(createVersion("1", null, null, false),
createVersion("2", null, null, false),
createVersion("3", null, null, false)).collect(Collectors.toList());
- doReturn(returnedVersions).when(versionDaoMock).list(itemId);
+ doReturn(returnedVersions).when(versionDaoMock).list(ITEM_ID);
- List<Version> versions = versioningManager.list(itemId);
+ List<Version> versions = versioningManager.list(ITEM_ID);
Assert.assertEquals(versions, returnedVersions);
}
@Test(expectedExceptions = Exception.class)
public void testGetNonExisting() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- doReturn(Optional.empty()).when(versionDaoMock).get(itemId, version);
- doThrow(new Exception()).when(versionDaoMock).sync(itemId, version);
+ doReturn(Optional.empty()).when(versionDaoMock).get(ITEM_ID, version);
+ doThrow(new Exception()).when(versionDaoMock).sync(ITEM_ID, version);
- versioningManager.get(itemId, version);
+ versioningManager.get(ITEM_ID, version);
}
@Test
public void testGetNonExistingForUser() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version requestedVersion = new Version(versionId);
+ Version requestedVersion = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
+ Version returnedVersion = createVersion(VERSION_ID, Draft, UpToDate, false);
doReturn(Optional.empty()).doReturn(Optional.of(returnedVersion))
- .when(versionDaoMock).get(itemId, requestedVersion);
+ .when(versionDaoMock).get(ITEM_ID, requestedVersion);
- Version version = versioningManager.get(itemId, requestedVersion);
+ Version version = versioningManager.get(ITEM_ID, requestedVersion);
Assert.assertEquals(version, returnedVersion);
- verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
- verify(versionDaoMock).sync(itemId, requestedVersion);
+ verify(versionDaoMock, times(2)).get(ITEM_ID, requestedVersion);
+ verify(versionDaoMock).sync(ITEM_ID, requestedVersion);
}
@Test
public void testGetOutOfSyncCertified() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version requestedVersion = new Version(versionId);
+ Version requestedVersion = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
- doReturn(Optional.of(createVersion(versionId, Certified, OutOfSync, false)))
+ Version returnedVersion = createVersion(VERSION_ID, Certified, UpToDate, false);
+ doReturn(Optional.of(createVersion(VERSION_ID, Certified, OutOfSync, false)))
.doReturn(Optional.of(returnedVersion))
- .when(versionDaoMock).get(itemId, requestedVersion);
+ .when(versionDaoMock).get(ITEM_ID, requestedVersion);
- Version version = versioningManager.get(itemId, requestedVersion);
+ Version version = versioningManager.get(ITEM_ID, requestedVersion);
Assert.assertEquals(version, returnedVersion);
- verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
- verify(versionDaoMock).forceSync(itemId, requestedVersion);
+ verify(versionDaoMock, times(2)).get(ITEM_ID, requestedVersion);
+ verify(versionDaoMock).forceSync(ITEM_ID, requestedVersion);
}
@Test
public void testGet() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version requestedVersion = new Version(versionId);
+ Version requestedVersion = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Draft, OutOfSync, true);
- doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, requestedVersion);
+ Version returnedVersion = createVersion(VERSION_ID, Draft, OutOfSync, true);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(ITEM_ID, requestedVersion);
- Version version = versioningManager.get(itemId, requestedVersion);
+ Version version = versioningManager.get(ITEM_ID, requestedVersion);
Assert.assertEquals(version, returnedVersion);
- verify(versionDaoMock).get(itemId, requestedVersion);
+ verify(versionDaoMock).get(ITEM_ID, requestedVersion);
verify(versionDaoMock, never()).sync(any(), any());
verify(versionDaoMock, never()).forceSync(any(), any());
}
@Test
public void testCreate() throws Exception {
- String itemId = "itemId";
Version requestedVersion = new Version();
String versionName = "versionName";
@@ -160,27 +161,27 @@ public class VersioningManagerImplTest {
doReturn(Stream.of(createVersion("1", null, null, false),
createVersion("2", null, null, false),
createVersion("3", null, null, false)).collect(Collectors.toList()))
- .when(versionDaoMock).list(itemId);
+ .when(versionDaoMock).list(ITEM_ID);
Version version =
- versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ versioningManager.create(ITEM_ID, requestedVersion, VersionCreationMethod.major);
Assert.assertNotNull(version);
Assert.assertEquals(version.getName(), versionName);
- verify(versionDaoMock).create(itemId, requestedVersion);
- verify(itemManagerMock).updateVersionStatus(itemId, Draft, null);
- verify(versionDaoMock).publish(eq(itemId), eq(requestedVersion), anyString());
+ verify(versionDaoMock).create(ITEM_ID, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(ITEM_ID, Draft, null);
+ verify(versionDaoMock)
+ .publish(eq(ITEM_ID), eq(requestedVersion), eq("Create version: versionName"));
}
@Test
public void testCreateBasedOn() throws Exception {
- String itemId = "itemId";
Version requestedVersion = new Version();
requestedVersion.setBaseId("baseVersionId");
Version baseVersion = createVersion(requestedVersion.getBaseId(), Certified, UpToDate, false);
// TODO: 12/13/2017 fix to eq(new Version("baseVersionId")) when version.equals will be fixed
- doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(itemId), any(Version.class));
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(ITEM_ID), any(Version.class));
String versionName = "4.0";
doReturn(versionName)
@@ -189,28 +190,27 @@ public class VersioningManagerImplTest {
doReturn(Stream.of(createVersion("1", null, null, false),
createVersion("2", null, null, false),
createVersion("3", null, null, false)).collect(Collectors.toList()))
- .when(versionDaoMock).list(itemId);
+ .when(versionDaoMock).list(ITEM_ID);
Version version =
- versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ versioningManager.create(ITEM_ID, requestedVersion, VersionCreationMethod.major);
Assert.assertNotNull(version);
Assert.assertEquals(version.getName(), versionName);
- verify(versionDaoMock).create(itemId, requestedVersion);
- verify(itemManagerMock).updateVersionStatus(itemId, Draft, null);
- verify(versionDaoMock).publish(eq(itemId), eq(requestedVersion), anyString());
+ verify(versionDaoMock).create(ITEM_ID, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(ITEM_ID, Draft, null);
+ verify(versionDaoMock).publish(eq(ITEM_ID), eq(requestedVersion), eq("Create version: 4.0"));
}
@Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
"Item itemId: create version failed, a version with the name 2.0 already exist")
public void testCreateWithExistingName() throws Exception {
- String itemId = "itemId";
Version version = new Version();
version.setBaseId("baseVersionId");
Version baseVersion = createVersion(version.getBaseId(), Certified, UpToDate, false);
// TODO: 12/13/2017 fix to eq(new Version("baseVersionId")) when version.equals will be fixed
- doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(itemId), any(Version.class));
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(ITEM_ID), any(Version.class));
String versionName = "2.0";
doReturn(versionName)
@@ -219,102 +219,88 @@ public class VersioningManagerImplTest {
doReturn(Stream.of(createVersion("1", null, null, false),
createVersion("2", null, null, false),
createVersion("3", null, null, false)).collect(Collectors.toList()))
- .when(versionDaoMock).list(itemId);
+ .when(versionDaoMock).list(ITEM_ID);
- versioningManager.create(itemId, version, VersionCreationMethod.major);
+ versioningManager.create(ITEM_ID, version, VersionCreationMethod.major);
}
@Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
"Item itemId: submit version failed, version versionId is already Certified")
public void testSubmitCertified() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
- doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+ Version returnedVersion = createVersion(VERSION_ID, Certified, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(ITEM_ID, version);
- versioningManager.submit(itemId, version, "Submit message");
+ versioningManager.submit(ITEM_ID, version, "Submit message");
}
@Test
public void testSubmit() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
ArgumentCaptor<Version> versionArgumentCaptor = ArgumentCaptor.forClass(Version.class);
- Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
- doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+ Version returnedVersion = createVersion(VERSION_ID, Draft, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(ITEM_ID, version);
String submitDescription = "Submit message";
- versioningManager.submit(itemId, version, submitDescription);
+ versioningManager.submit(ITEM_ID, version, submitDescription);
- verify(versionDaoMock).update(eq(itemId), versionArgumentCaptor.capture());
+ verify(versionDaoMock).update(eq(ITEM_ID), versionArgumentCaptor.capture());
Assert.assertEquals(Certified, versionArgumentCaptor.getValue().getStatus());
- verify(versionDaoMock).publish(itemId, version, submitDescription);
- verify(itemManagerMock).updateVersionStatus(itemId, Certified, Draft);
+ verify(versionDaoMock).publish(ITEM_ID, version, submitDescription);
+ verify(itemManagerMock).updateVersionStatus(ITEM_ID, Certified, Draft);
}
@Test
public void testPublish() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
String publishDescription = "Publish message";
- versioningManager.publish(itemId, version, publishDescription);
+ versioningManager.publish(ITEM_ID, version, publishDescription);
- verify(versionDaoMock).publish(itemId, version, publishDescription);
+ verify(versionDaoMock).publish(ITEM_ID, version, publishDescription);
}
@Test
public void testSync() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- versioningManager.sync(itemId, version);
+ versioningManager.sync(ITEM_ID, version);
- verify(versionDaoMock).sync(itemId, version);
+ verify(versionDaoMock).sync(ITEM_ID, version);
}
@Test
public void testForceSync() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- versioningManager.forceSync(itemId, version);
+ versioningManager.forceSync(ITEM_ID, version);
- verify(versionDaoMock).forceSync(itemId, version);
+ verify(versionDaoMock).forceSync(ITEM_ID, version);
}
@Test
public void testRevert() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
String revisionId = "revisionId";
- versioningManager.revert(itemId, version, revisionId);
+ versioningManager.revert(ITEM_ID, version, revisionId);
- verify(versionDaoMock).revert(itemId, version, revisionId);
+ verify(versionDaoMock).revert(ITEM_ID, version, revisionId);
}
@Test
public void testListRevisions() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
List<Revision> returnedRevisions =
Stream.of(new Revision(), new Revision()).collect(Collectors.toList());
doReturn(returnedRevisions)
- .when(versionDaoMock).listRevisions(itemId, version);
+ .when(versionDaoMock).listRevisions(ITEM_ID, version);
- List<Revision> revisions = versioningManager.listRevisions(itemId, version);
+ List<Revision> revisions = versioningManager.listRevisions(ITEM_ID, version);
Assert.assertEquals(revisions, returnedRevisions);
}