Tests added to increase coverage 82/104882/3
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>
Wed, 1 Apr 2020 15:11:21 +0000 (17:11 +0200)
committerDmitry Puzikov <d.puzikov2@partner.samsung.com>
Wed, 1 Apr 2020 19:12:13 +0000 (21:12 +0200)
Change-Id: I16a729385647cb691fb7c94bd8f26a3c19b1b99d
Issue-ID: SDC-2861
Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/CapabilityFilter.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/NodeFilter.java
catalog-be/src/main/java/org/openecomp/sdc/be/user/UserMessage.java
catalog-be/src/test/java/org/openecomp/sdc/be/facade/operations/CatalogOperationTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/CapabilityFilterTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/NodeFilterTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/user/UserMessageTest.java [new file with mode: 0644]

index 8afd951..0197c3d 100644 (file)
 
 package org.openecomp.sdc.be.tosca.model;
 
-
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
 import org.apache.commons.collections.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-
-
+@Getter
+@Setter
+@ToString
 public class CapabilityFilter {
 
-    List<Map<String, List<Object>>> properties;
-
-    public List<Map<String, List<Object>>> getProperties() {
-        return properties;
-    }
-
-    public void setProperties(List<Map<String, List<Object>>> properties) {
-        this.properties = properties;
-    }
+    private List<Map<String, List<Object>>> properties;
 
     public void addProperty(Map<String, List<Object>> property) {
         if(CollectionUtils.isEmpty(properties)) {
             this.properties = new ArrayList<>();
         }
-
         this.properties.add(property);
     }
-
-    @Override
-    public String toString() {
-        final StringBuilder sb = new StringBuilder("CapabilityFilter{");
-        sb.append("properties=").append(properties);
-        sb.append('}');
-        return sb.toString();
-    }
 }
index 79e9f57..f5511ed 100644 (file)
@@ -17,34 +17,13 @@ package org.openecomp.sdc.be.tosca.model;
 
 import java.util.List;
 import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
 
+@Getter
+@Setter
 public class NodeFilter {
-
-    Object tosca_id;
-    List<Map<String, List<Object>>> properties;
-    List<Map<String, CapabilityFilter>> capabilities;
-
-    public Object getTosca_id() {
-        return tosca_id;
-    }
-
-    public void setTosca_id(Object tosca_id) {
-        this.tosca_id = tosca_id;
-    }
-
-    public List<Map<String, CapabilityFilter>> getCapabilities() {
-        return capabilities;
-    }
-
-    public void setCapabilities(List<Map<String, CapabilityFilter>> capabilities) {
-        this.capabilities = capabilities;
-    }
-
-    public List<Map<String, List<Object>>> getProperties() {
-        return properties;
-    }
-
-    public void setProperties(List<Map<String, List<Object>>> properties) {
-        this.properties = properties;
-    }
+    private Object tosca_id;
+    private List<Map<String, List<Object>>> properties;
+    private List<Map<String, CapabilityFilter>> capabilities;
 }
\ No newline at end of file
index 362bf34..73943f6 100644 (file)
 
 package org.openecomp.sdc.be.user;
 
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
 import org.openecomp.sdc.be.catalog.api.ITypeMessage;
 
-public class UserMessage implements ITypeMessage{
+@Getter
+@Setter
+@AllArgsConstructor
+@ToString
+public class UserMessage implements ITypeMessage {
     private UserOperationEnum operation;
     private String userId;
     private String role;
 
-    public UserMessage(UserOperationEnum operation, String userId, String role) {
-        this.setOperation(operation);
-        this.setUserId(userId);
-        this.setRole(role);
-    }
-
-    public UserOperationEnum getOperation() {
-        return operation;
-    }
-
-    public void setOperation(UserOperationEnum operation) {
-        this.operation = operation;
-    }
-
-    public String getUserId() {
-        return userId;
-    }
-
-    public void setUserId(String userId) {
-        this.userId = userId;
-    }
-
-    public String getRole() {
-        return role;
-    }
-
-    public void setRole(String role) {
-        this.role = role;
-    }
-
-    @Override
-    public String toString() {
-        return "UserMessage [operation=" + operation + ", userId=" + userId + ", role=" + role + "]";
-    }
-
     @Override
     public String getMessageType() {
         return getClass().getSimpleName();
     }
-
 }
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 (file)
index 0000000..68cc4e7
--- /dev/null
@@ -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 (file)
index 0000000..5d221f8
--- /dev/null
@@ -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 (file)
index 0000000..72fcf5f
--- /dev/null
@@ -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 (file)
index 0000000..2e9f86d
--- /dev/null
@@ -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