summaryrefslogtreecommitdiffstats
path: root/vnf-sdk-function-test
diff options
context:
space:
mode:
Diffstat (limited to 'vnf-sdk-function-test')
-rw-r--r--vnf-sdk-function-test/.gitignore6
-rw-r--r--vnf-sdk-function-test/pom.xml214
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java89
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java96
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java32
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java72
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/exception/VnfSdkFuncTestException.java51
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java60
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java105
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java44
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java37
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java74
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java56
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java44
14 files changed, 980 insertions, 0 deletions
diff --git a/vnf-sdk-function-test/.gitignore b/vnf-sdk-function-test/.gitignore
new file mode 100644
index 0000000..67a2e60
--- /dev/null
+++ b/vnf-sdk-function-test/.gitignore
@@ -0,0 +1,6 @@
+target/
+.project
+.settings
+.classpath
+.class
+.checkstyle
diff --git a/vnf-sdk-function-test/pom.xml b/vnf-sdk-function-test/pom.xml
new file mode 100644
index 0000000..e91b92e
--- /dev/null
+++ b/vnf-sdk-function-test/pom.xml
@@ -0,0 +1,214 @@
+<?xml version="1.0"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.openo.vnf-sdk.function-test</groupId>
+ <artifactId>vnfsdk-functest-core-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>vnf-sdk-function-test</artifactId>
+ <name>vnf-sdk-function-test</name>
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.10</version>
+ <versionRange>[2.0,)</versionRange>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore/>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>org.openo.vnfsdk.functest.VnfSdkFuncTestApp</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-core</artifactId>
+ <version>0.8.0</version>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-core</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-assets</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-hibernate</artifactId>
+ <version>0.8.0</version>
+ </dependency>
+ <!-- lombok -->
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.16.4</version>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jersey2-jaxrs</artifactId>
+ <version>1.5.3</version>
+ </dependency>
+ <!-- jersey -->
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <version>2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <version>2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ <version>2.16</version>
+ </dependency>
+ <!-- consumer -->
+ <dependency>
+ <groupId>com.eclipsesource.jaxrs</groupId>
+ <artifactId>consumer</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>com.eclipsesource.jaxrs</groupId>
+ <artifactId>jersey-all</artifactId>
+ </exclusion>
+ </exclusions>
+ <version>5.0</version>
+ </dependency>
+ <!-- gson -->
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.18</version>
+ </dependency>
+ <!-- UT -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.4.182</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- UT end -->
+ </dependencies>
+</project>
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java
new file mode 100644
index 0000000..faca92e
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.openo.vnfsdk.functest.common.Config;
+import org.openo.vnfsdk.functest.common.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+import io.dropwizard.Application;
+import io.dropwizard.assets.AssetsBundle;
+import io.dropwizard.server.SimpleServerFactory;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+import io.swagger.jaxrs.config.BeanConfig;
+import io.swagger.jaxrs.listing.ApiListingResource;
+
+public class VnfSdkFuncTestApp extends Application<VnfSdkFuncTestAppConfiguration> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(VnfSdkFuncTestApp.class);
+
+ public static void main(String[] args) throws Exception {
+ new VnfSdkFuncTestApp().run(args);
+ }
+
+ @Override
+ public String getName() {
+ return "OPENO-VNFSDK-FunctionTest";
+ }
+
+ @Override
+ public void initialize(Bootstrap<VnfSdkFuncTestAppConfiguration> bootstrap) {
+ bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
+
+ }
+
+ private void initService() {
+ Thread registerExtsysService = new Thread(new ServiceRegistration());
+ registerExtsysService.setName("Register vnfsdk-functionTest service to Microservice Bus");
+ registerExtsysService.start();
+ }
+
+ @Override
+ public void run(VnfSdkFuncTestAppConfiguration configuration, Environment environment) {
+ LOGGER.info("Start to initialize vnfsdk function test.");
+ environment.jersey().packages("org.openo.vnfsdk.functest.resource");
+ environment.jersey().register(MultiPartFeature.class);
+ initSwaggerConfig(environment, configuration);
+ Config.setConfigration(configuration);
+ initService();
+ LOGGER.info("Initialize vnfsdk function test finished.");
+ }
+
+ private void initSwaggerConfig(Environment environment, VnfSdkFuncTestAppConfiguration configuration) {
+ environment.jersey().register(new ApiListingResource());
+ environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
+
+ BeanConfig config = new BeanConfig();
+ config.setTitle("Open-o VnfSdk Functest Service rest API");
+ config.setVersion("1.0.0");
+ config.setResourcePackage("org.openo.vnfsdk.functest.resource");
+
+ SimpleServerFactory simpleServerFactory = (SimpleServerFactory)configuration.getServerFactory();
+ String basePath = simpleServerFactory.getApplicationContextPath();
+ String rootPath = simpleServerFactory.getJerseyRootPath();
+ rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
+ basePath = basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath).toString();
+ config.setBasePath(basePath);
+ config.setScan(true);
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java
new file mode 100644
index 0000000..574fe0d
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import io.dropwizard.Configuration;
+import io.dropwizard.db.DataSourceFactory;
+
+public class VnfSdkFuncTestAppConfiguration extends Configuration {
+
+ @NotEmpty
+ private String template;
+
+ @NotEmpty
+ private String defaultName = "OPENO-VnfSdk-FuncTest";
+
+ @NotEmpty
+ private String msbServerAddr;
+
+ @Valid
+ private String serviceIp;
+
+ @Valid
+ @NotNull
+ private DataSourceFactory database = new DataSourceFactory();
+
+ @JsonProperty("database")
+ public DataSourceFactory getDataSourceFactory() {
+ return database;
+ }
+
+ @JsonProperty("database")
+ public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
+ this.database = dataSourceFactory;
+ }
+
+ @JsonProperty
+ public String getTemplate() {
+ return template;
+ }
+
+ @JsonProperty
+ public void setTemplate(String template) {
+ this.template = template;
+ }
+
+ @JsonProperty
+ public String getDefaultName() {
+ return defaultName;
+ }
+
+ @JsonProperty
+ public void setDefaultName(String name) {
+ this.defaultName = name;
+ }
+
+ @JsonProperty
+ public String getMsbServerAddr() {
+ return msbServerAddr;
+ }
+
+ @JsonProperty
+ public void setMsbServerAddr(String msbServerAddr) {
+ this.msbServerAddr = msbServerAddr;
+ }
+
+ @JsonProperty
+ public String getServiceIp() {
+ return serviceIp;
+ }
+
+ @JsonProperty
+ public void setServiceIp(String serviceIp) {
+ this.serviceIp = serviceIp;
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java
new file mode 100644
index 0000000..cb19c98
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.common;
+
+import org.openo.vnfsdk.functest.VnfSdkFuncTestAppConfiguration;
+
+public class Config {
+
+ private static VnfSdkFuncTestAppConfiguration configration;
+
+ public static VnfSdkFuncTestAppConfiguration getConfigration() {
+ return configration;
+ }
+
+ public static void setConfigration(VnfSdkFuncTestAppConfiguration config) {
+ configration = config;
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java
new file mode 100644
index 0000000..ab1566c
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.common;
+
+import org.openo.vnfsdk.functest.externalservice.entity.ServiceRegisterEntity;
+import org.openo.vnfsdk.functest.externalservice.msb.MicroserviceBusConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ServiceRegistration implements Runnable {
+
+ private final ServiceRegisterEntity funcTestEntity = new ServiceRegisterEntity();
+
+ private static final Logger LOG = LoggerFactory.getLogger(ServiceRegistration.class);
+
+ public ServiceRegistration() {
+ initServiceEntity();
+ }
+
+ @Override
+ public void run() {
+ LOG.info("start extsys microservice register");
+ boolean flag = false;
+ int retry = 0;
+ while(!flag && retry < 1000) {
+ LOG.info("VNF-SDK function test microservice register.retry:" + retry);
+ retry++;
+ flag = MicroserviceBusConsumer.registerService(funcTestEntity);
+ if(flag == false) {
+ LOG.warn("microservice register failed, sleep 30S and try again.");
+ threadSleep(30000);
+ } else {
+ LOG.info("microservice register success!");
+ break;
+ }
+ }
+ LOG.info("VNF-SDK function test microservice register end.");
+ }
+
+ private void threadSleep(int second) {
+ LOG.info("start sleep ....");
+ try {
+ Thread.sleep(second);
+ } catch(InterruptedException error) {
+ LOG.error("thread sleep error.errorMsg:" + error.getMessage());
+ }
+ LOG.info("sleep end .");
+ }
+
+ private void initServiceEntity() {
+ funcTestEntity.setServiceName("vnfsdk");
+ funcTestEntity.setProtocol("REST");
+ funcTestEntity.setVersion("v1");
+ funcTestEntity.setUrl("/openoapi/vnfsdk/v1");
+ funcTestEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8100", 0);
+ funcTestEntity.setVisualRange("1");
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/exception/VnfSdkFuncTestException.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/exception/VnfSdkFuncTestException.java
new file mode 100644
index 0000000..af2a612
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/exception/VnfSdkFuncTestException.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.exception;
+
+public class VnfSdkFuncTestException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ private String errorCode;
+
+ private String errorMsg;
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorMsg() {
+ return errorMsg;
+ }
+
+ public void setErrorMsg(String errorMsg) {
+ this.errorMsg = errorMsg;
+ }
+
+ public VnfSdkFuncTestException() {
+ super();
+ }
+
+ public VnfSdkFuncTestException(String errorCode, String errorMsg) {
+ this.errorCode = errorCode;
+ this.errorMsg = errorMsg;
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java
new file mode 100644
index 0000000..28ae31e
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.externalservice.entity;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ServiceNode {
+
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+ public int getTtl() {
+ return ttl;
+ }
+
+ public void setTtl(int ttl) {
+ this.ttl = ttl;
+ }
+
+ private String ip;
+
+ private String port;
+
+ private int ttl;
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java
new file mode 100644
index 0000000..b622a6c
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.externalservice.entity;
+
+import java.util.ArrayList;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ServiceRegisterEntity {
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getProtocol() {
+ return protocol;
+ }
+
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+
+ public String getVisualRange() {
+ return visualRange;
+ }
+
+ public void setVisualRange(String visualRange) {
+ this.visualRange = visualRange;
+ }
+
+ public ArrayList<ServiceNode> getNodes() {
+ return nodes;
+ }
+
+ public void setNodes(ArrayList<ServiceNode> nodes) {
+ this.nodes = nodes;
+ }
+
+ private String serviceName;
+
+ private String version;
+
+ private String url;
+
+ private String protocol;
+
+ private String visualRange;
+
+ private ArrayList<ServiceNode> nodes = new ArrayList<ServiceNode>();
+
+ public void setSingleNode(String ip, String port, int ttl) {
+ ServiceNode node = new ServiceNode();
+ if(ip != null && ip.length() > 0) {
+ node.setIp(ip);
+ } else {
+ node.setIp(null);
+ }
+ node.setPort(port);
+ node.setTtl(ttl);
+ nodes.add(node);
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java
new file mode 100644
index 0000000..1c7bdd6
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.externalservice.msb;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.openo.vnfsdk.functest.common.Config;
+import org.openo.vnfsdk.functest.externalservice.entity.ServiceRegisterEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+
+public class MicroserviceBusConsumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MicroserviceBusConsumer.class);
+
+ public static boolean registerService(ServiceRegisterEntity entity) {
+ ClientConfig config = new ClientConfig();
+ // LOG.info("microservice register body:" + ExtsysDbUtil.objectToString(entity));
+ try {
+ MicroserviceBusRest resourceserviceproxy = ConsumerFactory
+ .createConsumer(Config.getConfigration().getMsbServerAddr(), config, MicroserviceBusRest.class);
+ resourceserviceproxy.registerServce("false", entity);
+ } catch(Exception error) {
+ LOG.error("Microservice register failed!" + error.getMessage());
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java
new file mode 100644
index 0000000..02361c1
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.externalservice.msb;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+import org.openo.vnfsdk.functest.externalservice.entity.ServiceRegisterEntity;
+
+@Path("/openoapi/microservices/v1/services")
+public interface MicroserviceBusRest {
+
+ @Path("")
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate,
+ ServiceRegisterEntity entity) throws Exception;
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java
new file mode 100644
index 0000000..5c80314
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.eclipse.jetty.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.codahale.metrics.annotation.Timed;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@Path("/functest")
+@Api(tags = {" function test Management "})
+public class CommonManager {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommonManager.class);
+
+ @Path("")
+ @POST
+ @ApiOperation(value = "execute the function test")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
+ @Timed
+ public Response executeFuncTest() {
+ LOGGER.info("execute function test");
+ return null;
+ }
+
+ @Path("/{functestId}")
+ @GET
+ @ApiOperation(value = "get function test result by id")
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = String.class),
+ @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = "Unprocessable MicroServiceInfo Entity ", response = String.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "internal server error", response = String.class)})
+ @Timed
+ public Response queryResultByFuncTest(@ApiParam(value = "functestId") @PathParam("functestId") String instanceId) {
+ LOGGER.info("query functest result by id." + instanceId);
+ return null;
+
+ }
+
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java
new file mode 100644
index 0000000..acf8cc3
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.util;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+public class GsonUtil {
+
+ private final static Logger logger = LoggerFactory.getLogger(GsonUtil.class);
+
+ public static String generateId() {
+ return UUID.randomUUID().toString();
+ }
+
+ public static boolean isNotEmpty(String str) {
+ return str != null && !"".equals(str) && str.length() > 0;
+ }
+
+ /**
+ * change object to str.
+ */
+ public static String objectToString(Object obj) {
+ Gson gson = new Gson();
+ if(obj != null) {
+ return gson.toJson(obj);
+ } else {
+ return null;
+ }
+ }
+
+ public static String getNowTime() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ return sdf.format(new Date());
+ }
+}
diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java
new file mode 100644
index 0000000..4130952
--- /dev/null
+++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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 org.openo.vnfsdk.functest.util;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+public class RestResponseUtil {
+
+ public static Response getSuccessResponse(Object obj) {
+ if(obj != null) {
+ return Response.ok(obj).build();
+ } else {
+ return Response.ok().build();
+ }
+ }
+
+ public static Response getCreateSussceeResponse(Object obj) {
+ return Response.status(Status.CREATED).entity(obj).build();
+ }
+
+ public static Response getErrorResponse(Object obj) {
+ if(obj != null) {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj).build();
+ } else {
+ return Response.serverError().build();
+ }
+
+ }
+}