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 / ConfigTransactionLogDaoTest.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.HashMap;\r
21 import java.util.List;\r
22 import java.util.Map;\r
23 import org.junit.Assert;\r
24 import org.junit.Before;\r
25 import org.junit.FixMethodOrder;\r
26 import org.junit.Test;\r
27 import org.junit.runner.RunWith;\r
28 import org.junit.runners.MethodSorters;\r
29 import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants;\r
30 import org.onap.ccsdk.features.data.adaptor.dao.NamedQueryExecutorDao;\r
31 import org.onap.ccsdk.features.data.adaptor.dao.TransactionLogDao;\r
32 import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog;\r
33 import org.springframework.beans.factory.annotation.Autowired;\r
34 import org.springframework.test.context.ContextConfiguration;\r
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;\r
36 import com.att.eelf.configuration.EELFLogger;\r
37 import com.att.eelf.configuration.EELFManager;\r
38 \r
39 @RunWith(SpringJUnit4ClassRunner.class)\r
40 @ContextConfiguration(locations = {"classpath:test-context-h2db.xml"})\r
41 @FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
42 public class ConfigTransactionLogDaoTest {\r
43     private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigTransactionLogDaoTest.class);\r
44 \r
45     @Autowired\r
46     private TransactionLogDao transactionLogDao;\r
47 \r
48     @Autowired\r
49     private NamedQueryExecutorDao namedQueryExecutorDao;\r
50 \r
51     @Before\r
52     public void initialise() {\r
53 \r
54     }\r
55 \r
56     @Test\r
57     public void testQueryExecution() throws Exception {\r
58         String requestId = "12345";\r
59 \r
60         transactionLogDao\r
61                 .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, "Received Request"));\r
62 \r
63         List<TransactionLog> result = transactionLogDao.getTransactionsByRequestId(requestId);\r
64         logger.info("DB ArtifactReference :" + result);\r
65         Assert.assertNotNull("Failed to get Query Result", result);\r
66 \r
67         List<TransactionLog> result2 =\r
68                 transactionLogDao.getTransactionsByRequestId(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG);\r
69         logger.info("DB ArtifactReference :" + result2);\r
70         Assert.assertNotNull("Failed to get Query Result", result2);\r
71 \r
72         String namedsql = "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = :request_id";\r
73         Map<String, Object> parameters = new HashMap<>();\r
74         parameters.put("request_id", "12345");\r
75         List<Map<String, Object>> namedresult = namedQueryExecutorDao.query(namedsql, parameters);\r
76         logger.info("DB ArtifactReference :" + namedresult);\r
77         Assert.assertNotNull("Failed to get Query Result", namedresult);\r
78 \r
79     }\r
80 \r
81 }\r