Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1502#discussion_r61814182
  
    --- Diff: 
server/test/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceTest.java
 ---
    @@ -0,0 +1,119 @@
    +// 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.outofbandmanagement;
    +
    +import com.cloud.utils.exception.CloudRuntimeException;
    +import com.google.common.collect.ImmutableMap;
    +import 
org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse;
    +import org.junit.Assert;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.mockito.runners.MockitoJUnitRunner;
    +
    +@RunWith(MockitoJUnitRunner.class)
    +public class OutOfBandManagementServiceTest {
    +
    +    OutOfBandManagementServiceImpl oobmService = new 
OutOfBandManagementServiceImpl();
    +
    +    @Test
    +    public void testOutOfBandManagementDriverResponseEvent() {
    +        OutOfBandManagementDriverResponse r = new 
OutOfBandManagementDriverResponse("some result", "some error", false);
    +
    +        r.setSuccess(false);
    +        r.setAuthFailure(false);
    +        Assert.assertEquals(r.toEvent(), 
OutOfBandManagement.PowerState.Event.Unknown);
    +
    +        r.setSuccess(false);
    +        r.setAuthFailure(true);
    +        Assert.assertEquals(r.toEvent(), 
OutOfBandManagement.PowerState.Event.AuthError);
    +
    +        r.setAuthFailure(false);
    +        r.setSuccess(true);
    +        r.setPowerState(OutOfBandManagement.PowerState.On);
    +        Assert.assertEquals(r.toEvent(), 
OutOfBandManagement.PowerState.Event.On);
    +
    +        r.setPowerState(OutOfBandManagement.PowerState.Off);
    +        Assert.assertEquals(r.toEvent(), 
OutOfBandManagement.PowerState.Event.Off);
    +
    +        r.setPowerState(OutOfBandManagement.PowerState.Disabled);
    +        Assert.assertEquals(r.toEvent(), 
OutOfBandManagement.PowerState.Event.Disabled);
    +    }
    +
    +    private ImmutableMap<OutOfBandManagement.Option, String> 
buildRandomOptionsMap() {
    +        ImmutableMap.Builder<OutOfBandManagement.Option, String> builder = 
new ImmutableMap.Builder<>();
    +        builder.put(OutOfBandManagement.Option.ADDRESS, "localhost");
    +        builder.put(OutOfBandManagement.Option.DRIVER, "ipmitool");
    +        return builder.build();
    +    }
    +
    +    @Test
    +    public void testUpdateOutOfBandManagementConfigValid() {
    +        OutOfBandManagement config = new OutOfBandManagementVO(123L);
    +        Assert.assertEquals(config.getPowerState(), 
OutOfBandManagement.PowerState.Disabled);
    +        config = oobmService.updateConfig(config, buildRandomOptionsMap());
    +        Assert.assertEquals(config.getAddress(), "localhost");
    +        Assert.assertEquals(config.getDriver(), "ipmitool");
    +        Assert.assertEquals(config.getPowerState(), 
OutOfBandManagement.PowerState.Disabled);
    +    }
    +
    +    @Test
    +    public void testUpdateOutOfBandManagementConfigInValid() {
    +        try {
    +            oobmService.updateConfig(null, buildRandomOptionsMap());
    +            Assert.fail("CloudRuntimeException was expect for out-of-band 
management not configured for the host");
    +        } catch (CloudRuntimeException ignored) {
    +        }
    +
    +        try {
    +            oobmService.updateConfig(null, null);
    +            Assert.fail("CloudRuntimeException was expect for out-of-band 
management not configured for the host");
    +        } catch (CloudRuntimeException ignored) {
    +        }
    +
    +        OutOfBandManagement config = new OutOfBandManagementVO(123L);
    +        config.setAddress(null);
    +        config = oobmService.updateConfig(config, null);
    +        Assert.assertEquals(config.getAddress(), null);
    +        Assert.assertEquals(config.getPowerState(), 
OutOfBandManagement.PowerState.Disabled);
    --- End diff --
    
    Consider dividing this test method into three -- one for each failure 
scenario and another for the success scenario.  Also, for the failure methods, 
use the ``expected`` attribute on the ``@Test`` annotation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to