summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test
diff options
context:
space:
mode:
authorTomasz Golabek <tomasz.golabek@nokia.com>2019-08-29 13:32:30 +0200
committerTomasz Golabek <tomasz.golabek@nokia.com>2019-08-29 13:34:32 +0000
commit0a65bd7d842fb8617b3c6a7b2d4a16af583dc8be (patch)
tree785f6645b7aa2c8ffe4206f3b8dbf721dfd38f02 /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test
parentfbe82ee87f03ca9f581eeff47101698247cfe8b1 (diff)
unit tests - openecomp-be
Additional junit tests for item-rest-services and unique-type-rest-services Change-Id: I330954ad4eb432c126c7f163f9fdea30d3173cd9 Issue-ID: SDC-2326 Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/models/SyncEventTest.java43
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java135
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/VersionsImplTest.java212
3 files changed, 390 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/models/SyncEventTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/models/SyncEventTest.java
new file mode 100644
index 0000000000..a023f4a2a8
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/models/SyncEventTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.item.rest.models;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.Map;
+import org.junit.Test;
+
+public class SyncEventTest {
+
+ private static final String EVENT = "EVENT";
+ private static final String ORIGINATOR = "ORIGINATOR";
+ private static final String ENTITY_ID = "ENTITY";
+ private static final Map<String, Object> ATTRIBUTES = Collections.emptyMap();
+
+ @Test
+ public void shouldHaveValidGetters() {
+ SyncEvent syncEvent = new SyncEvent(EVENT, ORIGINATOR, ATTRIBUTES, ENTITY_ID);
+ assertEquals(syncEvent.getAttributes(), ATTRIBUTES);
+ assertEquals(syncEvent.getEntityId(), ENTITY_ID);
+ assertEquals(syncEvent.getEventType(), EVENT);
+ assertEquals(syncEvent.getOriginatorId(), ORIGINATOR);
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java
new file mode 100644
index 0000000000..d7e9c81823
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/ItemsImplTest.java
@@ -0,0 +1,135 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.item.rest.services;
+
+import static org.junit.Assert.assertEquals;
+import static org.openecomp.sdcrests.item.types.ItemAction.ARCHIVE;
+import static org.openecomp.sdcrests.item.types.ItemAction.RESTORE;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdcrests.item.types.ItemActionRequestDto;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ItemsImplTest {
+
+ private static final String ITEM_ID = "ITEM_ID";
+ private static final String USER = "USER";
+
+ @Mock
+ private ManagersProvider managersProvider;
+ @Mock
+ private ItemManager itemManager;
+ @Mock
+ private ItemActionRequestDto request;
+ @Mock
+ private Item item;
+ @Mock
+ private VersioningManager versioningManager;
+ @Mock
+ private ActivityLogManager activityManager;
+
+ @Test
+ public void shouldInitActionSideAffectsMap() {
+ ItemsImpl items = new ItemsImpl();
+ items.initActionSideAffectsMap();
+ assertEquals(items.getActionSideAffectsMap().size(),2);
+ }
+
+ @Test
+ public void shouldActOnEmptyItem() {
+ ItemsImpl items = new ItemsImpl();
+ items.initActionSideAffectsMap();
+ items.setManagersProvider(managersProvider);
+ Mockito.when(managersProvider.getItemManager()).thenReturn(itemManager);
+ Mockito.when(itemManager.get(Mockito.any())).thenReturn(null);
+ Response response = items.actOn(request, ITEM_ID, USER);
+ assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
+ }
+
+ @Test
+ public void shouldActOnARCHIVE() {
+ ItemsImpl items = new ItemsImpl();
+ items.initActionSideAffectsMap();
+ items.setManagersProvider(managersProvider);
+ Mockito.when(itemManager.get(Mockito.any())).thenReturn(item);
+ Mockito.when(request.getAction()).thenReturn(ARCHIVE);
+ Mockito.when(managersProvider.getItemManager()).thenReturn(itemManager);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ Mockito.when(versioningManager.list(Mockito.any())).thenReturn(getVersions());
+ Mockito.when(managersProvider.getActivityLogManager()).thenReturn(activityManager);
+ items.actOn(request, ITEM_ID, USER);
+ Mockito.verify(itemManager).archive(Mockito.any());
+ }
+
+ @Test
+ public void shouldActOnRESTORE() {
+ ItemsImpl items = new ItemsImpl();
+ items.initActionSideAffectsMap();
+ items.setManagersProvider(managersProvider);
+ Mockito.when(itemManager.get(Mockito.any())).thenReturn(item);
+ Mockito.when(request.getAction()).thenReturn(RESTORE);
+ Mockito.when(managersProvider.getItemManager()).thenReturn(itemManager);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ Mockito.when(versioningManager.list(Mockito.any())).thenReturn(getVersions());
+ Mockito.when(managersProvider.getActivityLogManager()).thenReturn(activityManager);
+ items.actOn(request, ITEM_ID, USER);
+ Mockito.verify(itemManager).restore(Mockito.any());
+ }
+
+ @Test
+ public void shouldGetItem() {
+ ItemsImpl items = new ItemsImpl();
+ items.initActionSideAffectsMap();
+ items.setManagersProvider(managersProvider);
+ Mockito.when(managersProvider.getItemManager()).thenReturn(itemManager);
+ Response response = items.getItem(ITEM_ID, USER);
+ assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
+ }
+
+ @Test
+ public void shouldList() {
+ ItemsImpl items = new ItemsImpl();
+ items.initActionSideAffectsMap();
+ items.setManagersProvider(managersProvider);
+ Mockito.when(managersProvider.getItemManager()).thenReturn(itemManager);
+ Response response = items.list(null, null, null, null, null, USER);
+ assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
+ }
+
+ private List<Version> getVersions() {
+ List<Version> versions = new ArrayList<>();
+ versions.add(new Version("1"));
+ versions.add(new Version("2"));
+ versions.add(new Version("3"));
+ return versions;
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/VersionsImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/VersionsImplTest.java
new file mode 100644
index 0000000000..8115051e7c
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/services/VersionsImplTest.java
@@ -0,0 +1,212 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdcrests.item.rest.services;
+
+import static org.junit.Assert.assertEquals;
+import static org.openecomp.sdcrests.item.types.VersionAction.Clean;
+import static org.openecomp.sdcrests.item.types.VersionAction.Commit;
+import static org.openecomp.sdcrests.item.types.VersionAction.Reset;
+import static org.openecomp.sdcrests.item.types.VersionAction.Revert;
+import static org.openecomp.sdcrests.item.types.VersionAction.Sync;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.conflicts.ConflictsManager;
+import org.openecomp.sdc.itempermissions.PermissionsManager;
+import org.openecomp.sdc.notification.services.NotificationPropagationManager;
+import org.openecomp.sdc.versioning.AsdcItemManager;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionState;
+import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdcrests.item.types.RevisionRequestDto;
+import org.openecomp.sdcrests.item.types.VersionActionRequestDto;
+
+@RunWith(MockitoJUnitRunner.class)
+public class VersionsImplTest {
+
+ private static final String ITEM_ID = "ITEM_ID";
+ private static final String VERSION_ID = "VERSION_ID";
+ private static final String USER = "USER";
+ private static final String REVISION_ID = "REVISION_ID";
+
+ @Mock
+ private ManagersProvider managersProvider;
+ @Mock
+ private VersionActionRequestDto request;
+ @Mock
+ private RevisionRequestDto revisionRequest;
+ @Mock
+ private VersioningManager versioningManager;
+ @Mock
+ private PermissionsManager permManager;
+ @Mock
+ private ActivityLogManager activityManager;
+ @Mock
+ private AsdcItemManager asdcManager;
+ @Mock
+ private Item item;
+ @Mock
+ private Version version;
+ @Mock
+ private NotificationPropagationManager notificationManager;
+ @Mock
+ private ConflictsManager conflictsManager;
+ @Mock
+ private VersionState state;
+
+ @Test
+ public void shouldActOnSync() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Sync);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ Mockito.when(managersProvider.getConflictsManager()).thenReturn(conflictsManager);
+ versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ Mockito.verify(versioningManager).sync(Mockito.any(), Mockito.any());
+ Mockito.verify(conflictsManager).finalizeMerge(Mockito.any(), Mockito.any());
+ }
+
+ @Test
+ public void shouldActOnCommitWhenAllowed() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Commit);
+ Mockito.when(managersProvider.getPermissionsManager()).thenReturn(permManager);
+ Mockito.when(permManager.isAllowed(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ Mockito.when(managersProvider.getActivityLogManager()).thenReturn(activityManager);
+ Mockito.when(managersProvider.getAsdcItemManager()).thenReturn(asdcManager);
+ Mockito.when(asdcManager.get(Mockito.any())).thenReturn(item);
+ Mockito.when(versioningManager.get(Mockito.any(), Mockito.any())).thenReturn(version);
+ Mockito.when(managersProvider.getNotificationPropagationManager()).thenReturn(notificationManager);
+ versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ Mockito.verify(versioningManager).publish(Mockito.any(), Mockito.any(), Mockito.any());
+ Mockito.verify(notificationManager).notifySubscribers(Mockito.any(), Mockito.any());
+ Mockito.verify(activityManager).logActivity(Mockito.any());
+ }
+
+ @Test
+ public void shouldActOnCommitWhenNotAllowed() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Commit);
+ Mockito.when(managersProvider.getPermissionsManager()).thenReturn(permManager);
+ Mockito.when(permManager.isAllowed(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(false);
+
+ Response response = versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ assertEquals(response.getStatus(), Response.Status.FORBIDDEN.getStatusCode());
+ }
+
+ @Test
+ public void shouldActOnClean() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Clean);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ Mockito.verify(versioningManager).clean(Mockito.any(), Mockito.any());
+ }
+
+ @Test
+ public void shouldActOnRevert() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Revert);
+ Mockito.when(request.getRevisionRequest()).thenReturn(revisionRequest);
+ Mockito.when(revisionRequest.getRevisionId()).thenReturn(REVISION_ID);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ Mockito.verify(versioningManager).revert(Mockito.any(), Mockito.any(), Mockito.any());
+ }
+
+ @Test(expected = CoreException.class)
+ public void shouldActOnRevertAndEmptyRevisionId() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Revert);
+ Mockito.when(request.getRevisionRequest()).thenReturn(revisionRequest);
+ Mockito.when(revisionRequest.getRevisionId()).thenReturn(null);
+ versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void shouldActOnOther() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(request.getAction()).thenReturn(Reset);
+ versions.actOn(request, ITEM_ID, VERSION_ID, USER);
+ }
+
+ @Test
+ public void shouldListRevision() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ List<Revision> revisions = getRevisions();
+ Mockito.when(versioningManager.listRevisions(Mockito.any(), Mockito.any())).thenReturn(revisions);
+ Response response = versions.listRevisions(ITEM_ID, VERSION_ID, USER);
+ Mockito.verify(versioningManager).listRevisions(Mockito.any(), Mockito.any());
+ assertEquals(response.getStatus(), Status.OK.getStatusCode());
+ }
+
+ @Test
+ public void shouldGetActivityLog() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(managersProvider.getActivityLogManager()).thenReturn(activityManager);
+ Mockito.when(activityManager.listLoggedActivities(Mockito.any(), Mockito.any())).thenReturn(Collections.emptyList());
+ Response activityLog = versions.getActivityLog(ITEM_ID, VERSION_ID, USER);
+ assertEquals(activityLog.getStatus(), Status.OK.getStatusCode());
+ }
+
+ @Test
+ public void shouldGet() {
+ VersionsImpl versions = new VersionsImpl();
+ versions.setManagersProvider(managersProvider);
+ Mockito.when(managersProvider.getVersioningManager()).thenReturn(versioningManager);
+ Mockito.when(versioningManager.get(Mockito.any(), Mockito.any())).thenReturn(version);
+ Mockito.when(version.getState()).thenReturn(state);
+ Mockito.when(state.getSynchronizationState()).thenReturn(SynchronizationState.Merging);
+ Response response = versions.get(ITEM_ID, VERSION_ID, USER);
+ assertEquals(response.getStatus(), Status.OK.getStatusCode());
+ }
+
+ private List<Revision> getRevisions() {
+ List<Revision> revisions = new ArrayList<>();
+ Revision revision = new Revision();
+ revision.setMessage("Initial TEST:TEST");
+ revisions.add(revision);
+ revisions.add(new Revision());
+ return revisions;
+ }
+} \ No newline at end of file