Skip to content

Commit 068fcea

Browse files
committed
CLOUDSTACK-9252: Add unit tests
1 parent 3fb18bd commit 068fcea

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.cloud.storage;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNull;
5+
import static org.mockito.Mockito.mock;
6+
import static org.mockito.Mockito.when;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
12+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
13+
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
14+
import org.junit.Before;
15+
import org.junit.Test;
16+
17+
public class ImageStoreDetailsUtilTest {
18+
19+
private final static long STORE_ID = 1l;
20+
private final static String STORE_UUID = "aaaa-aaaa-aaaa-aaaa";
21+
private final static String NFS_VERSION = "3";
22+
23+
ImageStoreDetailsUtil imageStoreDetailsUtil = new ImageStoreDetailsUtil();
24+
25+
ImageStoreDao imgStoreDao = mock(ImageStoreDao.class);
26+
ImageStoreDetailsDao imgStoreDetailsDao = mock(ImageStoreDetailsDao.class);
27+
28+
@Before
29+
public void setup() throws Exception {
30+
Map<String, String> imgStoreDetails = new HashMap<String, String>();
31+
imgStoreDetails.put("nfs.version", NFS_VERSION);
32+
when(imgStoreDetailsDao.getDetails(STORE_ID)).thenReturn(imgStoreDetails);
33+
34+
ImageStoreVO imgStoreVO = mock(ImageStoreVO.class);
35+
when(imgStoreVO.getId()).thenReturn(Long.valueOf(STORE_ID));
36+
when(imgStoreDao.findByUuid(STORE_UUID)).thenReturn(imgStoreVO);
37+
38+
imageStoreDetailsUtil.imageStoreDao = imgStoreDao;
39+
imageStoreDetailsUtil.imageStoreDetailsDao = imgStoreDetailsDao;
40+
}
41+
42+
@Test
43+
public void testGetNfsVersion(){
44+
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(STORE_ID);
45+
assertEquals(NFS_VERSION, nfsVersion);
46+
}
47+
48+
@Test
49+
public void testGetNfsVersionNotFound(){
50+
Map<String, String> imgStoreDetails = new HashMap<String, String>();
51+
imgStoreDetails.put("other.prop", "propValue");
52+
when(imgStoreDetailsDao.getDetails(STORE_ID)).thenReturn(imgStoreDetails);
53+
54+
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(STORE_ID);
55+
assertNull(nfsVersion);
56+
}
57+
58+
@Test
59+
public void testGetNfsVersionNoDetails(){
60+
Map<String, String> imgStoreDetails = new HashMap<String, String>();
61+
when(imgStoreDetailsDao.getDetails(STORE_ID)).thenReturn(imgStoreDetails);
62+
63+
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(STORE_ID);
64+
assertNull(nfsVersion);
65+
}
66+
67+
@Test
68+
public void testGetNfsVersionByUuid(){
69+
String nfsVersion = imageStoreDetailsUtil.getNfsVersionByUuid(STORE_UUID);
70+
assertEquals(NFS_VERSION, nfsVersion);
71+
}
72+
73+
@Test
74+
public void testGetNfsVersionByUuidNoImgStore(){
75+
when(imgStoreDao.findByUuid(STORE_UUID)).thenReturn(null);
76+
String nfsVersion = imageStoreDetailsUtil.getNfsVersionByUuid(STORE_UUID);
77+
assertNull(nfsVersion);
78+
}
79+
}

0 commit comments

Comments
 (0)