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 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;
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertTrue;
33 import static org.mockito.BDDMockito.given;
35 @RunWith(MockitoJUnitRunner.class)
36 public class AafServiceFactoryTest {
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";
45 private DmaapConfig dmaapConfig;
46 private AafServiceFactory aafServiceFactory;
49 public void setUp() throws Exception {
50 aafServiceFactory = new AafServiceFactory(dmaapConfig);
54 public void shouldBuildAafServiceForAafAdmin() {
57 AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_Admin);
59 assertEquals(ADMIN_USER, aafService.getIdentity());
60 assertEquals(AAF_URL, aafService.getAafUrl());
61 assertTrue(aafService.isUseAAF());
65 public void shouldBuildAafServiceForTopicManager() {
68 AafServiceImpl aafService = (AafServiceImpl) aafServiceFactory.initAafService(ServiceType.AAF_TopicMgr);
70 assertEquals(TOPIC_MANAGER, aafService.getIdentity());
71 assertEquals(AAF_URL, aafService.getAafUrl());
72 assertTrue(aafService.isUseAAF());
76 public void shouldCorrectlyCreateCredentialsForAafAdmin() {
79 AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_Admin);
81 assertEquals(ADMIN_USER, cred.getIdentity());
82 assertEquals(ADMIN_USER + ":" + new AafDecrypt().decrypt(ADMIN_PASS), cred.toString());
86 public void shouldCorrectlyCreateCredentialsForTopicManager() {
89 AafServiceFactory.AafCred cred = aafServiceFactory.getCred(ServiceType.AAF_TopicMgr);
91 assertEquals(TOPIC_MANAGER, cred.getIdentity());
92 assertEquals(TOPIC_MANAGER + ":" + new AafDecrypt().decrypt(MANAGER_PASS), cred.toString());
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);