1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos.devtools.datasources.utils.common.util; 17 18 import ohos.devtools.datasources.utils.device.entity.DeviceIPPortInfo; 19 import ohos.devtools.datasources.utils.device.entity.DeviceType; 20 import org.junit.Assert; 21 import org.junit.Before; 22 import org.junit.Test; 23 24 import java.util.List; 25 import java.util.Map; 26 27 /** 28 * Bean Util 29 * 30 * @since 2021/5/19 16:39 31 */ 32 public class BeanUtilTest { 33 private DeviceIPPortInfo deviceIPPortInfo; 34 private byte[] serializes; 35 36 /** 37 * functional testing init 38 * 39 * @tc.name: init 40 * @tc.number: OHOS_JAVA_common_BeanUtil_init_0001 41 * @tc.desc: init 42 * @tc.type: functional testing 43 * @tc.require: AR000FK61N 44 */ 45 @Before init()46 public void init() { 47 deviceIPPortInfo = new DeviceIPPortInfo(); 48 deviceIPPortInfo.setPort(1); 49 deviceIPPortInfo.setIp(""); 50 deviceIPPortInfo.setDeviceName(""); 51 deviceIPPortInfo.setDeviceID(""); 52 deviceIPPortInfo.setDeviceType(DeviceType.FULL_HOS_DEVICE); 53 serializes = BeanUtil.serialize(deviceIPPortInfo); 54 } 55 56 /** 57 * functional testing serialize 58 * 59 * @tc.name: serialize 60 * @tc.number: OHOS_JAVA_common_BeanUtil_serialize_0001 61 * @tc.desc: serialize 62 * @tc.type: functional testing 63 * @tc.require: AR000FK61N 64 */ 65 @Test testserialize()66 public void testserialize() { 67 byte[] serialize = BeanUtil.serialize(deviceIPPortInfo); 68 Assert.assertNotNull(serialize); 69 } 70 71 /** 72 * functional testing deserialize 73 * 74 * @tc.name: deserialize 75 * @tc.number: OHOS_JAVA_common_BeanUtil_deserialize_0001 76 * @tc.desc: deserialize 77 * @tc.type: functional testing 78 * @tc.require: AR000FK61M 79 */ 80 @Test testdeserialize()81 public void testdeserialize() { 82 Object obj = new BeanUtil().deserialize(serializes); 83 Assert.assertNotNull(obj); 84 } 85 86 /** 87 * functional testing getFiledsInfo 88 * 89 * @tc.name: getFiledsInfo 90 * @tc.number: OHOS_JAVA_common_BeanUtil_getFiledsInfo_0001 91 * @tc.desc: getFiledsInfo 92 * @tc.type: functional testing 93 * @tc.require: AR000FK61N 94 */ 95 @Test testgetFiledsInfo()96 public void testgetFiledsInfo() { 97 List<Map> fieldsInfo = BeanUtil.getFieldsInfo(deviceIPPortInfo); 98 Assert.assertNotNull(fieldsInfo); 99 } 100 101 /** 102 * functional testing getFileds 103 * 104 * @tc.name: getFileds 105 * @tc.number: OHOS_JAVA_common_BeanUtil_getFileds_0001 106 * @tc.desc: getFileds 107 * @tc.type: functional testing 108 * @tc.require: AR000FK61N 109 */ 110 @Test testgetFiled()111 public void testgetFiled() { 112 List<Map<String, Object>> fields = BeanUtil.getFields(deviceIPPortInfo); 113 Assert.assertNotNull(fields); 114 } 115 116 /** 117 * functional testing getFiledsInfo 118 * 119 * @tc.name: getFiledsInfo 120 * @tc.number: OHOS_JAVA_common_BeanUtil_getFiledsInfo_0001 121 * @tc.desc: getFiledsInfo 122 * @tc.type: functional testing 123 * @tc.require: AR000FK61N 124 */ 125 @Test testgetFiledsInfos()126 public void testgetFiledsInfos() { 127 Map<String, Object> fieldsInfoInfos = BeanUtil.getFiledsInfos(deviceIPPortInfo); 128 Assert.assertNotNull(fieldsInfoInfos); 129 } 130 131 /** 132 * functional testing getObjectAttributeNames 133 * 134 * @tc.name: getObjectAttributeNames 135 * @tc.number: OHOS_JAVA_common_BeanUtil_getObjectAttributeNames_0001 136 * @tc.desc: getObjectAttributeNames 137 * @tc.type: functional testing 138 * @tc.require: AR000FK61N 139 */ 140 @Test testgetObjectAttributeNames()141 public void testgetObjectAttributeNames() { 142 List<String> objectAttributeNames = BeanUtil.getObjectAttributeNames(deviceIPPortInfo); 143 Assert.assertNotNull(objectAttributeNames); 144 } 145 146 /** 147 * functional testing getObjectValue 148 * 149 * @tc.name: getObjectValue 150 * @tc.number: OHOS_JAVA_common_BeanUtil_getObjectValue_0001 151 * @tc.desc: getObjectValue 152 * @tc.type: functional testing 153 * @tc.require: AR000FK61N 154 */ 155 @Test testgetObjectValue()156 public void testgetObjectValue() { 157 List<String> objectValue = BeanUtil.getObjectValue(deviceIPPortInfo); 158 Assert.assertNotNull(objectValue); 159 } 160 161 /** 162 * functional testing getObjectName 163 * 164 * @tc.name: getObjectName 165 * @tc.number: OHOS_JAVA_common_BeanUtil_getObjectName_0001 166 * @tc.desc: getObjectName 167 * @tc.type: functional testing 168 * @tc.require: AR000FK61N 169 */ 170 @Test testgetObjectName()171 public void testgetObjectName() { 172 String objectName = BeanUtil.getObjectName(deviceIPPortInfo); 173 Assert.assertNotNull(objectName); 174 } 175 } 176