update link to upper-constraints.txt
[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 static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.BDDMockito.given;
26
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.runners.MockitoJUnitRunner;
33 import org.onap.dmaap.dbcapi.aaf.AafService.ServiceType;
34 import org.onap.dmaap.dbcapi.util.DmaapConfig;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class AafServiceFactoryTest {
38
39     private static final String USE_AAF = "true";
40     private static final String AAF_URL = "https://aaf.url/api";
41     private static final String ADMIN_USER = "admin_user";
42     private static final String TOPIC_MANAGER = "topic_manager";
43     private static final String ADMIN_PASS = "admin_pass";
44     private static final String MANAGER_PASS = "manager_pass";
45     @Mock
46     private DmaapConfig dmaapConfig;
47     private AafServiceFactory aafServiceFactory;
48
49     @BeforeClass
50     public static void setUpClass() {
51         System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
52     }
53
54     @Before
55     public void setUp() throws Exception {
56         aafServiceFactory = new AafServiceFactory(dmaapConfig);
57     }
58
59     @Test
60     public void shouldBuildAafServiceForAafAdmin() {
61         givenDmaapConfig();
62
63         AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_Admin);
64
65         assertEquals(ADMIN_USER, aafService.getIdentity());
66         assertEquals(AAF_URL, aafService.getAafUrl());
67         assertTrue(aafService.isUseAAF());
68     }
69
70     @Test
71     public void shouldBuildAafServiceForTopicManager() {
72         givenDmaapConfig();
73
74         AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_TopicMgr);
75
76         assertEquals(TOPIC_MANAGER, aafService.getIdentity());
77         assertEquals(AAF_URL, aafService.getAafUrl());
78         assertTrue(aafService.isUseAAF());
79     }
80
81     @Test
82     public void shouldCorrectlyCreateCredentialsForAafAdmin() {
83         givenDmaapConfig();
84
85         AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_Admin);
86
87         assertEquals(ADMIN_USER, cred.getIdentity());
88         assertEquals(ADMIN_USER + ":" + new AafDecrypt().decrypt(ADMIN_PASS), cred.toString());
89     }
90
91     @Test
92     public void shouldCorrectlyCreateCredentialsForTopicManager() {
93         givenDmaapConfig();
94
95         AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_TopicMgr);
96
97         assertEquals(TOPIC_MANAGER, cred.getIdentity());
98         assertEquals(TOPIC_MANAGER + ":" + new AafDecrypt().decrypt(MANAGER_PASS), cred.toString());
99     }
100
101     private void givenDmaapConfig() {
102         given(dmaapConfig.getProperty("UseAAF", "false")).willReturn(USE_AAF);
103         given(dmaapConfig.getProperty("aaf.URL", "https://authentication.domain.netset.com:8100/proxy/")).willReturn(AAF_URL);
104         given(dmaapConfig.getProperty("aaf.AdminUser", "noMechId@domain.netset.com")).willReturn(ADMIN_USER);
105         given(dmaapConfig.getProperty("aaf.TopicMgrUser", "noMechId@domain.netset.com")).willReturn(TOPIC_MANAGER);
106         given(dmaapConfig.getProperty("aaf.AdminPassword", "notSet")).willReturn(ADMIN_PASS);
107         given(dmaapConfig.getProperty("aaf.TopicMgrPassword", "notSet")).willReturn(MANAGER_PASS);
108     }
109 }