Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix secondary storage selectors feature #10546

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -49,8 +49,12 @@ public void setName(String name) {
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]));
}
}
Original file line number Diff line number Diff line change
@@ -40,8 +40,12 @@ public void setDomainId(String domainId) {
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);
}

Original file line number Diff line number Diff line change
@@ -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() {
Original file line number Diff line number Diff line change
@@ -36,10 +36,12 @@ public void setName(String name) {
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]));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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
Oops, something went wrong.