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>
* 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;
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
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();
--- /dev/null
+/*-
+ * ============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();
+ }
+}
+/*-
+ * ============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;
return new LifecycleBusinessLogic();
}
+ @Bean(name = "configurationProvider")
+ public ConfigurationProvider configurationProvider() {
+ return new ConfigurationProvider();
+ }
+
@Bean(name = "transactionManager")
public TransactionManager transactionManager() {
return new TransactionManager();
+/*-
+ * ============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;
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;
@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);
--- /dev/null
+/*-
+ * ============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
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
ThreadLocalsHolder.setUuid(REQUEST_ID);
}
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
}
@Test
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
ThreadLocalsHolder.setUuid(REQUEST_ID);
}
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
ThreadLocalsHolder.setUuid(REQUEST_ID);
}
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
}
@Test
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
}
@Test
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
ThreadLocalsHolder.setUuid(REQUEST_ID);
}
+/*-
+ * ============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;
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;
@Before
public void setUp() {
init(esConfig);
- auditingManager = new AuditingManager(auditingDao, cassandraDao);
+ auditingManager = new AuditingManager(auditingDao, cassandraDao, new TestConfigurationProvider());
}
@Test
+/*-
+ * ============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;
import fj.data.Either;
import mockit.Deencapsulation;
+import org.openecomp.sdc.test.utils.TestConfigurationProvider;
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()));
}
--- /dev/null
+/*-
+ * ============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
+/*-
+ * ============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;
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;
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
--- /dev/null
+/*-
+ * ============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
--- /dev/null
+/*-
+ * ============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);
+ }
+}