ce3e95224b6c31b82b079d4a1af97cd017efe504
[ccsdk/features.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
5  * in compliance with the License. You may obtain a copy of the License at\r
6  * \r
7  * http://www.apache.org/licenses/LICENSE-2.0\r
8  * \r
9  * Unless required by applicable law or agreed to in writing, software distributed under the License\r
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
11  * or implied. See the License for the specific language governing permissions and limitations under\r
12  * the License.\r
13  */\r
14 \r
15 package org.onap.ccsdk.config.data.adaptor.dao;\r
16 \r
17 import java.util.Date;\r
18 import org.junit.Assert;\r
19 import org.junit.Before;\r
20 import org.junit.FixMethodOrder;\r
21 import org.junit.Test;\r
22 import org.junit.runner.RunWith;\r
23 import org.junit.runners.MethodSorters;\r
24 import org.springframework.beans.factory.annotation.Autowired;\r
25 import org.springframework.test.context.ContextConfiguration;\r
26 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;\r
27 import com.att.eelf.configuration.EELFLogger;\r
28 import com.att.eelf.configuration.EELFManager;\r
29 \r
30 @RunWith(SpringJUnit4ClassRunner.class)\r
31 @ContextConfiguration(locations = {"classpath:test-context-h2db.xml"})\r
32 @FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
33 public class QueryExecutorDaoTest {\r
34     private static EELFLogger logger = EELFManager.getInstance().getLogger(QueryExecutorDaoTest.class);\r
35     \r
36     @Autowired\r
37     private QueryExecutorDao queryExecutorDao;\r
38     \r
39     @Before\r
40     public void initialise() {\r
41         \r
42     }\r
43     \r
44     @Test\r
45     public void testInsertQueryExecution() throws Exception {\r
46         \r
47         String sql = "INSERT INTO CONFIG_RESOURCE"\r
48                 + "(config_resource_id, resource_id, resource_type, template_name, recipe_name, request_id, resource_data, mask_data, created_date, updated_by) "\r
49                 + "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";\r
50         Object[] data =\r
51                 new Object[] {"12345", "vUSP - vDBE-IPX HUB", "1234567", "activate-action", "vrr-service-template",\r
52                         "resource-data", "mask-data", null, new Date(System.currentTimeMillis()), "ab1234"};\r
53         int result = queryExecutorDao.update(sql, data);\r
54         logger.info("Updated successfully rows :" + result);\r
55         Assert.assertNotNull("Failed to get Query Result", result);\r
56     }\r
57     \r
58     @Test\r
59     public void testUpdateQueryExecution() throws Exception {\r
60         \r
61         String sql = "UPDATE CONFIG_RESOURCE set recipe_name=? where config_resource_id=?";\r
62         Object[] data = new Object[] {"vce-service-template", "12345"};\r
63         int result = queryExecutorDao.update(sql, data);\r
64         logger.info("Updated successfully rows :" + result);\r
65         Assert.assertNotNull("Failed to get Query Result", result);\r
66     }\r
67     \r
68     @Test\r
69     public void testDeleteQueryExecution() throws Exception {\r
70         \r
71         String sql = "DELETE FROM CONFIG_RESOURCE where config_resource_id=?";\r
72         Object[] data = new Object[] {"12345"};\r
73         int result = queryExecutorDao.update(sql, data);\r
74         logger.info("Updated successfully rows :" + result);\r
75         Assert.assertNotNull("Failed to get Query Result", result);\r
76     }\r
77     \r
78 }\r