From d89a5d3cf1ed1f81cdda754464eff07781824053 Mon Sep 17 00:00:00 2001 From: franciscovila Date: Thu, 12 Oct 2023 11:09:43 +0100 Subject: Increase unit test coverage for backend Provided some Junit test coverage for backed Issue-ID: SDC-4654 Signed-off-by: franciscovila Change-Id: I91b3f4326256312ab998d32fce9eb13b3e39b8d1 --- .../nsa/cambria/client/CambriaConsumerTest.java | 36 ++ .../CsarGeneratorConfigurationTest.java | 55 ++ .../InternalToolConfigurationTest.java | 53 ++ .../SdcSchemaFileImportConfigurationTest.java | 53 ++ .../VrfObjectFixConfigurationTest.java | 67 +++ .../sdc/asdctool/enums/LifecycleStateEnumTest.java | 37 ++ .../sdc/asdctool/enums/SchemaZipFileEnumTest.java | 46 ++ .../ExportImportJanusGraphServletTest.java | 5 - .../sdc/config/CatalogBESpringConfigTest.java | 128 +++++ .../sdc/config/MicrometerSpringConfigTest.java | 44 ++ .../sdc/be/model/LifecycleStateEnumTest.java | 40 ++ .../sdc/be/model/dto/FilterConstraintDtoTest.java | 69 ++- .../operations/ArtifactsOperationsTest.java | 632 ++++++++++++++++++++- .../operations/ForwardingPathOperationTest.java | 212 +++++++ .../operations/GroupsOperationMockTest.java | 142 +++++ .../sdc/be/test/util/TestResourcesHandler.java | 15 - .../sdc/be/test/util/TestResourcesHandlerTest.java | 41 ++ 17 files changed, 1638 insertions(+), 37 deletions(-) create mode 100644 asdctool/src/test/java/com/att/nsa/cambria/client/CambriaConsumerTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/CsarGeneratorConfigurationTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/InternalToolConfigurationTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/SdcSchemaFileImportConfigurationTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/VrfObjectFixConfigurationTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/LifecycleStateEnumTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/config/CatalogBESpringConfigTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/config/MicrometerSpringConfigTest.java create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/LifecycleStateEnumTest.java create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ForwardingPathOperationTest.java create mode 100644 catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationMockTest.java create mode 100644 common-be-tests-utils/src/test/java/org/openecomp/sdc/be/test/util/TestResourcesHandlerTest.java diff --git a/asdctool/src/test/java/com/att/nsa/cambria/client/CambriaConsumerTest.java b/asdctool/src/test/java/com/att/nsa/cambria/client/CambriaConsumerTest.java new file mode 100644 index 0000000000..26ba1b4553 --- /dev/null +++ b/asdctool/src/test/java/com/att/nsa/cambria/client/CambriaConsumerTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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 com.att.nsa.cambria.client; + +import org.junit.Test; + +public class CambriaConsumerTest { + + private CambriaConsumer createTestSubject() { + return new CambriaConsumer(); + } + + @Test + public void testCtor() throws Exception { + new CambriaConsumer(); + } + +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/CsarGeneratorConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/CsarGeneratorConfigurationTest.java new file mode 100644 index 0000000000..aa842e3a0b --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/CsarGeneratorConfigurationTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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.asdctool.configuration; + +import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.internal.tool.CsarGenerator; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.tosca.CsarUtils; +import org.openecomp.sdc.be.tosca.ToscaExportHandler; +import static org.mockito.Mockito.mock; + +public class CsarGeneratorConfigurationTest { + + private CsarGeneratorConfiguration createTestSubject() { + return new CsarGeneratorConfiguration(); + } + + private static ToscaExportHandler toscaExportHandler; + private static CsarUtils csarUtils; + + @Test + public void testCsarGenerator() throws Exception { + CsarGeneratorConfiguration testSubject; + CsarGenerator result; + + // default test + testSubject = createTestSubject(); + JanusGraphDao janusGraphDao = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + ArtifactCassandraDao artifactCassandraDao = mock(ArtifactCassandraDao.class); + + result = testSubject.csarGenerator(janusGraphDao, csarUtils, toscaOperationFacade, artifactCassandraDao, toscaExportHandler); + } + +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/InternalToolConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/InternalToolConfigurationTest.java new file mode 100644 index 0000000000..a19186d26a --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/InternalToolConfigurationTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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.asdctool.configuration; + +import static org.mockito.Mockito.mock; + +import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.internal.tool.DeleteComponentHandler; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; + +public class InternalToolConfigurationTest { + + private InternalToolConfiguration createTestSubject() { + return new InternalToolConfiguration(); + } + + @Test + public void testDeleteComponentHandler() throws Exception { + InternalToolConfiguration testSubject; + DeleteComponentHandler result; + + // default test + testSubject = createTestSubject(); + JanusGraphDao janusGraphDao = mock(JanusGraphDao.class); + NodeTypeOperation nodeTypeOperation = mock(NodeTypeOperation.class); + TopologyTemplateOperation topologyTemplateOperation = mock(TopologyTemplateOperation.class); + + result = testSubject.deleteComponentHandler(janusGraphDao, nodeTypeOperation, topologyTemplateOperation); + } + +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/SdcSchemaFileImportConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/SdcSchemaFileImportConfigurationTest.java new file mode 100644 index 0000000000..d63f0bef83 --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/SdcSchemaFileImportConfigurationTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.asdctool.configuration; + +import org.junit.Test; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; +import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao; + +public class SdcSchemaFileImportConfigurationTest { + + private SdcSchemaFileImportConfiguration createTestSubject() { + return new SdcSchemaFileImportConfiguration(); + } + + @Test + public void testCassandraClient() throws Exception { + SdcSchemaFileImportConfiguration testSubject; + CassandraClient result; + + // default test + testSubject = createTestSubject(); + result = testSubject.cassandraClient(); + } + + @Test + public void testCassandraDao() throws Exception { + SdcSchemaFileImportConfiguration testSubject; + SdcSchemaFilesCassandraDao result; + + // default test + testSubject = createTestSubject(); + result = testSubject.sdcSchemaFilesCassandraDao(); + } + +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/VrfObjectFixConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/VrfObjectFixConfigurationTest.java new file mode 100644 index 0000000000..ad60652818 --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/VrfObjectFixConfigurationTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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.asdctool.configuration; + +import static org.mockito.Mockito.mock; + +import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.VrfObjectFixHandler; +import org.openecomp.sdc.be.dao.JanusGraphClientStrategy; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; + +public class VrfObjectFixConfigurationTest { + + private VrfObjectFixConfiguration createTestSubject() { + return new VrfObjectFixConfiguration(); + } + + @Test + public void testJanusGraphDao() throws Exception { + VrfObjectFixConfiguration testSubject; + JanusGraphDao result; + + // default test + testSubject = createTestSubject(); + result = testSubject.janusGraphDao(mock(JanusGraphClient.class)); + } + + @Test + public void testJanusGraphClientStrategy() throws Exception { + VrfObjectFixConfiguration testSubject; + JanusGraphClientStrategy result; + + // default test + testSubject = createTestSubject(); + result = testSubject.janusGraphClientStrategy(); + } + + @Test + public void testVrfObjectFixHandler() throws Exception { + VrfObjectFixConfiguration testSubject; + VrfObjectFixHandler result; + + // default test + testSubject = createTestSubject(); + result = testSubject.vrfObjectFixHandler(mock(JanusGraphDao.class)); + } + +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/LifecycleStateEnumTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/LifecycleStateEnumTest.java new file mode 100644 index 0000000000..1d5f91569c --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/LifecycleStateEnumTest.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. 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.asdctool.enums; + +import org.junit.Assert; +import org.junit.Test; + +public class LifecycleStateEnumTest { + + private LifecycleStateEnum createTestSubject() { + return LifecycleStateEnum.CERTIFIED; + } + + @Test + public void testEnumValue() throws Exception { + LifecycleStateEnum testSubject = createTestSubject(); + Assert.assertEquals(LifecycleStateEnum.CERTIFIED,testSubject); + } +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java new file mode 100644 index 0000000000..23f76aa002 --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. 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.asdctool.enums; + +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +public class SchemaZipFileEnumTest { + + @Test + public void testSchemaZipConstants() throws Exception { + SchemaZipFileEnum[] schemaFileList = SchemaZipFileEnum.values(); + for (SchemaZipFileEnum schemaZipFileEnum : schemaFileList) { + switch (schemaZipFileEnum.getFileName()) { + case "data" : + Assertions.assertArrayEquals(schemaZipFileEnum.getImportFileList(),SchemaZipFileEnum.SchemaZipConstants.EMPTY_IMPORT_LIST); + break; + case "relationships" : + Assertions.assertArrayEquals(schemaZipFileEnum.getImportFileList(),SchemaZipFileEnum.SchemaZipConstants.RELATIONSHIPS_TYPES_IMPORT_LIST); + break; + default: + Assertions.assertArrayEquals(schemaZipFileEnum.getImportFileList(),SchemaZipFileEnum.SchemaZipConstants.DATA_IMPORT_LIST); + break; + } + } + } + +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportJanusGraphServletTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportJanusGraphServletTest.java index 89a84462fe..9a7e16b602 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportJanusGraphServletTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportJanusGraphServletTest.java @@ -32,11 +32,6 @@ public class ExportImportJanusGraphServletTest { } @Test - @Disabled("Investigate" - + "org.opentest4j.AssertionFailedError: Expected java.lang.NullPointerException to be thrown, but nothing was thrown." - + "Possible reason is :" - + "if (log.isDebugEnabled())" - + "in ExportImportJanusGraphServlet#printJanusGraphConfigFile") public void testExport() throws Exception { ExportImportJanusGraphServlet testSubject; File janusGraphPropertiesFile = null; diff --git a/catalog-be/src/test/java/org/openecomp/sdc/config/CatalogBESpringConfigTest.java b/catalog-be/src/test/java/org/openecomp/sdc/config/CatalogBESpringConfigTest.java new file mode 100644 index 0000000000..354f37bf0f --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/config/CatalogBESpringConfigTest.java @@ -0,0 +1,128 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ + +package org.openecomp.sdc.config; + +import static org.mockito.Mockito.mock; + +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.Test; +import org.onap.sdc.security.PortalClient; +import org.openecomp.sdc.be.auditing.impl.ConfigurationProvider; +import org.openecomp.sdc.be.components.impl.ComponentLocker; +import org.openecomp.sdc.be.components.impl.lock.ComponentLockAspect; +import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter; +import org.openecomp.sdc.be.filters.PortalConfiguration; +import org.openecomp.sdc.be.filters.ThreadLocalUtils; +import org.openecomp.sdc.be.tosca.CommonCsarGenerator; +import org.openecomp.sdc.be.tosca.DefaultCsarGenerator; + +public class CatalogBESpringConfigTest { + + private CatalogBESpringConfig createTestSubject() { + return new CatalogBESpringConfig(mock(ComponentLocker.class)); + } + + @Test + public void testLifecycleBusinessLogic() throws Exception { + CatalogBESpringConfig testSubject; + LifecycleBusinessLogic result; + + // default test + testSubject = createTestSubject(); + result = testSubject.lifecycleBusinessLogic(); + } + + @Test + public void testConfigurationProvider() throws Exception { + CatalogBESpringConfig testSubject; + ConfigurationProvider result; + + // default test + testSubject = createTestSubject(); + result = testSubject.configurationProvider(); + } + + @Test + public void testAssetMetadataConverter() throws Exception { + CatalogBESpringConfig testSubject; + AssetMetadataConverter result; + + // default test + testSubject = createTestSubject(); + result = testSubject.assetMetadataConverter(); + } + + @Test + public void testComponentLockAspect() throws Exception { + CatalogBESpringConfig testSubject; + ComponentLockAspect result; + + // default test + testSubject = createTestSubject(); + result = testSubject.componentLockAspect(); + } + + @Test + public void testHttpClientConnectionManager() throws Exception { + CatalogBESpringConfig testSubject; + CloseableHttpClient result; + + // default test + testSubject = createTestSubject(); + result = testSubject.httpClientConnectionManager(); + } + + @Test + public void testPortalConfiguration() throws Exception { + CatalogBESpringConfig testSubject; + PortalConfiguration result; + + // default test + testSubject = createTestSubject(); + result = testSubject.portalConfiguration(); + } + + @Test + public void testThreadLocalUtils() throws Exception { + CatalogBESpringConfig testSubject; + ThreadLocalUtils result; + + // default test + testSubject = createTestSubject(); + result = testSubject.threadLocalUtils(); + } + + @Test + public void testPortalClient() throws Exception { + CatalogBESpringConfig testSubject; + PortalClient result; + + // default test + testSubject = createTestSubject(); + result = testSubject.portalClient(); + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/config/MicrometerSpringConfigTest.java b/catalog-be/src/test/java/org/openecomp/sdc/config/MicrometerSpringConfigTest.java new file mode 100644 index 0000000000..98bce96e4d --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/config/MicrometerSpringConfigTest.java @@ -0,0 +1,44 @@ +/* + * - + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.config; + +import io.micrometer.prometheus.PrometheusMeterRegistry; +import org.junit.Test; +import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; + +public class MicrometerSpringConfigTest { + + private MicrometerSpringConfig createTestSubject() { + return new MicrometerSpringConfig(); + } + + @Test + public void testPrometheusRegistry() throws Exception { + MicrometerSpringConfig testSubject; + PrometheusMeterRegistry result; + + // default test + testSubject = createTestSubject(); + result = testSubject.prometheusRegistry(); + } + +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/LifecycleStateEnumTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/LifecycleStateEnumTest.java new file mode 100644 index 0000000000..05389c9527 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/LifecycleStateEnumTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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; + +import org.junit.Assert; +import org.junit.Test; + +public class LifecycleStateEnumTest { + + @Test + public void testFindState() { + LifecycleStateEnum result = LifecycleStateEnum.findState("CERTIFIED"); + Assert.assertNotNull(result); + Assert.assertEquals(LifecycleStateEnum.CERTIFIED,result); + } + + @Test + public void testFindStateNull() { + LifecycleStateEnum result = LifecycleStateEnum.findState("mock"); + Assert.assertNull(result); + } +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java index e67fdc0f33..8bffdd6613 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/dto/FilterConstraintDtoTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -89,13 +90,75 @@ class FilterConstraintDtoTest { final ToscaGetFunctionDataDefinition toscaGetFunctionDataDefinition = readGetFunctionOpt.get(); assertEquals(toscaGetFunctionDataDefinition.getPropertyUniqueId(), propertyUniqueId); assertEquals(toscaGetFunctionDataDefinition.getPropertyName(), propertyName); - assertEquals(toscaGetFunctionDataDefinition.getPropertySource(), PropertySource.SELF); + assertEquals(PropertySource.SELF, toscaGetFunctionDataDefinition.getPropertySource()); assertEquals(toscaGetFunctionDataDefinition.getSourceUniqueId(), sourceUniqueId); assertEquals(toscaGetFunctionDataDefinition.getSourceName(), sourceName); - assertEquals(toscaGetFunctionDataDefinition.getFunctionType(), ToscaGetFunctionType.GET_INPUT); - assertEquals(toscaGetFunctionDataDefinition.getPropertyPathFromSource().size(), 2); + assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunctionDataDefinition.getFunctionType()); + assertEquals(2, toscaGetFunctionDataDefinition.getPropertyPathFromSource().size()); assertEquals(toscaGetFunctionDataDefinition.getPropertyPathFromSource().get(0), propertyPathFromSource.get(0)); assertEquals(toscaGetFunctionDataDefinition.getPropertyPathFromSource().get(1), propertyPathFromSource.get(1)); } + @Test + void readGetFunctionWithGetFunctionAsListValueAsMap() { + //given + final List propertyPathFromSource1 = List.of("input1", "path1"); + final String propertyUniqueId1 = "propertyUniqueIdValue1"; + final String propertyName1 = "propertyNameValue1"; + final String sourceUniqueId1 = "sourceUniqueIdValue1"; + final String sourceName1 = "sourceNameValue1"; + final Map toscaGetFunctionAsMap1 = Map.of( + "propertyUniqueId", propertyUniqueId1, + "propertyName", propertyName1, + "propertySource", PropertySource.SELF.getName(), + "sourceUniqueId", sourceUniqueId1, + "sourceName", sourceName1, + "functionType", ToscaGetFunctionType.GET_INPUT.getFunctionName(), + "propertyPathFromSource", propertyPathFromSource1 + ); + final List propertyPathFromSource2 = List.of("input2", "path2"); + final String propertyUniqueId2 = "propertyUniqueIdValue2"; + final String propertyName2 = "propertyNameValue2"; + final String sourceUniqueId2 = "sourceUniqueIdValue2"; + final String sourceName2 = "sourceNameValue2"; + final Map toscaGetFunctionAsMap2 = Map.of( + "propertyUniqueId", propertyUniqueId2, + "propertyName", propertyName2, + "propertySource", PropertySource.SELF.getName(), + "sourceUniqueId", sourceUniqueId2, + "sourceName", sourceName2, + "functionType", ToscaGetFunctionType.GET_INPUT.getFunctionName(), + "propertyPathFromSource", propertyPathFromSource2 + ); + + List toscaGetFunctionDataDefinitionList = new ArrayList<>(); + toscaGetFunctionDataDefinitionList.add(toscaGetFunctionAsMap1); + toscaGetFunctionDataDefinitionList.add(toscaGetFunctionAsMap2); + + final var filterConstraintDto = new FilterConstraintDto(); + filterConstraintDto.setValue(toscaGetFunctionDataDefinitionList); + //when + final Optional> readListGetFunctionOpt = filterConstraintDto.getAsListToscaGetFunction(); + //then + assertTrue(readListGetFunctionOpt.isPresent()); + final List toscaGetFunctionDataDefinition = readListGetFunctionOpt.get(); + assertEquals(toscaGetFunctionDataDefinition.get(0).getPropertyUniqueId(), propertyUniqueId1); + assertEquals(toscaGetFunctionDataDefinition.get(1).getPropertyUniqueId(), propertyUniqueId2); + assertEquals(toscaGetFunctionDataDefinition.get(0).getPropertyName(), propertyName1); + assertEquals(toscaGetFunctionDataDefinition.get(1).getPropertyName(), propertyName2); + assertEquals(PropertySource.SELF, toscaGetFunctionDataDefinition.get(0).getPropertySource()); + assertEquals(PropertySource.SELF, toscaGetFunctionDataDefinition.get(1).getPropertySource()); + assertEquals(toscaGetFunctionDataDefinition.get(0).getSourceUniqueId(), sourceUniqueId1); + assertEquals(toscaGetFunctionDataDefinition.get(1).getSourceUniqueId(), sourceUniqueId2); + assertEquals(toscaGetFunctionDataDefinition.get(0).getSourceName(), sourceName1); + assertEquals(toscaGetFunctionDataDefinition.get(1).getSourceName(), sourceName2); + assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunctionDataDefinition.get(0).getFunctionType()); + assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunctionDataDefinition.get(1).getFunctionType()); + assertEquals(2, toscaGetFunctionDataDefinition.get(0).getPropertyPathFromSource().size()); + assertEquals(2, toscaGetFunctionDataDefinition.get(1).getPropertyPathFromSource().size()); + assertEquals(toscaGetFunctionDataDefinition.get(0).getPropertyPathFromSource().get(0), propertyPathFromSource1.get(0)); + assertEquals(toscaGetFunctionDataDefinition.get(1).getPropertyPathFromSource().get(0), propertyPathFromSource2.get(0)); + assertEquals(toscaGetFunctionDataDefinition.get(0).getPropertyPathFromSource().get(1), propertyPathFromSource1.get(1)); + assertEquals(toscaGetFunctionDataDefinition.get(1).getPropertyPathFromSource().get(1), propertyPathFromSource2.get(1)); + } } \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperationsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperationsTest.java index 7bbb5a1263..8f872ca017 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperationsTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperationsTest.java @@ -20,22 +20,37 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import fj.data.Either; -import org.junit.Test; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; public class ArtifactsOperationsTest { @@ -43,6 +58,507 @@ public class ArtifactsOperationsTest { private static final String INSTANCE_ID = "instanceId"; private ArtifactsOperations testInstance = mock(ArtifactsOperations.class, CALLS_REAL_METHODS); + @Test + public void addArtifactToComponent() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = Collections.singletonMap(INSTANCE_ID, getArtifactsByInstance("name1")); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map artMap = new HashMap<>(); + artMap.put(INSTANCE_ID, artifactDef); + doReturn(Either.left(artifactDef)).when(testInstance).updateArtifactOnGraph(resource, + artifactDef, NodeTypeEnum.Resource, null, INSTANCE_ID, false, + false); + + Either ret = testInstance.addArtifactToComponent( + artifactDef, resource, NodeTypeEnum.Resource, false, "instanceId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void addArtifactToComponentEsId() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + artifactDef.setUniqueId(null); + artifactDef.setEsId(INSTANCE_ID); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map artMap = new HashMap<>(); + artMap.put(INSTANCE_ID, artifactDef); + doReturn(StorageOperationStatus.OK).when(testInstance).updateToscaDataOfToscaElement(Mockito.anyString(), + Mockito.any(), Mockito.any(), (List) Mockito.any(), Mockito.any()); + doReturn(Either.left(artifactDef)).when(testInstance).updateArtifactOnGraph(resource, + artifactDef, NodeTypeEnum.Resource, null, INSTANCE_ID, false, + false); + + Either ret = testInstance.addArtifactToComponent( + artifactDef, resource, NodeTypeEnum.Resource, false, "instanceId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void addArtifactToComponentFail() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = Collections.singletonMap(INSTANCE_ID, getArtifactsByInstance("name1")); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map artMap = new HashMap<>(); + artMap.put(INSTANCE_ID, artifactDef); + doReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)).when(testInstance).updateArtifactOnGraph(resource, + artifactDef, NodeTypeEnum.Resource, null, INSTANCE_ID, false, + false); + + Either ret = testInstance.addArtifactToComponent( + artifactDef, resource, NodeTypeEnum.Resource, false, "instanceId"); + + assertTrue(ret.isRight()); + } + + @Test + public void updateArtifactOnResource() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map artMap = new HashMap<>(); + artMap.put(INSTANCE_ID, artifactDef); + doReturn(StorageOperationStatus.OK).when(testInstance).updateToscaDataOfToscaElement(Mockito.anyString(), + Mockito.any(), Mockito.any(), (List) Mockito.any(), Mockito.any()); + doReturn(Either.left(artifactDef)).when(testInstance).updateArtifactOnGraph(resource, + artifactDef, NodeTypeEnum.Resource, null, INSTANCE_ID, false, + false); + + Either ret = testInstance.updateArtifactOnResource( + artifactDef, resource, "instanceId", NodeTypeEnum.Resource, "instanceId", false); + + assertTrue(ret.isLeft()); + } + + @Test + public void updateArtifactOnResourceFail() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = Collections.singletonMap(INSTANCE_ID, getArtifactsByInstance("name1")); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map artMap = new HashMap<>(); + artMap.put(INSTANCE_ID, artifactDef); + + doReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND)).when(testInstance).updateArtifactOnGraph(resource, + artifactDef, NodeTypeEnum.Resource, INSTANCE_ID, INSTANCE_ID, false, + false); + + Either ret = testInstance.updateArtifactOnResource( + artifactDef, resource, "instanceId", NodeTypeEnum.Resource, "instanceId", false); + + assertTrue(ret.isRight()); + } + + @Test + public void isCloneNeeded() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + + Either ret = testInstance.isCloneNeeded( + INSTANCE_ID, artifactDef, NodeTypeEnum.Resource); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById() { + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById2() { + Map instanceArtifacts = + Collections.singletonMap(INSTANCE_ID, getArtifactsByInstanceSettingUniqueId("artifactDefId")); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById3() { + Map instanceArtifacts = + Collections.singletonMap(INSTANCE_ID, getArtifactsByInstanceSettingUniqueId("artifactDefId")); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph("containerId", EdgeLabelEnum.INSTANCE_ARTIFACTS); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById4() { + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById5() { + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById6() { + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.SERVICE_API_ARTIFACTS); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifactById7_NotFound1() { + Map interfaceDefinitions = getInterfaceDataDefinitionsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.SERVICE_API_ARTIFACTS); + doReturn(Either.left(interfaceDefinitions)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.INTERFACE); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isRight()); + } + + @Test + public void getArtifactById7_NotFound2() { + Map interfaceDefinitions = getInterfaceDataDefinitionsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.SERVICE_API_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.INTERFACE); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isRight()); + } + + @Test + public void getArtifactById7_NotFound3() { + Map interfaceDefinitions = + getInterfaceDataDefinitionsWithOperationsByNameNotFound("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.SERVICE_API_ARTIFACTS); + doReturn(Either.left(interfaceDefinitions)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.INTERFACE); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isRight()); + } + + @Test + public void getArtifactById7() { + Map interfaceDefinitions = getInterfaceDataDefinitionsWithOperationsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph("containerId", + EdgeLabelEnum.INSTANCE_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, + EdgeLabelEnum.SERVICE_API_ARTIFACTS); + doReturn(Either.left(interfaceDefinitions)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.INTERFACE); + Either ret = testInstance.getArtifactById( + INSTANCE_ID, "artifactDefId", ComponentTypeEnum.RESOURCE_INSTANCE, "containerId"); + + assertTrue(ret.isLeft()); + } + + @Test + public void removeArtifactFromResource() { + Map instanceArtifacts = getMapArtifactsByName2("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(StorageOperationStatus.OK).when(testInstance).deleteToscaDataElement(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS, VertexTypeEnum.ARTIFACTS, + null, JsonPresentationFields.ARTIFACT_LABEL); + Either ret = testInstance.removeArifactFromResource( + INSTANCE_ID, "instanceId", NodeTypeEnum.Resource, false); + + assertTrue(ret.isLeft()); + } + + @Test + public void removeArtifactFromResource_Mandatory() { + Map instanceArtifacts = getMapArtifactsByName2("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(StorageOperationStatus.OK).when(testInstance).deleteToscaDataElement(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS, VertexTypeEnum.ARTIFACTS, + null, JsonPresentationFields.ARTIFACT_LABEL); + Either ret = testInstance.removeArifactFromResource( + INSTANCE_ID, "instanceId", NodeTypeEnum.Resource, true); + + assertTrue(ret.isLeft()); + } + + @Test + public void removeArtifactFromResource_NotFound() { + doReturn(Either.right(StorageOperationStatus.NOT_FOUND)).when(testInstance).getArtifactById(INSTANCE_ID, INSTANCE_ID); + Either ret = testInstance.removeArifactFromResource( + INSTANCE_ID, "instanceId", NodeTypeEnum.Resource, false); + + assertTrue(ret.isRight()); + } + + @Test + public void removeArtifactFromResource_NotFound2() { + doReturn(Either.right(StorageOperationStatus.NOT_FOUND)).when(testInstance).removeArtifactOnGraph(INSTANCE_ID, INSTANCE_ID, + NodeTypeEnum.Resource, false); + Either ret = testInstance.removeArifactFromResource( + INSTANCE_ID, "instanceId", NodeTypeEnum.Resource, false); + + assertTrue(ret.isRight()); + } + + @Test + public void getArtifacts() { + Map instanceArtifacts = getMapArtifactsByName2("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + + Either, StorageOperationStatus> ret = testInstance.getArtifacts(INSTANCE_ID, NodeTypeEnum.Resource, + ArtifactGroupTypeEnum.INFORMATIONAL, INSTANCE_ID); + + assertTrue(ret.isLeft()); + } + + @Test + public void getArtifacts_NotFound() { + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + + Either, StorageOperationStatus> ret = testInstance.getArtifacts(INSTANCE_ID, NodeTypeEnum.Resource, + ArtifactGroupTypeEnum.INFORMATIONAL, INSTANCE_ID); + + assertTrue(ret.isRight()); + } + + @Test + public void getArtifacts2() { + Map instanceArtifacts = getMapArtifactsByName2("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + + Either, StorageOperationStatus> ret = testInstance.getArtifacts(INSTANCE_ID); + + assertTrue(ret.isLeft()); + } + + @Test + public void addHeatEnvArtifact() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + ArtifactDefinition artifactDefHeat = new ArtifactDefinition(); + artifactDefHeat.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(StorageOperationStatus.OK).when(testInstance).updateToscaDataOfToscaElement(Mockito.anyString(), + Mockito.any(), Mockito.any(), (List) Mockito.any(), Mockito.any()); + Either ret = testInstance.addHeatEnvArtifact(artifactDef, artifactDefHeat, + resource, NodeTypeEnum.Resource, false, INSTANCE_ID); + + assertTrue(ret.isLeft()); + } + + @Test + public void getHeatArtifactByHeatEnvId() { + Map interfaceDefinitions = getInterfaceDataDefinitionsByName("artifactDefId"); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + ArtifactDefinition artifactDefHeat = new ArtifactDefinition(); + artifactDefHeat.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.TOSCA_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.SERVICE_API_ARTIFACTS); + doReturn(Either.left(interfaceDefinitions)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.INTERFACE); + Either ret = testInstance.getHeatArtifactByHeatEnvId( + INSTANCE_ID, artifactDefHeat, "containerId", ComponentTypeEnum.RESOURCE); + + assertTrue(ret.isRight()); + } + + @Test + public void updateHeatEnvArtifact() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setUniqueId("artifactId"); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + ArtifactDefinition artifactDefHeat = new ArtifactDefinition(); + artifactDefHeat.setUniqueId("newArtifactId"); + artifactDefHeat.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(StorageOperationStatus.OK).when(testInstance).updateToscaDataOfToscaElement(Mockito.anyString(), + Mockito.any(), Mockito.any(), (List) Mockito.any(), Mockito.any()); + + Either ret = testInstance.updateHeatEnvArtifact( + resource, artifactDef, "artifactId", "newArtifactId", NodeTypeEnum.Resource, INSTANCE_ID); + + assertTrue(ret.isLeft()); + } + + @Test + public void updateHeatEnvArtifact_NotFound() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setUniqueId("artifactId"); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + ArtifactDefinition artifactDefHeat = new ArtifactDefinition(); + artifactDefHeat.setUniqueId("newArtifactId"); + artifactDefHeat.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + Either ret = testInstance.updateHeatEnvArtifact( + resource, artifactDef, "artifactId", "newArtifactId", NodeTypeEnum.Resource, INSTANCE_ID); + + assertTrue(ret.isRight()); + } + + @Test + public void updateHeatEnvArtifactOnInstance() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setUniqueId("artifactId"); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + ArtifactDefinition artifactDefHeat = new ArtifactDefinition(); + artifactDefHeat.setUniqueId("newArtifactId"); + artifactDefHeat.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(StorageOperationStatus.OK).when(testInstance).updateToscaDataOfToscaElement(Mockito.anyString(), + Mockito.any(), Mockito.any(), (List) Mockito.any(), Mockito.any()); + + Either ret = testInstance.updateHeatEnvArtifactOnInstance( + resource, artifactDef, "artifactId", "newArtifactId", NodeTypeEnum.Resource, INSTANCE_ID); + + assertTrue(ret.isLeft()); + } + + @Test + public void updateHeatEnvPlaceholder() { + ArtifactDefinition artifactDef = new ArtifactDefinition(); + artifactDef.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + final Resource resource = new Resource(); + resource.setUniqueId(INSTANCE_ID); + Map instanceArtifacts = getMapArtifactsByName("artifactDefId"); + doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(INSTANCE_ID, EdgeLabelEnum.ARTIFACTS); + doReturn(Either.left(false)).when(testInstance).isCloneNeeded(Mockito.any(), + Mockito.any()); + Map artMap = new HashMap<>(); + artMap.put(INSTANCE_ID, artifactDef); + doReturn(StorageOperationStatus.OK).when(testInstance).updateToscaDataOfToscaElement(Mockito.anyString(), + Mockito.any(), Mockito.any(), (List) Mockito.any(), Mockito.any()); + doReturn(Either.left(artifactDef)).when(testInstance).updateArtifactOnGraph(resource, + artifactDef, NodeTypeEnum.Resource, null, INSTANCE_ID, false, + false); + + Either ret = testInstance.updateHeatEnvPlaceholder( + artifactDef, resource, NodeTypeEnum.Resource); + + assertTrue(ret.isLeft()); + } + @Test public void getInstanceArtifacts_collectAllInstanceArtifacts() throws Exception { Map instanceArtifacts = Collections.singletonMap(INSTANCE_ID, getArtifactsByInstance("name1")); @@ -53,7 +569,8 @@ public class ArtifactsOperationsTest { doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INSTANCE_ARTIFACTS); doReturn(Either.left(instanceDeploymentArtifacts)).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); - Either, StorageOperationStatus> allInstArtifacts = testInstance.getAllInstanceArtifacts(SERVICE_ID, INSTANCE_ID); + Either, StorageOperationStatus> allInstArtifacts = + testInstance.getAllInstanceArtifacts(SERVICE_ID, INSTANCE_ID); assertTrue(allInstArtifacts.isLeft()); assertEquals(allInstArtifacts.left().value().size(), 3); @@ -69,7 +586,8 @@ public class ArtifactsOperationsTest { doReturn(Either.left(instanceArtifacts)).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INSTANCE_ARTIFACTS); doReturn(Either.left(new HashMap<>())).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); - Either, StorageOperationStatus> allInstArtifacts = testInstance.getAllInstanceArtifacts(SERVICE_ID, "someOtherInstance"); + Either, StorageOperationStatus> allInstArtifacts = + testInstance.getAllInstanceArtifacts(SERVICE_ID, "someOtherInstance"); assertTrue(allInstArtifacts.isLeft()); assertTrue(allInstArtifacts.left().value().isEmpty()); @@ -77,8 +595,10 @@ public class ArtifactsOperationsTest { @Test public void getInstanceArtifacts_errorGettingInstanceArtifacts() throws Exception { - doReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR)).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INSTANCE_ARTIFACTS); - Either, StorageOperationStatus> allInstArtifacts = testInstance.getAllInstanceArtifacts(SERVICE_ID, INSTANCE_ID); + doReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR)).when(testInstance) + .getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INSTANCE_ARTIFACTS); + Either, StorageOperationStatus> allInstArtifacts = + testInstance.getAllInstanceArtifacts(SERVICE_ID, INSTANCE_ID); verify(testInstance, times(0)).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); assertTrue(allInstArtifacts.isRight()); } @@ -86,8 +606,10 @@ public class ArtifactsOperationsTest { @Test public void getAllInstanceArtifacts_errorGettingDeploymentArtifacts() throws Exception { doReturn(Either.left(new HashMap<>())).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INSTANCE_ARTIFACTS); - doReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR)).when(testInstance).getDataFromGraph(SERVICE_ID, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); - Either, StorageOperationStatus> allInstArtifacts = testInstance.getAllInstanceArtifacts(SERVICE_ID, INSTANCE_ID); + doReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR)).when(testInstance).getDataFromGraph(SERVICE_ID, + EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS); + Either, StorageOperationStatus> allInstArtifacts = + testInstance.getAllInstanceArtifacts(SERVICE_ID, INSTANCE_ID); assertTrue(allInstArtifacts.isRight()); } @@ -100,4 +622,86 @@ public class ArtifactsOperationsTest { artifactsByInstance.setMapToscaDataDefinition(artifactsByName); return artifactsByInstance; } + + private ToscaDataDefinition getArtifactsByInstanceSettingUniqueId(String ... artifactsNames) { + MapArtifactDataDefinition artifactsByInstance = new MapArtifactDataDefinition(); + Map artifactsByName = new HashMap<>(); + for (String artifactName : artifactsNames) { + ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(); + artifactDataDefinition.setUniqueId(artifactName); + artifactsByName.put(artifactName, artifactDataDefinition); + } + artifactsByInstance.setMapToscaDataDefinition(artifactsByName); + return artifactsByInstance; + } + + private Map getMapArtifactsByName(String ... artifactsNames) { + Map artifactsByName = new HashMap<>(); + for (String artifactName : artifactsNames) { + ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(); + artifactDataDefinition.setUniqueId(artifactName); + artifactDataDefinition.setGeneratedFromId("artifactId"); + artifactDataDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + artifactsByName.put(artifactName, artifactDataDefinition); + } + return artifactsByName; + } + + private Map getMapArtifactsByName2(String ... artifactsNames) { + Map artifactsByName = new HashMap<>(); + for (String artifactName : artifactsNames) { + ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(); + artifactDataDefinition.setUniqueId(INSTANCE_ID); + artifactDataDefinition.setMandatory(true); + artifactDataDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + artifactsByName.put(artifactName, artifactDataDefinition); + } + return artifactsByName; + } + + private Map getInterfaceDataDefinitionsByName(String ... artifactsNames) { + Map interfaceDataDefinitionsByName = new HashMap<>(); + for (String artifactName : artifactsNames) { + InterfaceDataDefinition interfaceDataDefinition = new InterfaceDataDefinition(); + interfaceDataDefinition.setUniqueId(artifactName); + interfaceDataDefinitionsByName.put(artifactName, interfaceDataDefinition); + } + return interfaceDataDefinitionsByName; + } + + private Map getInterfaceDataDefinitionsWithOperationsByName(String ... artifactsNames) { + Map interfaceDataDefinitionsByName = new HashMap<>(); + for (String artifactName : artifactsNames) { + Map operations = new HashMap<>(); + OperationDataDefinition operation1 = new OperationDataDefinition(); + operation1.setName("operation1"); + ArtifactDataDefinition impl1 = new ArtifactDataDefinition(); + impl1.setUniqueId(artifactName); + operation1.setImplementation(impl1); + operations.put(artifactName, operation1); + InterfaceDataDefinition interfaceDataDefinition = new InterfaceDataDefinition(); + interfaceDataDefinition.setUniqueId(artifactName); + interfaceDataDefinition.setOperations(operations); + interfaceDataDefinitionsByName.put(artifactName, interfaceDataDefinition); + } + return interfaceDataDefinitionsByName; + } + + private Map getInterfaceDataDefinitionsWithOperationsByNameNotFound(String ... artifactsNames) { + Map interfaceDataDefinitionsByName = new HashMap<>(); + for (String artifactName : artifactsNames) { + Map operations = new HashMap<>(); + OperationDataDefinition operation1 = new OperationDataDefinition(); + operation1.setName("operation1"); + ArtifactDataDefinition impl1 = new ArtifactDataDefinition(); + impl1.setUniqueId("implementation1"); + operation1.setImplementation(impl1); + operations.put(artifactName, operation1); + InterfaceDataDefinition interfaceDataDefinition = new InterfaceDataDefinition(); + interfaceDataDefinition.setUniqueId(artifactName); + interfaceDataDefinition.setOperations(operations); + interfaceDataDefinitionsByName.put(artifactName, interfaceDataDefinition); + } + return interfaceDataDefinitionsByName; + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ForwardingPathOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ForwardingPathOperationTest.java new file mode 100644 index 0000000000..9889e90bc0 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ForwardingPathOperationTest.java @@ -0,0 +1,212 @@ +/* + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2023 Nordix Foundation. 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.jsonjanusgraph.operations; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +import fj.data.Either; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.janusgraph.core.JanusGraphVertex; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + +@ExtendWith(MockitoExtension.class) +public class ForwardingPathOperationTest { + + @Mock + private JanusGraphDao janusGraphDao; + + @Mock + private JanusGraphVertex vertex; + + private ForwardingPathOperation test = mock(ForwardingPathOperation.class, CALLS_REAL_METHODS); + + @BeforeEach + public void setUp() throws Exception { + test.setJanusGraphDao(janusGraphDao); + } + + @Test + public void deleteForwardingPath() { + Service service = new Service(); + Set paths = Set.of("path1", "path2"); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + List list = new ArrayList<>(); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + list.add(graphVertex); + doReturn(Either.left(graphVertex)).when(janusGraphDao).getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + doReturn(StorageOperationStatus.OK).when(test).deleteToscaDataElements(graphVertex, EdgeLabelEnum.FORWARDING_PATH, + new ArrayList<>(paths)); + Either, StorageOperationStatus> ret = test.deleteForwardingPath(service, paths); + assertTrue(ret.isLeft()); + } + + @Test + public void deleteForwardingPath_NotFound() { + Service service = new Service(); + Set paths = Set.of("path1", "path2"); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + List list = new ArrayList<>(); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + list.add(graphVertex); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphDao).getVertexById(service.getUniqueId(), + JsonParseFlagEnum.NoParse); + Either, StorageOperationStatus> ret = test.deleteForwardingPath(service, paths); + assertTrue(ret.isRight()); + } + + @Test + public void deleteForwardingPath_ErrorDeleting() { + Service service = new Service(); + Set paths = Set.of("path1", "path2"); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + List list = new ArrayList<>(); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + list.add(graphVertex); + doReturn(Either.left(graphVertex)).when(janusGraphDao).getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + doReturn(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY).when(test).deleteToscaDataElements(graphVertex, EdgeLabelEnum.FORWARDING_PATH, + new ArrayList<>(paths)); + Either, StorageOperationStatus> ret = test.deleteForwardingPath(service, paths); + assertTrue(ret.isRight()); + } + + @Test + public void addForwardingPath() { + Service service = new Service(); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition("forwardingPath"); + doReturn(Either.left(graphVertex)).when(janusGraphDao).getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + doReturn(StorageOperationStatus.OK).when(test).addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.FORWARDING_PATH, + VertexTypeEnum.FORWARDING_PATH, List.of(forwardingPathDataDefinition), JsonPresentationFields.UNIQUE_ID); + Either ret = test.addForwardingPath(service.getUniqueId(), forwardingPathDataDefinition); + assertTrue(ret.isLeft()); + } + + @Test + public void addForwardingPath_NotFound() { + Service service = new Service(); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition("forwardingPath"); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphDao).getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + Either ret = test.addForwardingPath(service.getUniqueId(), forwardingPathDataDefinition); + assertTrue(ret.isRight()); + } + + @Test + public void updateForwardingPath() { + Service service = new Service(); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition("forwardingPath"); + doReturn(Either.left(graphVertex)).when(janusGraphDao).getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + doReturn(StorageOperationStatus.OK).when(test).updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.FORWARDING_PATH, + VertexTypeEnum.FORWARDING_PATH, List.of(forwardingPathDataDefinition), JsonPresentationFields.UNIQUE_ID); + Either ret = test.updateForwardingPath(service.getUniqueId(), forwardingPathDataDefinition); + assertTrue(ret.isLeft()); + } + + @Test + public void updateForwardingPath_Error() { + Service service = new Service(); + String uniqueId = "uniqueId"; + service.setUniqueId(uniqueId); + Map hasProps1 = new HashMap<>(); + hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + GraphVertex graphVertex = new GraphVertex(); + graphVertex.setVertex(vertex); + graphVertex.setUniqueId(uniqueId); + graphVertex.setMetadataProperties(hasProps1); + ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition("forwardingPath"); + doReturn(Either.left(graphVertex)).when(janusGraphDao).getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + doReturn(StorageOperationStatus.ARTIFACT_NOT_FOUND).when(test).updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.FORWARDING_PATH, + VertexTypeEnum.FORWARDING_PATH, List.of(forwardingPathDataDefinition), JsonPresentationFields.UNIQUE_ID); + Either ret = test.updateForwardingPath(service.getUniqueId(), forwardingPathDataDefinition); + assertTrue(ret.isRight()); + } +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationMockTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationMockTest.java new file mode 100644 index 0000000000..9c633b6ad8 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationMockTest.java @@ -0,0 +1,142 @@ +/* + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2023 Nordix Foundation. 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.jsonjanusgraph.operations; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +import com.google.gson.Gson; +import fj.data.Either; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.janusgraph.core.JanusGraphVertex; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + +@ExtendWith(MockitoExtension.class) +public class GroupsOperationMockTest { + + @Mock + private JanusGraphDao janusGraphDao; + + @Mock + private JanusGraphVertex vertex; + + protected static final String CONTAINER_ID = "containerId"; + protected static final String CONTAINER_NAME = "containerName"; + + private GroupsOperation test = mock(GroupsOperation.class, CALLS_REAL_METHODS); + + @BeforeEach + public void setUp() throws Exception { + test.setJanusGraphDao(janusGraphDao); + } + + @Test + public void deleteCalculatedCapabilitiesWithProperties() { + GroupDefinition g1 = createGroupDefinition("g1"); + GroupDefinition g2 = createGroupDefinition("g2"); + List listGroup = new ArrayList<>(); + listGroup.add(g1); + listGroup.add(g2); + GraphVertex createdGraphVertex = createBasicContainerGraphVertex(); + doReturn(Either.left(createdGraphVertex)).when(janusGraphDao).getChildVertex(createdGraphVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES, + JsonParseFlagEnum.ParseJson); + doReturn(Either.left(createdGraphVertex)).when(janusGraphDao).getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse); + doReturn(Either.left(createdGraphVertex)).when(test).updateOrCopyOnUpdate(createdGraphVertex, createdGraphVertex, + EdgeLabelEnum.CALCULATED_CAPABILITIES); + doReturn(Either.left(createdGraphVertex)).when(janusGraphDao).getChildVertex(createdGraphVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, + JsonParseFlagEnum.ParseJson); + doReturn(Either.left(createdGraphVertex)).when(test).updateOrCopyOnUpdate(createdGraphVertex, createdGraphVertex, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); + final StorageOperationStatus ret = test.deleteCalculatedCapabilitiesWithProperties(CONTAINER_ID, listGroup); + assertEquals(StorageOperationStatus.OK, ret); + } + + @Test + public void deleteCalculatedCapabilitiesWithProperties_NotFound() { + GroupDefinition g1 = createGroupDefinition("g1"); + GroupDefinition g2 = createGroupDefinition("g2"); + List listGroup = new ArrayList<>(); + listGroup.add(g1); + listGroup.add(g2); + GraphVertex createdGraphVertex = createBasicContainerGraphVertex(); + doReturn(Either.left(createdGraphVertex)).when(janusGraphDao).getVertexById(CONTAINER_ID, JsonParseFlagEnum.NoParse); + doReturn(Either.left(createdGraphVertex)).when(janusGraphDao).getChildVertex(createdGraphVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES, + JsonParseFlagEnum.ParseJson); + doReturn(Either.left(createdGraphVertex)).when(test).updateOrCopyOnUpdate(createdGraphVertex, createdGraphVertex, + EdgeLabelEnum.CALCULATED_CAPABILITIES); + doReturn(Either.left(createdGraphVertex)).when(janusGraphDao).getChildVertex(createdGraphVertex, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, + JsonParseFlagEnum.ParseJson); + doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(test).updateOrCopyOnUpdate(createdGraphVertex, createdGraphVertex, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES); + final StorageOperationStatus ret = test.deleteCalculatedCapabilitiesWithProperties(CONTAINER_ID, listGroup); + assertEquals(StorageOperationStatus.NOT_FOUND, ret); + } + + private GroupDefinition createGroupDefinition(String id) { + GroupDefinition groupDefinition = new GroupDefinition(); + groupDefinition.setUniqueId(id); + groupDefinition.setInvariantName("name" + id); + return groupDefinition; + } + + private GraphVertex createBasicContainerGraphVertex() { + GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE); + resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID); + resource.addMetadataProperty(GraphPropertyEnum.NAME, CONTAINER_NAME); + resource.setJsonMetadataField(JsonPresentationFields.NAME, CONTAINER_NAME); + resource.setJsonMetadataField(JsonPresentationFields.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + Map groups = new HashMap<>(); + GroupDefinition g1 = createGroupDefinition("g1"); + GroupDefinition g2 = createGroupDefinition("g2"); + groups.put(g1.getInvariantName(), new GroupDataDefinition(g1)); + groups.put(g2.getInvariantName(), new GroupDataDefinition(g2)); + resource.setJson(groups); + return resource; + } +} diff --git a/common-be-tests-utils/src/main/java/org/openecomp/sdc/be/test/util/TestResourcesHandler.java b/common-be-tests-utils/src/main/java/org/openecomp/sdc/be/test/util/TestResourcesHandler.java index 2e3b906a5d..8863f0024e 100644 --- a/common-be-tests-utils/src/main/java/org/openecomp/sdc/be/test/util/TestResourcesHandler.java +++ b/common-be-tests-utils/src/main/java/org/openecomp/sdc/be/test/util/TestResourcesHandler.java @@ -76,10 +76,6 @@ public class TestResourcesHandler { } } - public static byte[] getResourceAsByteArray(final Path resourcePath) throws IOException { - return getResourceAsByteArray(resourcePath.toString()); - } - /** * Reads a file in the given path. * The method forces an assertion fail if the resource could not be loaded. @@ -102,15 +98,4 @@ public class TestResourcesHandler { public static byte[] getResourceBytesOrFail(final Path resourcePath) { return getResourceBytesOrFail(resourcePath.toString()); } - - /** - * Gets the input stream of a resource file - * - * @param resourcePath The resource file path - * @return - * The resource input stream - */ - public static URL getFileUrl(final String resourcePath) { - return Thread.currentThread().getContextClassLoader().getResource(resourcePath); - } } diff --git a/common-be-tests-utils/src/test/java/org/openecomp/sdc/be/test/util/TestResourcesHandlerTest.java b/common-be-tests-utils/src/test/java/org/openecomp/sdc/be/test/util/TestResourcesHandlerTest.java new file mode 100644 index 0000000000..c51bf62cca --- /dev/null +++ b/common-be-tests-utils/src/test/java/org/openecomp/sdc/be/test/util/TestResourcesHandlerTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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.test.util; + +import static junit.framework.TestCase.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +import org.junit.Test; + +public class TestResourcesHandlerTest { + + @Test + public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, + InvocationTargetException, InstantiationException { + Constructor constructor = TestResourcesHandler.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + +} -- cgit 1.2.3-korg