diff options
author | Tomasz Golabek <tomasz.golabek@nokia.com> | 2019-04-11 14:29:49 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-04-30 11:34:29 +0000 |
commit | 7e28cea706ca5e0ca423fde637a7846eaaa2e1e0 (patch) | |
tree | ad9f416df381ce6bad81344e1f7f2cce4d30b25b /catalog-be/src/test/java | |
parent | 96a163f5a9fa81f23b9859a63a8401c1659c187c (diff) |
Some unit tests for catalog-be
Code coverage for some classes from catalog-be increased.
Some refactor made if needed.
Change-Id: Ia9348f624984ab7e5f9aa53c0adf33cf5867fa07
Issue-ID: SDC-2220
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
Diffstat (limited to 'catalog-be/src/test/java')
7 files changed, 326 insertions, 80 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponceTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponceTest.java index e4d3c9bce9..c95b80295e 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponceTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusOfServiceListResponceTest.java @@ -1,12 +1,39 @@ +/*- + * ============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.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 DistributionStatusOfServiceListResponceTest { + + @Test + public void shouldHaveValidDefaultConstructor() { + assertThat(DistributionStatusOfServiceListResponce.class, hasValidBeanConstructor()); + } + @Test public void shouldHaveValidGettersAndSetters() { assertThat(DistributionStatusOfServiceListResponce.class, hasValidGettersAndSetters()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusTest.java index f8ce8ade58..1b3633ca56 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/DistributionStatusTest.java @@ -1,39 +1,49 @@ +/*- + * ============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 org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + import org.junit.Test; public class DistributionStatusTest { - private DistributionStatus createTestSubject() { - return DistributionStatus.DEPLOYED; - } - @Test - public void testGetName() throws Exception { - DistributionStatus testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); + public void deployedStatusShouldProvideCorrectStrings() { + assertThat(DistributionStatus.DEPLOYED.getName(), is("Deployed")); + assertThat(DistributionStatus.DEPLOYED.getAuditingStatus(), is("DEPLOYED")); } @Test - public void testGetAuditingStatus() throws Exception { - DistributionStatus testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAuditingStatus(); + public void shouldGetStatusByAuditingStatusName() { + DistributionStatus deployed = DistributionStatus.getStatusByAuditingStatusName("DEPLOYED"); + assertThat(deployed, is(DistributionStatus.DEPLOYED)); } @Test - public void testGetStatusByAuditingStatusName() throws Exception { - String auditingStatus = ""; - DistributionStatus result; - - // default test - result = DistributionStatus.getStatusByAuditingStatusName(auditingStatus); + public void shouldNotGetStatusByAuditingStatusName() { + DistributionStatus deployed = DistributionStatus.getStatusByAuditingStatusName("DIFFERENT_THAN_DEPLOYED"); + assertThat(deployed, is(nullValue())); } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/GenericArtifactQueryInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/GenericArtifactQueryInfoTest.java new file mode 100644 index 0000000000..e814605a71 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/GenericArtifactQueryInfoTest.java @@ -0,0 +1,55 @@ +/*- + * ============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.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.hamcrest.MatcherAssert.assertThat; + +import java.util.Collections; +import java.util.Set; +import org.junit.Test; + +public class GenericArtifactQueryInfoTest { + + private static final String ARTIFACT_UNIQUE_ID = "artifactId"; + private static final String PARENT_ID = "parentId"; + private static final Set<String> FIELDS = Collections.emptySet(); + + @Test + public void shouldHaveValidDefaultConstructor() { + assertThat(GenericArtifactQueryInfo.class, hasValidBeanConstructor()); + } + + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(GenericArtifactQueryInfo.class, hasValidGettersAndSetters()); + } + + @Test + public void shouldTestConstructorCorrectlySetFields(){ + GenericArtifactQueryInfo genericArtifactQueryInfo = new GenericArtifactQueryInfo(FIELDS, PARENT_ID, + ARTIFACT_UNIQUE_ID); + assertThat(genericArtifactQueryInfo.getArtifactUniqueId(), is(ARTIFACT_UNIQUE_ID)); + assertThat(genericArtifactQueryInfo.getFields(), is(FIELDS)); + assertThat(genericArtifactQueryInfo.getParentId(), is(PARENT_ID)); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupDefinitionInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupDefinitionInfoTest.java index 1fb44a0cb7..bc8041bfda 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupDefinitionInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupDefinitionInfoTest.java @@ -1,29 +1,120 @@ +/*- + * ============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.Ignore; +import java.util.ArrayList; +import java.util.List; import org.junit.Test; + +import com.google.code.beanmatchers.BeanMatchers; +import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition; import org.openecomp.sdc.be.model.GroupDefinition; import org.openecomp.sdc.be.model.GroupInstance; -import com.google.code.beanmatchers.BeanMatchers; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; - +import static org.hamcrest.Matchers.matchesPattern; public class GroupDefinitionInfoTest { - @Test - public void testCtor() { - new GroupDefinitionInfo(new GroupDefinition()); - new GroupDefinitionInfo(new GroupInstance()); - } - - @Ignore("the test fails on null pointer how ever the method does exists.") - @Test + + private static final String ARTIFACT_NAME = "artifactName"; + private static final String TO_STRING_REGEXP = "GroupDefinitionInfo \\[org.openecomp.sdc.be.info.GroupDefinitionInfo@" + + ".*" + ", isBase=true, artifacts=\\[org.openecomp.sdc.be.info.ArtifactDefinitionInfo@" + ".*" + "\\]\\]"; + private static final String GROUP_UUID = "GROUP_UUID"; + private static final String INVARIANT_UUID = "INVARIANT_UUID"; + private static final String VERSION = "VERSION"; + private static final String UNIQUE_ID = "UNIQUE_ID"; + private static final String DESC = "DESC"; + private static final String NAME = "NAME"; + + @Test + public void shouldHaveValidDefaultConstructor() { + assertThat(GroupDefinitionInfo.class, hasValidBeanConstructor()); + } + + @Test + public void testShouldConstructObjectFromGroupDefinition() { + GroupDefinition groupDefinition = createGroupDefinition(); + GroupDefinitionInfo groupDefinitionInfo = new GroupDefinitionInfo(groupDefinition); + assertThat(groupDefinitionInfo.getName(), is(groupDefinition.getName())); + assertThat(groupDefinitionInfo.getDescription(), is(groupDefinition.getDescription())); + assertThat(groupDefinitionInfo.getUniqueId(), is(groupDefinition.getUniqueId())); + assertThat(groupDefinitionInfo.getVersion(), is(groupDefinition.getVersion())); + assertThat(groupDefinitionInfo.getInvariantUUID(), is(groupDefinition.getInvariantUUID())); + assertThat(groupDefinitionInfo.getGroupUUID(), is(groupDefinition.getGroupUUID())); + } + + @Test + public void testShouldConstructObjectFromGroupInstance() { + GroupInstanceDataDefinition groupInstanceDataDefinition = createGroupInstanceDataDefinition(); + GroupInstance groupInstance = new GroupInstance(groupInstanceDataDefinition); + GroupDefinitionInfo groupDefinitionInfo = new GroupDefinitionInfo(groupInstance); + assertThat(groupDefinitionInfo.getName(), is(groupInstanceDataDefinition.getGroupName())); + assertThat(groupDefinitionInfo.getDescription(), is(groupInstanceDataDefinition.getDescription())); + assertThat(groupDefinitionInfo.getGroupInstanceUniqueId(), is(groupInstanceDataDefinition.getUniqueId())); + assertThat(groupDefinitionInfo.getVersion(), is(groupInstanceDataDefinition.getVersion())); + assertThat(groupDefinitionInfo.getInvariantUUID(), is(groupInstanceDataDefinition.getInvariantUUID())); + assertThat(groupDefinitionInfo.getGroupUUID(), is(groupInstanceDataDefinition.getGroupUUID())); + } + + @Test public void shouldHaveValidGettersAndSetters() { - assertThat(GroupDefinitionInfo.class, BeanMatchers.hasValidGettersAndSetters()); + assertThat(GroupDefinitionInfo.class, BeanMatchers.hasValidGettersAndSettersExcluding("artifacts", "properties")); } - + @Test public void testToString() { - (new GroupDefinitionInfo()).toString(); + GroupDefinitionInfo groupDefinitionInfo = new GroupDefinitionInfo(); + List<ArtifactDefinitionInfo> artifacts = new ArrayList<>(); + ArtifactDefinitionInfo artifactDefinitionInfo = new ArtifactDefinitionInfo(); + artifactDefinitionInfo.setArtifactName(ARTIFACT_NAME); + artifacts.add(artifactDefinitionInfo); + groupDefinitionInfo.setArtifacts(artifacts); + groupDefinitionInfo.setIsBase(true); + assertThat(groupDefinitionInfo.toString(), matchesPattern(TO_STRING_REGEXP)); } + + private GroupDefinition createGroupDefinition() { + GroupDataDefinition groupDataDefinition = new GroupDataDefinition(); + groupDataDefinition.setName(NAME); + groupDataDefinition.setDescription(DESC); + groupDataDefinition.setUniqueId(UNIQUE_ID); + groupDataDefinition.setVersion(VERSION); + groupDataDefinition.setInvariantUUID(INVARIANT_UUID); + groupDataDefinition.setGroupUUID(GROUP_UUID); + return new GroupDefinition(groupDataDefinition); + } + + private GroupInstanceDataDefinition createGroupInstanceDataDefinition() { + GroupInstanceDataDefinition groupInstanceDataDefinition = new GroupInstanceDataDefinition(); + groupInstanceDataDefinition.setGroupName(NAME); + groupInstanceDataDefinition.setDescription(DESC); + groupInstanceDataDefinition.setUniqueId(UNIQUE_ID); + groupInstanceDataDefinition.setVersion(VERSION); + groupInstanceDataDefinition.setInvariantUUID(INVARIANT_UUID); + groupInstanceDataDefinition.setGroupUUID(GROUP_UUID); + return groupInstanceDataDefinition; + } + }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupTemplateInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupTemplateInfoTest.java index 03573e13c6..dcce6fdb9b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupTemplateInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/GroupTemplateInfoTest.java @@ -1,13 +1,38 @@ +/*- + * ============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.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 GroupTemplateInfoTest { + @Test + public void shouldHaveValidDefaultConstructor() { + assertThat(DistributionStatusOfServiceListResponce.class, hasValidBeanConstructor()); + } @Test public void shouldHaveValidGettersAndSetters() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/NodeTypeInfoToUpdateArtifactsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/NodeTypeInfoToUpdateArtifactsTest.java index 25c71cfb41..388d63757b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/info/NodeTypeInfoToUpdateArtifactsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/NodeTypeInfoToUpdateArtifactsTest.java @@ -1,56 +1,54 @@ +/*- + * ============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.Test; -import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; -import org.openecomp.sdc.be.model.ArtifactDefinition; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import java.util.Collections; import java.util.EnumMap; import java.util.List; import java.util.Map; +import org.junit.Test; +import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; +import org.openecomp.sdc.be.model.ArtifactDefinition; public class NodeTypeInfoToUpdateArtifactsTest { - private NodeTypeInfoToUpdateArtifacts createTestSubject() { - return new NodeTypeInfoToUpdateArtifacts("", null); - } + private static final String NAME = "NAME"; + private static final Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> NODE_TYPES_ARTIFACTS_TO_HANDLE = Collections + .emptyMap(); @Test - public void testGetNodeName() throws Exception { - NodeTypeInfoToUpdateArtifacts testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getNodeName(); + public void shouldHaveValidGettersAndSetters() { + assertThat(NodeTypeInfoToUpdateArtifacts.class, hasValidGettersAndSetters()); } @Test - public void testSetNodeName() throws Exception { - NodeTypeInfoToUpdateArtifacts testSubject; - String nodeName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setNodeName(nodeName); - } - - @Test - public void testGetNodeTypesArtifactsToHandle() throws Exception { - NodeTypeInfoToUpdateArtifacts testSubject; - Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getNodeTypesArtifactsToHandle(); - } - - @Test - public void testSetNodeTypesArtifactsToHandle() throws Exception { - NodeTypeInfoToUpdateArtifacts testSubject; - Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = null; - - // default test - testSubject = createTestSubject(); - testSubject.setNodeTypesArtifactsToHandle(nodeTypesArtifactsToHandle); + public void shouldConstructCorrectObject() { + NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(NAME, + NODE_TYPES_ARTIFACTS_TO_HANDLE); + assertThat(nodeTypeInfoToUpdateArtifacts.getNodeName(), is(NAME)); + assertThat(nodeTypeInfoToUpdateArtifacts.getNodeTypesArtifactsToHandle(), is(NODE_TYPES_ARTIFACTS_TO_HANDLE)); } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/info/RelationshipListTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/info/RelationshipListTest.java new file mode 100644 index 0000000000..ac657ddfff --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/info/RelationshipListTest.java @@ -0,0 +1,40 @@ +/*- + * ============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.info; + +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 RelationshipListTest { + + @Test + public void shouldHaveValidDefaultConstructor() { + assertThat(RelationshipList.class, hasValidBeanConstructor()); + } + + @Test + public void shouldHaveValidGettersAndSetters() { + assertThat(RelationshipList.class, hasValidGettersAndSetters()); + } + +}
\ No newline at end of file |