aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DaoStatusConverterTest.java88
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/Neo4jStatusConverterTest.java68
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/OperationUtilsTest.java90
3 files changed, 246 insertions, 0 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DaoStatusConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DaoStatusConverterTest.java
new file mode 100644
index 0000000000..4a71c9106a
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DaoStatusConverterTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============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.sdc.be.model.operations.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class DaoStatusConverterTest {
+
+ @Test
+ public void shouldConvertJanusGraphStatusToStorageStatus() {
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(null),
+ StorageOperationStatus.GENERAL_ERROR);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.OK),
+ StorageOperationStatus.OK);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.NOT_CONNECTED),
+ StorageOperationStatus.CONNECTION_FAILURE);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.NOT_FOUND),
+ StorageOperationStatus.NOT_FOUND);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.NOT_CREATED),
+ StorageOperationStatus.SCHEMA_ERROR);
+ assertEquals(DaoStatusConverter
+ .convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.INDEX_CANNOT_BE_CHANGED),
+ StorageOperationStatus.SCHEMA_ERROR);
+ assertEquals(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.MISSING_UNIQUE_ID),
+ StorageOperationStatus.BAD_REQUEST);
+ assertEquals(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ALREADY_LOCKED),
+ StorageOperationStatus.FAILED_TO_LOCK_ELEMENT);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
+ JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION), StorageOperationStatus.SCHEMA_VIOLATION);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.INVALID_ID),
+ StorageOperationStatus.INVALID_ID);
+ assertEquals(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.MATCH_NOT_FOUND),
+ StorageOperationStatus.MATCH_NOT_FOUND);
+ assertEquals(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT),
+ StorageOperationStatus.BAD_REQUEST);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ALREADY_EXIST),
+ StorageOperationStatus.ENTITY_ALREADY_EXISTS);
+ assertEquals(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
+ JanusGraphOperationStatus.PROPERTY_NAME_ALREADY_EXISTS),
+ StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS);
+ assertEquals(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.INVALID_PROPERTY),
+ StorageOperationStatus.INVALID_PROPERTY);
+ }
+
+ @Test
+ public void shouldConvertCassandraStatusToStorageStatus() {
+ assertEquals(DaoStatusConverter.convertCassandraStatusToStorageStatus(null),
+ StorageOperationStatus.GENERAL_ERROR);
+ assertEquals(DaoStatusConverter.convertCassandraStatusToStorageStatus(CassandraOperationStatus.OK),
+ StorageOperationStatus.OK);
+ assertEquals(DaoStatusConverter
+ .convertCassandraStatusToStorageStatus(CassandraOperationStatus.CLUSTER_NOT_CONNECTED),
+ StorageOperationStatus.CONNECTION_FAILURE);
+ assertEquals(DaoStatusConverter
+ .convertCassandraStatusToStorageStatus(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED),
+ StorageOperationStatus.STORAGE_NOT_AVAILABLE);
+ assertEquals(DaoStatusConverter.convertCassandraStatusToStorageStatus(CassandraOperationStatus.NOT_FOUND),
+ StorageOperationStatus.NOT_FOUND);
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/Neo4jStatusConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/Neo4jStatusConverterTest.java
new file mode 100644
index 0000000000..f5bfc96ca4
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/Neo4jStatusConverterTest.java
@@ -0,0 +1,68 @@
+/*-
+ * ============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.sdc.be.model.operations.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+public class Neo4jStatusConverterTest {
+
+ @Test
+ public void shouldConvertNeo4jStatusToStorageStatus() {
+ assertEquals(StorageOperationStatus.GENERAL_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(null));
+ assertEquals(StorageOperationStatus.OK,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.OK));
+ assertEquals(StorageOperationStatus.CONNECTION_FAILURE,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.NOT_CONNECTED));
+ assertEquals(StorageOperationStatus.PERMISSION_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.NOT_AUTHORIZED));
+ assertEquals(StorageOperationStatus.STORAGE_NOT_AVAILABLE,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.DB_NOT_AVAILABLE));
+ assertEquals(StorageOperationStatus.HTTP_PROTOCOL_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.HTTP_PROTOCOL_ERROR));
+ assertEquals(StorageOperationStatus.READ_ONLY_STORAGE,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.DB_READ_ONLY));
+ assertEquals(StorageOperationStatus.BAD_REQUEST,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.BAD_REQUEST));
+ assertEquals(StorageOperationStatus.STORAGE_LEGACY_INDEX_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.LEGACY_INDEX_ERROR));
+ assertEquals(StorageOperationStatus.SCHEMA_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.SCHEMA_ERROR));
+ assertEquals(StorageOperationStatus.TRANSACTION_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.TRANSACTION_ERROR));
+ assertEquals(StorageOperationStatus.EXEUCTION_FAILED,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.EXECUTION_FAILED));
+ assertEquals(StorageOperationStatus.ENTITY_ALREADY_EXISTS,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.ENTITY_ALREADY_EXIST));
+ assertEquals(StorageOperationStatus.BAD_REQUEST,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.WRONG_INPUT));
+ assertEquals(StorageOperationStatus.GENERAL_ERROR,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.GENERAL_ERROR));
+ assertEquals(StorageOperationStatus.OPERATION_NOT_SUPPORTED,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.NOT_SUPPORTED));
+ assertEquals(StorageOperationStatus.NOT_FOUND,
+ Neo4jStatusConverter.convertNeo4jStatusToStorageStatus(Neo4jOperationStatus.NOT_FOUND));
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/OperationUtilsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/OperationUtilsTest.java
new file mode 100644
index 0000000000..78b4a0e338
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/OperationUtilsTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.sdc.be.model.operations.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import fj.data.Either;
+import java.util.Collections;
+import java.util.Map;
+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.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.StorageException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class OperationUtilsTest {
+
+ public static final String ID = "ID";
+ @Mock
+ private JanusGraphDao janusGraphDao;
+ @Mock
+ private PropertyOperation propertyOperation;
+
+ private JanusGraphOperationStatus status = JanusGraphOperationStatus.OK;
+
+ @Test(expected = StorageException.class)
+ public void shouldThrowStorageException() {
+ OperationUtils operationUtils = new OperationUtils(janusGraphDao);
+ Mockito.when(janusGraphDao.rollback()).thenReturn(status);
+ operationUtils.onJanusGraphOperationFailure(status);
+ }
+
+ @Test
+ public void shouldFillPropertiesAndReceiveLeftProjection() {
+ NodeTypeEnum capability = NodeTypeEnum.Capability;
+ Map<String, PropertyDefinition> definitions = Collections.emptyMap();
+ Mockito.when(propertyOperation.findPropertiesOfNode(capability, ID)).thenReturn(Either.left(definitions));
+ Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result =
+ OperationUtils.fillProperties(ID, propertyOperation, capability);
+ assertTrue(result.isLeft());
+ assertEquals(result.left().value(), definitions);
+ }
+
+ @Test
+ public void shouldFillPropertiesAndReceiveRightProjectionWithAlreadyExistStatus() {
+ NodeTypeEnum capability = NodeTypeEnum.Capability;
+ Mockito.when(propertyOperation.findPropertiesOfNode(capability, ID))
+ .thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST));
+ Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result =
+ OperationUtils.fillProperties(ID, propertyOperation, capability);
+ assertTrue(result.isRight());
+ assertEquals(result.right().value(), JanusGraphOperationStatus.ALREADY_EXIST);
+ }
+
+ @Test
+ public void shouldFillPropertiesAndReceiveRightProjectionWithOKStatus() {
+ NodeTypeEnum capability = NodeTypeEnum.Capability;
+ Mockito.when(propertyOperation.findPropertiesOfNode(capability, ID))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result =
+ OperationUtils.fillProperties(ID, propertyOperation, capability);
+ assertTrue(result.isRight());
+ assertEquals(result.right().value(), JanusGraphOperationStatus.OK);
+ }
+} \ No newline at end of file