Some unit tests for catalog-be 39/84339/5
authorTomasz Golabek <tomasz.golabek@nokia.com>
Fri, 5 Apr 2019 12:46:13 +0000 (14:46 +0200)
committerOren Kleks <orenkle@amdocs.com>
Mon, 22 Apr 2019 06:15:17 +0000 (06:15 +0000)
Code coverage for some classes from catalog-be increased.
Some refactor made if needed.

Change-Id: I1b292cfbe4b0d2aa4fbe22871da3228aa434b823
Issue-ID: SDC-2220
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
18 files changed:
catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java
catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/ConfigurationProvider.java [new file with mode: 0644]
catalog-be/src/main/java/org/openecomp/sdc/config/CatalogBESpringConfig.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/category/AuditCategoryEventFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/category/AuditGetCategoryHierarchyEventTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistributionEngineFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistributionEventFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/ecompopenv/AuditEcompOpEnvEventTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/externalapi/AuditExternalApiEventFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/resourceadmin/AuditResourceAdminEventFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditUserEventFuncTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransitionTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/AnnotationValidatorTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/monitoring/EsGatewayTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/test/utils/TestConfigurationProvider.java [new file with mode: 0644]

index f7c46b2..4e2b85e 100644 (file)
  * 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.be.auditing.impl;
 
 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
