mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fix secondary storage selectors feature (#10546)
This commit is contained in:
parent
8df1161f14
commit
16b7b71e36
@ -49,8 +49,12 @@ public class GenericPresetVariable {
|
||||
fieldNamesToIncludeInToString.add("name");
|
||||
}
|
||||
|
||||
/***
|
||||
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
|
||||
* This method should not be overridden or changed.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
public final String toString() {
|
||||
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, fieldNamesToIncludeInToString.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,8 +40,12 @@ public class Resource {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
/***
|
||||
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
|
||||
* This method should not be overridden or changed.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
public final String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.heuristics.presetvariables;
|
||||
|
||||
public class Domain extends GenericHeuristicPresetVariable{
|
||||
public class Domain extends GenericHeuristicPresetVariable {
|
||||
private String id;
|
||||
|
||||
public String getId() {
|
||||
|
||||
@ -36,10 +36,12 @@ public class GenericHeuristicPresetVariable {
|
||||
fieldNamesToIncludeInToString.add("name");
|
||||
}
|
||||
|
||||
/***
|
||||
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
|
||||
* This method should not be overridden or changed.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("GenericHeuristicPresetVariable %s",
|
||||
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
|
||||
this, fieldNamesToIncludeInToString.toArray(new String[0])));
|
||||
public final String toString() {
|
||||
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, fieldNamesToIncludeInToString.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AccountTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
Account variable = new Account();
|
||||
variable.setName("test name");
|
||||
variable.setId("test id");
|
||||
|
||||
Domain domainVariable = new Domain();
|
||||
domainVariable.setId("domain id");
|
||||
domainVariable.setName("domain name");
|
||||
variable.setDomain(domainVariable);
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "id", "domain");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DomainTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
Domain variable = new Domain();
|
||||
variable.setName("test name");
|
||||
variable.setId("test id");
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "id");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GenericHeuristicPresetVariableTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
GenericHeuristicPresetVariable variable = new GenericHeuristicPresetVariable();
|
||||
variable.setName("test name");
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SecondaryStorageTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
SecondaryStorage variable = new SecondaryStorage();
|
||||
variable.setName("test name");
|
||||
variable.setId("test id");
|
||||
variable.setProtocol("test protocol");
|
||||
variable.setUsedDiskSize(1L);
|
||||
variable.setTotalDiskSize(2L);
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "id",
|
||||
"protocol", "usedDiskSize", "totalDiskSize");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SnapshotTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
Snapshot variable = new Snapshot();
|
||||
variable.setName("test name");
|
||||
variable.setSize(1L);
|
||||
variable.setHypervisorType(Hypervisor.HypervisorType.KVM);
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "size",
|
||||
"hypervisorType");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.storage.Storage;
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TemplateTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
Template variable = new Template();
|
||||
variable.setName("test name");
|
||||
variable.setTemplateType(Storage.TemplateType.USER);
|
||||
variable.setHypervisorType(Hypervisor.HypervisorType.KVM);
|
||||
variable.setFormat(Storage.ImageFormat.QCOW2);
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "templateType",
|
||||
"hypervisorType", "format");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
// 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.storage.heuristics.presetvariables;
|
||||
|
||||
import com.cloud.storage.Storage;
|
||||
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VolumeTest {
|
||||
|
||||
@Test
|
||||
public void toStringTestReturnsValidJson() {
|
||||
Volume variable = new Volume();
|
||||
variable.setName("test name");
|
||||
variable.setFormat(Storage.ImageFormat.QCOW2);
|
||||
variable.setSize(1L);
|
||||
|
||||
String expected = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(variable, "name", "format",
|
||||
"size");
|
||||
String result = variable.toString();
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user