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