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.workflow.services.types.WorkflowVersion;
25 import org.onap.sdc.workflow.services.types.WorkflowVersionState;
26 import org.openecomp.sdc.versioning.dao.types.Version;
27 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.context.annotation.ComponentScan;
30 import org.springframework.context.annotation.Configuration;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
34 @ContextConfiguration(classes = VersionMapperTest.VersionMapperSpringTestConfig.class)
35 @RunWith(SpringJUnit4ClassRunner.class)
36 public class VersionMapperTest {
39 @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStateMapper.class})
40 public static class VersionMapperSpringTestConfig { }
43 VersionMapper versionMapper;
47 public void shouldMapVersionToWorkflowVersion() {
48 Version version = createVersion();
49 WorkflowVersion mappedWorkflowVersion = versionMapper.versionToWorkflowVersion(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 = versionMapper.workflowVersionToVersion(workflowVersion);
62 assertEquals(mappedVersion.getId(), workflowVersion.getId());
63 assertEquals(mappedVersion.getBaseId(), workflowVersion.getBaseId());
64 assertEquals(mappedVersion.getDescription(), workflowVersion.getDescription());
65 assertEquals(mappedVersion.getName(), workflowVersion.getName());
66 assertEquals(mappedVersion.getCreationTime(), workflowVersion.getCreationTime());
67 assertEquals(mappedVersion.getModificationTime(), workflowVersion.getModificationTime());
71 private Version createVersion() {
72 Version version = new Version("version_id");
73 version.setBaseId("base_version_id");
74 version.setName("1.0");
75 version.setCreationTime(new Date());
76 version.setModificationTime(new Date());
77 version.setDescription("version_description");
78 version.setStatus(VersionStatus.Draft);
84 private WorkflowVersion createWorkflowVersion() {
85 WorkflowVersion workflowVersion = new WorkflowVersion();
86 workflowVersion.setId("wf_version_id");
87 workflowVersion.setBaseId("wf_base_version_id");
88 workflowVersion.setName("1.0");
89 workflowVersion.setCreationTime(new Date());
90 workflowVersion.setModificationTime(new Date());
91 workflowVersion.setDescription("version_description");
92 workflowVersion.setState(WorkflowVersionState.CERTIFIED);
94 return workflowVersion;