2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.sdc.be.components.impl;
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;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
38 import static org.junit.Assert.assertEquals;
40 @RunWith(MockitoJUnitRunner.class)
41 public class AnnotationBusinessLogicTest {
42 private static final String TEST = "TEST";
45 private AnnotationTypeOperations annotationTypeOperations;
47 private AnnotationValidator annotationValidator;
49 private InputDefinition inputDefinition;
51 private Annotation annotation;
53 private AnnotationTypeDefinition dbAnnotationTypeDefinition;
56 public void checkGetter() {
57 AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
59 assertEquals(annotationBusinessLogic.getAnnotationTypeOperations(), annotationTypeOperations);
63 public void shouldValidateAndMergeAnnotationsAndAssignToInput() {
64 AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
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);