Some unit tests for catalog-be 35/84435/3
authorTomasz Golabek <tomasz.golabek@nokia.com>
Sun, 7 Apr 2019 13:05:51 +0000 (15:05 +0200)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Mon, 8 Apr 2019 08:41:17 +0000 (08:41 +0000)
Code coverage for some classes from catalog-be increased.
Some refactor made if needed.

Change-Id: I33114eed03d4e176896fd803b54fb77787c34283
Issue-ID: SDC-2220
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java
catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfo.java
catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactAccessListTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfoTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTemplateInfoTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTypesInfoTest.java

index 635a082..fa3a333 100644 (file)
@@ -16,6 +16,8 @@
  * 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.info;
@@ -24,12 +26,14 @@ import java.util.List;
 
 public class ArtifactAccessList {
 
+    ArtifactAccessList() {}
+
+    private List<ArtifactAccessInfo> artifacts;
+
     public ArtifactAccessList(List<ArtifactAccessInfo> artifacts) {
         this.artifacts = artifacts;
     }
 
-    private List<ArtifactAccessInfo> artifacts;
-
     public List<ArtifactAccessInfo> getArtifacts() {
         return artifacts;
     }
index bf257ee..dcb5f42 100644 (file)
@@ -16,6 +16,8 @@
  * 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.info;
@@ -31,13 +33,15 @@ public class ArtifactDefinitionInfo {
     private String artifactVersion;
     private String artifactUUID;
 
+    ArtifactDefinitionInfo() {
+    }
+
     public ArtifactDefinitionInfo(ArtifactDefinition artifactDefinition) {
         uniqueId = artifactDefinition.getUniqueId();
         artifactName = artifactDefinition.getArtifactName();
         artifactDisplayName = artifactDefinition.getArtifactDisplayName();
         artifactVersion = artifactDefinition.getArtifactVersion();
         artifactUUID = artifactDefinition.getArtifactUUID();
-
     }
 
     public String getUniqueId() {
index 89be01c..ad73636 100644 (file)
@@ -1,34 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2018 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.info;
 
-import java.util.List;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
+import java.util.ArrayList;
+import java.util.List;
 import org.junit.Test;
 
-
 public class ArtifactAccessListTest {
 
-       private ArtifactAccessList createTestSubject() {
-               return new ArtifactAccessList(null);
-       }
-
        @Test
-       public void testGetArtifacts() throws Exception {
-               ArtifactAccessList testSubject;
-               List<ArtifactAccessInfo> result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getArtifacts();
+       public void shouldHaveValidGettersAndSetters() {
+               assertThat(ArtifactAccessList.class, hasValidGettersAndSetters());
        }
 
-
        @Test
-       public void testSetArtifacts() throws Exception {
-               ArtifactAccessList testSubject;
-               List<ArtifactAccessInfo> artifacts = null;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setArtifacts(artifacts);
+       public void testCtor() {
+               List<ArtifactAccessInfo> artifacts = new ArrayList<>();
+               ArtifactAccessList artifactAccessList = new ArtifactAccessList(artifacts);
+               assertThat(artifactAccessList.getArtifacts(), is(artifacts));
        }
+
 }
\ No newline at end of file
index b73874e..2811c15 100644 (file)
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2018 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.info;
 
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
 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.model.ArtifactDefinition;
 
-
+@RunWith(MockitoJUnitRunner.Silent.class)
 public class ArtifactDefinitionInfoTest {
 
-       private ArtifactDefinitionInfo createTestSubject() {
-               return new ArtifactDefinitionInfo(new ArtifactDefinition());
-       }
+       @Mock
+       private ArtifactDefinition artifactDefinition;
 
-       
-       @Test
-       public void testGetUniqueId() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String result;
+       private static final String VERSION = "VERSION";
+       private static final String DISPLAY_NAME = "DISPLAY NAME";
+       private static final String UUID = "1";
+       private static final byte[] PAYLOAD_DATA = "Test".getBytes();
+       private static final String NAME = "Name";
 
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getUniqueId();
-       }
-
-       
        @Test
-       public void testSetUniqueId() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String uniqueId = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setUniqueId(uniqueId);
+       public void shouldHaveValidGettersAndSetters() {
+               assertThat(ArtifactDefinitionInfo.class, hasValidGettersAndSetters());
        }
 
-       
        @Test
-       public void testGetArtifactName() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String result;
+       public void testCtor() {
+               Mockito.when(artifactDefinition.getPayloadData()).thenReturn(PAYLOAD_DATA);
+               Mockito.when(artifactDefinition.getArtifactName()).thenReturn(NAME);
+               Mockito.when(artifactDefinition.getArtifactDisplayName()).thenReturn(DISPLAY_NAME);
+               Mockito.when(artifactDefinition.getArtifactVersion()).thenReturn(VERSION);
+               Mockito.when(artifactDefinition.getArtifactUUID()).thenReturn(UUID);
+
+               ArtifactDefinitionInfo artifactDefinitionInfo = new ArtifactDefinitionInfo(artifactDefinition);
+               assertThat(artifactDefinitionInfo.getArtifactDisplayName(), is(DISPLAY_NAME));
+               assertThat(artifactDefinitionInfo.getArtifactName(), is(NAME));
+               assertThat(artifactDefinitionInfo.getArtifactVersion(), is(VERSION));
+               assertThat(artifactDefinitionInfo.getArtifactUUID(), is(UUID));
 
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getArtifactName();
        }
 
-       
-       @Test
-       public void testSetArtifactName() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String artifactName = "";
 
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setArtifactName(artifactName);
-       }
-
-       
-       @Test
-       public void testGetArtifactDisplayName() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getArtifactDisplayName();
-       }
-
-       
-       @Test
-       public void testSetArtifactDisplayName() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String artifactDisplayName = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setArtifactDisplayName(artifactDisplayName);
-       }
-
-       
-       @Test
-       public void testGetArtifactVersion() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getArtifactVersion();
-       }
-
-       
-       @Test
-       public void testSetArtifactVersion() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String artifactVersion = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setArtifactVersion(artifactVersion);
-       }
-
-       
-       @Test
-       public void testGetArtifactUUID() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getArtifactUUID();
-       }
-
-       
-       @Test
-       public void testSetArtifactUUID() throws Exception {
-               ArtifactDefinitionInfo testSubject;
-               String artifactUUID = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setArtifactUUID(artifactUUID);
-       }
 }
