|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.cloudstack.api.command.user.volume; |
| 19 | + |
| 20 | +import com.cloud.exception.InvalidParameterValueException; |
| 21 | +import junit.framework.TestCase; |
| 22 | +import org.junit.After; |
| 23 | +import org.junit.Before; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.mockito.MockitoAnnotations; |
| 27 | +import org.mockito.junit.MockitoJUnitRunner; |
| 28 | +import org.springframework.test.util.ReflectionTestUtils; |
| 29 | + |
| 30 | +@RunWith(MockitoJUnitRunner.class) |
| 31 | +public class CheckAndRepairVolumeCmdTest extends TestCase { |
| 32 | + private CheckAndRepairVolumeCmd checkAndRepairVolumeCmd; |
| 33 | + private AutoCloseable closeable; |
| 34 | + |
| 35 | + @Before |
| 36 | + public void setup() { |
| 37 | + closeable = MockitoAnnotations.openMocks(this); |
| 38 | + checkAndRepairVolumeCmd = new CheckAndRepairVolumeCmd(); |
| 39 | + } |
| 40 | + |
| 41 | + @After |
| 42 | + public void tearDown() throws Exception { |
| 43 | + closeable.close(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testGetRepair() { |
| 48 | + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", "all"); |
| 49 | + assertEquals("all", checkAndRepairVolumeCmd.getRepair()); |
| 50 | + |
| 51 | + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", "LEAKS"); |
| 52 | + assertEquals("leaks", checkAndRepairVolumeCmd.getRepair()); |
| 53 | + |
| 54 | + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", null); |
| 55 | + assertNull(checkAndRepairVolumeCmd.getRepair()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test(expected = InvalidParameterValueException.class) |
| 59 | + public void testGetRepairInvalid() { |
| 60 | + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", "RANDOM STRING"); |
| 61 | + checkAndRepairVolumeCmd.getRepair(); |
| 62 | + } |
| 63 | +} |
0 commit comments