Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / AnnotationBusinessLogicTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.be.components.impl;
21
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.Mockito;
26 import org.mockito.junit.MockitoJUnitRunner;
27 import org.openecomp.sdc.be.components.validation.AnnotationValidator;
28 import org.openecomp.sdc.be.datatypes.elements.Annotation;
29 import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
30 import org.openecomp.sdc.be.model.InputDefinition;
31 import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
32
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37
38 import static org.junit.Assert.assertEquals;
39
40 @RunWith(MockitoJUnitRunner.class)
41 public class AnnotationBusinessLogicTest {
42     private static final String TEST = "TEST";
43
44     @Mock
45     private AnnotationTypeOperations annotationTypeOperations;
46     @Mock
47     private AnnotationValidator annotationValidator;
48     @Mock
49     private InputDefinition inputDefinition;
50     @Mock
51     private Annotation annotation;
52     @Mock
53     private AnnotationTypeDefinition dbAnnotationTypeDefinition;
54
55     @Test
56     public void checkGetter() {
57         AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
58             annotationValidator);
59         assertEquals(annotationBusinessLogic.getAnnotationTypeOperations(), annotationTypeOperations);
60     }
61
62     @Test
63     public void shouldValidateAndMergeAnnotationsAndAssignToInput() {
64         AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
65             annotationValidator);
66         Map<String, InputDefinition> inputs = new HashMap<>();
67         inputs.put(TEST, inputDefinition);
68         List<Annotation> annotations = new ArrayList<>();
69         annotations.add(annotation);
70         Mockito.when(inputDefinition.getAnnotations()).thenReturn(annotations);
71         Mockito.when(annotationTypeOperations.getLatestType(Mockito.any())).thenReturn(dbAnnotationTypeDefinition);
72         annotationBusinessLogic.validateAndMergeAnnotationsAndAssignToInput(inputs);
73         List<Annotation> result = inputDefinition.getAnnotations();
74         assertEquals(result.size(),1);
75     }
76 }