diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index ac6dee1aea9..8bf6fce881c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -58,7 +59,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the network offering") private String networkOfferingName; - @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of the network offering") + @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, description = "the display text of the network offering, defaults to the value of 'name'.") private String displayText; @Parameter(name = ApiConstants.TRAFFIC_TYPE, @@ -182,7 +183,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? networkOfferingName : displayText; } public String getTags() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java index 304b29071e6..c2d8b3b6839 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java @@ -36,6 +36,7 @@ import org.apache.cloudstack.api.response.VsphereStoragePoliciesResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import com.cloud.offering.DiskOffering; @@ -56,7 +57,7 @@ public class CreateDiskOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.DISK_SIZE, type = CommandType.LONG, required = false, description = "size of the disk offering in GB (1GB = 1,073,741,824 bytes)") private Long diskSize; - @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "alternate display text of the disk offering", length = 4096) + @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, description = "An alternate display text of the disk offering, defaults to 'name'.", length = 4096) private String displayText; @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the disk offering") @@ -179,7 +180,7 @@ public class CreateDiskOfferingCmd extends BaseCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? offeringName : displayText; } public String getOfferingName() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java index 24f5682a218..d947f6f0659 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java @@ -59,7 +59,7 @@ public class CreateServiceOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.CPU_SPEED, type = CommandType.INTEGER, required = false, description = "the CPU speed of the service offering in MHz.") private Integer cpuSpeed; - @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of the service offering") + @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, description = "The display text of the service offering, defaults to 'name'.") private String displayText; @Parameter(name = ApiConstants.PROVISIONINGTYPE, type = CommandType.STRING, description = "provisioning type used to create volumes. Valid values are thin, sparse, fat.") @@ -258,10 +258,7 @@ public class CreateServiceOfferingCmd extends BaseCmd { } public String getDisplayText() { - if (StringUtils.isEmpty(displayText)) { - throw new InvalidParameterValueException("Failed to create service offering because the offering display text has not been spified."); - } - return displayText; + return StringUtils.isEmpty(displayText) ? serviceOfferingName : displayText; } public String getProvisioningType() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java index f1c2a5b48a9..b69e7f4a828 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -56,7 +57,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the vpc offering") private String vpcOfferingName; - @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of " + "the vpc offering") + @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, description = "the display text of the vpc offering, defaults to the 'name'") private String displayText; @Parameter(name = ApiConstants.SUPPORTED_SERVICES, @@ -115,7 +116,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? vpcOfferingName : displayText; } public List getSupportedServices() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java index 47018b3b38d..ecab3930e8b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java @@ -34,6 +34,7 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; @@ -55,8 +56,7 @@ public class RegisterIsoCmd extends BaseCmd implements UserCmd { @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, - required = true, - description = "the display text of the ISO. This is usually used for display purposes.", + description = "the display text of the ISO, defaults to the 'name'", length = 4096) private String displayText; @@ -133,7 +133,7 @@ public class RegisterIsoCmd extends BaseCmd implements UserCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? isoName : displayText; } public void setDisplayText(String displayText) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java index a0902d6b66a..a5742e8d0de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -61,7 +62,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the project") private String name; - @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "display text of the project") + @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, description = "The display text of the project, defaults to the 'name“.") private String displayText; // /////////////////////////////////////////////////// @@ -98,7 +99,7 @@ public class CreateProjectCmd extends BaseAsyncCreateCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? name : displayText; } @Override diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java index a21cbfbdef7..ea4b5995bf3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java @@ -29,6 +29,7 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -67,8 +68,7 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd implements UserCmd { @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, - required = true, - description = "the display text of the template. This is usually used for display purposes.", + description = "The display text of the template, defaults to the 'name'.", length = 4096) private String displayText; @@ -144,7 +144,7 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd implements UserCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? templateName : displayText; } public Boolean isFeatured() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java index 255b11aaa24..1a5e851d884 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java @@ -39,6 +39,7 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; @@ -60,8 +61,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd { @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, - required = true, - description = "the display text of the template. This is usually used for display purposes.", + description = "The display text of the template, defaults to 'name'.", length = 4096) private String displayText; @@ -176,7 +176,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? templateName : displayText; } public String getFormat() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index af7004941b9..40048a2cd6c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.api.command.user.vpc; import com.cloud.network.NetworkService; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; @@ -72,8 +73,8 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the VPC") private String vpcName; - @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of " + - "the VPC") + @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, description = "The display text of the VPC, defaults to its 'name'.") + private String displayText; @Parameter(name = ApiConstants.CIDR, type = CommandType.STRING, required = true, description = "the cidr of the VPC. All VPC " + @@ -137,7 +138,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { } public String getDisplayText() { - return displayText; + return StringUtils.isEmpty(displayText) ? vpcName : displayText; } public Long getVpcOffering() { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmdTest.java new file mode 100644 index 00000000000..e28720f6aac --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmdTest.java @@ -0,0 +1,37 @@ +// 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.command.admin.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.springframework.test.util.ReflectionTestUtils; + +public class CreateDiskOfferingCmdTest { + + @InjectMocks + private CreateDiskOfferingCmd createDiskOfferingCmd = new CreateDiskOfferingCmd(); + + @Test + public void testGetDisplayTextWhenEmpty() { + String netName = "net-offering"; + ReflectionTestUtils.setField(createDiskOfferingCmd , "offeringName", netName); + Assert.assertEquals(createDiskOfferingCmd.getDisplayText(), netName); + } + +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java new file mode 100644 index 00000000000..8b95456a84c --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java @@ -0,0 +1,37 @@ +// 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.command.admin.offering; + +import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.springframework.test.util.ReflectionTestUtils; + +public class CreateNetworkOfferingCmdTest { + + @InjectMocks + private CreateNetworkOfferingCmd createNetworkOfferingCmd = new CreateNetworkOfferingCmd(); + + @Test + public void createVpcNtwkOffWithEmptyDisplayText() { + String netName = "network"; + ReflectionTestUtils.setField(createNetworkOfferingCmd, "networkOfferingName", netName); + Assert.assertEquals(createNetworkOfferingCmd.getDisplayText(), netName); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java new file mode 100644 index 00000000000..717b5c3262d --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java @@ -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.api.command.admin.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CreateServiceOfferingCmdTest { + + @InjectMocks + private CreateServiceOfferingCmd createServiceOfferingCmd; + + @Test + public void testGetDisplayTextWhenEmpty() { + String netName = "net-offering"; + ReflectionTestUtils.setField(createServiceOfferingCmd, "serviceOfferingName", netName); + Assert.assertEquals(createServiceOfferingCmd.getDisplayText(), netName); + } + +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java index 18a2882c678..16b716d7d63 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java @@ -25,6 +25,8 @@ import org.junit.Test; import org.apache.cloudstack.api.ApiCmdTestUtil; import org.apache.cloudstack.api.ApiConstants; +import org.springframework.test.util.ReflectionTestUtils; + public class CreateVPCOfferingCmdTest { @@ -61,4 +63,12 @@ public class CreateVPCOfferingCmdTest { Assert.assertNull(cmd.getServiceProviders()); } + @Test + public void testCreateVPCOfferingWithEmptyDisplayText() { + CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd(); + String netName = "net-vpc"; + ReflectionTestUtils.setField(cmd,"vpcOfferingName", netName); + Assert.assertEquals(cmd.getDisplayText(), netName); + } + } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java new file mode 100644 index 00000000000..55a41c61ce6 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java @@ -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.api.command.user.iso; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class RegisterIsoCmdTest { + + @InjectMocks + private RegisterIsoCmd registerIsoCmd = new RegisterIsoCmd(); + + @Test + public void testGetDisplayTextWhenEmpty() { + String netName = "net-iso"; + ReflectionTestUtils.setField(registerIsoCmd, "isoName", netName); + Assert.assertEquals(registerIsoCmd.getDisplayText(), netName); + } + +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java new file mode 100644 index 00000000000..ee3193123e0 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java @@ -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.api.command.user.project; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CreateProjectCmdTest { + + @InjectMocks + private CreateProjectCmd createProjectCmd = new CreateProjectCmd(); + + @Test + public void testGetDisplayTextWhenEmpty() { + String netName = "net-project"; + ReflectionTestUtils.setField(createProjectCmd , "name", netName); + Assert.assertEquals(createProjectCmd.getDisplayText(), netName); + } + +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java index dfd3b6e2e25..0c31e501519 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java @@ -30,6 +30,8 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + import java.util.ArrayList; @RunWith(MockitoJUnitRunner.class) @@ -139,4 +141,12 @@ public class RegisterTemplateCmdTest { testIsDeployAsIsBase(Hypervisor.HypervisorType.XenServer, true, false); testIsDeployAsIsBase(Hypervisor.HypervisorType.Any, true, false); } + + @Test + public void testGetDisplayTextWhenEmpty() { + registerTemplateCmd = new RegisterTemplateCmd(); + String netName = "net-template"; + ReflectionTestUtils.setField(registerTemplateCmd , "templateName", netName); + Assert.assertEquals(registerTemplateCmd.getDisplayText(), netName); + } } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java index 92ac0057873..17c8e2392ed 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java @@ -133,6 +133,12 @@ public class CreateVPCCmdTest extends TestCase { Assert.assertTrue(cmd.getDisplayVpc()); } + public void testGetDisplayTextWhenEmpty() { + String netName = "net-vpc"; + ReflectionTestUtils.setField(cmd, "vpcName", netName); + Assert.assertEquals(cmd.getDisplayText(), netName); + } + public void testCreate() throws ResourceAllocationException { Vpc vpc = Mockito.mock(Vpc.class); ReflectionTestUtils.setField(cmd, "zoneId", 1L); diff --git a/server/src/test/java/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java b/server/src/test/java/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java index 72bd7bb0cd8..a37b3afea31 100644 --- a/server/src/test/java/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java +++ b/server/src/test/java/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java @@ -249,5 +249,4 @@ public class CreateNetworkOfferingTest extends TestCase { // System.out.println("Creating Vpc Network Offering"); assertNotNull("Vpc Isolated network offering with Vpc and Netscaler provider ", off); } - } diff --git a/server/src/test/resources/db.properties b/server/src/test/resources/db.properties index 5eefc45ea50..e1cc0487aea 100644 --- a/server/src/test/resources/db.properties +++ b/server/src/test/resources/db.properties @@ -17,7 +17,7 @@ # management server clustering parameters, change cluster.node.IP to the machine IP address -# in which the management server is running +# in which the management server is running cluster.node.IP=127.0.0.1 cluster.servlet.port=9090 diff --git a/test/integration/smoke/test_projects.py b/test/integration/smoke/test_projects.py index 79d364fa47b..91fc722527c 100644 --- a/test/integration/smoke/test_projects.py +++ b/test/integration/smoke/test_projects.py @@ -1820,3 +1820,125 @@ class TestProjectSuspendActivate(cloudstackTestCase): "VM should be in Running state after project activation" ) return + +class TestProjectWithEmptyDisplayText(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + cls.testClient = super( + TestProjectWithEmptyDisplayText, + cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services + # Get Zone + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.hypervisor = cls.testClient.getHypervisorInfo() + cls.domain = get_domain(cls.api_client) + cls.services['mode'] = cls.zone.networktype + cls.template = get_test_template( + cls.api_client, + cls.zone.id, + cls.hypervisor + ) + cls._cleanup = [] + cls.isGlobalSettingInvalid = False + configs = Configurations.list( + cls.api_client, + name='project.invite.required' + ) + + if (configs[0].value).lower() != 'false': + cls.isGlobalSettingInvalid = True + return + + # Create account, service offering, disk offering etc. + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + cls._cleanup.append(cls.disk_offering) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"], + domainid=cls.domain.id + ) + cls._cleanup.append(cls.service_offering) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.append(cls.account) + cls.user = Account.create( + cls.api_client, + cls.services["account"], + admin=True, + domainid=cls.domain.id + ) + cls._cleanup.append(cls.user) + + # Create project as a domain admin + cls.project = Project.create( + cls.api_client, + cls.services["project"], + account=cls.account.name, + domainid=cls.account.domainid + ) + cls._cleanup.append(cls.project) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + return + + @classmethod + def tearDownClass(cls): + super(TestProjectWithEmptyDisplayText, cls).tearDownClass() + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + if self.isGlobalSettingInvalid: + self.skipTest("'project.invite.required' should be set to false") + return + + def tearDown(self): + super(TestProjectWithEmptyDisplayText, self).tearDown() + + @attr( + tags=[ + "advanced", + "basic", + "sg", + "eip", + "advancedns", + "simulator"], + required_hardware="false") + def test_11_create_project_with_empty_displayText(self): + """ create Project with Empty DisplayText + """ + # Validate the following + # 1. Create a project. + # 2. Give empty displayText + # 3. Verify displayText takes content of Project name. + + self.services["project"]["displaytext"] = "" + + # Create project as a domain admin + project = Project.create( + self.apiclient, + self.services["project"], + account=self.account.name, + domainid=self.account.domainid + ) + + self.cleanup.append(project) + + self.assertEqual( + project.displaytext, + project.name, + "displayText does not matches project name" + ) + + return diff --git a/ui/src/views/image/RegisterOrUploadIso.vue b/ui/src/views/image/RegisterOrUploadIso.vue index cf1435a6034..6219429a7fb 100644 --- a/ui/src/views/image/RegisterOrUploadIso.vue +++ b/ui/src/views/image/RegisterOrUploadIso.vue @@ -260,7 +260,6 @@ export default { url: [{ required: true, message: this.$t('label.upload.iso.from.local') }], file: [{ required: true, message: this.$t('message.error.required.input') }], name: [{ required: true, message: this.$t('message.error.required.input') }], - displaytext: [{ required: true, message: this.$t('message.error.required.input') }], zoneid: [{ required: true, message: this.$t('message.error.select') }], ostypeid: [{ required: true, message: this.$t('message.error.select') }] }) diff --git a/ui/src/views/image/RegisterOrUploadTemplate.vue b/ui/src/views/image/RegisterOrUploadTemplate.vue index e4d4687c326..500d0270746 100644 --- a/ui/src/views/image/RegisterOrUploadTemplate.vue +++ b/ui/src/views/image/RegisterOrUploadTemplate.vue @@ -441,7 +441,6 @@ export default { url: [{ required: true, message: this.$t('message.error.required.input') }], file: [{ required: true, message: this.$t('message.error.required.input') }], name: [{ required: true, message: this.$t('message.error.required.input') }], - displaytext: [{ required: true, message: this.$t('message.error.required.input') }], zoneids: [ { type: 'array', required: true, message: this.$t('message.error.select') }, { diff --git a/ui/src/views/network/CreateVpc.vue b/ui/src/views/network/CreateVpc.vue index fb2d110f92c..663538f97b1 100644 --- a/ui/src/views/network/CreateVpc.vue +++ b/ui/src/views/network/CreateVpc.vue @@ -222,7 +222,6 @@ export default { }) this.rules = reactive({ name: [{ required: true, message: this.$t('message.error.required.input') }], - displaytext: [{ required: true, message: this.$t('message.error.required.input') }], zoneid: [{ required: true, message: this.$t('label.required') }], cidr: [{ required: true, message: this.$t('message.error.required.input') }], vpcofferingid: [{ required: true, message: this.$t('label.required') }] diff --git a/ui/src/views/offering/AddComputeOffering.vue b/ui/src/views/offering/AddComputeOffering.vue index ae8e07e652b..e5127becc70 100644 --- a/ui/src/views/offering/AddComputeOffering.vue +++ b/ui/src/views/offering/AddComputeOffering.vue @@ -707,7 +707,6 @@ export default { }) this.rules = reactive({ name: [{ required: true, message: this.$t('message.error.required.input') }], - displaytext: [{ required: true, message: this.$t('message.error.required.input') }], cpunumber: [ { required: true, message: this.$t('message.error.required.input') }, this.naturalNumberRule diff --git a/ui/src/views/offering/AddDiskOffering.vue b/ui/src/views/offering/AddDiskOffering.vue index 880eae5135c..f11380aaf65 100644 --- a/ui/src/views/offering/AddDiskOffering.vue +++ b/ui/src/views/offering/AddDiskOffering.vue @@ -357,7 +357,6 @@ export default { }) this.rules = reactive({ name: [{ required: true, message: this.$t('message.error.required.input') }], - displaytext: [{ required: true, message: this.$t('message.error.required.input') }], disksize: [ { required: true, message: this.$t('message.error.required.input') }, { type: 'number', validator: this.validateNumber } diff --git a/ui/src/views/offering/AddNetworkOffering.vue b/ui/src/views/offering/AddNetworkOffering.vue index abdb9da05f9..80159f3c113 100644 --- a/ui/src/views/offering/AddNetworkOffering.vue +++ b/ui/src/views/offering/AddNetworkOffering.vue @@ -577,7 +577,6 @@ export default { }) this.rules = reactive({ name: [{ required: true, message: this.$t('message.error.name') }], - displaytext: [{ required: true, message: this.$t('message.error.description') }], networkrate: [{ type: 'number', validator: this.validateNumber }], serviceofferingid: [{ required: true, message: this.$t('message.error.select') }], domainid: [{ type: 'array', required: true, message: this.$t('message.error.select') }], diff --git a/ui/src/views/offering/AddVpcOffering.vue b/ui/src/views/offering/AddVpcOffering.vue index 9b9d576517f..07f36f8f3a5 100644 --- a/ui/src/views/offering/AddVpcOffering.vue +++ b/ui/src/views/offering/AddVpcOffering.vue @@ -245,7 +245,6 @@ export default { }) this.rules = reactive({ name: [{ required: true, message: this.$t('message.error.name') }], - displaytext: [{ required: true, message: this.$t('message.error.description') }], domainid: [{ type: 'array', required: true, message: this.$t('message.error.select') }], zoneid: [{ type: 'array',