org.apache.commons.lang.reflect.FieldUtils Java Examples

The following examples show how to use org.apache.commons.lang.reflect.FieldUtils. 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: PomIOTest.java    From pom-manipulation-ext with Apache License 2.0 8 votes vote down vote up
@Test
public void testRoundTripPOMs()
                throws Exception
{
    URL resource = PomIOTest.class.getResource( filename );
    assertNotNull( resource );
    File pom = new File( resource.getFile() );
    assertTrue( pom.exists() );

    File targetFile = folder.newFile( "target.xml" );
    FileUtils.copyFile( pom, targetFile );

    List<Project> projects = pomIO.parseProject( targetFile );

    assertNull( projects.get( 0 ).getModel().getModelEncoding() );

    // We don't want this to be the execution root so that it doesn't add "Modified by" which breaks the comparison
    FieldUtils.writeDeclaredField( projects.get( 0 ), "executionRoot", false, true);
    HashSet<Project> changed = new HashSet<>(projects);
    pomIO.rewritePOMs( changed );

    assertTrue( FileUtils.contentEqualsIgnoreEOL( pom, targetFile, StandardCharsets.UTF_8.toString() ) );
    assertTrue( FileUtils.contentEquals( targetFile, pom ) );
}
 
Example #2
Source File: CliTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void checkLocalRepositoryWithDefaults() throws Exception
{
    Cli c = new Cli();
    File settings = writeSettings( temp.newFile());

    TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-s", settings.toString()} } );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
    assertEquals( "File " + new File( ms.getRequest().getLocalRepository().getBasedir() ).getParentFile().toString()
                                  + " was not equal to " + System.getProperty( "user.home" ) + File.separatorChar
                                  + ".m2",
                  new File( ms.getRequest().getLocalRepository().getBasedir() ).getParentFile().toString(),
                  System.getProperty( "user.home" ) + File.separatorChar + ".m2" );

}
 
Example #3
Source File: PurRepository_GetObjectInformation_IT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void testDeletedFlagForObject( Callable<RepositoryElementInterface> elementProvider ) throws Exception {
  TransDelegate transDelegate = new TransDelegate( purRepository, unifiedRepository );
  JobDelegate jobDelegate = new JobDelegate( purRepository, unifiedRepository );
  FieldUtils.writeField( purRepository, "transDelegate", transDelegate, true );
  FieldUtils.writeField( purRepository, "jobDelegate", jobDelegate, true );

  RepositoryElementInterface element = elementProvider.call();
  RepositoryDirectoryInterface directory = purRepository.findDirectory( element.getRepositoryDirectory().getPath() );
  element.setRepositoryDirectory( directory );

  purRepository.save( element, null, null );
  assertNotNull( "Element was saved", element.getObjectId() );

  RepositoryObject information;
  information = purRepository.getObjectInformation( element.getObjectId(), element.getRepositoryElementType() );
  assertNotNull( information );
  assertFalse( information.isDeleted() );

  purRepository.deleteTransformation( element.getObjectId() );
  assertNotNull( "Element was moved to Trash", unifiedRepository.getFileById( element.getObjectId().getId() ) );

  information = purRepository.getObjectInformation( element.getObjectId(), element.getRepositoryElementType() );
  assertNotNull( information );
  assertTrue( information.isDeleted() );
}
 
Example #4
Source File: TextFileInputDialogTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
Example #5
Source File: RefreshableDataSourceTest.java    From das with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws SQLException, IllegalAccessException {
    DasClient client = DasClientFactory.getClient("MySqlSimple");
    SqlBuilder sqlBuilder = SqlBuilder.selectCount().from(Person.PERSON).intoObject();
    Number before = client.queryObject(sqlBuilder);

    DataSourceConfigure oldConfig = DataSourceConfigureLocatorManager.getInstance().getDataSourceConfigure("dal_shard_0");
    DataSourceConfigure newConfig = new DataSourceConfigure(oldConfig.getName(), oldConfig.getProperties());
    DataSourceConfigureChangeEvent event = new DataSourceConfigureChangeEvent("testEvent", newConfig, oldConfig);

    ConcurrentHashMap<String, DataSource> dss = (ConcurrentHashMap<String, DataSource>) FieldUtils.readStaticField(DataSourceLocator.class, "cache", true);
    RefreshableDataSource dataSource = (RefreshableDataSource) dss.get("dal_shard_0");
    SingleDataSource oldSingleDataSource = ((AtomicReference<SingleDataSource>)FieldUtils.readField(dataSource, "dataSourceReference", true)).get();
    dataSource.configChanged(event);
    Number after = client.queryObject(sqlBuilder);

    //verify datasource changed
    assertNotSame(oldSingleDataSource, ((AtomicReference<SingleDataSource>)FieldUtils.readField(dataSource, "dataSourceReference", true)).get());
    //verify new datasource work fine
    assertEquals(before, after);
}
 
