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