Skip to content

Commit 16b7b71

Browse files
authored
Fix secondary storage selectors feature (#10546)
1 parent 8df1161 commit 16b7b71

File tree

11 files changed

+323
-7
lines changed

11 files changed

+323
-7
lines changed

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/GenericPresetVariable.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ public void setName(String name) {
4949
fieldNamesToIncludeInToString.add("name");
5050
}
5151

52+
/***
53+
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
54+
* This method should not be overridden or changed.
55+
*/
5256
@Override
53-
public String toString() {
57+
public final String toString() {
5458
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, fieldNamesToIncludeInToString.toArray(new String[0]));
5559
}
5660
}

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Resource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public void setDomainId(String domainId) {
4040
this.domainId = domainId;
4141
}
4242

43+
/***
44+
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
45+
* This method should not be overridden or changed.
46+
*/
4347
@Override
44-
public String toString() {
48+
public final String toString() {
4549
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
4650
}
4751

server/src/main/java/org/apache/cloudstack/storage/heuristics/presetvariables/Domain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.heuristics.presetvariables;
1818

19-
public class Domain extends GenericHeuristicPresetVariable{
19+
public class Domain extends GenericHeuristicPresetVariable {
2020
private String id;
2121

2222
public String getId() {

server/src/main/java/org/apache/cloudstack/storage/heuristics/presetvariables/GenericHeuristicPresetVariable.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public void setName(String name) {
3636
fieldNamesToIncludeInToString.add("name");
3737
}
3838

39+
/***
40+
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
41+
* This method should not be overridden or changed.
42+
*/
3943
@Override
40-
public String toString() {
41-
return String.format("GenericHeuristicPresetVariable %s",
42-
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
43-
this, fieldNamesToIncludeInToString.toArray(new String[0])));
44+
public final String toString() {
45+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, fieldNamesToIncludeInToString.toArray(new String[0]));
4446
}
4547
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.heuristics.presetvariables;
19+
20+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.mockito.junit.MockitoJUnitRunner;
25+
26+
@RunWith(MockitoJUnitRunner.class)
27+
public class AccountTest {
28+
29+
@Test
30+
public void toStringTestReturnsValidJson() {
31+
Account variable = new Account();
32+
variable.setName("test name");
33+
variable.setId("test id");
34+
35+
Domain domainVariable = new Domain();
36+
domainVariable.setId("domain id");
37+
domainVariable.setName("domain name");
38+
variable.setDomain(domainVariable);
39+
40+
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "id", "domain");
41+
String result = variable.toString();
42+
43+
Assert.assertEquals(expected, result);
44+
}
45+
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.heuristics.presetvariables;
19+
20+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.mockito.junit.MockitoJUnitRunner;
25+
26+
@RunWith(MockitoJUnitRunner.class)
27+
public class DomainTest {
28+
29+
@Test
30+
public void toStringTestReturnsValidJson() {
31+
Domain variable = new Domain();
32+
variable.setName("test name");
33+
variable.setId("test id");
34+
35+
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "id");
36+
String result = variable.toString();
37+
38+
Assert.assertEquals(expected, result);
39+
}
40+
41+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.heuristics.presetvariables;
19+
20+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.mockito.junit.MockitoJUnitRunner;
25+
26+
@RunWith(MockitoJUnitRunner.class)
27+
public class GenericHeuristicPresetVariableTest {
28+
29+
@Test
30+
public void toStringTestReturnsValidJson() {
31+
GenericHeuristicPresetVariable variable = new GenericHeuristicPresetVariable();
32+
variable.setName("test name");
33+
34+
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name");
35+
String result = variable.toString();
36+
37+
Assert.assertEquals(expected, result);
38+
}
39+
40+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.heuristics.presetvariables;
19+
20+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.mockito.junit.MockitoJUnitRunner;
25+
26+
@RunWith(MockitoJUnitRunner.class)
27+
public class SecondaryStorageTest {
28+
29+
@Test
30+
public void toStringTestReturnsValidJson() {
31+
SecondaryStorage variable = new SecondaryStorage();
32+
variable.setName("test name");
33+
variable.setId("test id");
34+
variable.setProtocol("test protocol");
35+
variable.setUsedDiskSize(1L);
36+
variable.setTotalDiskSize(2L);
37+
38+
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "id",
39+
"protocol", "usedDiskSize", "totalDiskSize");
40+
String result = variable.toString();
41+
42+
Assert.assertEquals(expected, result);
43+
}
44+
45+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.heuristics.presetvariables;
19+
20+
import com.cloud.hypervisor.Hypervisor;
21+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.mockito.junit.MockitoJUnitRunner;
26+
27+
@RunWith(MockitoJUnitRunner.class)
28+
public class SnapshotTest {
29+
30+
@Test
31+
public void toStringTestReturnsValidJson() {
32+
Snapshot variable = new Snapshot();
33+
variable.setName("test name");
34+
variable.setSize(1L);
35+
variable.setHypervisorType(Hypervisor.HypervisorType.KVM);
36+
37+
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "size",
38+
"hypervisorType");
39+
String result = variable.toString();
40+
41+
Assert.assertEquals(expected, result);
42+
}
43+
44+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.heuristics.presetvariables;
19+
20+
import com.cloud.hypervisor.Hypervisor;
21+
import com.cloud.storage.Storage;
22+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
23+
import org.junit.Assert;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.mockito.junit.MockitoJUnitRunner;
27+
28+
@RunWith(MockitoJUnitRunner.class)
29+
public class TemplateTest {
30+
31+
@Test
32+
public void toStringTestReturnsValidJson() {
33+
Template variable = new Template();
34+
variable.setName("test name");
35+
variable.setTemplateType(Storage.TemplateType.USER);
36+
variable.setHypervisorType(Hypervisor.HypervisorType.KVM);
37+
variable.setFormat(Storage.ImageFormat.QCOW2);
38+
39+
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "templateType",
40+
"hypervisorType", "format");
41+
String result = variable.toString();
42+
43+
Assert.assertEquals(expected, result);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)