Fix OSGi wiring issues
[ccsdk/features.git] / blueprints-processor / adaptors / data-adaptor-provider / src / test / java / org / onap / ccsdk / config / data / adaptor / service / ConfigResourceNodeTest.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.config.data.adaptor.service;\r
19 \r
20 import java.util.HashMap;\r
21 import java.util.Map;\r
22 import org.junit.Assert;\r
23 import org.junit.Before;\r
24 import org.junit.Test;\r
25 import org.junit.runner.RunWith;\r
26 import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants;\r
27 import org.onap.ccsdk.config.data.adaptor.dao.ConfigPropertyMapDao;\r
28 import org.onap.ccsdk.config.data.adaptor.dao.ConfigResourceDao;\r
29 import org.onap.ccsdk.config.data.adaptor.dao.NamedQueryExecutorDao;\r
30 import org.onap.ccsdk.config.data.adaptor.dao.QueryExecutorDao;\r
31 import org.onap.ccsdk.config.data.adaptor.dao.TransactionLogDao;\r
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
34 import org.springframework.beans.factory.annotation.Autowired;\r
35 import org.springframework.test.context.ContextConfiguration;\r
36 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;\r
37 \r
38 @RunWith(SpringJUnit4ClassRunner.class)\r
39 @ContextConfiguration(locations = {"classpath:test-context-h2db.xml"})\r
40 public class ConfigResourceNodeTest {\r
41 \r
42     ConfigResourceNode configResourceNode;\r
43 \r
44     ConfigResourceService configResourceService;\r
45 \r
46     @Autowired\r
47     TransactionLogDao transactionLogDao;\r
48 \r
49     @Autowired\r
50     ConfigResourceDao configResourceDao;\r
51 \r
52     @Autowired\r
53     QueryExecutorDao queryExecutorDao;\r
54 \r
55     @Autowired\r
56     NamedQueryExecutorDao namedQueryExecutorDao;\r
57 \r
58     @Autowired\r
59     ConfigPropertyMapDao configPropertyMapDao;\r
60 \r
61     @Before\r
62     public void before() {\r
63         configResourceService = new ConfigResourceServiceImpl(transactionLogDao, configResourceDao, queryExecutorDao,\r
64                 namedQueryExecutorDao, configPropertyMapDao);\r
65         configResourceNode = new ConfigResourceNode(configResourceService);\r
66     }\r
67 \r
68     @Test\r
69     public void testSaveConfigTransactionLog() throws Exception {\r
70         Map<String, String> inParams = new HashMap<>();\r
71         inParams.put(DataAdaptorConstants.INPUT_PARAM_MESSAGE_TYPE, "messageType");\r
72         inParams.put(DataAdaptorConstants.INPUT_PARAM_MESSAGE, "message");\r
73         SvcLogicContext ctx = new SvcLogicContext();\r
74         ctx.setAttribute("request-id", "requestId12345");\r
75 \r
76         configResourceNode.saveConfigTransactionLog(inParams, ctx);\r
77 \r
78         Assert.assertTrue(!transactionLogDao.getTransactionsByRequestId("requestId12345").isEmpty());\r
79     }\r
80 \r
81     @Test(expected = SvcLogicException.class)\r
82     public void testSaveConfigTransactionLogException() throws Exception {\r
83         configResourceNode = new ConfigResourceNode(null);\r
84         configResourceNode.saveConfigTransactionLog(new HashMap<>(), new SvcLogicContext());\r
85     }\r
86 }\r