From 523dd7a1328e7be22f0e3cecd0cc504462a70ee7 Mon Sep 17 00:00:00 2001 From: vempo Date: Sat, 17 Nov 2018 18:58:36 +0200 Subject: [PATCH] Unit-tests for mappers in item services Change-Id: I44b2574a70f6ad357dd0528f9bf4b3608ec33063 Issue-ID: SDC-1917 Signed-off-by: vempo (cherry picked from commit 03fb4087901e4cf56b02f6a9456d987f28844a2f) --- .../item-rest/item-rest-services/pom.xml | 6 +- .../mapping/MapActivityLogEntityToDtoTest.java | 70 ++++++++++++++++++ .../item/rest/mapping/MapItemToDtoTest.java | 72 +++++++++++++++++++ .../item/rest/mapping/MapRevisionToDtoTest.java | 57 +++++++++++++++ .../item/rest/mapping/MapVersionToDtoTest.java | 82 ++++++++++++++++++++++ 5 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDtoTest.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDtoTest.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDtoTest.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDtoTest.java diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/pom.xml b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/pom.xml index 2afd375a44..afda696e7d 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/pom.xml +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/pom.xml @@ -52,7 +52,11 @@ org.springframework spring-context - ${spring.framework.version} + + + junit + junit + test diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDtoTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDtoTest.java new file mode 100644 index 0000000000..3bfc3f7afc --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapActivityLogEntityToDtoTest.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdcrests.item.rest.mapping; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; +import org.junit.Test; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.activitylog.dao.type.ActivityType; +import org.openecomp.sdcrests.item.types.ActivityLogDto; + +/** + * This class was generated. + */ +public class MapActivityLogEntityToDtoTest { + + @Test() + public void testConversion() { + + final ActivityLogEntity source = new ActivityLogEntity(); + + final String id = "e8ad437b-8d86-4819-954f-57fb9161a912"; + source.setId(id); + + final ActivityType type = ActivityType.Upload_Artifact; + source.setType(type); + + final String user = "278dbb70-469d-4a5f-bea2-bc62fa9d4671"; + source.setUser(user); + + final Date timestamp = new Date(); + source.setTimestamp(timestamp); + + final String comment = "1cf631a9-016b-4914-9ced-ded9d5ba9469"; + source.setComment(comment); + + final boolean success = true; + source.setSuccess(true); + + final String message = "9b5e29e9-b47a-4ece-b8a0-b68f4b346e3b"; + source.setMessage(message); + + final ActivityLogDto target = new ActivityLogDto(); + final MapActivityLogEntityToDto mapper = new MapActivityLogEntityToDto(); + mapper.doMapping(source, target); + + assertEquals(id, target.getId()); + assertEquals(timestamp, target.getTimestamp()); + assertEquals(type.name(), target.getType()); + assertEquals(comment, target.getComment()); + assertEquals(user, target.getUser()); + assertEquals(success, target.getStatus().isSuccess()); + assertEquals(message, target.getStatus().getMessage()); + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDtoTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDtoTest.java new file mode 100644 index 0000000000..1de05e77c9 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDtoTest.java @@ -0,0 +1,72 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdcrests.item.rest.mapping; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.util.Collections; +import java.util.Map; +import org.junit.Test; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; +import org.openecomp.sdcrests.item.types.ItemDto; + +/** + * This class was generated. + */ +public class MapItemToDtoTest { + + @Test + public void testConversion() { + + final Item source = new Item(); + + final String id = "8c3cf5c1-956d-4701-9805-41ee7496a4b0"; + source.setId(id); + + final String type = "0df6dc63-30a9-453c-9d20-ccd839b30e55"; + source.setType(type); + + final String name = "fa425317-c53a-4ad2-94f5-9a33f2b76e67"; + source.setName(name); + + final String owner = "db08f579-7f4c-4d1a-ae92-a1c1c27c8cc6"; + source.setOwner(owner); + + final ItemStatus status = ItemStatus.ARCHIVED; + source.setStatus(status); + + final String description = "9b5e29e9-b47a-4ece-b8a0-b68f4b346e3b"; + source.setDescription(description); + + final Map properties = Collections.emptyMap(); + source.setProperties(properties); + + final ItemDto target = new ItemDto(); + final MapItemToDto mapper = new MapItemToDto(); + mapper.doMapping(source, target); + + assertEquals(id, target.getId()); + assertEquals(type, target.getType()); + assertEquals(name, target.getName()); + assertEquals(description, target.getDescription()); + assertEquals(owner, target.getOwner()); + assertEquals(status.name(), target.getStatus()); + assertSame(properties, target.getProperties()); + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDtoTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDtoTest.java new file mode 100644 index 0000000000..f9df2093b8 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapRevisionToDtoTest.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdcrests.item.rest.mapping; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; +import org.junit.Test; +import org.openecomp.sdc.versioning.dao.types.Revision; +import org.openecomp.sdcrests.item.types.RevisionDto; + +/** + * This class was generated. + */ +public class MapRevisionToDtoTest { + + @Test() + public void testConversion() { + + final Revision source = new Revision(); + + final String id = "ecbf1a77-a420-4655-b2fc-e403a703036d"; + source.setId(id); + + final String message = "2f2a55c8-90b6-413c-bf31-168108e75cb3"; + source.setMessage(message); + + final Date time = new Date(); + source.setTime(time); + + final String user = "503cf667-028b-4d53-bf76-68ad85edf51d"; + source.setUser(user); + + final RevisionDto target = new RevisionDto(); + final MapRevisionToDto mapper = new MapRevisionToDto(); + mapper.doMapping(source, target); + + assertEquals(id, target.getId()); + assertEquals(message, target.getMessage()); + assertEquals(time, target.getTime()); + assertEquals(user, target.getUser()); + } +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDtoTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDtoTest.java new file mode 100644 index 0000000000..706de57ac7 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/test/java/org/openecomp/sdcrests/item/rest/mapping/MapVersionToDtoTest.java @@ -0,0 +1,82 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdcrests.item.rest.mapping; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.util.Collections; +import java.util.Date; +import java.util.Map; +import org.junit.Test; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionState; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdcrests.item.types.VersionDto; + +/** + * This class was generated. + */ +public class MapVersionToDtoTest { + + @Test() + public void testConversion() { + + final Version source = new Version(); + + final String id = "2cb11529-5b9c-4561-a6d6-9188d3df84d6"; + source.setId(id); + + final String name = "c9798995-750d-4759-99ac-7942b24e356a"; + source.setName(name); + + final String description = "269d595d-e818-41d0-a991-bf6dccab8125"; + source.setDescription(description); + + final String baseId = "d8efa2d7-8def-4646-8b9d-363ae102cde0"; + source.setBaseId(baseId); + + final Date creationTime = new Date(); + source.setCreationTime(creationTime); + + final Date modificationTime = new Date(); + source.setModificationTime(modificationTime); + + final VersionStatus status = VersionStatus.Deleted; + source.setStatus(status); + + final VersionState state = new VersionState(); + source.setState(state); + + final Map additionalInfo = Collections.emptyMap(); + source.setAdditionalInfo(additionalInfo); + + final VersionDto target = new VersionDto(); + final MapVersionToDto mapper = new MapVersionToDto(); + mapper.doMapping(source, target); + + assertEquals(id, target.getId()); + assertEquals(name, target.getName()); + assertEquals(description, target.getDescription()); + assertEquals(baseId, target.getBaseId()); + assertSame(status, target.getStatus()); + assertSame(state, target.getState()); + assertEquals(creationTime, target.getCreationTime()); + assertEquals(modificationTime, target.getModificationTime()); + assertSame(additionalInfo, target.getAdditionalInfo()); + } +} -- 2.16.6