Missing header and fix unit test failures

This commit is contained in:
nvazquez 2018-05-18 08:08:47 -03:00
parent 5f00a3e00e
commit 526149dc3b
3 changed files with 46 additions and 8 deletions

View File

@ -1,3 +1,20 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.apache.cloudstack.api.response;
import com.cloud.serializer.Param;

View File

@ -173,7 +173,9 @@ public class BackupVO implements Backup {
if (StringUtils.isNotBlank(volumes)) {
String[] strIds = StringUtils.substringBetween(volumes,"[", "]").split(",");
for (String strId: strIds) {
volumeIds.add(Long.valueOf(strId));
if (StringUtils.isNotBlank(strId)) {
volumeIds.add(Long.valueOf(strId));
}
}
}
}
@ -186,21 +188,23 @@ public class BackupVO implements Backup {
public void setVolumeIds(List<Long> volumes) {
if (CollectionUtils.isEmpty(volumes)) {
this.volumeIds = new ArrayList<>();
volumeIds = new ArrayList<>();
} else {
this.volumeIds = new ArrayList<>(volumes);
volumeIds = new ArrayList<>(volumes);
}
convertVolumeIdsToString();
}
private void convertVolumeIdsToString() {
StringJoiner stringJoiner = new StringJoiner(",", "[", "]");
if (CollectionUtils.isNotEmpty(this.volumeIds)) {
for (Long volId : this.volumeIds) {
if (CollectionUtils.isNotEmpty(volumeIds)) {
for (Long volId : volumeIds) {
stringJoiner.add(String.valueOf(volId));
}
volumes = stringJoiner.toString();
} else {
volumes = null;
}
this.volumes = stringJoiner.toString();
}
protected String getVolumes() {

View File

@ -43,7 +43,7 @@ public class BackupVOTest {
@Test
public void testVolumeIdsEmptyList() {
vo.setVolumeIds(new ArrayList<>());
Assert.assertEquals("[]", vo.getVolumes());
Assert.assertEquals(null, vo.getVolumes());
Assert.assertEquals(new ArrayList<>(), vo.getVolumeIds());
}
@ -54,8 +54,25 @@ public class BackupVOTest {
}
@Test
public void testDecodeVolumesString() {
public void testDecodeVolumesStringNotEmptyList() {
vo.setVolumes("[1,2,3,4]");
Assert.assertEquals(ids, vo.getVolumeIds());
}
@Test
public void testDecodeVolumesStringEmptyList() {
vo.setVolumes(null);
Assert.assertEquals(new ArrayList<>(), vo.getVolumeIds());
}
@Test
public void testSetVolumeIdsMultipleTimes() {
List<Long> list = Arrays.asList(1L, 2L);
vo.setVolumeIds(list);
Assert.assertEquals("[1,2]", vo.getVolumes());
vo.setVolumeIds(new ArrayList<>());
Assert.assertEquals(null, vo.getVolumes());
vo.setVolumeIds(ids);
Assert.assertEquals("[1,2,3,4]", vo.getVolumes());
}
}