/*
* This file is part of the TimeFinder project.
* Visit http://www.timefinder.de for more information.
* Copyright 2008 the original author or authors.
*
* 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 de.timefinder.core;
import de.timefinder.algo.ncp.NoCollisionPrinciple;
import de.timefinder.data.access.Dao;
import de.timefinder.core.util.ApplicationSettings;
import de.timefinder.core.util.Translator;
import java.util.Random;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import static org.junit.Assert.*;
import org.springframework.richclient.application.support.DefaultApplicationWindow;
/**
* This class tests wether some beans are properly configured to be used
* in the application without an exception.
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class ApplicationCtxTest {
private static ApplicationContext ctx;
@BeforeClass
public static void setUpClass() throws Exception {
// ctx = new ClassPathXmlApplicationContext(new String[]{ApplicationSettings.APP_CONTEXT, ApplicationSettings.COMMANDS_CONTEXT});
ctx = ApplicationSettings.getApplicationContext();
}
@Test
public void testAppContext() {
Object obj = ctx.getBean("random");
assertNotNull(obj);
assertTrue(obj instanceof Random);
obj = ctx.getBean("eventDao");
assertNotNull(obj);
Dao dao = (Dao) obj;
assertTrue(dao.getAll().size() >= 0);
}
@Test
public void testCommandContext() {
Object obj = ctx.getBean("lifecycleAdvisor");
assertNotNull(obj);
LifecycleAdvisor advisor = (LifecycleAdvisor)obj;
advisor.setOpeningWindow(new DefaultApplicationWindow());
advisor.createWindowCommandManager();
assertTrue(advisor.getMenuBarCommandGroup().getMemberCount() > 3);
}
@Test
public void testTranslator() {
ToI18N o = (ToI18N) ctx.getAutowireCapableBeanFactory().autowire(ToI18N.class, 0, false);
assertNotNull(o.getTranslator());
}
// @Test
// public void testConstraint() {
// RasterConstraint rc = (RasterConstraint) ctx.getBean("rasterConstraint");
// RasterConstraint rc2 = (RasterConstraint) ctx.getBean("rasterConstraint");
// assertNotNull(rc);
// assertNotNull(rc2);
// assertNotSame(rc, rc2);
// assertNotNull(rc.getRaster());
// assertNotSame(rc.getRaster(), rc2.getRaster());
//
// EventSetConstraint esc = (EventSetConstraint) ctx.getBean("eventSetConstraint");
// assertNotNull(esc.getEventSet());
// }
@Test
public void testConstraint() {
try {
ctx.getBean("rasterConstraint");
assertTrue(false);
} catch (NoSuchBeanDefinitionException ex) {
assertTrue(true);
}
try {
ctx.getBean("eventSetConstraint");
assertTrue(false);
} catch (NoSuchBeanDefinitionException ex) {
assertTrue(true);
}
}
@Test
public void testNcp() {
NoCollisionPrinciple ncp = (NoCollisionPrinciple) ctx.getBean("ncp");
assertNotNull(ncp);
assertNotNull(ncp.getDataPool());
}
private static class ToI18N {
private Translator tr;
@Autowired
public void setTranslator(Translator translator) {
tr = translator;
}
public Translator getTranslator() {
return tr;
}
}
}