-import org.openecomp.sdc.be.config.ConfigurationManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
@@ -30,6 +31,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
 import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
 import org.openecomp.sdc.common.log.wrappers.Logger;
 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -39,15 +41,17 @@ public class AuditingManager {
 
     private final AuditingDao auditingDao;
     private final AuditCassandraDao cassandraDao;
+    private final ConfigurationProvider configurationProvider;
 
-    public AuditingManager(AuditingDao auditingDao, AuditCassandraDao cassandraDao) {
+    @Autowired
+    public AuditingManager(AuditingDao auditingDao, AuditCassandraDao cassandraDao, ConfigurationProvider configurationProvider) {
         this.auditingDao = auditingDao;
         this.cassandraDao = cassandraDao;
+        this.configurationProvider = configurationProvider;
     }
 
-
     public String auditEvent(AuditEventFactory factory) {
-        if (ConfigurationManager.getConfigurationManager().getConfiguration().isDisableAudit()) {
+        if (configurationProvider.getConfiguration().isDisableAudit()) {
             return null;
         }
         String msg = factory.getLogMessage();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/ConfigurationProvider.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/ConfigurationProvider.java
new file mode 100644 (file)
index 0000000..eea1b30
--- /dev/null
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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.auditing.impl;
+
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.springframework.stereotype.Component;
+
+@Component("configurationProvider")
+public class ConfigurationProvider {
+
+    public Configuration getConfiguration() {
+        return ConfigurationManager.getConfigurationManager().getConfiguration();
+    }
+}
index aa5cdac..75f7154 100644 (file)
@@ -1,5 +1,27 @@
+/*-
+ * ============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 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;
@@ -41,6 +63,11 @@ public class CatalogBESpringConfig {
         return new LifecycleBusinessLogic();
     }
 
+    @Bean(name = "configurationProvider")
+    public ConfigurationProvider configurationProvider() {
+        return new ConfigurationProvider();
+    }
+
     @Bean(name = "transactionManager")
     public TransactionManager transactionManager() {
         return new TransactionManager();
index 665793b..bfaccdd 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl;
 
 import org.junit.Before;
@@ -19,6 +40,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
 import org.openecomp.sdc.be.resources.data.auditing.ConsumerEvent;
 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
@@ -46,7 +68,7 @@ public class AuditConsumerEventFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
         consumer = new ConsumerDefinition();
         consumer.setConsumerName(USER_ID);
         ThreadLocalsHolder.setUuid(REQUEST_ID);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java
new file mode 100644 (file)
index 0000000..203a70d
--- /dev/null
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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.auditing.impl;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Before;
+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.auditing.api.AuditEventFactory;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AuditingManagerTest {
+
+    private static final String MSG = "msg";
+    private String msg = "Any message";
+    private AuditingManager auditingManager;
+
+    @Mock
+    private AuditingGenericEvent auditEvent;
+    @Mock
+    private AuditingDao auditingDao;
+    @Mock
+    private AuditCassandraDao cassandraDao;
+    @Mock
+    private AuditEventFactory eventFactory;
+
+    @Before
+    public void setUp() throws Exception {
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
+        Mockito.when(eventFactory.getLogMessage()).thenReturn(msg);
+        Mockito.when(eventFactory.getDbEvent()).thenReturn(auditEvent);
+        Mockito.when(eventFactory.getAuditingEsType()).thenReturn(MSG);
+        Mockito.when(cassandraDao.saveRecord(auditEvent)).thenReturn(CassandraOperationStatus.OK);
+        Mockito.when(auditingDao.addRecord(auditEvent, MSG)).thenReturn(
+            ActionStatus.OK);
+    }
+
+    @Test
+    public void testShouldAuditEvent() {
+        String result = auditingManager.auditEvent(eventFactory);
+        assertThat(result, is(msg));
+        Mockito.verify(cassandraDao).saveRecord(auditEvent);
+        Mockito.verify(auditingDao).addRecord(auditEvent, MSG);
+    }
+
+
+}
\ No newline at end of file
index 9f08bbb..4c0a672 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.category;
 
 import org.junit.Before;
@@ -19,6 +40,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
 import org.openecomp.sdc.be.resources.data.auditing.CategoryEvent;
 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -44,7 +66,7 @@ public class AuditCategoryEventFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
         ThreadLocalsHolder.setUuid(REQUEST_ID);
     }
 
index 7f0f3f5..f887355 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.category;
 
 import org.junit.Before;
@@ -18,6 +39,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
 import org.openecomp.sdc.be.resources.data.auditing.GetCategoryHierarchyEvent;
 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -42,7 +64,7 @@ public class AuditGetCategoryHierarchyEventTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
     }
 
     @Test
index 25cf1fb..f184c78 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.distribution;
 
 import org.junit.Before;
@@ -20,6 +41,7 @@ import org.openecomp.sdc.be.resources.data.auditing.DistributionEngineEvent;
 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -45,7 +67,7 @@ public class AuditDistributionEngineFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
         ThreadLocalsHolder.setUuid(REQUEST_ID);
     }
 
index 4c9c633..ab3b054 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.distribution;
 
 import org.junit.Before;
@@ -18,6 +39,7 @@ import org.openecomp.sdc.be.dao.impl.AuditingDao;
 import org.openecomp.sdc.be.resources.data.auditing.*;
 import org.openecomp.sdc.be.resources.data.auditing.model.*;
 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -44,7 +66,7 @@ public class AuditDistributionEventFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
         ThreadLocalsHolder.setUuid(REQUEST_ID);
     }
 
index 95beb9c..ebae816 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.ecompopenv;
 
 import org.junit.Before;
@@ -18,6 +39,7 @@ import org.openecomp.sdc.be.dao.impl.AuditingDao;
 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
 import org.openecomp.sdc.be.resources.data.auditing.EcompOperationalEnvironmentEvent;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -44,7 +66,7 @@ public class AuditEcompOpEnvEventTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
     }
 
     @Test
index a247d61..7205b07 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.externalapi;
 
 import org.junit.Before;
@@ -21,6 +42,7 @@ import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -48,7 +70,7 @@ public class AuditExternalApiEventFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
     }
 
     @Test
index 781702c..b6671fe 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.resourceadmin;
 
 import org.junit.Before;
@@ -24,6 +45,7 @@ import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
 import org.openecomp.sdc.common.api.Constants;
 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -49,7 +71,7 @@ public class AuditResourceAdminEventFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
         ThreadLocalsHolder.setUuid(REQUEST_ID);
     }
 
index 9652e88..3db9337 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.auditing.impl.usersadmin;
 
 import org.junit.Before;
@@ -18,6 +39,7 @@ import org.openecomp.sdc.be.dao.impl.AuditingDao;
 import org.openecomp.sdc.be.model.User;
 import org.openecomp.sdc.be.resources.data.auditing.*;
 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -43,7 +65,7 @@ public class AuditUserEventFuncTest {
     @Before
     public void setUp() {
         init(esConfig);
-        auditingManager = new AuditingManager(auditingDao, cassandraDao);
+        auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
     }
 
     @Test
index fc93b40..0f18de2 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.components.lifecycle;
 
 import org.junit.Test;
@@ -18,6 +39,7 @@ import org.openecomp.sdc.exception.ResponseFormat;
 
 import fj.data.Either;
 import mockit.Deencapsulation;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 public class CertificationRequestTransitionTest extends LifecycleTestBase {
 
@@ -25,7 +47,7 @@ public class CertificationRequestTransitionTest extends LifecycleTestBase {
        
        private CertificationRequestTransition createTestSubject() {
                return new CertificationRequestTransition(
-                               new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao())),
+                               new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao(), new TestConfigurationProvider())),
                                new ToscaElementLifecycleOperation(), new ServiceBusinessLogic(), new ToscaOperationFacade(), new TitanDao(new TitanGraphClient()));
        }
 
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/AnnotationValidatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/AnnotationValidatorTest.java
new file mode 100644 (file)
index 0000000..480c8cf
--- /dev/null
@@ -0,0 +1,117 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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.components.validation;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+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.components.impl.utils.ExceptionUtils;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.Annotation;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AnnotationValidatorTest {
+
+    private static final String TYPE = "type";
+    private static final String UNIQUE_ID = "1";
+    private static final String OWNER = "owner";
+    private static final String DESC = "desc";
+    private static final String TEST = "test";
+    private static final String PROP_NAME = "propName";
+    private Map<String, DataTypeDefinition> allData;
+    private List<PropertyDefinition> annotationTypeProperties;
+    private AnnotationValidator annotationValidator;
+    private List<PropertyDataDefinition> propertyDataDefinitions = new ArrayList<>();
+    private PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition();;
+
+    @Mock
+    private ComponentsUtils componentsUtils;
+    @Mock
+    private ApplicationDataTypeCache dataTypeCache;
+    @Mock
+    private PropertyValidator propertyValidator;
+    @Mock
+    private ExceptionUtils exceptionUtils;
+
+    @Before
+    public void setUp() throws Exception {
+        annotationValidator = new AnnotationValidator(propertyValidator, exceptionUtils, dataTypeCache, componentsUtils);
+        allData = Collections.emptyMap();
+        Either<Map<String, DataTypeDefinition>, TitanOperationStatus> cacheResponse = Either.left(allData);
+        Mockito.when(dataTypeCache.getAll()).thenReturn(cacheResponse);
+        annotationTypeProperties = Collections.emptyList();
+        propertyDataDefinitions = new ArrayList<>();
+    }
+
+    @Test
+    public void testValidateAnnotationsProperties() {
+        Annotation annotation = prepareAnnotation();
+        AnnotationTypeDefinition annotationTypeDefinition = prepareAnnotationTypeDefinition();
+        List<PropertyDefinition> properties = new ArrayList<>();
+        properties.add(new PropertyDefinition(propertyDataDefinition));
+
+        List<Annotation> annotations = annotationValidator
+            .validateAnnotationsProperties(annotation, annotationTypeDefinition);
+
+        Mockito.verify(propertyValidator).thinPropertiesValidator(properties, annotationTypeProperties, allData);
+        assertThat(annotations.get(0), is(annotation));
+    }
+
+    private AnnotationTypeDefinition prepareAnnotationTypeDefinition() {
+        AnnotationTypeDefinition annotationTypeDefinition = new AnnotationTypeDefinition();
+        annotationTypeDefinition.setProperties(annotationTypeProperties);
+        annotationTypeDefinition.setCreationTime(System.currentTimeMillis());
+        annotationTypeDefinition.setType(TYPE);
+        annotationTypeDefinition.setHighestVersion(true);
+        annotationTypeDefinition.setUniqueId(UNIQUE_ID);
+        annotationTypeDefinition.setOwnerId(OWNER);
+        annotationTypeDefinition.setDescription(DESC);
+        return annotationTypeDefinition;
+    }
+
+    private Annotation prepareAnnotation(){
+        Annotation annotation = new Annotation();
+        annotation.setName(TEST);
+        annotation.setDescription(DESC);
+        propertyDataDefinition.setName(PROP_NAME);
+        propertyDataDefinitions.add(propertyDataDefinition);
+        annotation.setProperties(propertyDataDefinitions);
+        annotation.setType(TYPE);
+        return annotation;
+    }
+
+}
\ No newline at end of file
index 74ce6f1..fdcd6d8 100644 (file)
@@ -1,3 +1,24 @@
+/*-
+ * ============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.be.impl;
 
 import fj.data.Either;
@@ -31,6 +52,7 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource;
 import org.openecomp.sdc.exception.ResponseFormat;
 
 import java.util.List;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
 
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
@@ -38,7 +60,7 @@ import static org.mockito.Mockito.when;
 public class ComponentsUtilsTest {
 
        private ComponentsUtils createTestSubject() {
-               return new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao()));
+               return new ComponentsUtils(new AuditingManager(new AuditingDao(), new AuditCassandraDao(), new TestConfigurationProvider()));
        }
 
        @Before
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/monitoring/EsGatewayTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/monitoring/EsGatewayTest.java
new file mode 100644 (file)
index 0000000..71ee14f
--- /dev/null
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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.monitoring;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import org.junit.Before;
+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.components.impl.MonitoringBusinessLogic;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.common.api.Constants;
+import org.springframework.web.context.WebApplicationContext;
+
+@RunWith(MockitoJUnitRunner.class)
+public class EsGatewayTest {
+
+    private static final String MYWEBAPP = "/mywebapp";
+    private static final String SERVLET_MY_SERVLET = "/servlet/MyServlet";
+    private static final String PATH_INFO = "/a/b;c=123";
+    private static final String QUERY_STRING = "d=789";
+    private static final String PORT = "8080";
+    private static final String LOCALHOST = "localhost";
+    private EsGateway esGateway;
+
+    @Mock
+    HttpServletRequest request;
+    @Mock
+    ServletContext servletContext;
+    @Mock
+    HttpSession session;
+    @Mock
+    WebAppContextWrapper contextWrapper;
+    @Mock
+    WebApplicationContext webApplicationContext;
+    @Mock
+    MonitoringBusinessLogic monitoringBusinessLogic;
+
+    @Before
+    public void setUp() throws Exception {
+        esGateway = new EsGateway();
+        Mockito.when(request.getSession()).thenReturn(session);
+        Mockito.when(session.getServletContext()).thenReturn(servletContext);
+        Mockito.when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(contextWrapper);
+        Mockito.when(contextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
+        Mockito.when(webApplicationContext.getBean(MonitoringBusinessLogic.class)).thenReturn(monitoringBusinessLogic);
+    }
+
+    @Test
+    public void testShouldRewriteTarget() {
+        mockMonitoringBusinessLogic();
+        mockRequestParameters();
+        String redirectedUrl = esGateway.rewriteTarget(request);
+        assertThat(redirectedUrl, is("http://localhost:8080/mywebapp/servlet/MyServlet/a/b;c=123?d=789"));
+    }
+
+    @Test
+    public void testShouldGetModifiedUrl() {
+        mockMonitoringBusinessLogic();
+        mockRequestParameters();
+        String modifiedUrl = esGateway.getModifiedUrl(request);
+        assertThat(modifiedUrl, is("http://localhost:8080/mywebapp/servlet/MyServlet/a/b;c=123?d=789"));
+    }
+
+    @Test
+    public void shouldTestGetMonitoringBL() {
+        MonitoringBusinessLogic monitoringBL = esGateway.getMonitoringBL(servletContext);
+        assertThat(monitoringBL, is(notNullValue()));
+    }
+
+    private void mockMonitoringBusinessLogic(){
+        Mockito.when(monitoringBusinessLogic.getEsHost()).thenReturn(LOCALHOST);
+        Mockito.when(monitoringBusinessLogic.getEsPort()).thenReturn(PORT);
+    }
+
+    private void mockRequestParameters(){
+        Mockito.when(request.getContextPath()).thenReturn(MYWEBAPP);
+        Mockito.when(request.getServletPath()).thenReturn(SERVLET_MY_SERVLET);
+        Mockito.when(request.getPathInfo()).thenReturn(PATH_INFO);
+        Mockito.when(request.getQueryString()).thenReturn(QUERY_STRING);
+    }
+}
\ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/TestConfigurationProvider.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/TestConfigurationProvider.java
new file mode 100644 (file)
index 0000000..f0130c6
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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.test.utils;
+
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.auditing.impl.ConfigurationProvider;
+import org.openecomp.sdc.be.config.Configuration;
+
+public class TestConfigurationProvider extends ConfigurationProvider {
+    public Configuration getConfiguration() {
+        return Mockito.mock(Configuration.class);
+    }
+}