2 * Copyright 2016 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.aai.esr.db.util;
18 import static org.junit.Assert.assertEquals;
20 import org.junit.Test;
21 import org.onap.aai.esr.entity.db.VnfmData;
22 import org.onap.aai.esr.util.HqlFactory;
25 public class HqlFactoryTest {
28 public void when_input_entity_output_udatehql() {
29 VnfmData data = new VnfmData();
30 String filter = "vnfmId='xd03dsfsdfsfsdfsd'";
31 data.setName("csarName");
34 "update VnfmData set name='csarName',type='NS' where vnfmId='xd03dsfsdfsfsdfsd'";
35 String actual = HqlFactory.getUpdateHql(data, null, filter);
36 assertEquals(expect, actual);
40 public void when_input_null_testContain_output_false() {
41 boolean expect = false;
42 boolean actual = HqlFactory.contain(null, "name");
43 assertEquals(expect, actual);
44 String[] src = new String[0];
45 actual = HqlFactory.contain(src, "name");
46 assertEquals(expect, actual);
48 actual = HqlFactory.contain(src, null);
49 assertEquals(expect, actual);
53 public void when_input_src_contain_target_testContain_output_true() {
54 boolean expect = true;
55 String [] src = {"name", "type"};
56 String target = "name";
57 boolean actual = HqlFactory.contain(src, target);
58 assertEquals(expect, actual);
62 public void when_input_src_not_contain_target_testContain_output_false() {
63 boolean expect = false;
64 String [] src = {"name", "type"};
65 String target = "version";
66 boolean actual = HqlFactory.contain(src, target);
67 assertEquals(expect, actual);
71 public void testGetOidFilter() {
72 // fail("Not yet implemented");
73 String key = "csarId";
74 String value = "xd03dsfsdfsfsdfsd";
75 String expect = "csarId= 'xd03dsfsdfsfsdfsd'";
76 String actual = HqlFactory.getOidFilter(key, value);
77 assertEquals(expect, actual);
81 public void when_input_entity_output_queryhql() {
82 VnfmData data = new VnfmData();
83 String filter = "vnfmId";
84 data.setName("csarName");
86 String expect = "select q.vnfmId from VnfmData as q where q.name='csarName' and q.type='NS'";
87 String actual = HqlFactory.getQueryHql(data, filter);
88 assertEquals(expect, actual);