From 3075304c7f0a4814e2de297fb6ca54e48ffe7b91 Mon Sep 17 00:00:00 2001 From: Murali-P Date: Mon, 30 Jan 2017 20:25:40 +0530 Subject: VNF SDK Function test init Code Resolved:VNFSDK-21 Function test base code Change-Id: Ib8070d0549acdea4775bd325c5a282d5e2a708e0 Signed-off-by: Murali-P --- .../openo/vnfsdk/functest/VnfSdkFuncTestApp.java | 89 +++++++++++++++++ .../functest/VnfSdkFuncTestAppConfiguration.java | 96 +++++++++++++++++++ .../org/openo/vnfsdk/functest/common/Config.java | 32 +++++++ .../functest/common/ServiceRegistration.java | 72 ++++++++++++++ .../exception/VnfSdkFuncTestException.java | 51 ++++++++++ .../externalservice/entity/ServiceNode.java | 60 ++++++++++++ .../entity/ServiceRegisterEntity.java | 105 +++++++++++++++++++++ .../msb/MicroserviceBusConsumer.java | 44 +++++++++ .../externalservice/msb/MicroserviceBusRest.java | 37 ++++++++ .../vnfsdk/functest/resource/CommonManager.java | 74 +++++++++++++++ .../org/openo/vnfsdk/functest/util/GsonUtil.java | 56 +++++++++++ .../vnfsdk/functest/util/RestResponseUtil.java | 44 +++++++++ 12 files changed, 760 insertions(+) create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestApp.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/VnfSdkFuncTestAppConfiguration.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/Config.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/common/ServiceRegistration.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/exception/VnfSdkFuncTestException.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceNode.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/ServiceRegisterEntity.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusConsumer.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/msb/MicroserviceBusRest.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/GsonUtil.java create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/util/RestResponseUtil.java (limited to 'vnf-sdk-function-test/src') 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 { + + 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 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 getNodes() { + return nodes; + } + + public void setNodes(ArrayList nodes) { + this.nodes = nodes; + } + + private String serviceName; + + private String version; + + private String url; + + private String protocol; + + private String visualRange; + + private ArrayList nodes = new ArrayList(); + + 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(); + } + + } +} -- cgit 1.2.3-korg