2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.dbcapi.aaf;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.BDDMockito.given;
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;
36 @RunWith(MockitoJUnitRunner.class)
37 public class AafServiceFactoryTest {
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";
46 private DmaapConfig dmaapConfig;
47 private AafServiceFactory aafServiceFactory;
50 public static void setUpClass() {
51 System.setProperty("ConfigFile", "src/test/resources/dmaapbc.properties");
55 public void setUp() throws Exception {
56 aafServiceFactory = new AafServiceFactory(dmaapConfig);
60 public void shouldBuildAafServiceForAafAdmin() {
63 AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_Admin);
65 assertEquals(ADMIN_USER, aafService.getIdentity());
66 assertEquals(AAF_URL, aafService.getAafUrl());
67 assertTrue(aafService.isUseAAF());
71 public void shouldBuildAafServiceForTopicManager() {
74 AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_TopicMgr);
76 assertEquals(TOPIC_MANAGER, aafService.getIdentity());
77 assertEquals(AAF_URL, aafService.getAafUrl());
78 assertTrue(aafService.isUseAAF());
82 public void shouldCorrectlyCreateCredentialsForAafAdmin() {
85 AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_Admin);
87 assertEquals(ADMIN_USER, cred.getIdentity());
88 assertEquals(ADMIN_USER + ":" + new AafDecrypt().decrypt(ADMIN_PASS), cred.toString());
92 public void shouldCorrectlyCreateCredentialsForTopicManager() {
95 AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_TopicMgr);
97 assertEquals(TOPIC_MANAGER, cred.getIdentity());
98 assertEquals(TOPIC_MANAGER + ":" + new AafDecrypt().decrypt(MANAGER_PASS), cred.toString());
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);