2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.sdc.workflow.services.impl.mappers;
19 import static org.junit.Assert.assertEquals;
21 import java.util.Date;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.onap.sdc.common.versioning.persistence.types.InternalVersion;
25 import org.onap.sdc.common.versioning.services.types.Version;
26 import org.onap.sdc.common.versioning.services.types.VersionStatus;
27 import org.onap.sdc.workflow.services.types.WorkflowVersion;
28 import org.onap.sdc.workflow.services.types.WorkflowVersionState;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.ComponentScan;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
35 @ContextConfiguration(classes = VersionMapperTest.VersionMapperSpringTestConfig.class)
36 @RunWith(SpringJUnit4ClassRunner.class)
37 public class VersionMapperTest {
40 @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStateMapper.class})
41 public static class VersionMapperSpringTestConfig { }
44 VersionMapper versionMapper;
47 public void shouldMapVersionToWorkflowVersion() {
48 Version version = createVersion();
49 WorkflowVersion mappedWorkflowVersion = versionMapper.fromVersion(version);
50 assertEquals(mappedWorkflowVersion.getId(), version.getId());
51 assertEquals(mappedWorkflowVersion.getBaseId(), version.getBaseId());
52 assertEquals(mappedWorkflowVersion.getDescription(), version.getDescription());
53 assertEquals(mappedWorkflowVersion.getName(), version.getName());
54 assertEquals(mappedWorkflowVersion.getCreationTime(), version.getCreationTime());
55 assertEquals(mappedWorkflowVersion.getModificationTime(), version.getModificationTime());
59 public void shouldMapWorkflowVersionToVersion() {
60 WorkflowVersion workflowVersion = createWorkflowVersion();
61 Version mappedVersion = new Version();
62 versionMapper.toVersion(workflowVersion, mappedVersion);
63 assertEquals(mappedVersion.getDescription(), workflowVersion.getDescription());
67 private Version createVersion() {
68 InternalVersion version = new InternalVersion();
69 version.setId("version_id");
70 version.setBaseId("base_version_id");
71 version.setName("1.0");
72 version.setCreationTime(new Date());
73 version.setModificationTime(new Date());
74 version.setDescription("version_description");
75 version.setStatus(VersionStatus.Draft);
81 private WorkflowVersion createWorkflowVersion() {
82 WorkflowVersion workflowVersion = new WorkflowVersion();
83 workflowVersion.setId("wf_version_id");
84 workflowVersion.setBaseId("wf_base_version_id");
85 workflowVersion.setName("1.0");
86 workflowVersion.setCreationTime(new Date());
87 workflowVersion.setModificationTime(new Date());
88 workflowVersion.setDescription("version_description");
89 workflowVersion.setState(WorkflowVersionState.CERTIFIED);
91 return workflowVersion;