Example #6
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateOffsetIdLess() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {

	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	mqQueueExcutorService.updateOffset(consumerQueueDto, consumerQueueDto.getOffset() - 1);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateOffsetIdLess error", consumerQueueRef.get().getOffset(), consumerQueueDto.getOffset());
}
 
Example #7
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateOffsetIdMore() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {

	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	mqQueueExcutorService.updateOffset(consumerQueueDto, consumerQueueDto.getOffset() + 1);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateOffsetIdLess error", consumerQueueRef.get().getOffset() + 1,
			consumerQueueDto.getOffset());
}
 
Example #8
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateLastIdLess() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {

	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);
	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	MessageDto messageDto = new MessageDto();
	messageDto.setId(consumerQueueDto.getLastId() - 1);
	mqQueueExcutorService.updateLastId(consumerQueueDto, messageDto);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateLastIdLess error", consumerQueueRef.get().getLastId(), consumerQueueDto.getOffset());
}
 
Example #9
Source File: MqQueueExcutorServiceTest.java    From pmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateLastIdMore() throws NoSuchMethodException, SecurityException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException {
	MockMqClientBase mockMqClientBase = new MockMqClientBase();
	ConsumerQueueDto consumerQueueDto = buildDefaultConsumerQueueDto();
	consumerQueueDto.setPullBatchSize(100);
	MqQueueExcutorService mqQueueExcutorService = new MqQueueExcutorService(mockMqClientBase, consumerGroupName,
			consumerQueueDto);

	mqQueueExcutorService.updateQueueMeta(consumerQueueDto);

	consumerQueueDto = buildDefaultConsumerQueueDto();
	MessageDto messageDto = new MessageDto();
	messageDto.setId(consumerQueueDto.getOffset() + 1);
	mqQueueExcutorService.updateLastId(consumerQueueDto, messageDto);
	Field f = FieldUtils.getDeclaredField(MqQueueExcutorService.class, "consumerQueueRef", true);
	@SuppressWarnings("unchecked")
	AtomicReference<ConsumerQueueDto> consumerQueueRef = (AtomicReference<ConsumerQueueDto>) (f
			.get(mqQueueExcutorService));
	assertEquals("testUpdateLastIdMore error", consumerQueueRef.get().getLastId() + 1,
			consumerQueueDto.getLastId());
}
 
Example #10
Source File: SFTPPutDialogTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
Example #11
Source File: Serializer.java    From das with Apache License 2.0 6 votes vote down vote up
default Object readField(Object target, String fieldName) {
    try {
        return FieldUtils.readField(target, fieldName, true);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example #12
Source File: TextFileInputDialogTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
Example #13
Source File: ConnectionsControllerTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  // a tricky initialisation - first inject private fields
  controller = new ConnectionsController();
  connectionsTable = mock( XulTree.class );
  FieldUtils.writeDeclaredField( controller, "connectionsTable", connectionsTable, true );

  // and then spy the controller
  controller = spy( controller );

  databaseDialog = mock( DatabaseDialog.class );
  doReturn( databaseDialog ).when( controller ).getDatabaseDialog();
  databaseMeta = mock( DatabaseMeta.class );
  doReturn( databaseMeta ).when( databaseDialog ).getDatabaseMeta();
  doNothing().when( controller ).refreshConnectionList();
  doNothing().when( controller ).showAlreadyExistsMessage();

  repository = mock( Repository.class );
  controller.init( repository );
}
 
Example #14
Source File: TestConfigCenterConfigurationSource.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void destroy_inited() throws IllegalAccessException {
  AtomicInteger count = new AtomicInteger();
  ConfigCenterClient configCenterClient = new MockUp<ConfigCenterClient>() {
    @Mock
    void destroy() {
      count.incrementAndGet();
    }
  }.getMockInstance();
  ConfigCenterConfigurationSourceImpl configCenterSource = new ConfigCenterConfigurationSourceImpl();
  FieldUtils.writeDeclaredField(configCenterSource, "configCenterClient", configCenterClient, true);

  configCenterSource.destroy();

  Assert.assertEquals(1, count.get());
}
 
Example #15
Source File: TestKieConfigurationSource.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void destroy_inited() throws IllegalAccessException {
  AtomicInteger count = new AtomicInteger();
  KieClient kieClient = new MockUp<KieClient>() {
    @Mock
    void destroy() {
      count.incrementAndGet();
    }
  }.getMockInstance();
  KieConfigurationSourceImpl kieSource = new KieConfigurationSourceImpl();
  FieldUtils
      .writeDeclaredField(kieSource, "kieClient", kieClient, true);

  kieSource.destroy();

  Assert.assertEquals(1, count.get());
}
 
Example #16
Source File: BaseHomematicClient.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Adds the battery info datapoint to the specified device if the device has
 * batteries.
 */
protected void addBatteryInfo(HmDevice device) throws HomematicClientException {
    HmBattery battery = HmBatteryTypeProvider.getBatteryType(device.getType());
    if (battery != null) {
        for (HmChannel channel : device.getChannels()) {
            if ("0".equals(channel.getNumber())) {
                try {
                    logger.debug("Adding battery type to device {}: {}", device.getType(), battery.getInfo());
                    HmDatapoint dp = new HmDatapoint();
                    FieldUtils.writeField(dp, "name", "BATTERY_TYPE", true);
                    FieldUtils.writeField(dp, "writeable", Boolean.FALSE, true);
                    FieldUtils.writeField(dp, "valueType", 20, true);
                    dp.setValue(battery.getInfo());
                    channel.addDatapoint(dp);
                } catch (IllegalAccessException ex) {
                    throw new HomematicClientException(ex.getMessage(), ex);
                }
            }
        }
    }
}
 
Example #17
Source File: Schema.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private <T extends Annotation> T getAnnotation( Class<? extends Entity> entityClass, PropertyDescriptor descriptor,
                                                Class<T> annotationClass ) {
    try {
        if ( ( descriptor.getReadMethod() != null ) && descriptor.getReadMethod()
                                                                 .isAnnotationPresent( annotationClass ) ) {
            return descriptor.getReadMethod().getAnnotation( annotationClass );
        }
        if ( ( descriptor.getWriteMethod() != null ) && descriptor.getWriteMethod()
                                                                  .isAnnotationPresent( annotationClass ) ) {
            return descriptor.getWriteMethod().getAnnotation( annotationClass );
        }
        Field field = FieldUtils.getField( entityClass, descriptor.getName(), true );
        if ( field != null ) {
            if ( field.isAnnotationPresent( annotationClass ) ) {
                return field.getAnnotation( annotationClass );
            }
        }
    }
    catch ( Exception e ) {
        logger.error( "Could not retrieve the annotations", e );
    }
    return null;
}
 
Example #18
Source File: CloneUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void copyFields(Object source, Object target, String... fieldNames)
{
	Assert.assertNotNull(source);
	Assert.assertNotNull(target);
	Assert.assertSame(source.getClass(), target.getClass());

	for (String fieldName : fieldNames)
	{
		try
		{
			Field field = FieldUtils.getField(source.getClass(), fieldName, true);
			field.setAccessible(true);
			field.set(target, field.get(source));
		}
		catch (Exception e)
		{
			Logger.getLogger(CloneUtils.class).warn(e.getMessage());
		}
	}
}
 
Example #19
Source File: HomegearClient.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Parses the device informations into the binding model.
 */
@SuppressWarnings("unchecked")
private HmDevice parseDevice(Map<String, ?> deviceData) throws IllegalAccessException {
    HmDevice device = new HmDevice();

    FieldUtils.writeField(device, "address", deviceData.get("ADDRESS"), true);
    FieldUtils.writeField(device, "type", deviceData.get("TYPE"), true);
    FieldUtils.writeField(device, "hmInterface", HmInterface.HOMEGEAR, true);

    Object[] channelList = (Object[]) deviceData.get("CHANNELS");
    for (int i = 0; i < channelList.length; i++) {
        Map<String, ?> channelData = (Map<String, ?>) channelList[i];
        device.addChannel(parseChannel(device, channelData));
    }

    return device;
}
 
Example #20
Source File: SFTPPutDialogTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
Example #21
Source File: KNSLegacyDataAdapterImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * @see ValueHolderFieldPair for information on why we need to do field sychronization related to weaving
 */
private void searchValueHolderFieldPairs(Class<?> type, List<ValueHolderFieldPair> pairs) {
    if (type.equals(Object.class)) {
        return;
    }
    for (Field valueHolderField : type.getDeclaredFields()) {
        Matcher matcher = VALUE_HOLDER_FIELD_PATTERN.matcher(valueHolderField.getName());
        if (matcher.matches()) {
            valueHolderField.setAccessible(true);
            String fieldName = matcher.group(1);
            Field valueField = FieldUtils.getDeclaredField(type, fieldName, true);
            if (valueField != null) {
                pairs.add(new ValueHolderFieldPair(valueField, valueHolderField));
            }
        }
    }
    searchValueHolderFieldPairs(type.getSuperclass(), pairs);
}
 
Example #22
Source File: CliTest.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Test
public void checkLocalRepositoryWithExplicitMavenRepoAndSettings() throws Exception
{
    File folder = temp.newFolder();
    Cli c = new Cli();
    TestUtils.executeMethod( c, "run", new Object[] { new String[]
                    { "--settings=" + getClass().getResource("/settings-test.xml").getFile(),
                                    "-Dmaven.repo.local=" + folder.toString() }} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getLocalRepository().getBasedir(), folder.toString() );
    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
}
 
Example #23
Source File: CliTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void checkLocalRepositoryWithExplicitMavenRepo() throws Exception
{
    File folder = temp.newFolder();
    Cli c = new Cli();
    TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-Dmaven.repo.local=" + folder.toString() }} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
}
 
Example #24
Source File: CliTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void checkTargetMatchesWithRun() throws Exception
{
    Cli c = new Cli();
    File pom1 = temp.newFile( );

    c.run( new String[] { "-f", pom1.toString() } );

    assertEquals( "Session file should match", pom1,
                  ( (ManipulationSession) FieldUtils.readField( c, "session", true ) ).getPom() );
}
 
Example #25
Source File: AWSClientFactory.java    From awseb-deployment-plugin with Apache License 2.0 5 votes vote down vote up
<T extends AmazonWebServiceClient> String getEndpointFor(T client) {
    try {
        URI endpointUri = (URI) FieldUtils.readField(client, "endpoint", true);

        return endpointUri.toASCIIString();
    } catch (Exception e) {
        return null;
    }
}
 
Example #26
Source File: SalesforceInputDialogTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }
  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
Example #27
Source File: JSONManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws IOException, IllegalAccessException
{
    FieldUtils.writeField(jsonManipulator, "jsonIO", new JSONIO(), true);

    URL resource = JSONIOTest.class.getResource( "npm-shrinkwrap.json");
    npmFile = tf.newFile();
    pluginFile = tf.newFile();

    FileUtils.copyURLToFile( resource, npmFile );

    URL resource2 = JSONIOTest.class.getResource( "amg-plugin-registry.json");
    FileUtils.copyURLToFile( resource2, pluginFile );
}
 
Example #28
Source File: SalesforceInputDialogTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void restoreNullInPropsUi() throws Exception {
  if ( changedPropsUi ) {
    Field props = getPropsField();
    FieldUtils.writeStaticField( props, null, true );
  }
}
 
Example #29
Source File: CliTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void checkLocalRepositoryWithSettings() throws Exception
{
    Cli c = new Cli();
    TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-settings=" + getClass().getResource( "/settings-test.xml").getFile() }} );

    ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true );
    MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true );

    assertEquals( ms.getRequest().getLocalRepository().getBasedir(),
                  ms.getRequest().getLocalRepositoryPath().toString() );
}
 
Example #30
Source File: GaInputStepTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void getNextDataEntry_WithPaging() throws Exception {
  final int recordsCount = 30;

  final String stepName = "GaInputStepTest";

  StepMeta stepMeta = new StepMeta( stepName, stepName, new GaInputStepMeta() );

  Trans trans = mock( Trans.class );

  TransMeta transMeta = mock( TransMeta.class );
  when( transMeta.findStep( stepName ) ).thenReturn( stepMeta );

  GaInputStepData data = new GaInputStepData();

  GaInputStep step = new GaInputStep( stepMeta, data, 0, transMeta, trans );

  FieldUtils.writeField( FieldUtils.getField( GaInputStep.class, "data", true ), step, data, true );

  Analytics.Data.Ga.Get mockQuery = prepareMockQuery( recordsCount );
  step = spy( step );
  doReturn( mockQuery ).when( step ).getQuery( any( Analytics.class ) );

  for ( int i = 0; i < recordsCount; i++ ) {
    List<String> next = step.getNextDataEntry();
    assertEquals( Integer.toString( i + 1 ), next.get( 0 ) );
  }
  assertNull( step.getNextDataEntry() );
}