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);
41 public void testEndsWith() {
42 String re=DbFilter.createDatabaseRegex("*abc");
43 assertEquals(".*abc", re);
46 public void testMultiple() {
47 String re=DbFilter.createDatabaseRegex("abc*ff*fa");
48 assertEquals("abc.*ff.*fa", re);
52 public void testPlaceholder() {
53 String re=DbFilter.createDatabaseRegex("abc?ef");
54 assertEquals("abc.{1,1}ef", re);
57 public void testCombined() {
58 String re=DbFilter.createDatabaseRegex("abc?ff*fa");
59 assertEquals("abc.{1,1}ff.*fa", re);
62 public void testFilterCheck() {
63 assertTrue(DbFilter.hasSearchParams("abc?"));
64 assertTrue(DbFilter.hasSearchParams("bac*"));
65 assertFalse(DbFilter.hasSearchParams("abc+"));
68 public void testRangeConversion() {
70 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"gte\":2230,\"boost\":2}}}}",
71 DbFilter.getRangeQuery("port", ">=2230").toJSON(),true);
72 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"gt\":2230,\"boost\":2}}}}",
73 DbFilter.getRangeQuery("port", ">2230").toJSON(),true);
74 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"lte\":2230,\"boost\":2}}}}",
75 DbFilter.getRangeQuery("port", "<=2230").toJSON(),true);
76 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"port\":{\"lt\":2230,\"boost\":2}}}}",
77 DbFilter.getRangeQuery("port", "<2230").toJSON(),true);
78 JSONAssert.assertEquals("", "{\"query\":{\"range\":{\"timestamp\":{\"lt\":\"2018-01-01T23:59:59.0Z\",\"boost\":2}}}}",
79 DbFilter.getRangeQuery("timestamp", "<2018-01-01T23:59:59.0Z").toJSON(),true);
80 } catch (JSONException e) {