|
| 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 | +package org.apache.cloudstack.api.command.test; |
| 18 | + |
| 19 | +import junit.framework.TestCase; |
| 20 | +import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd; |
| 21 | +import org.apache.cloudstack.usage.Usage; |
| 22 | +import org.apache.cloudstack.usage.UsageService; |
| 23 | +import org.junit.Before; |
| 24 | +import org.junit.Rule; |
| 25 | +import org.junit.Test; |
| 26 | +import org.junit.rules.ExpectedException; |
| 27 | +import org.mockito.Mockito; |
| 28 | + |
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.List; |
| 31 | + |
| 32 | +public class UsageCmdTest extends TestCase { |
| 33 | + |
| 34 | + private GetUsageRecordsCmd getUsageRecordsCmd; |
| 35 | + |
| 36 | + @Rule |
| 37 | + public ExpectedException expectedException = ExpectedException.none(); |
| 38 | + |
| 39 | + @Before |
| 40 | + public void setUp() { |
| 41 | + |
| 42 | + getUsageRecordsCmd = new GetUsageRecordsCmd() { |
| 43 | + |
| 44 | + }; |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testExecuteSuccess() { |
| 49 | + UsageService usageService = Mockito.mock(UsageService.class); |
| 50 | + getUsageRecordsCmd._usageService = usageService; |
| 51 | + getUsageRecordsCmd.execute(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testExecuteEmptyResult() { |
| 56 | + |
| 57 | + UsageService usageService = Mockito.mock(UsageService.class); |
| 58 | + |
| 59 | + List usageRecords = new ArrayList<Usage>(); |
| 60 | + |
| 61 | + Mockito.when(usageService.getUsageRecords(getUsageRecordsCmd)).thenReturn( |
| 62 | + usageRecords); |
| 63 | + |
| 64 | + getUsageRecordsCmd._usageService = usageService; |
| 65 | + getUsageRecordsCmd.execute(); |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments