2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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=========================================================
21 package org.onap.sdc.tosca.parser.elements.queries;
23 import static org.junit.jupiter.api.Assertions.assertFalse;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.mockito.Mockito.when;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.jupiter.MockitoExtension;
32 import org.onap.sdc.tosca.parser.enums.SdcTypes;
33 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
34 import org.onap.sdc.toscaparser.api.NodeTemplate;
35 import org.onap.sdc.toscaparser.api.elements.Metadata;
37 @ExtendWith(MockitoExtension.class)
38 public class TopologyTemplateQueryTest {
41 private Metadata metadata;
44 private NodeTemplate nodeTemplate;
47 public void objectIsNotTopologyTemplate() {
48 assertThrows(IllegalArgumentException.class, () -> {
49 TopologyTemplateQuery.newBuilder(SdcTypes.CP).build();
54 public void templateIsFoundByTypeOnly() {
55 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
57 when(nodeTemplate.getMetaData()).thenReturn(metadata);
58 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
59 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
63 public void templateIsNotFoundWhenMetadataIsNull() {
64 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
66 when(nodeTemplate.getMetaData()).thenReturn(null);
67 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
71 public void templateIsFoundIfItIsService() {
72 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
74 when(nodeTemplate.getMetaData()).thenReturn(metadata);
75 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
76 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
80 public void templateIsFoundByTypeAndCUUID() {
81 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
82 .customizationUUID("345")
84 when(nodeTemplate.getMetaData()).thenReturn(metadata);
85 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
86 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
87 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
91 public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsNotSet() {
92 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
94 when(nodeTemplate.getMetaData()).thenReturn(metadata);
95 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
96 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
100 public void templateIsFoundWhenTypeIsMatchedCuuidIsProvidedAndCuuidIsNullInMetadata() {
101 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
102 .customizationUUID("2345")
104 when(nodeTemplate.getMetaData()).thenReturn(metadata);
105 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
106 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
107 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
111 public void templateIsFoundWhenTypeIsMatchedAndCuuidIsNullInMetadata() {
112 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
114 when(nodeTemplate.getMetaData()).thenReturn(metadata);
115 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
116 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
117 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
121 public void templateIsNotFoundWhenTypeIsMatchedAndCuuidIsSet() {
122 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
123 .customizationUUID("345")
125 when(nodeTemplate.getMetaData()).thenReturn(metadata);
126 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
127 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
128 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
132 public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsSet() {
133 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CR)
134 .customizationUUID("345")
136 when(nodeTemplate.getMetaData()).thenReturn(metadata);
137 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
138 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));