2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.common.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
29 import org.json.JSONException;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter;
33 public class TestDatabaseFilterConversion {
36 public void testStartsWith() {
37 String re = DbFilter.createDatabaseRegex("abc*");
38 assertEquals("abc.*", re);
42 public void testEndsWith() {
43 String re = DbFilter.createDatabaseRegex("*abc");
44 assertEquals(".*abc", re);
48 public void testMultiple() {
49 String re = DbFilter.createDatabaseRegex("abc*ff*fa");
50 assertEquals("abc.*ff.*fa", re);
54 public void testPlaceholder() {
55 String re = DbFilter.createDatabaseRegex("abc?ef");
56 assertEquals("abc.{1,1}ef", re);
60 public void testCombined() {
61 String re = DbFilter.createDatabaseRegex("abc?ff*fa");
62 assertEquals("abc.{1,1}ff.*fa", re);
66 public void testFilterCheck() {
67 assertTrue(DbFilter.hasSearchParams("abc?"));
68 assertTrue(DbFilter.hasSearchParams("bac*"));
69 assertFalse(DbFilter.hasSearchParams("abc+"));
73 public void testRangeConversion() {
75 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"gte\":2230,\"boost\":2}}}}",
76 DbFilter.getRangeQuery("port", ">=2230").toJSON(), true);
77 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"gt\":2230,\"boost\":2}}}}",
78 DbFilter.getRangeQuery("port", ">2230").toJSON(), true);
79 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"lte\":2230,\"boost\":2}}}}",
80 DbFilter.getRangeQuery("port", "<=2230").toJSON(), true);
81 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"lt\":2230,\"boost\":2}}}}",
82 DbFilter.getRangeQuery("port", "<2230").toJSON(), true);
83 JSONAssert.assertEquals("",
84 "{\"query\":{\"range\":{\"timestamp\":{\"lt\":\"2018-01-01T23:59:59.0Z\",\"boost\":2}}}}",
85 DbFilter.getRangeQuery("timestamp", "<2018-01-01T23:59:59.0Z").toJSON(), true);
86 } catch (JSONException e) {