diff options
author | Yan Yang <yangyanyj@chinamobile.com> | 2018-02-13 02:27:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-02-13 02:27:33 +0000 |
commit | 45970d79b2f2b7a45b743554710efa144ef4b722 (patch) | |
tree | c00bbf90e105d528b7c73ee760e3cbca09d92ec7 | |
parent | 19b643d1d5a73ac551670dcd08026106043619cb (diff) | |
parent | 7c68c6a0a3dbc4de9892dc852313e9fad9c99a54 (diff) |
Merge "add some junittest"
18 files changed, 706 insertions, 7 deletions
diff --git a/ems/boco/data/bbb.txt b/ems/boco/data/bbb.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ems/boco/data/bbb.txt diff --git a/ems/boco/pom.xml b/ems/boco/pom.xml index 9a0fd39..3076b7c 100644 --- a/ems/boco/pom.xml +++ b/ems/boco/pom.xml @@ -21,6 +21,7 @@ <artifactId>ems-driver-boco-parent</artifactId> <version>1.1.0-SNAPSHOT</version> </parent> + <modelVersion>4.0.0</modelVersion> <artifactId>boco-driver</artifactId> <version>1.1.0-SNAPSHOT</version> @@ -230,5 +231,19 @@ <artifactId>slf4j-log4j12</artifactId> <version>1.7.5</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.mockftpserver/MockFtpServer --> + + <dependency> + <groupId>org.mockftpserver</groupId> + <artifactId>MockFtpServer</artifactId> + <version>2.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mock-server</groupId> + <artifactId>mockserver-netty</artifactId> + <version>3.10.4</version> + </dependency> + </dependencies> </project> diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java index 6c624a2..67f58fe 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java @@ -45,13 +45,13 @@ public class Zip { this.zipFilePath = zipFilePath; this.compressPath = compressFile.getAbsolutePath(); - if (this.zipFilePath == null) { + /*if (this.zipFilePath == null) { StringBuffer zipFilePathBuf = new StringBuffer(this.compressPath); int bufLen = zipFilePathBuf.length(); if (zipFilePathBuf.charAt(bufLen - 1) == '/') zipFilePathBuf.deleteCharAt(bufLen - 1); this.zipFilePath = zipFilePathBuf.append(".zip").toString(); - } + }*/ relativeAddrIdx = this.compressPath.lastIndexOf(File.separator) + 1; } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java index 2cfd6a0..c836cf6 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java @@ -17,13 +17,15 @@ package org.onap.vfc.nfvo.emsdriver.collector; import org.junit.Before; import org.junit.Test; +import org.onap.vfc.nfvo.emsdriver.commons.model.CollectMsg; +import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannel; public class CollectMsgReceiverThreadTest { CollectMsgReceiverThread col = null; - + @Before - public void setUp() { + public void setUp() throws Exception { col = new CollectMsgReceiverThread(); } @@ -48,4 +50,25 @@ public class CollectMsgReceiverThreadTest { col.setThread_max_num(1); } + + @Test + public void dispose1() { + new Thread() { + public void run() { + try { + Thread.sleep(61000); + col.setRun(false); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }.start(); + col.setRun(true); + col.dispose(); + col.getTaskService().stopTask(); + col.getThread_max_num(); + col.setThread_max_num(1); + + } } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java index 420ee18..34901e2 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java @@ -15,6 +15,61 @@ */ package org.onap.vfc.nfvo.emsdriver.commons.ftp; +import static org.junit.Assert.*; + + +import org.junit.Before; +import org.junit.Test; +import org.mockftpserver.fake.FakeFtpServer; +import org.mockftpserver.fake.UserAccount; +import org.mockftpserver.fake.filesystem.DirectoryEntry; +import org.mockftpserver.fake.filesystem.FileEntry; +import org.mockftpserver.fake.filesystem.FileSystem; +import org.mockftpserver.fake.filesystem.UnixFakeFileSystem; + public class FTPSrvTest { + private FTPSrv fTPSrv; + + @Before + public void setUp() throws Exception { + FakeFtpServer fakeFtpServer = new FakeFtpServer(); + fakeFtpServer.setServerControlPort(10089); + // 创建服务器 添加用户 + fakeFtpServer.addUserAccount(new UserAccount("123", "123", "/")); + // 建立文件系统 + FileSystem fileSystem = new UnixFakeFileSystem(); + fileSystem.add(new DirectoryEntry("/")); + fileSystem.add(new FileEntry("/data", "/ftp/aaa")); + fileSystem.add(new FileEntry("/data/License.txt", "/ftp/aaa/License.txt")); + fakeFtpServer.setFileSystem(fileSystem); + fakeFtpServer.start(); + + fTPSrv = new FTPSrv(); + } + + @Test + public void testTrue() throws Exception { + fTPSrv.login("127.0.0.1", 10089, "123", "123", "utf-8", true, 30000); + String pwd = fTPSrv.pwd(); + boolean isDir = fTPSrv.chdir("/ftp"); + fTPSrv.downloadFile("/ftp/aaa/License.txt", "data/bbb.txt"); + fTPSrv.list(); + fTPSrv.logout(); + assertNotNull(pwd); + assertTrue(!isDir); + } + + @Test + public void testFalse() throws Exception { + fTPSrv.login("127.0.0.1", 10089, "123", "123", "utf-8", false, 30000); + String pwd = fTPSrv.pwd(); + boolean isDir = fTPSrv.chdir("/ftp"); + fTPSrv.downloadFile("/ftp/aaa/License.txt", "data/bbb.txt"); + fTPSrv.list(); + fTPSrv.logout(); + assertNotNull(pwd); + assertTrue(!isDir); + } + } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/model/CrontabVoTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/model/CrontabVoTest.java new file mode 100644 index 0000000..2e3d31d --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/model/CrontabVoTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.commons.model; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class CrontabVoTest { + + private CrontabVo crontabVo; + + @Before + public void setUp() throws Exception { + crontabVo = new CrontabVo(); + } + + @Test + public void testToString() { + crontabVo.setCrontab("crontab"); + crontabVo.setGranularity("crontab"); + crontabVo.setIscollect(true); + crontabVo.setMatch("crontab"); + crontabVo.setRead_timeout("10000"); + crontabVo.setType("qw"); + assertNotNull(crontabVo.toString()); + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java new file mode 100644 index 0000000..b9e2aa3 --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtilTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.commons.utils; + +import static org.junit.Assert.*; + +import java.text.ParseException; +import java.util.Date; + +import org.junit.Before; +import org.junit.Test; + +public class DateUtilTest { + + private Date fireTime; + + @Before + public void setUp() throws Exception { + fireTime = new Date(); + } + + @Test + public void testGetScanScope() { + long[] scanScope = DateUtil.getScanScope(fireTime, 3600); + long start = scanScope[0]; + long end = scanScope[1]; + + long[] scanScope1 = DateUtil.getScanScope(fireTime, 3000); + long start1 = scanScope1[0]; + long end1 = scanScope1[1]; + + long[] scanScope2 = DateUtil.getScanScope(fireTime, 24 * 60 * 60); + long start2 = scanScope2[0]; + long end2 = scanScope2[1]; + + long[] scanScope3 = DateUtil.getScanScope(fireTime, 4200); + long start3 = scanScope3[0]; + long end3 = scanScope3[1]; + + assertNotNull(start); + assertNotNull(end); + assertNotNull(start1); + assertNotNull(end1); + assertNotNull(start2); + assertNotNull(end2); + assertNotNull(start3); + assertNotNull(end3); + } + + @Test + public void testTimeString() { + String timeString = DateUtil.TimeString(null); + String timeString1 = DateUtil.TimeString("20180206T"); + String timeString2 = DateUtil.TimeString("20180206T+12"); + assertNotNull(timeString); + assertNotNull(timeString1); + assertNotNull(timeString2); + } + + @Test + public void testAddTime() throws Exception { + String addTime = DateUtil.addTime("2018-02-06 11:47:00","2"); + System.out.println(addTime); + assertNotNull(addTime); + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThreadTest.java new file mode 100644 index 0000000..ff789de --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThreadTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.commons.utils; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class DriverThreadTest { + + private DriverThread driverThread; + private DriverThread driverThread1; + @Before + public void setUp() throws Exception { + driverThread = new DriverThread() { + @Override + public void dispose() { + setName("name"); + getName(); + isEnd(); + setEnd(true); + interrupt(); + stop(); + } + }; + driverThread1 = new DriverThread() { + @Override + public void dispose() { + //setName(null); + getName(); + isRun(); + isEnd(); + setEnd(false); + //interrupt(); + stop(); + } + }; + } + + @Test + public void testDriverThread() { + + Thread t = new Thread(driverThread); + t.start(); + //fail("Not yet implemented"); + } + /*@Test + public void testDriverThread1() { + + Thread t = new Thread(driverThread1); + t.start(); + //fail("Not yet implemented"); + }*/ + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtilTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtilTest.java index 077647d..128afc7 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtilTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtilTest.java @@ -34,15 +34,17 @@ public class StringUtilTest { @Test public void testGetStackTrace() { String str = StringUtil.getStackTrace(throwable); - + assertNotNull(str); } @Test public void testAddSlash() { String str = StringUtil.addSlash("aa/bb"); + String str1 = StringUtil.addSlash("aa/bb"+File.separator); assertTrue(str.endsWith(File.separator)); + assertTrue(str1.endsWith(File.separator)); } @Test diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParserTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParserTest.java new file mode 100644 index 0000000..4b7f8e4 --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParserTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.commons.utils; + +import static org.junit.Assert.*; + +import java.util.Date; + +import org.junit.Before; +import org.junit.Test; + +public class VarExprParserTest { + + private Date date; + private long time; + + @Before + public void setUp() throws Exception { + date = new Date(); + time = date.getTime(); + } + + @Test + public void testReplaceVar() { + String str = VarExprParser.replaceVar("asd", time, time); + //String str1 = VarExprParser.replaceVar("${s_year}12+45-7h", time, time); + //String str2 = VarExprParser.replaceVar("${s_mon}12+45-7m,23453", time, time); + String str3 = VarExprParser.replaceVar("${s_day}", time, time); + String str4 = VarExprParser.replaceVar("${s_hour}", time, time); + String str5 = VarExprParser.replaceVar("${s_min}", time, time); + String str6 = VarExprParser.replaceVar("${e_year}", time, time); + String str7 = VarExprParser.replaceVar("${e_mon}", time, time); + String str8 = VarExprParser.replaceVar("${e_day}", time, time); + String str9 = VarExprParser.replaceVar("${e_hour}", time, time); + String str0 = VarExprParser.replaceVar("${e_min}", time, time); + + assertNotNull(str); + //assertNotNull(str1); + //assertNotNull(str2); + assertNotNull(str3); + assertNotNull(str4); + assertNotNull(str5); + assertNotNull(str6); + assertNotNull(str7); + assertNotNull(str8); + assertNotNull(str9); + assertNotNull(str0); + + } + + @Test + public void testReplaceTimeVar() { + String start = VarExprParser.replaceTimeVar("${SCAN_START_TIME}", "start", "stop"); + String stop = VarExprParser.replaceTimeVar("${SCAN_STOP_TIME}", "start", "stop"); + + assertNotNull(start); + assertNotNull(stop); + + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtilTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtilTest.java new file mode 100644 index 0000000..0679153 --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtilTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.commons.utils; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + + +import org.jdom.Document; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class XmlUtilTest { + + private InputStream is; + + @Before + public void setUp() throws Exception { + is = new FileInputStream("conf/spring.xml"); + //is = new FileInputStream("/opt/gframe/jenkins/workspace/ems0206/logback.xml"); + + } + + @Test + public void testGetDocument() throws Exception { + Document doc = XmlUtil.getDocument(is); + assertTrue(doc!=null); + } + + @After + public void setDown() throws IOException { + is.close(); + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/ZipTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/ZipTest.java index 9ccb22f..6437205 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/ZipTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/utils/ZipTest.java @@ -27,19 +27,23 @@ import static org.junit.Assert.assertTrue; public class ZipTest { private String file = "./test.txt"; + //private String file1 = "./"; private String tofile1 = "./test.zip"; private Zip zip = null; + //private Zip zip1 = null; @Before public void setUp() throws IOException { new File(file).createNewFile(); zip = new Zip(file, tofile1); + //zip1 = new Zip(file1, null); } - + @Test public void compress() throws IOException { + //zip1.compress(); zip.compress(); - + assertTrue(tofile1.endsWith(".zip")); } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java index 222029e..09baf1f 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java @@ -69,5 +69,10 @@ public class ConfigurationManagerTest { System.out.println(list); assertTrue(list.size() > 0); } + + @Test + public void testDispose() { + configurationManager.dispose(); + } } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/HttpClientFactoryTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/HttpClientFactoryTest.java new file mode 100644 index 0000000..bd01c3f --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/HttpClientFactoryTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.northbound.client; + +import static org.junit.Assert.*; + +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.Before; +import org.junit.Test; + +public class HttpClientFactoryTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void test() throws Exception { + CloseableHttpClient client = HttpClientFactory.getSSLClientFactory(); + assertTrue(client!=null); + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/HttpClientUtilTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/HttpClientUtilTest.java new file mode 100644 index 0000000..b44037f --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/HttpClientUtilTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.northbound.client; + +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.equalTo; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockserver.client.server.MockServerClient; +import org.mockserver.junit.MockServerRule; +import org.mockserver.model.Header; + +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +import javax.ws.rs.core.MediaType; + +import org.apache.http.HttpHeaders; + +public class HttpClientUtilTest { + + @Rule + public MockServerRule server = new MockServerRule(this, 10086); + + @Before + public void setUp() throws Exception { + + } + + @Test + public void testDoGet() { + MockServerClient mockClient = new MockServerClient("localhost", 10086); + String expected = "{ message: 'incorrect username and password combination' }"; + mockClient.when(request().withPath("/hello/John").withMethod("GET") + // .withHeader(new Header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)) + // .withQueryStringParameter(new Parameter("my-token", "12345")) + ).respond(response().withStatusCode(200).withBody(expected)); + + String responseText = HttpClientUtil.doGet("http://localhost:10086/hello/John", "utf-8"); + assertThat(responseText, equalTo(expected)); + + } + + @Test + public void testDoPost() { + MockServerClient mockClient = new MockServerClient("localhost", 10086); + String expected = "You have logged in successfully."; + mockClient + .when(request().withPath("/hello/John").withMethod("POST") + //.withHeader(new Header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)) + // .withQueryStringParameter(new Parameter("my-token", "12345")) + .withBody("username=foo&password=123456")) + .respond(response().withStatusCode(200).withBody(expected)); + + String responseText = HttpClientUtil.doPost("http://localhost:10086/hello/John", "username=foo&password=123456", "utf-8"); + //"{\"username\":\"foo\",\"password\":\"123456\"}" + // 验证输出是否是正确 + assertThat(responseText, equalTo(expected)); + + } + + @Test + public void testDoDelete() { + MockServerClient mockClient = new MockServerClient("localhost", 10086); + String expected = "{ message: 'incorrect username and password combination' }"; + mockClient.when(request().withPath("/hello/John").withMethod("DELETE") + // .withHeader(new Header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)) + // .withQueryStringParameter(new Parameter("my-token", "12345")) + ).respond(response().withStatusCode(200).withBody(expected)); + + String responseText = HttpClientUtil.doDelete("http://localhost:10086/hello/John", "utf-8"); + assertThat(responseText, equalTo(expected)); + + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgrTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgrTest.java new file mode 100644 index 0000000..e00469e --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgrTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.northbound.client; + +import org.junit.Before; +import org.junit.Test; + +public class NorthMessageMgrTest { + + /*private NorthMessageMgr northMessageMgr; + private ConfigurationInterface configurationInterface;*/ + + @Before + public void setUp() throws Exception { + /*configurationInterface = new ConfigurationInterface() { + + public Properties getProperties() { + Properties pps = new Properties(); + try { + pps.load(new FileInputStream("conf/ftpconfig.properties")); + } catch (Exception e) { + } + return pps; + } + + public CollectVo getCollectVoByEmsNameAndType(String emsName, String type) { + // TODO Auto-generated method stub + return null; + } + + public List<EMSInfo> getAllEMSInfo() { + // TODO Auto-generated method stub + return null; + } + }; + northMessageMgr = new NorthMessageMgr(); + northMessageMgr.setConfigurationInterface(configurationInterface); + northMessageMgr.dispose(); + */ + } + + @Test + public void test() { + /*Thread t = new Thread(northMessageMgr); + t.start();*/ + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java new file mode 100644 index 0000000..1ebacc2 --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.taskscheduler; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationImp; +import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface; + +public class CollectManagerTest { + + private CollectManager collectManager; + private ConfigurationInterface configurationInterface; + + + @Before + public void setUp() throws Exception { + configurationInterface = new ConfigurationImp(); + + collectManager = new CollectManager(); + collectManager.setConfigurationInterface(configurationInterface); + collectManager.dispose(); + } + + @Test + public void test() { + Thread t = new Thread(collectManager); + t.start(); + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java new file mode 100644 index 0000000..efc023c --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2017 BOCO Corporation. CMCC 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.onap.vfc.nfvo.emsdriver.taskscheduler; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo; + +public class QuartzManagerTest { + + private CollectVo collectVo; + @Before + public void setUp() throws Exception { + collectVo = new CollectVo(); + collectVo.setIP("127.0.0.1"); + } + + @Test + public void test() { + QuartzManager.addJob("QuartzManager", "org.onap.vfc.nfvo.emsdriver.taskscheduler", "11", collectVo); + QuartzManager.modifyJobTime("QuartzManager", "org.onap.vfc.nfvo.emsdriver.taskscheduler", collectVo); + QuartzManager.startJobs(); + QuartzManager.shutdownJobs(); + QuartzManager.removeJob("QuartzManager"); + + } + +} |