Use versioning, zusammen and session libs from sdc-common-be
[sdc/sdc-workflow-designer.git] / workflow-designer-be / src / test / java / org / onap / sdc / workflow / services / impl / mappers / WorkflowMapperTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.sdc.workflow.services.impl.mappers;
18
19
20 import static org.junit.Assert.assertEquals;
21 import static org.onap.sdc.workflow.TestUtil.createItem;
22 import static org.onap.sdc.workflow.TestUtil.createWorkflow;
23
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.onap.sdc.common.versioning.services.types.Item;
27 import org.onap.sdc.common.versioning.services.types.ItemStatus;
28 import org.onap.sdc.workflow.services.impl.ItemType;
29 import org.onap.sdc.workflow.services.types.ArchivingStatus;
30 import org.onap.sdc.workflow.services.types.Workflow;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.annotation.ComponentScan;
33 import org.springframework.context.annotation.Configuration;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36
37 @ContextConfiguration(classes = WorkflowMapperTest.WorkflowMapperSpringTestConfig.class)
38 @RunWith(SpringJUnit4ClassRunner.class)
39 public class WorkflowMapperTest {
40
41     @Configuration
42     @ComponentScan(basePackageClasses = {WorkflowMapper.class})
43     public static class WorkflowMapperSpringTestConfig { }
44
45     @Autowired
46     WorkflowMapper workflowMapper;
47
48     @Test
49     public void shouldMapItemToWorkflow() {
50
51         Item item = createItem(1, false, true, ItemStatus.ACTIVE);
52         Workflow mappedWorkflow = workflowMapper.fromItem(item);
53         assertEquals(mappedWorkflow.getId(), item.getId());
54         assertEquals(mappedWorkflow.getDescription(), item.getDescription());
55         assertEquals(mappedWorkflow.getName(), item.getName());
56         assertEquals(mappedWorkflow.getArchiving().name(), item.getStatus().name());
57     }
58
59     @Test
60     public void shouldMapWorkflowToItem() {
61
62         Workflow workflow = createWorkflow(1, true, ArchivingStatus.ARCHIVED);
63         Item mappedItem = new Item();
64         workflowMapper.toItem(workflow, mappedItem);
65         assertEquals(ItemType.WORKFLOW.name(), mappedItem.getType());
66         assertEquals(workflow.getDescription(), mappedItem.getDescription());
67         assertEquals(workflow.getName(), mappedItem.getName());
68     }
69
70 }