Search in sources :

Example 66 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project heron by twitter.

the class RuntimeManagerRunnerTest method testUpdateTopologyUserRuntimeConfig.

@PrepareForTest({ NetworkUtils.class, Runtime.class })
@Test
public void testUpdateTopologyUserRuntimeConfig() throws Exception {
    String testConfig = "topology.user:test,testSpout:topology.user:1,testBolt:topology.user:4";
    URL expectedURL = new URL("http://host:1/runtime_config/update?topologyid=topology-id&" + "runtime-config=topology.user:test&runtime-config=testSpout:topology.user:1&" + "runtime-config=testBolt:topology.user:4");
    // Success case
    ISchedulerClient client = mock(ISchedulerClient.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    HttpURLConnection connection = mock(HttpURLConnection.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.UPDATE, client);
    TopologyManager.TManagerLocation location = TopologyManager.TManagerLocation.newBuilder().setTopologyName("topology-name").setTopologyId("topology-id").setHost("host").setControllerPort(1).setServerPort(2).build();
    when(manager.getTManagerLocation(TOPOLOGY_NAME)).thenReturn(location);
    when(connection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
    PowerMockito.mockStatic(Runtime.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(runtime)).thenReturn(manager);
    PowerMockito.mockStatic(NetworkUtils.class);
    PowerMockito.when(NetworkUtils.getProxiedHttpConnectionIfNeeded(eq(expectedURL), any(NetworkUtils.TunnelConfig.class))).thenReturn(connection);
    runner.updateTopologyUserRuntimeConfig(TOPOLOGY_NAME, testConfig);
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HttpURLConnection(java.net.HttpURLConnection) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) URL(java.net.URL) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 67 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project hudson-2.x by hudson.

the class CascadingUtilTest method testRenameCascadingParentLinks.

@Test
@PrepareForTest(Hudson.class)
public void testRenameCascadingParentLinks() throws Exception {
    String oldName = "oldCascadingProject";
    String newName = "newCascadingProject";
    List<Job> jobs = new ArrayList<Job>();
    FreeStyleProject project1 = new FreeStyleProjectMock(oldName);
    FreeStyleProjectMock project2 = new FreeStyleProjectMock("child");
    project2.setCascadingProject(project1);
    jobs.add(project1);
    jobs.add(project2);
    mockStatic(Hudson.class);
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getAllItems(Job.class)).andReturn(jobs);
    expect(Hudson.getInstance()).andReturn(hudson);
    replay(Hudson.class, hudson);
    CascadingUtil.renameCascadingParentLinks(oldName, newName);
    verify(Hudson.class, hudson);
    assertEquals(newName, project2.getCascadingProjectName());
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) Job(hudson.model.Job) FreeStyleProject(hudson.model.FreeStyleProject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 68 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project hudson-2.x by hudson.

the class CascadingUtilTest method testGetAllItems.

@Test
@PrepareForTest(Hudson.class)
public void testGetAllItems() throws Exception {
    FreeStyleProject project1 = new FreeStyleProjectMock("p1");
    FreeStyleProjectMock project2 = new FreeStyleProjectMock("p2");
    FreeStyleProjectMock project3 = new FreeStyleProjectMock("p3");
    FreeStyleProjectMock project4 = new FreeStyleProjectMock("p4");
    List<Job> jobs = new ArrayList<Job>();
    jobs.add(project1);
    jobs.add(project2);
    jobs.add(project3);
    jobs.add(project4);
    Hudson hudson = createMock(Hudson.class);
    mockStatic(Hudson.class);
    expect(hudson.getAllItems(Job.class)).andReturn(jobs).anyTimes();
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replay(Hudson.class, hudson);
    project2.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(project1, "p2");
    project3.setCascadingProject(project1);
    CascadingUtil.linkCascadingProjectsToChild(project1, "p3");
    project4.setCascadingProject(project3);
    CascadingUtil.linkCascadingProjectsToChild(project3, "p4");
    List<Job> jobs1 = CascadingUtil.getCascadingParents(Job.class, project1);
    List<Job> jobs2 = CascadingUtil.getCascadingParents(Job.class, project2);
    List<Job> jobs3 = CascadingUtil.getCascadingParents(Job.class, project3);
    List<Job> jobs4 = CascadingUtil.getCascadingParents(Job.class, project4);
    verify(Hudson.class, hudson);
    assertEquals(0, jobs1.size());
    assertFalse(jobs1.contains(project1));
    assertFalse(jobs1.contains(project2));
    assertFalse(jobs1.contains(project3));
    assertFalse(jobs1.contains(project4));
    assertEquals(3, jobs2.size());
    assertTrue(jobs2.contains(project1));
    assertFalse(jobs2.contains(project2));
    assertTrue(jobs2.contains(project3));
    assertTrue(jobs2.contains(project4));
    assertEquals(2, jobs3.size());
    assertTrue(jobs3.contains(project1));
    assertTrue(jobs3.contains(project2));
    assertFalse(jobs3.contains(project3));
    assertFalse(jobs3.contains(project4));
    assertEquals(3, jobs4.size());
    assertTrue(jobs4.contains(project1));
    assertTrue(jobs4.contains(project2));
    assertTrue(jobs4.contains(project3));
    assertFalse(jobs4.contains(project4));
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project hudson-2.x by hudson.

the class FunctionsTest method testIsAuthorFalse.

@Test
@PrepareForTest(User.class)
public void testIsAuthorFalse() throws Exception {
    mockStatic(User.class);
    User user = createMock(User.class);
    expect(user.getId()).andReturn(USER);
    expect(User.current()).andReturn(user);
    Job job = createMock(FreeStyleProject.class);
    expect(job.getCreatedBy()).andReturn("user").times(2);
    replay(User.class, user, job);
    boolean result = Functions.isAuthor(job);
    verify(User.class, user, job);
    assertFalse(result);
}
Also used : User(hudson.model.User) Job(hudson.model.Job) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 70 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project hudson-2.x by hudson.

the class FunctionsTest method testIsAuthorUserIdNull.

@Test
@PrepareForTest(User.class)
public void testIsAuthorUserIdNull() throws Exception {
    mockStatic(User.class);
    User user = createMock(User.class);
    expect(user.getId()).andReturn(null);
    expect(User.current()).andReturn(user);
    Job job = createMock(FreeStyleProject.class);
    expect(job.getCreatedBy()).andReturn(USER).times(2);
    replay(User.class, user, job);
    boolean result = Functions.isAuthor(job);
    verify(User.class, user, job);
    assertFalse(result);
}
Also used : User(hudson.model.User) Job(hudson.model.Job) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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