diff options
author | sonicke <10112215@zte.com.cn> | 2019-02-26 10:42:20 +0800 |
---|---|---|
committer | sonicke <10112215@zte.com.cn> | 2019-02-26 10:42:20 +0800 |
commit | 3062ee6e0b4ed88c5a3b10ebf8188341c5b92987 (patch) | |
tree | 2904938caca419838128bedeeaaf727bb5c957b8 /zte/sfc-driver | |
parent | 1d55cb187443fedb1004fc25b8ff7e956152adf6 (diff) |
unit test for sfc-driver
Issue-ID: VFC-1264
Change-Id: Iac257093e670e0bdaa8936c648e29b9acbe1ffbf
Signed-off-by: Zhuoyao Huang <10112215@zte.com.cn>
Diffstat (limited to 'zte/sfc-driver')
11 files changed, 97 insertions, 156 deletions
diff --git a/zte/sfc-driver/sfc-driver/pom.xml b/zte/sfc-driver/sfc-driver/pom.xml index 18270e1..90f4ad6 100644 --- a/zte/sfc-driver/sfc-driver/pom.xml +++ b/zte/sfc-driver/sfc-driver/pom.xml @@ -143,6 +143,11 @@ <artifactId>powermock-core</artifactId> <version>1.6.6</version> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.16.8</version> + </dependency> </dependencies> <build> <plugins> diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/MsbRegisterEntity.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/MsbRegisterEntity.java index 3bef7d4..2946576 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/MsbRegisterEntity.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/MsbRegisterEntity.java @@ -16,11 +16,12 @@ package org.onap.sfc.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; -import java.util.ArrayList; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) +@Data public class MsbRegisterEntity { private String serviceName; private String version; @@ -28,52 +29,4 @@ public class MsbRegisterEntity { private String protocol; private String visualRange; private List<NodeEntity> nodes; - - 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 List<NodeEntity> getNodes() { - return nodes; - } - - public void setNodes(List<NodeEntity> nodes) { - this.nodes = nodes; - } } diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/NodeEntity.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/NodeEntity.java index 493266e..2e849df 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/NodeEntity.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/NodeEntity.java @@ -16,34 +16,12 @@ package org.onap.sfc.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; @JsonIgnoreProperties(ignoreUnknown = true) +@Data public class NodeEntity { private String ip; private String port; private String ttl; - - 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 String getTtl() { - return ttl; - } - - public void setTtl(String ttl) { - this.ttl = ttl; - } } diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/Result.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/Result.java index 9d5922b..96e0ed6 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/Result.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/Result.java @@ -15,6 +15,9 @@ */ package org.onap.sfc.entity; +import lombok.Data; + +@Data public class Result { private String id; @@ -23,12 +26,4 @@ public class Result { this.id = uuid; } - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - } diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/SdnControllerInfo.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/SdnControllerInfo.java index 5aee863..8630095 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/SdnControllerInfo.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/SdnControllerInfo.java @@ -16,32 +16,11 @@ package org.onap.sfc.entity; +import lombok.Data; + +@Data public class SdnControllerInfo { String url; String userName; String password; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } } diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/PortInfo.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/PortInfo.java index 0eda970..a2f2a9f 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/PortInfo.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/PortInfo.java @@ -18,44 +18,13 @@ package org.onap.sfc.entity.portpair; import com.google.gson.annotations.SerializedName; +import lombok.Data; +@Data public class PortInfo { private String encapsulation; private String ip; private String mac; @SerializedName("port-name") private String portName; - - public String getEncapsulation() { - return encapsulation; - } - - - public String getPortName() { - return portName; - } - - public void setPortName(String portName) { - this.portName = portName; - } - - public void setEncapsulation(String encapsulation) { - this.encapsulation = encapsulation; - } - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public String getMac() { - return mac; - } - - public void setMac(String mac) { - this.mac = mac; - } } diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/ServiceFunctionParameter.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/ServiceFunctionParameter.java index 28dd1b8..569a05b 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/ServiceFunctionParameter.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/entity/portpair/ServiceFunctionParameter.java @@ -16,26 +16,12 @@ package org.onap.sfc.entity.portpair; import com.google.gson.annotations.SerializedName; +import lombok.Data; +@Data public class ServiceFunctionParameter { @SerializedName("service-function-parameter") private String serviceFunctionParamter; @SerializedName("service-function-parameter-value") private String getServiceFunctionParamterValue; - - public String getServiceFunctionParamter() { - return serviceFunctionParamter; - } - - public void setServiceFunctionParamter(String serviceFunctionParamter) { - this.serviceFunctionParamter = serviceFunctionParamter; - } - - public String getGetServiceFunctionParamterValue() { - return getServiceFunctionParamterValue; - } - - public void setGetServiceFunctionParamterValue(String getServiceFunctionParamterValue) { - this.getServiceFunctionParamterValue = getServiceFunctionParamterValue; - } } diff --git a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/resources/MsbServiceRegister.java b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/resources/MsbServiceRegister.java index aa52050..e801578 100644 --- a/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/resources/MsbServiceRegister.java +++ b/zte/sfc-driver/sfc-driver/src/main/java/org/onap/sfc/resources/MsbServiceRegister.java @@ -15,6 +15,7 @@ */ package org.onap.sfc.resources; +import lombok.Setter; import org.onap.sfc.utils.SfcDriverUtil; import org.onap.sfc.entity.MsbRegisterEntity; import org.onap.sfc.service.ConfigInfo; @@ -25,6 +26,13 @@ import org.slf4j.LoggerFactory; public class MsbServiceRegister implements Runnable { private final Logger LOGGER = LoggerFactory.getLogger(MsbServiceRegister.class); MsbRegisterEntity entity; + + @Setter + private int sleepSeconds = 30000; + + @Setter + private int retry = 20; + public MsbServiceRegister() { initInfo(); @@ -40,7 +48,7 @@ public class MsbServiceRegister implements Runnable { public void run() { boolean flag = false; int retryTimes=0; - while (!flag && retryTimes<20) + while (!flag && retryTimes< retry) { try { LOGGER.info("Register Msb start:"); @@ -53,7 +61,8 @@ public class MsbServiceRegister implements Runnable { } catch (Exception e) { LOGGER.error("Register Msb failed",e); //e.printStackTrace(); - threadSleep(30000); + threadSleep(sleepSeconds); + retryTimes++; } } diff --git a/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/TestMsbRegister.java b/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/TestMsbRegister.java index 64fe21b..994a701 100644 --- a/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/TestMsbRegister.java +++ b/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/TestMsbRegister.java @@ -19,6 +19,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.onap.sfc.entity.MsbRegisterEntity; +import org.onap.sfc.service.ConfigInfo; import org.onap.sfc.utils.SfcDriverUtil; public class TestMsbRegister { @@ -26,6 +27,9 @@ public class TestMsbRegister { @Test public void test_registerMsb() { + SfcDriverConfig sfcDriverConfig = new SfcDriverConfig(); + sfcDriverConfig.setServiceIp("127.0.0.1"); + ConfigInfo.setConfig(sfcDriverConfig); MsbRegisterEntity entity = SfcDriverUtil.getMsbRegisterInfo(); assert entity.getUrl().equals("/api/ztesdncdriver/v1"); } diff --git a/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/entity/ResultTest.java b/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/entity/ResultTest.java new file mode 100644 index 0000000..4dc0209 --- /dev/null +++ b/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/entity/ResultTest.java @@ -0,0 +1,28 @@ +package org.onap.sfc.entity; + +import org.junit.Test; + +/** + * Copyright 2018 ZTE Corporation. + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ +public class ResultTest { + @Test + public void getId() throws Exception { + String uuid = "123"; + Result result = new Result(uuid); + assert result.getId().equals(uuid); + } + +}
\ No newline at end of file diff --git a/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/resources/MsbServiceRegisterTest.java b/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/resources/MsbServiceRegisterTest.java new file mode 100644 index 0000000..03b9fbf --- /dev/null +++ b/zte/sfc-driver/sfc-driver/src/test/java/org/onap/sfc/resources/MsbServiceRegisterTest.java @@ -0,0 +1,35 @@ +package org.onap.sfc.resources; + +import org.junit.Test; +import org.onap.sfc.SfcDriverConfig; +import org.onap.sfc.service.ConfigInfo; + +/** + * Copyright 2018 ZTE Corporation. + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ +public class MsbServiceRegisterTest { + @Test + public void run() throws Exception { + SfcDriverConfig sfcDriverConfig = new SfcDriverConfig(); + sfcDriverConfig.setServiceIp("127.0.0.1"); + sfcDriverConfig.setMsbServiceUrl("http://127.0.0.0:21180/microservices"); + ConfigInfo.setConfig(sfcDriverConfig); + MsbServiceRegister msbServiceRegister = new MsbServiceRegister(); + msbServiceRegister.setSleepSeconds(1); + msbServiceRegister.setRetry(1); + msbServiceRegister.run(); + } + +}
\ No newline at end of file |