/*
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Jasig licenses this file to you 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 the following location:
*
* 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.jasig.cas.services.web;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.jasig.cas.services.DefaultServicesManagerImpl;
import org.jasig.cas.services.InMemoryServiceRegistryDaoImpl;
import org.jasig.cas.services.RegisteredServiceImpl;
import org.jasig.cas.services.ServicesManager;
import org.jasig.cas.web.support.ArgumentExtractor;
import org.jasig.cas.web.support.CasArgumentExtractor;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
/**
*
* @author Scott Battaglia
* @since 3.1
*
*/
public class ServiceThemeResolverTests {
private ServiceThemeResolver serviceThemeResolver;
private ServicesManager servicesManager;
@Before
public void setUp() throws Exception {
this.servicesManager = new DefaultServicesManagerImpl(new InMemoryServiceRegistryDaoImpl());
this.serviceThemeResolver = new ServiceThemeResolver();
this.serviceThemeResolver.setDefaultThemeName("test");
this.serviceThemeResolver.setServicesManager(this.servicesManager);
this.serviceThemeResolver.setArgumentExtractors(Arrays.asList((ArgumentExtractor) new CasArgumentExtractor()));
final Map<String, String> mobileBrowsers = new HashMap<String, String>();
mobileBrowsers.put("Mozilla", "theme");
this.serviceThemeResolver.setMobileBrowsers(mobileBrowsers);
}
@Test
public void testGetServiceTheme() {
final RegisteredServiceImpl r = new RegisteredServiceImpl();
r.setTheme("myTheme");
r.setId(1000);
r.setName("Test Service");
r.setServiceId("myServiceId");
this.servicesManager.save(r);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("service", "myServiceId");
request.addHeader("User-Agent", "Mozilla");
assertEquals("myTheme", this.serviceThemeResolver.resolveThemeName(request));
}
@Test
public void testGetDefaultService() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("service", "myServiceId");
request.addHeader("User-Agent", "Mozilla");
assertEquals("test", this.serviceThemeResolver.resolveThemeName(request));
}
@Test
public void testGetDefaultServiceWithNoServicesManager() {
this.serviceThemeResolver.setServicesManager(null);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("service", "myServiceId");
request.addHeader("User-Agent", "Mozilla");
assertEquals("test", this.serviceThemeResolver.resolveThemeName(request));
}
}