From c72d565bb58226b20625b2bce5f0019046bee649 Mon Sep 17 00:00:00 2001 From: "Sonsino, Ofir (os0695)" Date: Tue, 10 Jul 2018 14:20:54 +0300 Subject: Merge 1806 code of vid-common Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) --- .../java/org/onap/vid/config/DataSourceConfig.java | 81 +++++++++++++++++++ .../java/org/onap/vid/config/JobAdapterConfig.java | 33 ++++++++ .../vid/config/JobCommandsConfigWithMockedMso.java | 90 ++++++++++++++++++++++ .../MockedAaiClientAndFeatureManagerConfig.java | 21 +++++ 4 files changed, 225 insertions(+) create mode 100644 vid-app-common/src/test/java/org/onap/vid/config/DataSourceConfig.java create mode 100644 vid-app-common/src/test/java/org/onap/vid/config/JobAdapterConfig.java create mode 100644 vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java create mode 100644 vid-app-common/src/test/java/org/onap/vid/config/MockedAaiClientAndFeatureManagerConfig.java (limited to 'vid-app-common/src/test/java/org/onap/vid/config') diff --git a/vid-app-common/src/test/java/org/onap/vid/config/DataSourceConfig.java b/vid-app-common/src/test/java/org/onap/vid/config/DataSourceConfig.java new file mode 100644 index 000000000..eb9239e17 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/config/DataSourceConfig.java @@ -0,0 +1,81 @@ +package org.onap.vid.config; + + +import org.hibernate.SessionFactory; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.hibernate4.HibernateTransactionManager; +import org.springframework.orm.hibernate4.LocalSessionFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableTransactionManagement +public class DataSourceConfig { + + @Bean + @Autowired + public LocalSessionFactoryBean sessionFactory(DataSource dataSource) { + LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(dataSource); + //I used this class org.openecomp.portalsdk.core.conf.HibernateConfiguration to learn how to config the session factory + // and use the following url for actual h2 properties + //https://github.com/levi-putna/Hibernate-H2-Example/blob/master/hibernate-h2-example/src/hibernate.cfg.xml + Properties properties = getH2Properties(); + + properties.put("hibernate.default_schema", "PUBLIC"); + properties.put("connection.pool_size", 10); + properties.put("cache.provider_class", "org.hibernate.cache.internal.NoCacheProvider"); + properties.put("hibernate.show_sql", false); + properties.put("hbm2ddl.auto", "create"); + properties.put("hibernate.hbm2ddl.auto", "create"); + + sessionFactory.setHibernateProperties(properties); + sessionFactory.setPackagesToScan("org.onap"); + return sessionFactory; + } + + @Bean + public DataSource getDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.h2.Driver"); + dataSource.setUrl("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1"); + dataSource.setUsername("sa"); + dataSource.setPassword(""); + return dataSource; + } + + public Properties getH2Properties() { + Properties properties = new Properties(); + properties.put("dialect", "org.hibernate.dialect.H2Dialect"); + return properties; + } + + public Properties getSqliteProperties() { + Properties properties = new Properties(); + properties.put("connection.driver_class", "org.sqlite.JDBC"); + properties.put("connection.url", "jdbc:sqlite:memory:myDb"); + properties.put("connection.username", "sa"); + properties.put("connection.password", "sa"); + properties.put("dialect", "com.enigmabridge.hibernate.dialect.SQLiteDialect"); + return properties; + } + + @Bean + public DataAccessService dataAccessService() { + return new DataAccessServiceImpl(); + } + + @Bean + @Autowired + public PlatformTransactionManager transactionManager(SessionFactory sessionFactory) { + return new HibernateTransactionManager(sessionFactory); + } +} diff --git a/vid-app-common/src/test/java/org/onap/vid/config/JobAdapterConfig.java b/vid-app-common/src/test/java/org/onap/vid/config/JobAdapterConfig.java new file mode 100644 index 000000000..7b999b404 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/config/JobAdapterConfig.java @@ -0,0 +1,33 @@ +package org.onap.vid.config; + + +import org.hibernate.SessionFactory; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.JobsBrokerService; +import org.onap.vid.job.impl.JobAdapterImpl; +import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl; +import org.onap.vid.properties.VidProperties; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableTransactionManagement +public class JobAdapterConfig { + + @Bean + public JobAdapter jobAdapter() { + return new JobAdapterImpl(); + } + + @Bean + public JobsBrokerService jobsBrokerService(DataAccessService dataAccessService, SessionFactory sessionFactory) { + int maxOpenedInstantiationRequestsToMso = Integer.parseInt(SystemProperties.getProperty(VidProperties.MSO_MAX_OPENED_INSTANTIATION_REQUESTS)); + int pollingIntervalSeconds = Integer.parseInt(SystemProperties.getProperty(VidProperties.MSO_ASYNC_POLLING_INTERVAL_SECONDS)); + + return new JobsBrokerServiceInDatabaseImpl(dataAccessService, sessionFactory, maxOpenedInstantiationRequestsToMso, pollingIntervalSeconds); + } + +} diff --git a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java new file mode 100644 index 000000000..245623aa3 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java @@ -0,0 +1,90 @@ +package org.onap.vid.config; + +import org.hibernate.SessionFactory; +import org.mockito.Mockito; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.util.HttpsAuthClient; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.JobsBrokerService; +import org.onap.vid.job.command.InProgressStatusCommand; +import org.onap.vid.job.command.JobCommandFactory; +import org.onap.vid.job.command.ServiceInstantiationCommand; +import org.onap.vid.job.impl.JobAdapterImpl; +import org.onap.vid.job.impl.JobWorker; +import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.onap.vid.services.AsyncInstantiationBusinessLogicImpl; +import org.onap.vid.services.AuditService; +import org.onap.vid.services.AuditServiceImpl; +import org.onap.portalsdk.core.service.DataAccessService; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.togglz.core.manager.FeatureManager; + +@Configuration +public class JobCommandsConfigWithMockedMso { + + @Bean + public RestMsoImplementation restMso() { + return Mockito.mock(RestMsoImplementation.class); + } + + @Bean + public JobsBrokerService jobsBrokerService(DataAccessService dataAccessService, SessionFactory sessionFactory) { + return new JobsBrokerServiceInDatabaseImpl(dataAccessService, sessionFactory, 200, 0); + } + + @Bean + public HttpsAuthClient httpsAuthClientFactory(){ + return new HttpsAuthClient("some random path"); + } + + @Bean + public JobAdapter jobAdapter() { + return new JobAdapterImpl(); + } + + @Bean + public JobCommandFactory jobCommandFactory(ApplicationContext applicationContext) { + return new JobCommandFactory(applicationContext); + } + + @Bean + public JobWorker jobWorker(JobsBrokerService jobsBrokerService, JobCommandFactory jobCommandFactory) { + JobWorker jobWorker = new JobWorker(); + jobWorker.setJobsBrokerService(jobsBrokerService); + jobWorker.setJobCommandFactory(jobCommandFactory); + return jobWorker; + } + + @Bean + public AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic(DataAccessService dataAccessService, + JobAdapter jobAdapter, + JobsBrokerService jobsBrokerService, + SessionFactory sessionFactory, + AaiClientInterface aaiClient) { + return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiClient); + } + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public ServiceInstantiationCommand serviceInstantiationCommand() { + return new ServiceInstantiationCommand(); + } + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public InProgressStatusCommand inProgressStatusCommand() { + return new InProgressStatusCommand(); + } + + @Bean + public AuditService auditService() { + return new AuditServiceImpl(); + } + +} diff --git a/vid-app-common/src/test/java/org/onap/vid/config/MockedAaiClientAndFeatureManagerConfig.java b/vid-app-common/src/test/java/org/onap/vid/config/MockedAaiClientAndFeatureManagerConfig.java new file mode 100644 index 000000000..1a4eb528e --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/config/MockedAaiClientAndFeatureManagerConfig.java @@ -0,0 +1,21 @@ +package org.onap.vid.config; + +import org.mockito.Mockito; +import org.onap.vid.aai.AaiClientInterface; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.togglz.core.manager.FeatureManager; + +@Configuration +public class MockedAaiClientAndFeatureManagerConfig { + + @Bean + public FeatureManager featureManager() { + return Mockito.mock(FeatureManager.class); + } + + @Bean + public AaiClientInterface aaiClient() { + return Mockito.mock(AaiClientInterface.class); + } +} -- cgit 1.2.3-korg