Search in sources :

Example 1 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project opennms by OpenNMS.

the class DroolsTicketerServiceLayerTest method setUp.

@Before
public void setUp() throws Exception {
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    MockLogAppender.setupLogging();
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
    m_easyMockUtils = new EasyMockUtils();
    m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
    EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
    EasyMock.replay(m_configDao);
    m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
    m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
    m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
    m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
    m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
    EasyMock.reset(m_configDao);
    m_alarm = new OnmsAlarm();
    m_alarm.setId(1);
    m_alarm.setLogMsg("Test Logmsg");
    m_alarm.setDescription("Test Description");
    m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
    m_ticket = new Ticket();
    m_ticket.setId("4");
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Ticket(org.opennms.api.integration.ticketing.Ticket) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Resource(org.springframework.core.io.Resource) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Plugin(org.opennms.api.integration.ticketing.Plugin) Before(org.junit.Before)

Example 2 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project opennms by OpenNMS.

the class ProvisionerIT method testProvisionerServiceRescanAfterAddingSnmpNms7838.

// fail if we take more than five minutes
@Test(timeout = 300000)
// Start the test with an empty SNMP agent
@JUnitSnmpAgent(host = "198.51.100.201", port = 161, resource = "classpath:/snmpwalk-empty.properties")
public void testProvisionerServiceRescanAfterAddingSnmpNms7838() throws Exception {
    importFromResource("classpath:/requisition_then_scan2.xml", Boolean.TRUE.toString());
    final List<OnmsNode> nodes = getNodeDao().findAll();
    final OnmsNode node = nodes.get(0);
    runPendingScans();
    m_nodeDao.flush();
    assertEquals(1, getInterfaceDao().countAll());
    // Make sure that the OnmsIpInterface doesn't have an ifIndex
    assertNull(getInterfaceDao().get(node, "198.51.100.201").getIfIndex());
    // Make sure that no OnmsSnmpInterface records exist for the node
    assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 4));
    assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 5));
    LOG.info("******************** ADDING SNMP DATA ********************");
    // Add some SNMP data to the agent
    m_mockSnmpDataProvider.setDataForAddress(new SnmpAgentAddress(addr("198.51.100.201"), 161), new DefaultResourceLoader().getResource("classpath:/snmpTestData3.properties"));
    // Rescan
    m_mockEventIpcManager.sendEventToListeners(nodeUpdated(node.getId()));
    runPendingScans();
    m_nodeDao.flush();
    // Make sure that a second interface was added from the SNMP agent data
    assertEquals(2, getInterfaceDao().countAll());
    // Verify the ifIndex entries
    assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getIfIndex().intValue());
    assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getSnmpInterface().getIfIndex().intValue());
    assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getIfIndex().intValue());
    assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getSnmpInterface().getIfIndex().intValue());
}
Also used : SnmpAgentAddress(org.opennms.netmgt.snmp.SnmpAgentAddress) OnmsNode(org.opennms.netmgt.model.OnmsNode) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 3 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project spring-boot by spring-projects.

the class DataSourceInitializerTests method multipleScriptsAppliedInLexicalOrder.

@Test
public void multipleScriptsAppliedInLexicalOrder() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:true", "spring.datasource.schema:" + ClassUtils.addResourcePathToPackagePath(getClass(), "lexical-schema-*.sql"), "spring.datasource.data:" + ClassUtils.addResourcePathToPackagePath(getClass(), "data.sql"));
    this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    ReverseOrderResourceLoader resourceLoader = new ReverseOrderResourceLoader(new DefaultResourceLoader());
    this.context.setResourceLoader(resourceLoader);
    this.context.refresh();
    DataSource dataSource = this.context.getBean(DataSource.class);
    assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
    assertThat(dataSource).isNotNull();
    JdbcOperations template = new JdbcTemplate(dataSource);
    assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class)).isEqualTo(1);
}
Also used : JdbcOperations(org.springframework.jdbc.core.JdbcOperations) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 4 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project spring-boot by spring-projects.

the class EnableAutoConfigurationImportSelectorTests method setup.

@Before
public void setup() {
    this.importSelector.setBeanFactory(this.beanFactory);
    this.importSelector.setEnvironment(this.environment);
    this.importSelector.setResourceLoader(new DefaultResourceLoader());
}
Also used : DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Example 5 with DefaultResourceLoader

use of org.springframework.core.io.DefaultResourceLoader in project spring-framework by spring-projects.

the class FreeMarkerConfigurerTests method freeMarkerConfigurationAsBean.

// SPR-12448
@Test
public void freeMarkerConfigurationAsBean() {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class);
    loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader());
    loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
    RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
    configDef.getPropertyValues().add("templateLoader", loaderDef);
    beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
    beanFactory.getBean(Configuration.class);
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test)

Aggregations

DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)69 Test (org.junit.jupiter.api.Test)28 ResourceLoader (org.springframework.core.io.ResourceLoader)20 Resource (org.springframework.core.io.Resource)11 Before (org.junit.Before)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 IOException (java.io.IOException)7 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)6 InputStream (java.io.InputStream)4 URLClassLoader (java.net.URLClassLoader)4 Test (org.junit.Test)4 Environment (org.springframework.core.env.Environment)4 File (java.io.File)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)3 LRUCacheManager (io.syndesis.common.util.cache.LRUCacheManager)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)2