Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2F63F2009D9 for ; Tue, 3 May 2016 00:14:38 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2DEBE1609B0; Tue, 3 May 2016 00:14:38 +0200 (CEST) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 75CB71602C5 for ; Tue, 3 May 2016 00:14:37 +0200 (CEST) Received: (qmail 16692 invoked by uid 500); 2 May 2016 22:14:31 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 16681 invoked by uid 99); 2 May 2016 22:14:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 May 2016 22:14:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 44D98DFBDE; Mon, 2 May 2016 22:14:31 +0000 (UTC) From: jburwell To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request: CLOUDSTACK-9299: Out-of-band Management f... Content-Type: text/plain Message-Id: <20160502221431.44D98DFBDE@git1-us-west.apache.org> Date: Mon, 2 May 2016 22:14:31 +0000 (UTC) archived-at: Mon, 02 May 2016 22:14:38 -0000 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 buildRandomOptionsMap() { + ImmutableMap.Builder 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---