made unit test for checking blacklisted sites. Introduced a new constructor to be able to inject repository for testing.
parent
d6109fd1ae
commit
9a3625ae2b
|
@ -41,6 +41,24 @@ public class DefaultBlacklistedSiteService implements BlacklistedSiteService {
|
|||
@Autowired
|
||||
private BlacklistedSiteRepository repository;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public DefaultBlacklistedSiteService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for test harness.
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
public DefaultBlacklistedSiteService(BlacklistedSiteRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.openid.connect.service.BlacklistedSiteService#getAll()
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2013 The MITRE Corporation
|
||||
* and the MIT Kerberos and Internet Trust Consortium
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
package org.mitre.openid.connect.service.impl;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mitre.openid.connect.model.BlacklistedSite;
|
||||
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
||||
import org.mockito.Mockito;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author wkim
|
||||
*
|
||||
*/
|
||||
public class TestDefaultBlacklistedSiteService {
|
||||
|
||||
private BlacklistedSite site1;
|
||||
private BlacklistedSite site2;
|
||||
|
||||
private String uri1 = "black1";
|
||||
private String uri2 = "black2";
|
||||
private String uri3 = "not-black";
|
||||
|
||||
private BlacklistedSiteRepository mockRepository;
|
||||
|
||||
private DefaultBlacklistedSiteService service;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void prepare() throws Exception {
|
||||
|
||||
site1 = new BlacklistedSite();
|
||||
site2 = new BlacklistedSite();
|
||||
|
||||
site1.setUri(uri1);
|
||||
site2.setUri(uri2);
|
||||
|
||||
Set<BlacklistedSite> blackListedSitesSet = Sets.newHashSet(site1, site2);
|
||||
|
||||
mockRepository = Mockito.mock(BlacklistedSiteRepository.class);
|
||||
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
|
||||
|
||||
service = new DefaultBlacklistedSiteService(mockRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test finding blacklisted sites from the repository.
|
||||
*/
|
||||
@Test
|
||||
public void isBlacklisted_yes() {
|
||||
|
||||
assertTrue(service.isBlacklisted(uri1));
|
||||
assertTrue(service.isBlacklisted(uri2));
|
||||
|
||||
Mockito.verify(mockRepository, times(2)).getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for finding a site that is not blacklisted in the repository.
|
||||
*/
|
||||
@Test
|
||||
public void isBlacklisted_no() {
|
||||
|
||||
assertFalse(service.isBlacklisted(uri3));
|
||||
|
||||
Mockito.verify(mockRepository).getAll();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue