diff options
Diffstat (limited to 'adapters/mso-vfc-adapter/src')
14 files changed, 472 insertions, 115 deletions
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java new file mode 100644 index 0000000000..3034cbcac3 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vfc; + +import java.util.Arrays; +import javax.xml.ws.Endpoint; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.feature.LoggingFeature; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.swagger.Swagger2Feature; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.onap.so.adapters.vfc.rest.HealthCheckHandler; +import org.onap.so.adapters.vfc.rest.VfcAdapterRest; +import org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + + +@Configuration +public class CXFConfiguration { + + @Autowired + private Bus bus; + + @Autowired + private VfcAdapterRest vfcAdapterRest; + + @Autowired + private HealthCheckHandler healthCheckHandler; + + @Autowired + private JaxRsFilterLogging jaxRsFilterLogging; + + @Autowired + private ObjectMapper mapper; + + @Bean + public ServletRegistrationBean cxfServlet() { + return new ServletRegistrationBean(new CXFServlet(), "/services/*"); + } + + @Bean + public Server rsServer() { + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); + endpoint.setBus(bus); + endpoint.setServiceBeans(Arrays.<Object>asList(vfcAdapterRest, healthCheckHandler)); + endpoint.setAddress("/"); + endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature())); + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging)); + return endpoint.create(); + } + + @Bean + public Swagger2Feature createSwaggerFeature() { + Swagger2Feature swagger2Feature = new Swagger2Feature(); + swagger2Feature.setPrettyPrint(true); + swagger2Feature.setTitle("SO Request Adapter"); + swagger2Feature.setContact("The ONAP SO team"); + swagger2Feature.setDescription("This project is the SO Orchestration Engine"); + swagger2Feature.setVersion("1.0.0"); + swagger2Feature.setResourcePackage("org.onap.so.adapters.requestdb"); + swagger2Feature.setScan(true); + return swagger2Feature; + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/MSOVfcApplication.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java index c6d141391d..5bb83a7c1b 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/MSOVfcApplication.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java @@ -18,19 +18,18 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc.application; +package org.onap.so.adapters.vfc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.ComponentScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication(scanBasePackages = {"org.onap.so"}) -@EnableJpaRepositories({"org.onap.so.db.request.data.repository"}) -@EntityScan({"org.onap.so.db.request.beans"}) public class MSOVfcApplication { public static void main(String... args) { diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java new file mode 100644 index 0000000000..2ff66d2c25 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vfc; + + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Profile({"!test"}) +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager", + basePackages = { "org.onap.so.db.request.data.repository" } + ) +public class RequestDBConfig { + + @Primary + @Bean(name = "requestDataSource") + @ConfigurationProperties(prefix = "spring.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); + } + + @Primary + @Bean(name = "requestEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean + entityManagerFactory( + EntityManagerFactoryBuilder builder, + @Qualifier("requestDataSource") DataSource dataSource + ) { + return builder + .dataSource(dataSource) + .packages("org.onap.so.db.request.beans") + .persistenceUnit("requestDB") + .build(); + } + + @Primary + @Bean(name = "requestTransactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("requestEntityManagerFactory") EntityManagerFactory + entityManagerFactory + ) { + return new JpaTransactionManager(entityManagerFactory); + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java deleted file mode 100644 index a97549189d..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.vfc.application; - -import javax.annotation.PostConstruct; -import javax.ws.rs.ApplicationPath; - -import org.glassfish.jersey.server.ResourceConfig; -import org.onap.so.adapters.vfc.HealthCheckHandler; -import org.onap.so.adapters.vfc.VfcAdapterRest; -import org.springframework.context.annotation.Configuration; - -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; - -@Configuration -@ApplicationPath("/vfc") -public class JerseyConfiguration extends ResourceConfig { - - public JerseyConfiguration() { - - } - - @PostConstruct - public void setUp() { - register(VfcAdapterRest.class); - register(HealthCheckHandler.class); - - this.register(ApiListingResource.class); - this.register(SwaggerSerializers.class); - - BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.2"); - beanConfig.setSchemes(new String[] { "http" }); - beanConfig.setHost("localhost:8080"); - beanConfig.setBasePath("/"); - beanConfig.setResourcePackage("org.onap.so.adapters.vfc.application"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); - } -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/AaiUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java index a4f05158a8..6ae2ba0aca 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/AaiUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import org.onap.so.adapters.vfc.model.RestfulResponse; diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/HealthCheckHandler.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/HealthCheckHandler.java index 8fcf315641..c39a165338 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/HealthCheckHandler.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/HealthCheckHandler.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import javax.ws.rs.HEAD; import javax.ws.rs.Path; diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcAdapterRest.java index e07753b33a..9489ef14f5 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcAdapterRest.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcAdapterRest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -28,7 +28,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - import org.onap.so.adapters.vfc.exceptions.ApplicationException; import org.onap.so.adapters.vfc.model.NSResourceInputParameter; import org.onap.so.adapters.vfc.model.NsOperationKey; diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcManager.java index 47d3842c03..2dbc444bc3 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcManager.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcManager.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import java.util.HashMap; import java.util.Map; @@ -48,6 +48,7 @@ import org.onap.so.requestsdb.RequestsDbConstant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; import org.springframework.data.domain.Example; import org.springframework.stereotype.Component; @@ -60,6 +61,7 @@ import org.springframework.stereotype.Component; * @version ONAP Amsterdam Release 2017-08-28 */ @Component +@Primary public class VfcManager { private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class); @@ -67,25 +69,23 @@ public class VfcManager { /** * nfvo url map */ - private static Map<String, String> nfvoUrlMap; + private Map<String, String> nfvoUrlMap; + @Autowired private ResourceOperationStatusRepository resourceOperationStatusRepository; @Autowired private RestfulUtil restfulUtil; - static { - nfvoUrlMap = new HashMap<>(); - nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); - nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); - nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); - nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL); - nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL); - nfvoUrlMap.put(Step.SCALE, CommonConstant.NFVO_SCALE_URL); - } - - public VfcManager() { - + + public VfcManager() { + nfvoUrlMap = new HashMap<>(); + nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); + nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); + nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); + nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL); + nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL); + nfvoUrlMap.put(Step.SCALE, CommonConstant.NFVO_SCALE_URL); } /** diff --git a/adapters/mso-vfc-adapter/src/main/resources/application-local.yaml b/adapters/mso-vfc-adapter/src/main/resources/application-local.yaml new file mode 100644 index 0000000000..0519f50c46 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/resources/application-local.yaml @@ -0,0 +1,34 @@ +server: + port: 8091 + tomcat: + max-threads: 50 +ssl-enable: false +mso: + logPath: logs + site-name: localSite +spring: + datasource: + url: jdbc:mariadb://localhost:3306/requestdb + username: mso + password: mso123 + driver-class-name: org.mariadb.jdbc.Driver + initialize: true + initialization-mode: never + jpa: + generate-ddl: false + show-sql: false + hibernate: + ddl-auto: validate + naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy + enable-lazy-load-no-trans: true + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + security: + usercredentials: + - + username: bpel + password: '$2a$12$1xyutEZNfjGewIZRfKaE8eZE99f5sYFUmmM80BobI65KNjmcK0JuO' + role: BPEL-Client + - + username: mso_admin + password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa' + role: ACTUATOR diff --git a/adapters/mso-vfc-adapter/src/main/resources/application.yaml b/adapters/mso-vfc-adapter/src/main/resources/application.yaml index ba574ba3e9..2cee9cf7dc 100644 --- a/adapters/mso-vfc-adapter/src/main/resources/application.yaml +++ b/adapters/mso-vfc-adapter/src/main/resources/application.yaml @@ -1,37 +1,32 @@ -logging: - path: logs - -# H2 -spring: - datasource: - url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1; - username: sa - password: sa - driver-class-name: org.h2.Driver - intialize: true - h2: - console: - enabled: true - path: /h2 server: port: 8080 tomcat: max-threads: 50 -mso: - site-name: localSite -#Actuator -management: - security: - enabled: false - basic: - enabled: false - metrics: - se-global-registry: false - export: - prometheus: - enabled: true # Whether exporting of metrics to Prometheus is enabled. - step: 1m # Step size (i.e. reporting frequency) to use. +mso: + site-name: unknown + logPath: ./logs/vfc/ +spring: + datasource: + url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + driver-class-name: org.mariadb.jdbc.Driver + dbcp2: + initial-size: 5 + max-total: 20 + validation-query: select 1 + test-on-borrow: true + jpa: + show-sql: false + hibernate: + dialect: org.hibernate.dialect.MySQL5Dialect + ddl-auto: validate + naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy + enable-lazy-load-no-trans: true +#Actuator +management: + context-path: /manage diff --git a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java index ec3741dc1a..efd3359821 100644 --- a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java +++ b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java @@ -25,13 +25,13 @@ import static org.junit.Assert.*; import org.junit.Test; public class ApplicationExceptionTest { - private ApplicationException application = new ApplicationException(0,null); + private ApplicationException application = new ApplicationException(500,null); @Test public void testApplicationException() { - application.setErrorCode(0); + application.setErrorCode(500); application.setErrorMsg("ErrorMsg"); - assertEquals(application.getErrorCode(), 0); + assertEquals(application.getErrorCode(), 500); assertEquals(application.getErrorMsg(), "ErrorMsg"); } diff --git a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java new file mode 100644 index 0000000000..e5324d348a --- /dev/null +++ b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vfc.rest; +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; +import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +@Configuration +@Profile({"test"}) +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager", + basePackages = { "org.onap.so.db.request.data.repository"} + ) +public class EmbeddedMariaDbConfig { + + @Bean + MariaDB4jSpringService mariaDB4jSpringService() { + return new MariaDB4jSpringService(); + } + + @Primary + @Bean(name = "requestDataSource") + @ConfigurationProperties(prefix = "spring.datasource") + DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, + @Value("${mariaDB4j.databaseName}") String databaseName, + @Value("${spring.datasource.username}") String datasourceUsername, + @Value("${spring.datasource.password}") String datasourcePassword, + @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { + //Create our database with default root user and no password + mariaDB4jSpringService.getDB().createDB(databaseName); + + DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration(); + + return DataSourceBuilder + .create() + .username(datasourceUsername) + .password(datasourcePassword) + .url(config.getURL(databaseName)) + .driverClassName(datasourceDriver) + .build(); + } + + @Primary + @Bean(name = "requestEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean + entityManagerFactory( + EntityManagerFactoryBuilder builder, + @Qualifier("requestDataSource") DataSource dataSource + ) { + return builder + .dataSource(dataSource) + .packages("org.onap.so.db.request.beans") + .persistenceUnit("requestDB") + .build(); + } + + @Primary + @Bean(name = "requestTransactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("requestEntityManagerFactory") EntityManagerFactory + entityManagerFactory + ) { + return new JpaTransactionManager(entityManagerFactory); + } +} diff --git a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java new file mode 100644 index 0000000000..10fa02a1d1 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.vfc.rest; + +import static org.junit.Assert.*; + + + +import javax.ws.rs.core.Response; + +import org.json.JSONException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vfc.MSOVfcApplication; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MSOVfcApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class HealthCheckHandlerTest { + + @LocalServerPort + private int port; + + TestRestTemplate restTemplate = new TestRestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + + + @Test + public void testHealthcheck() throws JSONException { + + HttpEntity<String> entity = new HttpEntity<String>(null, headers); + + ResponseEntity<String> response = restTemplate.exchange( + createURLWithPort("manage/health"), + HttpMethod.GET, entity, String.class); + + assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value()); + } + + private String createURLWithPort(String uri) { + return "http://localhost:" + port + uri; + } +} diff --git a/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml b/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml index ab5fa612eb..64de62c2d6 100644 --- a/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml +++ b/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml @@ -1,6 +1,51 @@ + +server: + port: 8080 + tomcat: + max-threads: 50 +ssl-enable: false mso: + logPath: logs site-name: localSite - msb-ip: "127.0.0.1" - msb-port: 8080 + infra-requests: + archived: + period: 1 +spring: + datasource: + url: jdbc:mariadb://localhost:3307/requestdb + username: root + password: password + driver-class-name: org.mariadb.jdbc.Driver + initialize: true + initialization-mode: never + jpa: + generate-ddl: false + show-sql: false + hibernate: + ddl-auto: validate + naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy + enable-lazy-load-no-trans: true + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + security: + usercredentials: + - + username: test + password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu' + role: BPEL-Client +mariaDB4j: + dataDir: + port: 3307 + databaseName: requestdb +#Actuator +management: + security: + enabled: false + basic: + enabled: false +flyway: + baseline-on-migrate: false + url: jdbc:mariadb://localhost:3307/requestdb + user: root + password: password |