9ea007cec8ff852dddd10dedab88c089b59f2a25
[sdc/sdc-workflow-designer.git] /
1 /*
2  * Copyright © 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 package org.onap.sdc.workflow.api.types;
17
18 import static junit.framework.TestCase.assertEquals;
19 import static junit.framework.TestCase.fail;
20
21 import java.util.Arrays;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.onap.sdc.workflow.persistence.types.ParameterEntity;
26 import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
27 import org.onap.sdc.workflow.services.exceptions.VersionValidationException;
28 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
29
30 @RunWith(SpringJUnit4ClassRunner.class)
31 public class WorkflowVersionValidatorTest {
32
33     private static final String ITEM1_ID = "item_id_1";
34
35     @InjectMocks
36     private WorkflowVersionValidator versionValidator;
37
38     @Test
39     public void invalidInputs() {
40         WorkflowVersion workflowVersion = new WorkflowVersion();
41         workflowVersion.setDescription("version description");
42         ParameterEntity input = new ParameterEntity();
43         input.setName("input1");
44         workflowVersion.setInputs(Arrays.asList(input, input));
45         try {
46             versionValidator.validate(ITEM1_ID, workflowVersion);
47             fail("Should have thrown VersionValidationException but did not!");
48
49         } catch (VersionValidationException ex) {
50             assertEquals(String.format("Error creating or modifying version for workflow with id %s: %s", ITEM1_ID,
51                     "Input name must be unique"), ex.getMessage());
52         }
53     }
54
55     @Test
56     public void invalidOtputs(){
57         WorkflowVersion workflowVersion = new WorkflowVersion();
58         workflowVersion.setDescription("version description");
59         ParameterEntity output = new ParameterEntity();
60         output.setName("output1");
61         workflowVersion.setOutputs(Arrays.asList(output, output));
62         try {
63             versionValidator.validate(ITEM1_ID, workflowVersion);
64             fail("Should have thrown VersionValidationException but did not!");
65
66         } catch (VersionValidationException ex) {
67             assertEquals(String.format("Error creating or modifying version for workflow with id %s: %s", ITEM1_ID,
68                     "Output name must be unique"), ex.getMessage());
69         }
70     }
71 }