\ No newline at end of file
index 8b820ea..5991341 100644 (file)
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2018 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.info;
 
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
 import java.util.LinkedList;
 import java.util.List;
 
 import org.junit.Test;
 
-
 public class ArtifactTemplateInfoTest {
 
-       private ArtifactTemplateInfo createTestSubject() {
-               return new ArtifactTemplateInfo();
-       }
-
-       @Test
-       public void testCtor() throws Exception {
-               new ArtifactTemplateInfo("mock", "mock", "mock", new LinkedList<>());
-       }
-       
-       @Test
-       public void testGetType() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getType();
-       }
-
-       
-       @Test
-       public void testSetType() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String type = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setType(type);
-       }
-
-       
-       @Test
-       public void testGetFileName() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getFileName();
-       }
-
-       
-       @Test
-       public void testSetFileName() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String fileName = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setFileName(fileName);
-       }
-
-       
-       @Test
-       public void testGetEnv() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getEnv();
-       }
-
-       
-       @Test
-       public void testSetEnv() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String env = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setEnv(env);
-       }
-
-       
-       @Test
-       public void testGetRelatedArtifactsInfo() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               List<ArtifactTemplateInfo> result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getRelatedArtifactsInfo();
-       }
-
-       
-       @Test
-       public void testSetRelatedArtifactsInfo() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               List<ArtifactTemplateInfo> relatedArtifactsInfo = null;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setRelatedArtifactsInfo(relatedArtifactsInfo);
-       }
-
-       
-       @Test
-       public void testGetGroupName() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getGroupName();
-       }
-
-       
-       @Test
-       public void testSetGroupName() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String groupName = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setGroupName(groupName);
-       }
-
-       
-       @Test
-       public void testIsBase() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               boolean result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.isBase();
-       }
+       private static final String TYPE = "TYPE";
+       private static final String FILENAME = "FILENAME";
+       private static final String ENV = "ENV";
 
-       
        @Test
-       public void testSetBase() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               boolean isBase = false;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setBase(isBase);
+       public void shouldHaveValidGettersAndSetters() {
+               assertThat(ArtifactTemplateInfo.class, hasValidGettersAndSetters());
        }
 
-       
        @Test
-       public void testGetDescription() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getDescription();
+       public void testDefaultCtor() {
+               assertThat(ArtifactTemplateInfo.class, hasValidBeanConstructor());
        }
 
-       
        @Test
-       public void testSetDescription() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String description = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setDescription(description);
-       }
-
-       
-       @Test
-       public void testToString() throws Exception {
-               ArtifactTemplateInfo testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.toString();
+       public void testCtor() {
+               List<ArtifactTemplateInfo> artifactsInfo = new LinkedList<>();
+               ArtifactTemplateInfo artifactTemplateInfo = new ArtifactTemplateInfo(TYPE, FILENAME, ENV, artifactsInfo);
+               assertThat(artifactTemplateInfo.getType(), is(TYPE));
+               assertThat(artifactTemplateInfo.getFileName(), is(FILENAME));
+               assertThat(artifactTemplateInfo.getEnv(), is(ENV));
+               assertThat(artifactTemplateInfo.getRelatedArtifactsInfo(), is(artifactsInfo));
        }
 
-       
-       
 }
\ No newline at end of file
index b129247..ba76898 100644 (file)
@@ -1,14 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2018 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.info;
 
+import org.junit.Assert;
 import org.junit.Test;
 
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-
 public class ArtifactTypesInfoTest {
     @Test
     public void shouldHaveValidGettersAndSetters() {
         assertThat(ArtifactTypesInfo.class, hasValidGettersAndSetters());
     }
+
+    @Test
+    public void testDefaultCtor() {
+        Assert.assertThat(ArtifactTypesInfo.class, hasValidBeanConstructor());
+    }
 }
\ No newline at end of file