Search in sources :

Example 76 with PrepareForTest

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();
}
Also used : File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 77 with PrepareForTest

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();
}
Also used : Script(com.cloud.utils.script.Script) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 78 with PrepareForTest

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();
}
Also used : File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 79 with PrepareForTest

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();
}
Also used : Script(com.cloud.utils.script.Script) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 80 with PrepareForTest

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");
}
Also used : Script(com.cloud.utils.script.Script) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)196 Test (org.junit.Test)194 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)30 StringWriter (java.io.StringWriter)28 PrintWriter (java.io.PrintWriter)27 File (java.io.File)24 ArrayList (java.util.ArrayList)16 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)14 Method (java.lang.reflect.Method)13 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)12 Config (com.twitter.heron.spi.common.Config)12 Matchers.anyString (org.mockito.Matchers.anyString)12 DialogInterface (android.content.DialogInterface)11 Intent (android.content.Intent)11 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)11 Job (hudson.model.Job)11 IOException (java.io.IOException)11 Date (java.util.Date)10 HashMap (java.util.HashMap)10