[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / test / java / org / onap / dmaap / dbcapi / aaf / AafServiceFactoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dmaap.dbcapi.aaf;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.runners.MockitoJUnitRunner;
28 import org.onap.dmaap.dbcapi.aaf.AafService.ServiceType;
29 import org.onap.dmaap.dbcapi.util.DmaapConfig;
30
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertTrue;
33 import static org.mockito.BDDMockito.given;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class AafServiceFactoryTest {
37
38     private static final String USE_AAF = "true";
39     private static final String AAF_URL = "https://aaf.url/api";
40     private static final String ADMIN_USER = "admin_user";
41     private static final String TOPIC_MANAGER = "topic_manager";
42     private static final String ADMIN_PASS = "admin_pass";
43     private static final String MANAGER_PASS = "manager_pass";
44     @Mock
45     private DmaapConfig dmaapConfig;
46     private AafServiceFactory aafServiceFactory;
47
48     @Before
49     public void setUp() throws Exception {
50         aafServiceFactory = new AafServiceFactory(dmaapConfig);
51     }
52
53     @Test
54     public void shouldBuildAafServiceForAafAdmin() {
55         givenDmaapConfig();
56
57         AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_Admin);
58
59         assertEquals(ADMIN_USER, aafService.getIdentity());
60         assertEquals(AAF_URL, aafService.getAafUrl());
61         assertTrue(aafService.isUseAAF());
62     }
63
64     @Test
65     public void shouldBuildAafServiceForTopicManager() {
66         givenDmaapConfig();
67
68         AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_TopicMgr);
69
70         assertEquals(TOPIC_MANAGER, aafService.getIdentity());
71         assertEquals(AAF_URL, aafService.getAafUrl());
72         assertTrue(aafService.isUseAAF());
73     }
74
75     @Test
76     public void shouldCorrectlyCreateCredentialsForAafAdmin() {
77         givenDmaapConfig();
78
79         AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_Admin);
80
81         assertEquals(ADMIN_USER, cred.getIdentity());
82         assertEquals(ADMIN_USER + ":" + new AafDecrypt().decrypt(ADMIN_PASS), cred.toString());
83     }
84
85     @Test
86     public void shouldCorrectlyCreateCredentialsForTopicManager() {
87         givenDmaapConfig();
88
89         AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_TopicMgr);
90
91         assertEquals(TOPIC_MANAGER, cred.getIdentity());
92         assertEquals(TOPIC_MANAGER + ":" + new AafDecrypt().decrypt(MANAGER_PASS), cred.toString());
93     }
94
95     private void givenDmaapConfig() {
96         given(dmaapConfig.getProperty("UseAAF", "false")).willReturn(USE_AAF);
97         given(dmaapConfig.getProperty("aaf.URL", "https://authentication.domain.netset.com:8100/proxy/")).willReturn(AAF_URL);
98         given(dmaapConfig.getProperty("aaf.AdminUser", "noMechId@domain.netset.com")).willReturn(ADMIN_USER);
99         given(dmaapConfig.getProperty("aaf.TopicMgrUser", "noMechId@domain.netset.com")).willReturn(TOPIC_MANAGER);
100         given(dmaapConfig.getProperty("aaf.AdminPassword", "notSet")).willReturn(ADMIN_PASS);
101         given(dmaapConfig.getProperty("aaf.TopicMgrPassword", "notSet")).willReturn(MANAGER_PASS);
102     }
103 }