use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class ConfigDriveBuilderTest method getProgramToGenerateIsoTestGenIsoExistsbutNotExecutable.
@Test(expected = CloudRuntimeException.class)
@PrepareForTest({ File.class, ConfigDriveBuilder.class })
public void getProgramToGenerateIsoTestGenIsoExistsbutNotExecutable() throws Exception {
PowerMockito.mockStatic(File.class);
File genIsoFileMock = Mockito.mock(File.class);
Mockito.doReturn(true).when(genIsoFileMock).exists();
Mockito.doReturn(false).when(genIsoFileMock).canExecute();
PowerMockito.whenNew(File.class).withArguments("/usr/bin/genisoimage").thenReturn(genIsoFileMock);
ConfigDriveBuilder.getProgramToGenerateIso();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class ConfigDriveBuilderTest method linkUserDataTest.
@Test
@PrepareForTest({ File.class, Script.class, ConfigDriveBuilder.class })
public void linkUserDataTest() throws Exception {
File fileMock = Mockito.mock(File.class);
Mockito.doReturn(true).when(fileMock).exists();
PowerMockito.mockStatic(File.class, Script.class);
PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(fileMock);
Script scriptMock = Mockito.mock(Script.class);
PowerMockito.whenNew(Script.class).withAnyArguments().thenReturn(scriptMock);
Mockito.doReturn(StringUtils.EMPTY).when(scriptMock).execute();
String tempDirName = "test";
ConfigDriveBuilder.linkUserData(tempDirName);
Mockito.verify(scriptMock).add(tempDirName + ConfigDrive.cloudStackConfigDriveName + "userdata/user_data.txt");
Mockito.verify(scriptMock).add(tempDirName + ConfigDrive.openStackConfigDriveName + "user_data");
Mockito.verify(scriptMock).execute();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class ConfigDriveBuilderTest method getProgramToGenerateIsoTestNotGenIsoMkIsoInLinux.
@Test
@PrepareForTest({ File.class, ConfigDriveBuilder.class })
public void getProgramToGenerateIsoTestNotGenIsoMkIsoInLinux() throws Exception {
PowerMockito.mockStatic(File.class);
File genIsoFileMock = Mockito.mock(File.class);
Mockito.doReturn(false).when(genIsoFileMock).exists();
File mkIsoProgramInLinuxFileMock = Mockito.mock(File.class);
Mockito.doReturn(true).when(mkIsoProgramInLinuxFileMock).exists();
Mockito.doReturn(true).when(mkIsoProgramInLinuxFileMock).canExecute();
PowerMockito.whenNew(File.class).withArguments("/usr/bin/genisoimage").thenReturn(genIsoFileMock);
PowerMockito.whenNew(File.class).withArguments("/usr/bin/mkisofs").thenReturn(mkIsoProgramInLinuxFileMock);
ConfigDriveBuilder.getProgramToGenerateIso();
Mockito.verify(genIsoFileMock, Mockito.times(1)).exists();
Mockito.verify(genIsoFileMock, Mockito.times(0)).canExecute();
Mockito.verify(genIsoFileMock, Mockito.times(0)).getCanonicalPath();
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(2)).exists();
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(1)).canExecute();
Mockito.verify(mkIsoProgramInLinuxFileMock, Mockito.times(1)).getCanonicalPath();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class ConfigDriveBuilderTest method linkUserDataTestUserDataFilePathDoesNotExist.
@Test
@PrepareForTest({ File.class, Script.class, ConfigDriveBuilder.class })
public void linkUserDataTestUserDataFilePathDoesNotExist() throws Exception {
File fileMock = Mockito.mock(File.class);
Mockito.doReturn(false).when(fileMock).exists();
PowerMockito.mockStatic(File.class, Script.class);
PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(fileMock);
Script scriptMock = Mockito.mock(Script.class);
PowerMockito.whenNew(Script.class).withAnyArguments().thenReturn(scriptMock);
ConfigDriveBuilder.linkUserData("test");
Mockito.verify(scriptMock, times(0)).execute();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class ConfigDriveBuilderTest method linkUserDataTestUserDataFilePathExistAndExecutionPresentedSomeError.
@Test(expected = CloudRuntimeException.class)
@PrepareForTest({ File.class, Script.class, ConfigDriveBuilder.class })
public void linkUserDataTestUserDataFilePathExistAndExecutionPresentedSomeError() throws Exception {
File fileMock = Mockito.mock(File.class);
Mockito.doReturn(true).when(fileMock).exists();
PowerMockito.mockStatic(File.class, Script.class);
PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(fileMock);
Script scriptMock = Mockito.mock(Script.class);
PowerMockito.whenNew(Script.class).withAnyArguments().thenReturn(scriptMock);
Mockito.doReturn("message").when(scriptMock).execute();
ConfigDriveBuilder.linkUserData("test");
}
Aggregations