Upload the ESR server seed code.
[aai/esr-server.git] / esr-core / esr-mgr / src / test / java / org / onap / aai / esr / db / util / HqlFactoryTest.java
1 /**
2  * Copyright 2016 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.aai.esr.db.util;
17
18 import static org.junit.Assert.assertEquals;
19
20 import org.junit.Test;
21 import org.onap.aai.esr.entity.db.VnfmData;
22 import org.onap.aai.esr.util.HqlFactory;
23
24
25 public class HqlFactoryTest {
26
27   @Test
28   public void when_input_entity_output_udatehql() {
29     VnfmData data = new VnfmData();
30     String filter = "vnfmId='xd03dsfsdfsfsdfsd'";
31     data.setName("csarName");
32     data.setType("NS");
33     String expect =
34         "update VnfmData set name='csarName',type='NS' where vnfmId='xd03dsfsdfsfsdfsd'";
35     String actual = HqlFactory.getUpdateHql(data, null, filter);
36     assertEquals(expect, actual);
37   }
38
39   @Test
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);
47     src = new String[1];
48     actual = HqlFactory.contain(src, null);
49     assertEquals(expect, actual);
50   }
51
52   @Test
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);
59   }
60
61   @Test
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);
68   }
69
70   @Test
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);
78   }
79
80   @Test
81   public void when_input_entity_output_queryhql() {
82     VnfmData data = new VnfmData();
83     String filter = "vnfmId";
84     data.setName("csarName");
85     data.setType("NS");
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);
89   }
90
91 }