hybrid server and client configuration services unit tests done.
parent
6ece7f5efc
commit
8c8aeeb892
|
@ -0,0 +1,114 @@
|
|||
/*******************************************************************************
|
||||
* 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.client.service.impl;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mitre.oauth2.model.RegisteredClient;
|
||||
import org.mitre.openid.connect.config.ServerConfiguration;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* @author wkim
|
||||
*
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TestHybridClientConfigurationService {
|
||||
|
||||
@Mock
|
||||
private StaticClientConfigurationService mockStaticService;
|
||||
|
||||
@Mock
|
||||
private DynamicRegistrationClientConfigurationService mockDynamicService;
|
||||
|
||||
@InjectMocks
|
||||
private HybridClientConfigurationService hybridService;
|
||||
|
||||
// test fixture
|
||||
|
||||
@Mock
|
||||
private RegisteredClient mockClient;
|
||||
|
||||
@Mock
|
||||
private ServerConfiguration mockServerConfig;
|
||||
|
||||
private String issuer = "https://www.example.com/";
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
|
||||
Mockito.reset(mockDynamicService, mockStaticService);
|
||||
|
||||
Mockito.when(mockServerConfig.getIssuer()).thenReturn(issuer);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClientConfiguration_useStatic() {
|
||||
|
||||
Mockito.when(mockStaticService.getClientConfiguration(mockServerConfig)).thenReturn(mockClient);
|
||||
|
||||
RegisteredClient result = hybridService.getClientConfiguration(mockServerConfig);
|
||||
|
||||
Mockito.verify(mockStaticService).getClientConfiguration(mockServerConfig);
|
||||
Mockito.verify(mockDynamicService, Mockito.never()).getClientConfiguration(Mockito.any(ServerConfiguration.class));
|
||||
assertEquals(mockClient, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClientConfiguration_useDynamic() {
|
||||
|
||||
Mockito.when(mockStaticService.getClientConfiguration(mockServerConfig)).thenReturn(null);
|
||||
Mockito.when(mockDynamicService.getClientConfiguration(mockServerConfig)).thenReturn(mockClient);
|
||||
|
||||
RegisteredClient result = hybridService.getClientConfiguration(mockServerConfig);
|
||||
|
||||
Mockito.verify(mockStaticService).getClientConfiguration(mockServerConfig);
|
||||
Mockito.verify(mockDynamicService).getClientConfiguration(mockServerConfig);
|
||||
assertEquals(mockClient, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the behavior when the issuer is not known.
|
||||
*/
|
||||
@Test
|
||||
public void getClientConfiguration_noIssuer() {
|
||||
|
||||
// The mockServerConfig is known to both services
|
||||
Mockito.when(mockStaticService.getClientConfiguration(mockServerConfig)).thenReturn(mockClient);
|
||||
Mockito.when(mockDynamicService.getClientConfiguration(mockServerConfig)).thenReturn(mockClient);
|
||||
|
||||
// But oh noes! We're going to ask it to find us some other issuer
|
||||
ServerConfiguration badIssuer = Mockito.mock(ServerConfiguration.class);
|
||||
Mockito.when(badIssuer.getIssuer()).thenReturn("www.badexample.com");
|
||||
|
||||
RegisteredClient result = hybridService.getClientConfiguration(badIssuer);
|
||||
|
||||
Mockito.verify(mockStaticService).getClientConfiguration(badIssuer);
|
||||
Mockito.verify(mockDynamicService).getClientConfiguration(badIssuer);
|
||||
assertThat(result, is(nullValue()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/*******************************************************************************
|
||||
* 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.client.service.impl;
|
||||
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mitre.openid.connect.config.ServerConfiguration;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* @author wkim
|
||||
*
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TestHybridServerConfigurationService {
|
||||
|
||||
@Mock
|
||||
private StaticServerConfigurationService mockStaticService;
|
||||
|
||||
@Mock
|
||||
private DynamicServerConfigurationService mockDynamicService;
|
||||
|
||||
@InjectMocks
|
||||
private HybridServerConfigurationService hybridService;
|
||||
|
||||
@Mock
|
||||
private ServerConfiguration mockServerConfig;
|
||||
|
||||
private String issuer = "https://www.example.com/";
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
|
||||
Mockito.reset(mockDynamicService, mockStaticService);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getServerConfiguration_useStatic() {
|
||||
|
||||
Mockito.when(mockStaticService.getServerConfiguration(issuer)).thenReturn(mockServerConfig);
|
||||
|
||||
ServerConfiguration result = hybridService.getServerConfiguration(issuer);
|
||||
|
||||
Mockito.verify(mockStaticService).getServerConfiguration(issuer);
|
||||
Mockito.verify(mockDynamicService, Mockito.never()).getServerConfiguration(Mockito.anyString());
|
||||
assertEquals(mockServerConfig, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerConfiguration_useDynamic() {
|
||||
|
||||
Mockito.when(mockStaticService.getServerConfiguration(issuer)).thenReturn(null);
|
||||
Mockito.when(mockDynamicService.getServerConfiguration(issuer)).thenReturn(mockServerConfig);
|
||||
|
||||
ServerConfiguration result = hybridService.getServerConfiguration(issuer);
|
||||
|
||||
Mockito.verify(mockStaticService).getServerConfiguration(issuer);
|
||||
Mockito.verify(mockDynamicService).getServerConfiguration(issuer);
|
||||
assertEquals(mockServerConfig, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the behavior when the issuer is not known.
|
||||
*/
|
||||
@Test
|
||||
public void getServerConfiguration_noIssuer() {
|
||||
|
||||
Mockito.when(mockStaticService.getServerConfiguration(issuer)).thenReturn(mockServerConfig);
|
||||
Mockito.when(mockDynamicService.getServerConfiguration(issuer)).thenReturn(mockServerConfig);
|
||||
|
||||
String badIssuer = "www.badexample.com";
|
||||
|
||||
ServerConfiguration result = hybridService.getServerConfiguration(badIssuer);
|
||||
|
||||
Mockito.verify(mockStaticService).getServerConfiguration(badIssuer);
|
||||
Mockito.verify(mockDynamicService).getServerConfiguration(badIssuer);
|
||||
assertThat(result, is(nullValue()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue