### Question:
LocalTaskExecutor { @SuppressWarnings("unchecked") public void execute() { AbstractElasticJobExecutor jobExecutor; CloudJobFacade jobFacade = new CloudJobFacade(getShardingContexts(), getJobConfigurationContext(), new JobEventBus()); switch (localCloudJobConfiguration.getTypeConfig().getJobType()) { case SIMPLE: jobExecutor = new SimpleJobExecutor(getJobInstance(SimpleJob.class), jobFacade); break; case DATAFLOW: jobExecutor = new DataflowJobExecutor(getJobInstance(DataflowJob.class), jobFacade); break; case SCRIPT: jobExecutor = new ScriptJobExecutor(jobFacade); break; default: throw new UnsupportedOperationException(localCloudJobConfiguration.getTypeConfig().getJobType().name()); } jobExecutor.execute(); }  @SuppressWarnings("unchecked") void execute();  }### Answer:
@Test public void assertSimpleJob() { new LocalTaskExecutor(new LocalCloudJobConfiguration(new SimpleJobConfiguration(JobCoreConfiguration .newBuilder(TestSimpleJob.class.getSimpleName(), "*/2 * * * * ?", 3).build(), TestSimpleJob.class.getName()), 1)).execute(); Assert.assertThat(TestSimpleJob.getShardingContext().getJobName(), Is.is(TestSimpleJob.class.getSimpleName())); Assert.assertThat(TestSimpleJob.getShardingContext().getShardingItem(), Is.is(1)); Assert.assertThat(TestSimpleJob.getShardingContext().getShardingTotalCount(), Is.is(3)); Assert.assertThat(TestSimpleJob.getShardingContext().getShardingItem(), Is.is(1)); Assert.assertNull(TestSimpleJob.getShardingContext().getShardingParameter()); Assert.assertThat(TestSimpleJob.getShardingContext().getJobParameter(), Is.is("")); }
@Test public void assertSpringSimpleJob() { new LocalTaskExecutor(new LocalCloudJobConfiguration(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder( TestSimpleJob.class.getSimpleName(), "*/2 * * * * ?", 3).shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").jobParameter("dbName=dangdang").build(), TestSimpleJob.class.getName()), 1, "testSimpleJob", "applicationContext.xml")).execute(); Assert.assertThat(TestSimpleJob.getShardingContext().getJobName(), Is.is(TestSimpleJob.class.getSimpleName())); Assert.assertThat(TestSimpleJob.getShardingContext().getShardingTotalCount(), Is.is(3)); Assert.assertThat(TestSimpleJob.getShardingContext().getJobParameter(), Is.is("dbName=dangdang")); Assert.assertThat(TestSimpleJob.getShardingContext().getShardingItem(), Is.is(1)); Assert.assertThat(TestSimpleJob.getShardingParameters().size(), Is.is(1)); Assert.assertThat(TestSimpleJob.getShardingParameters().iterator().next(), Is.is("Shanghai")); }
@Test public void assertDataflowJob() { TestDataflowJob.setInput(Arrays.asList("1", "2", "3")); new LocalTaskExecutor(new LocalCloudJobConfiguration(new DataflowJobConfiguration(JobCoreConfiguration .newBuilder(TestDataflowJob.class.getSimpleName(), "*/2 * * * * ?", 10).build(), TestDataflowJob.class.getName(), false), 5)).execute(); Assert.assertFalse(TestDataflowJob.getOutput().isEmpty()); for (String each : TestDataflowJob.getOutput()) { Assert.assertTrue(each.endsWith("-d")); } }
@Test public void assertScriptJob() throws IOException { new LocalTaskExecutor(new LocalCloudJobConfiguration( new ScriptJobConfiguration(JobCoreConfiguration.newBuilder("TestScriptJob", "*/2 * * * * ?", 3).build(), buildScriptCommandLine()), 1)).execute(); }
@Test(expected = JobSystemException.class) public void assertNotExistsJobClass() { new LocalTaskExecutor(new LocalCloudJobConfiguration(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("not exist", "*/2 * * * * ?", 3).build(), "not exist"), 1)).execute(); }