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 org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.runners.MockitoJUnitRunner;
27 import org.onap.sdc.tosca.parser.enums.SdcTypes;
28 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
29 import org.onap.sdc.toscaparser.api.NodeTemplate;
30 import org.onap.sdc.toscaparser.api.elements.Metadata;
32 import static org.junit.Assert.assertTrue;
33 import static org.mockito.Mockito.when;
34 import static org.testng.Assert.assertFalse;
36 @RunWith(MockitoJUnitRunner.class)
37 public class TopologyTemplateQueryTest {
40 private Metadata metadata;
43 private NodeTemplate nodeTemplate;
45 @Test(expected=IllegalArgumentException.class)
46 public void objectIsNotTopologyTemplate() {
47 TopologyTemplateQuery.newBuilder(SdcTypes.CP)
52 public void templateIsFoundByTypeOnly() {
53 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
55 when(nodeTemplate.getMetaData()).thenReturn(metadata);
56 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
57 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
58 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
62 public void templateIsNotFoundWhenMetadataIsNull() {
63 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
65 when(nodeTemplate.getMetaData()).thenReturn(null);
66 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
70 public void templateIsFoundIfItIsService() {
71 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
73 when(nodeTemplate.getMetaData()).thenReturn(metadata);
74 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
75 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
79 public void templateIsFoundByTypeAndCUUID() {
80 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
81 .customizationUUID("345")
83 when(nodeTemplate.getMetaData()).thenReturn(metadata);
84 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
85 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
86 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
90 public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsNotSet() {
91 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
93 when(nodeTemplate.getMetaData()).thenReturn(metadata);
94 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
95 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
99 public void templateIsFoundWhenTypeIsMatchedCuuidIsProvidedAndCuuidIsNullInMetadata() {
100 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
101 .customizationUUID("2345")
103 when(nodeTemplate.getMetaData()).thenReturn(metadata);
104 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
105 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
106 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
110 public void templateIsFoundWhenTypeIsMatchedAndCuuidIsNullInMetadata() {
111 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
113 when(nodeTemplate.getMetaData()).thenReturn(metadata);
114 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
115 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
116 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
120 public void templateIsNotFoundWhenTypeIsMatchedAndCuuidIsSet() {
121 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
122 .customizationUUID("345")
124 when(nodeTemplate.getMetaData()).thenReturn(metadata);
125 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
126 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
127 assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
131 public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsSet() {
132 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CR)
133 .customizationUUID("345")
135 when(nodeTemplate.getMetaData()).thenReturn(metadata);
136 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
137 when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
138 assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));