Java Code Examples for org.powermock.api.mockito.PowerMockito#field()

The following examples show how to use org.powermock.api.mockito.PowerMockito#field() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeployTaskTest.java    From celos with Apache License 2.0 5 votes vote down vote up
@Test
public void testCelosCiDeployStart() throws Exception {


    String hadoopCoreUrl = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/config/core-site.xml").getFile();
    String hadoopHdfsUrl = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/config/hdfs-site.xml").getFile();

    File celosWfDir = tempDir.newFolder();
    File defDir = tempDir.newFolder();
    File hdfsDir = tempDir.newFolder();
    File deployDir = new File(Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/deploy").getFile());

    String targetFileStr = "{\n" +
            "    \"defaults.dir.uri\": \"" + defDir.getAbsolutePath() +"\",\n" +
            "    \"workflows.dir.uri\": \"" + celosWfDir.getAbsolutePath() +"\",\n" +
            "    \"hadoop.hdfs-site.xml\": \"" + hadoopHdfsUrl +"\",\n" +
            "    \"hadoop.core-site.xml\": \"" + hadoopCoreUrl +"\"\n" +
            "}\n";

    File targetFile = tempDir.newFile();
    FileOutputStream stream = new FileOutputStream(targetFile);
    stream.write(targetFileStr.getBytes());
    stream.flush();

    CiCommandLine commandLine = new CiCommandLine(targetFile.toURI().toString(), "DEPLOY", deployDir.getAbsolutePath(), "workflow", "testDir", "uname", false, null, "/some/hdfs/root");

    DeployTask deployTask = new DeployTask(commandLine);

    Field f = PowerMockito.field(CelosCiContext.class, "hdfsPrefix");
    f.set(deployTask.getCiContext(), hdfsDir.getAbsolutePath());

    deployTask.start();
    Assert.assertArrayEquals(celosWfDir.list(), new String[] {"workflow.js"});
    Set<String> resultSet = getFilesWithoutCrc(new File(hdfsDir, "some/hdfs/root/workflow"));
    Assert.assertEquals(Sets.newHashSet("file1", "file2"), resultSet);

}
 
Example 2
Source File: OvsdbNodeUpdateCommandTest.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
static Operations setOpField() throws Exception {
    Field opField = PowerMockito.field(Operations.class, "op");
    Operations mockOp = mock(Operations.class);
    opField.set(Operations.class, mockOp);
    return mockOp;
}
 
Example 3
Source File: UndeployTaskTest.java    From celos with Apache License 2.0 4 votes vote down vote up
@Test
public void testCelosCiUndeployStart() throws Exception {


    String hadoopCoreUrl = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/config/core-site.xml").getFile();
    String hadoopHdfsUrl = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/config/hdfs-site.xml").getFile();

    File celosWfDir = tempDir.newFolder();
    File defDir = tempDir.newFolder();
    File hdfsDir = tempDir.newFolder();
    File deployDir = new File(Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/deploy").getFile());

    String targetFileStr = "{\n" +
            "    \"defaults.dir.uri\": \"" + defDir.getAbsolutePath() +"\",\n" +
            "    \"workflows.dir.uri\": \"" + celosWfDir.getAbsolutePath() +"\",\n" +
            "    \"hadoop.hdfs-site.xml\": \"" + hadoopHdfsUrl +"\",\n" +
            "    \"hadoop.core-site.xml\": \"" + hadoopCoreUrl +"\"\n" +
            "}\n";

    File targetFile = tempDir.newFile();
    FileOutputStream stream = new FileOutputStream(targetFile);
    stream.write(targetFileStr.getBytes());
    stream.flush();

    CiCommandLine commandLine = new CiCommandLine(targetFile.toURI().toString(), "UNDEPLOY", null, "workflow", "testDir", "uname", false, null, "/some/hdfs/root");

    UndeployTask undeployTask = new UndeployTask(commandLine);

    Field f = PowerMockito.field(CelosCiContext.class, "hdfsPrefix");
    f.set(undeployTask.getCiContext(), hdfsDir.getAbsolutePath());

    File workflowFile = new File(celosWfDir, "workflow.js");
    workflowFile.createNewFile();

    File hdfsDirFullPath = new File(hdfsDir, "some/hdfs/root/workflow");
    hdfsDirFullPath.mkdirs();
    new File(hdfsDirFullPath, "file1").createNewFile();
    new File(hdfsDirFullPath, "file2").createNewFile();

    Assert.assertTrue(workflowFile.exists());
    Assert.assertEquals(Sets.newHashSet("file1", "file2"), Sets.newHashSet(hdfsDirFullPath.list()));

    undeployTask.start();

    Assert.assertFalse(workflowFile.exists());
    Assert.assertFalse(hdfsDirFullPath.exists());
}