CLOUDSTACK-8641 - Adding unit tests
- Making sure that the boolean value is false and also that the
updateHostPassword() method gets called.
Signed-off-by: Rohit Yadav <[email protected]>
This closes #596
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/984fafce
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/984fafce
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/984fafce
Branch: refs/heads/reporter
Commit: 984fafce77f4a7831ff1c0f30dd433d28225f490
Parents: c3c8baf
Author: wilderrodrigues <[email protected]>
Authored: Thu Jul 16 13:38:54 2015 +0200
Committer: Rohit Yadav <[email protected]>
Committed: Thu Jul 16 18:28:27 2015 +0530
----------------------------------------------------------------------
.../command/test/UpdateHostPasswordCmdTest.java | 97 ++++++++++++++++++++
1 file changed, 97 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/984fafce/api/test/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
----------------------------------------------------------------------
diff --git
a/api/test/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
b/api/test/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
new file mode 100644
index 0000000..12f9da3
--- /dev/null
+++
b/api/test/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
@@ -0,0 +1,97 @@
+// 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.test;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import junit.framework.TestCase;
+
+import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.resource.ResourceService;
+import com.cloud.server.ManagementService;
+
+public class UpdateHostPasswordCmdTest extends TestCase {
+
+ private UpdateHostPasswordCmd updateHostPasswordCmd;
+ private ManagementService managementServer;
+ private ResourceService resourceService;
+ private ResponseGenerator responseGenerator;
+
+ @Override
+ @Before
+ public void setUp() {
+ responseGenerator = Mockito.mock(ResponseGenerator.class);
+ managementServer = Mockito.mock(ManagementService.class);
+ resourceService = Mockito.mock(ResourceService.class);
+ updateHostPasswordCmd = new UpdateHostPasswordCmd();
+ }
+
+ @Test
+ public void testExecuteForNullResult() {
+
+ updateHostPasswordCmd._mgr = managementServer;
+ updateHostPasswordCmd._resourceService = resourceService;
+
+ try {
+
Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(false);
+ } catch (final InvalidParameterValueException e) {
+ fail(e.getMessage());
+ } catch (final IllegalArgumentException e) {
+ fail(e.getMessage());
+ }
+
+ try {
+ updateHostPasswordCmd.execute();
+ } catch (final ServerApiException exception) {
+ Assert.assertEquals("Failed to update config",
exception.getDescription());
+ }
+
+ assertFalse("The attribute updatePasswdOnHost should be false, but it
isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost());
+ verify(managementServer,
times(1)).updateHostPassword(updateHostPasswordCmd);
+ }
+
+ @Test
+ public void testCreateSuccess() {
+
+ updateHostPasswordCmd._mgr = managementServer;
+ updateHostPasswordCmd._resourceService = resourceService;
+ updateHostPasswordCmd._responseGenerator = responseGenerator;
+
+ try {
+
Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(true);
+ } catch (final Exception e) {
+ fail("Received exception when success expected " + e.getMessage());
+ }
+
+ try {
+ updateHostPasswordCmd.execute();
+ } catch (final ServerApiException exception) {
+ assertEquals("Failed to update config",
exception.getDescription());
+ }
+
+ assertFalse("The attribute updatePasswdOnHost should be false, but it
isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost());
+ verify(managementServer,
times(1)).updateHostPassword(updateHostPasswordCmd);
+ }
+}
\ No newline at end of file