aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>2020-04-01 17:11:21 +0200
committerDmitry Puzikov <d.puzikov2@partner.samsung.com>2020-04-01 21:12:13 +0200
commit0968bd68620bbd22e7ab855c9252be4178953a3a (patch)
treed36262a7874c0995d02bc68d7c86f9c889e649b0 /catalog-be/src/test
parent0323dc0535e4af4c5aa2d7ef4a3fb4eb4cb9a813 (diff)
Tests added to increase coverage
Change-Id: I16a729385647cb691fb7c94bd8f26a3c19b1b99d Issue-ID: SDC-2861 Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/facade/operations/CatalogOperationTest.java76
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/CapabilityFilterTest.java64
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java39
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/user/UserMessageTest.java59
4 files changed, 238 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/facade/operations/CatalogOperationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/facade/operations/CatalogOperationTest.java
new file mode 100644
index 0000000000..68cc4e764b
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/facade/operations/CatalogOperationTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.facade.operations;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.catalog.api.IStatus;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
+import org.openecomp.sdc.be.catalog.impl.ComponentMessage;
+import org.openecomp.sdc.be.catalog.impl.DmaapProducer;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CatalogOperationTest {
+ @Mock
+ private DmaapProducer msProducer;
+ @Mock
+ private Resource component;
+ @Captor
+ private ArgumentCaptor<ComponentMessage> messageCaptor;
+
+ private CatalogOperation catalogOperation;
+
+ @Before
+ public void setUp() {
+ catalogOperation = new CatalogOperation(msProducer);
+ }
+
+ @Test
+ public void updateCatalogTest() {
+ when(component.getLifecycleState()).thenReturn(LifecycleStateEnum.CERTIFIED);
+ when(component.getResourceType()).thenReturn(ResourceTypeEnum.ABSTRACT);
+ when(component.getLastUpdateDate()).thenReturn(System.currentTimeMillis());
+ when(component.getLastUpdaterUserId()).thenReturn("mock-id");
+ when(component.getCategories()).thenReturn(null);
+ when(msProducer.pushMessage(any(ComponentMessage.class))).thenReturn(IStatus.getSuccessStatus());
+
+ catalogOperation.updateCatalog(ChangeTypeEnum.LIFECYCLE, component);
+
+ Mockito.verify(msProducer).pushMessage(messageCaptor.capture());
+ ComponentMessage message = messageCaptor.getValue();
+ assertThat(message.getChangeType()).isEqualTo(ChangeTypeEnum.LIFECYCLE);
+ assertThat(message.getResourceType()).isEqualTo(ResourceTypeEnum.ABSTRACT.name());
+ assertThat(message.getLifecycleState()).isEqualTo(LifecycleStateEnum.CERTIFIED.name());
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/CapabilityFilterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/CapabilityFilterTest.java
new file mode 100644
index 0000000000..5d221f81f0
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/CapabilityFilterTest.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.tosca.model;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+
+public class CapabilityFilterTest {
+ private CapabilityFilter createCapabilityFilter() {
+ return new CapabilityFilter();
+ }
+
+ private Map<String, List<Object>> createProperty() {
+ Map<String, List<Object>> property = new HashMap<>();
+ List<Object> mockValue = new ArrayList<>();
+ mockValue.add("mock-value-0");
+ property.put("mock-key", mockValue);
+ return property;
+ }
+
+ @Test
+ public void testDefaultCtor() {
+ assertThat(CapabilityFilter.class, hasValidBeanConstructor());
+ }
+
+ @Test
+ public void testGettersSetters() {
+ assertThat(CapabilityFilter.class, hasValidGettersAndSetters());
+ }
+
+ @Test
+ public void testAddProperty() {
+ CapabilityFilter capabilityFilter = createCapabilityFilter();
+ Map<String, List<Object>> property = createProperty();
+ capabilityFilter.addProperty(property);
+ assertThat(capabilityFilter.getProperties(), hasItem(property));
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java
new file mode 100644
index 0000000000..72fcf5f2dc
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.tosca.model;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+
+public class NodeFilterTest {
+ @Test
+ public void testDefaultCtor() {
+ assertThat(NodeFilter.class, hasValidBeanConstructor());
+ }
+
+ @Test
+ public void testGettersSetters() {
+ assertThat(NodeFilter.class, hasValidGettersAndSetters());
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/user/UserMessageTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/user/UserMessageTest.java
new file mode 100644
index 0000000000..2e9f86dd59
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/user/UserMessageTest.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.user;
+
+import static com.google.code.beanmatchers.BeanMatchers.isABeanWithValidGettersAndSettersExcluding;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.isA;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+
+public class UserMessageTest {
+ private static final UserOperationEnum USER_OPERATION = UserOperationEnum.CREATE;
+ private static final String USER_ID = "mock-user";
+ private static final String ROLE = "mock-role";
+
+ private UserMessage createUserMessage() {
+ return new UserMessage(USER_OPERATION, USER_ID, ROLE);
+ }
+
+ @Test
+ public void testCtor() {
+ UserMessage userMessage = createUserMessage();
+ assertThat(userMessage, isA(UserMessage.class));
+ assertThat(userMessage.getOperation(), is(USER_OPERATION));
+ assertThat(userMessage.getUserId(), is(USER_ID));
+ assertThat(userMessage.getRole(), is(ROLE));
+ }
+
+ @Test
+ public void testGettersSetters() {
+ UserMessage userMessage = createUserMessage();
+ assertThat(userMessage, isABeanWithValidGettersAndSettersExcluding("messageType"));
+ }
+
+ @Test
+ public void testGetMessageType() {
+ UserMessage userMessage = createUserMessage();
+ assertThat(userMessage.getMessageType(), is(UserMessage.class.getSimpleName()));
+ }
+} \ No newline at end of file