4 * ============LICENSE_START==========================================
6 * ===================================================================
7 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
39 package org.onap.portalapp.portal.service;
41 import java.util.ArrayList;
42 import java.util.List;
44 import org.hibernate.criterion.Criterion;
45 import org.hibernate.criterion.ProjectionList;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.mockito.InjectMocks;
51 import org.mockito.Matchers;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.MockitoAnnotations;
55 import org.onap.portalapp.portal.domain.BasicAuthCredentials;
56 import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
57 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
58 import org.onap.portalsdk.core.service.DataAccessService;
59 import org.powermock.api.mockito.PowerMockito;
60 import org.powermock.core.classloader.annotations.PrepareForTest;
61 import org.powermock.modules.junit4.PowerMockRunner;
63 @RunWith(PowerMockRunner.class)
64 @PrepareForTest({CipherUtil.class})
66 public class BasicAuthenticationCredentialServiceImplTest {
69 private DataAccessService dataAccessService;
72 private BasicAuthenticationCredentialServiceImpl serviceImpl = new BasicAuthenticationCredentialServiceImpl();
75 public void setup() throws CipherUtilException {
76 MockitoAnnotations.initMocks(this);
81 public void unt_getBasicAuthCredentialByUsernameAndPassword() throws CipherUtilException {
82 PowerMockito.mockStatic(CipherUtil.class);
83 PowerMockito.when(CipherUtil.decryptPKC(Matchers.anyString())).thenReturn("password1234");
84 List credList=new ArrayList<>();
85 BasicAuthCredentials basicAuthCredentials=new BasicAuthCredentials();
86 basicAuthCredentials.setPassword("password");
87 //basicAuthCredentials.setId(123L);
88 credList.add(basicAuthCredentials);
89 Mockito.when(dataAccessService.getList(Matchers.any(),(ProjectionList)Matchers.isNull() , Matchers.anyListOf(Criterion.class),(List)Matchers.isNull())).thenReturn(credList);
90 BasicAuthCredentials credentials = serviceImpl.getBasicAuthCredentialByUsernameAndPassword("abc1234",
92 Assert.assertNotNull(credentials);
97 public void unt_getBasicAuthCredentialByUsernameAndPassword_withException() {
98 List credList=new ArrayList<>();
99 BasicAuthCredentials basicAuthCredentials=new BasicAuthCredentials();
100 basicAuthCredentials.setPassword("password");
101 credList.add(basicAuthCredentials);
102 Mockito.when(dataAccessService.getList(Matchers.any(),(ProjectionList)Matchers.isNull() , Matchers.anyListOf(Criterion.class),(List)Matchers.isNull())).thenReturn(credList);
103 BasicAuthCredentials credentials = serviceImpl.getBasicAuthCredentialByUsernameAndPassword("abc1234",
105 Assert.assertNull(credentials);