diff options
author | Tomasz Golabek <tomasz.golabek@nokia.com> | 2019-04-07 15:05:51 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-04-08 08:41:17 +0000 |
commit | 67437109d8df88ff494f8bd14faef44b7f5a2dee (patch) | |
tree | 9836911166cff8df40b4c278d9dfd9d13206e8e4 /catalog-be/src/test/java | |
parent | a8e3bf27eec7832a89522b776f08dda8dc0985d2 (diff) |
Some unit tests for catalog-be
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>
Diffstat (limited to 'catalog-be/src/test/java')
4 files changed, 152 insertions, 292 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactAccessListTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactAccessListTest.java index 89be01cbfc..ad73636482 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactAccessListTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactAccessListTest.java @@ -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 diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfoTest.java index b73874ea3a..2811c1535d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactDefinitionInfoTest.java @@ -1,122 +1,69 @@ +/*- + * ============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 diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTemplateInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTemplateInfoTest.java index 8b820eaa74..5991341502 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTemplateInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTemplateInfoTest.java @@ -1,186 +1,60 @@ +/*- + * ============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 diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTypesInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTypesInfoTest.java index b129247acc..ba76898a33 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTypesInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/ArtifactTypesInfoTest.java @@ -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 |