aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java')
-rw-r--r--sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java183
1 files changed, 183 insertions, 0 deletions
diff --git a/sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java b/sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java
new file mode 100644
index 0000000..a9af7d9
--- /dev/null
+++ b/sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java
@@ -0,0 +1,183 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-tosca
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.tosca.parser.elements.queries;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.sdc.tosca.parser.enums.EntityTemplateType;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class EntityQueryTest {
+ @Mock
+ private Metadata metadata;
+
+ @Test
+ public void findEntityWhenUuidAndCuudNotSetAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenMetadataIsNull() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .build();
+ assertFalse(entityQuery.isSearchCriteriaMatched(null,"abc"));
+ }
+
+ @Test
+ public void findEntityWhenMetadataIsNullAndUuidsAreProvided() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE)
+ .customizationUUID("2345")
+ .uUID("9700")
+ .build();
+ assertFalse(entityQuery.isSearchCriteriaMatched(null, ""));
+ }
+
+ @Test
+ public void findEntityWhenUuidIsSetAndMatchedAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("123")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, "abc"));
+ }
+
+ @Test
+ public void findEntityWhenUuidIsSetAndMatchedAndCuuidIsNullAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("123")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn(null);
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenUuidAndCuuidAreSetAndMatchedAndCuuidIsNullAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("123")
+ .customizationUUID("567")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn(null);
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.POLICY)
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, "qwe"));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedPartiallyAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.POLICY)
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("444");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenUuidIsSetAndDoesNotMatchAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("7890")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeIsNull() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.POLICY)
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, null));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeIsNotMatched() {
+ EntityQuery entityQuery = EntityQuery.newBuilder("a.policies.b")
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, "abc"));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeIsMatched() {
+ EntityQuery entityQuery = EntityQuery.newBuilder("a.groups.b")
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, "a.groups.b"));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreNotMatchedAndToscaTypeIsMatched() {
+ EntityQuery entityQuery = EntityQuery.newBuilder("a.groups.b")
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("12345");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("3456");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, "a.groups.b"));
+ }
+}