From ecdf5839b8c1c17b0b774466627c7ee10e83e764 Mon Sep 17 00:00:00 2001 From: “shentao” Date: Sun, 18 Sep 2016 19:17:29 +0800 Subject: modify common module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id2553bbffe2a3aea2e944c0a8fcec771b5ccf277 Signed-off-by: “shentao” --- .../roa/impl/ServiceGatewayRoaModuleImplTest.java | 366 ++++++++++----------- .../service/impl/ServiceGatewayImplTest.java | 144 ++++---- 2 files changed, 255 insertions(+), 255 deletions(-) (limited to 'servicegateway/service/src/test/java/org') diff --git a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java index fabe83d7..adbcd757 100644 --- a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java +++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImplTest.java @@ -1,183 +1,183 @@ -/* - * Copyright (c) 2016, 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.gso.gui.servicegateway.roa.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.sql.SQLException; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; -import org.openo.baseservice.util.RestUtils; -import org.openo.gso.gui.servicegateway.exception.HttpCode; -import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl; -import org.openo.gso.gui.servicegateway.util.http.HttpUtil; - -import mockit.Mock; -import mockit.MockUp; - -/** - * Test ServicemgrRoaModuleImpl class.
- *

- *

- * - * @author - * @version GSO 0.5 2016/8/3 - */ -public class ServiceGatewayRoaModuleImplTest { - - /** - * File path - */ - private static final String FILE_PATH = "src/test/resources/json/"; - - /** - * Service ROA. - */ - ServiceGatewayRoaModuleImpl serviceRoa = new ServiceGatewayRoaModuleImpl(); - - /** - * Service manager. - */ - ServiceGatewayImpl serviceManager = new ServiceGatewayImpl(); - - - /** - * Http request. - */ - HttpServletRequest httpRequest; - - /** - * Rest response. - */ - RestfulResponse responseSuccess; - - /** - * Before executing UT, start sql.
- * - * @since GSO 0.5 - */ - @Before - public void start() throws IOException, SQLException { - responseSuccess = new RestfulResponse(); - responseSuccess.setStatus(HttpCode.RESPOND_OK); - } - - - - /** - * After executing UT, close session
- * - * @since GSO 0.5 - */ - @After - public void stop() { - - } - - /** - * Test create service.
- * - * @throws ServiceException when fail to operate database or parameter is wrong. - * @since GSO 0.5 - */ - @Test - public void testCreateService() throws ServiceException { - // mock request body - mockGetRequestBody(FILE_PATH + "createServiceInstance.json"); - - mockPost(responseSuccess); - - serviceRoa.createService(httpRequest); - } - - /** - * Test delete service.
- * - * @throws ServiceException when fail to operate database or parameter is wrong. - * @since GSO 0.5 - */ - @Test - public void testDeleteService() throws ServiceException { - serviceRoa.deleteService("1", httpRequest); - } - - /** - * Mock to get request body.
- * - * @param file json file path. - * @since GSO 0.5 - */ - private void mockGetRequestBody(final String file) { - new MockUp() { - - @Mock - public String getRequestBody(HttpServletRequest request) { - return getJsonString(file); - } - }; - } - - /** - * Mock rest request for post.
- * - * @param response rest response - * @since GSO 0.5 - */ - private void mockPost(final RestfulResponse response) { - new MockUp() { - - @Mock - public RestfulResponse post(final String url, Object sendObj, HttpServletRequest httpRequest) { - return response; - } - }; - } - - /** - * Get json string from file.
- * - * @param file the path of file - * @return json string - * @throws IOException when fail to read - * @since GSO 0.5 - */ - private String getJsonString(final String file) { - if(StringUtils.isEmpty(file)) { - return ""; - } - - String json = null; - try { - FileInputStream fileStream = new FileInputStream(new File(file)); - json = IOUtils.toString(fileStream); - } catch(Exception e) { - Assert.fail(e.getMessage()); - } - - return json; - } -} +/* + * Copyright (c) 2016, 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.gso.gui.servicegateway.roa.impl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.sql.SQLException; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.baseservice.util.RestUtils; +import org.openo.gso.gui.servicegateway.exception.HttpCode; +import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl; +import org.openo.gso.gui.servicegateway.util.http.HttpUtil; + +import mockit.Mock; +import mockit.MockUp; + +/** + * Test ServicemgrRoaModuleImpl class.
+ *

+ *

+ * + * @author + * @version GSO 0.5 2016/8/3 + */ +public class ServiceGatewayRoaModuleImplTest { + + /** + * File path + */ + private static final String FILE_PATH = "src/test/resources/json/"; + + /** + * Service ROA. + */ + ServiceGatewayRoaModuleImpl serviceRoa = new ServiceGatewayRoaModuleImpl(); + + /** + * Service manager. + */ + ServiceGatewayImpl serviceManager = new ServiceGatewayImpl(); + + + /** + * Http request. + */ + HttpServletRequest httpRequest; + + /** + * Rest response. + */ + RestfulResponse responseSuccess; + + /** + * Before executing UT, start sql.
+ * + * @since GSO 0.5 + */ + @Before + public void start() throws IOException, SQLException { + responseSuccess = new RestfulResponse(); + responseSuccess.setStatus(HttpCode.RESPOND_OK); + } + + + + /** + * After executing UT, close session
+ * + * @since GSO 0.5 + */ + @After + public void stop() { + + } + + /** + * Test create service.
+ * + * @throws ServiceException when fail to operate database or parameter is wrong. + * @since GSO 0.5 + */ + @Test + public void testCreateService() throws ServiceException { + // mock request body + mockGetRequestBody(FILE_PATH + "createServiceInstance.json"); + + mockPost(responseSuccess); + + serviceRoa.createService(httpRequest); + } + + /** + * Test delete service.
+ * + * @throws ServiceException when fail to operate database or parameter is wrong. + * @since GSO 0.5 + */ + @Test + public void testDeleteService() throws ServiceException { + serviceRoa.deleteService("1", httpRequest); + } + + /** + * Mock to get request body.
+ * + * @param file json file path. + * @since GSO 0.5 + */ + private void mockGetRequestBody(final String file) { + new MockUp() { + + @Mock + public String getRequestBody(HttpServletRequest request) { + return getJsonString(file); + } + }; + } + + /** + * Mock rest request for post.
+ * + * @param response rest response + * @since GSO 0.5 + */ + private void mockPost(final RestfulResponse response) { + new MockUp() { + + @Mock + public RestfulResponse post(final String url, Object sendObj, HttpServletRequest httpRequest) { + return response; + } + }; + } + + /** + * Get json string from file.
+ * + * @param file the path of file + * @return json string + * @throws IOException when fail to read + * @since GSO 0.5 + */ + private String getJsonString(final String file) { + if(StringUtils.isEmpty(file)) { + return ""; + } + + String json = null; + try { + FileInputStream fileStream = new FileInputStream(new File(file)); + json = IOUtils.toString(fileStream); + } catch(Exception e) { + Assert.fail(e.getMessage()); + } + + return json; + } +} diff --git a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java index bf2efa02..fddebe00 100644 --- a/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java +++ b/servicegateway/service/src/test/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImplTest.java @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2016, 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.gso.gui.servicegateway.service.impl; - - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * Test ServiceGatewayImpl Class.
- *

- *

- * - * @author - * @version GSO 0.5 2016/8/3 - */ -public class ServiceGatewayImplTest { - - /** - * Service manager. - */ - ServiceGatewayImpl serviceManager = new ServiceGatewayImpl(); - - /** - * Http request. - */ - HttpServletRequest httpRequest; - - @Before - public void start() { - } - - /** - * Invalid parameter.
- * - * @throws ServiceException when parameter is wrong. - * @since GSO 0.5 - */ - @Test(expected = ServiceException.class) - public void testCreateServiceFail() throws ServiceException { - serviceManager.createService(null, httpRequest); - } - - /** - * Invalid parameter.
- * - * @throws ServiceException when parameter is wrong. - * @since GSO 0.5 - */ - @Test(expected = ServiceException.class) - public void testDeleteServiceFail() throws ServiceException { - serviceManager.deleteService(null, httpRequest); - } - -} +/* + * Copyright (c) 2016, 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.gso.gui.servicegateway.service.impl; + + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * Test ServiceGatewayImpl Class.
+ *

+ *

+ * + * @author + * @version GSO 0.5 2016/8/3 + */ +public class ServiceGatewayImplTest { + + /** + * Service manager. + */ + ServiceGatewayImpl serviceManager = new ServiceGatewayImpl(); + + /** + * Http request. + */ + HttpServletRequest httpRequest; + + @Before + public void start() { + } + + /** + * Invalid parameter.
+ * + * @throws ServiceException when parameter is wrong. + * @since GSO 0.5 + */ + @Test(expected = ServiceException.class) + public void testCreateServiceFail() throws ServiceException { + serviceManager.createService(null, httpRequest); + } + + /** + * Invalid parameter.
+ * + * @throws ServiceException when parameter is wrong. + * @since GSO 0.5 + */ + @Test(expected = ServiceException.class) + public void testDeleteServiceFail() throws ServiceException { + serviceManager.deleteService(null, httpRequest); + } + +} -- cgit