Java Code Examples for org.apache.commons.lang3.reflect.FieldUtils#writeField()
The following examples show how to use
org.apache.commons.lang3.reflect.FieldUtils#writeField() .
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: TestTwilioAckEventHandler.java From arcusplatform with Apache License 2.0 | 6 votes |
public void buildMocks(String anweredBy,String host, String sigHost,String callStatus) throws Exception{ URIBuilder builder = new URIBuilder("/ivr/event/ack") .addParameter(TwilioBaseHandler.SCRIPT_PARAM, "alarm.smoke.triggered") .addParameter(TwilioHelper.NOTIFICATION_ID_PARAM_NAME, "place:"+UUID.randomUUID()) .addParameter(TwilioHelper.PERSON_ID_PARAM_NAME, "test") .addParameter(TwilioHelper.NOTIFICATION_EVENT_TIME_PARAM_NAME, "12345678910") .addParameter(TwilioHelper.CALL_STATUS_PARAM_KEY, callStatus) .addParameter(TwilioHelper.ANSWEREDBY_PARAM_KEY, anweredBy); String testURI=builder.build().toString(); FieldUtils.writeField(handler, "twilioAccountAuth", "AUTHKEY", true); String protocol =TwilioHelper.PROTOCOL_HTTPS; String sig = Base64.encodeToString(HmacUtils.hmacSha1 ("AUTHKEY", protocol + sigHost + testURI)); EasyMock.expect(request.getMethod()).andReturn(HttpMethod.GET).anyTimes(); EasyMock.expect(request.getUri()).andReturn(testURI).anyTimes(); EasyMock.expect(request.headers()).andReturn(httpHeaders).anyTimes(); EasyMock.expect(httpHeaders.contains(TwilioHelper.SIGNATURE_HEADER_KEY)).andReturn(true).anyTimes(); EasyMock.expect(httpHeaders.get(TwilioHelper.SIGNATURE_HEADER_KEY)).andReturn(sig).anyTimes(); EasyMock.expect(httpHeaders.get(TwilioHelper.HOST_HEADER_KEY)).andReturn(host).anyTimes(); EasyMock.expect(mockPopulationCacheMgr.getPopulationByPlaceId(EasyMock.anyObject(UUID.class))).andReturn(Population.NAME_GENERAL); }
Example 2
Source File: LdapObjectMapper.java From library with Apache License 2.0 | 6 votes |
/** * Method used to extract the values from a given attribute and put it into the domain model object * * @param clazz to instantiate the domain object * @param attributes to extract the values * @return an {@link Optional} of the domain object */ private Optional<T> extractValue(Class<T> clazz, Attributes attributes) { try { final T instance = clazz.getDeclaredConstructor().newInstance(); final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(instance.getClass(), LdapAttribute.class); for (Field field : fields) { final LdapAttribute annotation = field.getAnnotation(LdapAttribute.class); final Attribute attribute = attributes.get(annotation.value()); if (attribute != null) { FieldUtils.writeField(field, instance, attribute.get(), true); } } return Optional.of(instance); } catch (Exception ex) { ex.printStackTrace(); } return Optional.empty(); }
Example 3
Source File: CacheStatisticsControllerEnricher.java From keycloak with Apache License 2.0 | 6 votes |
@Override public void enrich(Object testCase) { Validate.notNull(registry.get(), "registry should not be null"); Validate.notNull(jmxConnectorRegistry.get(), "jmxConnectorRegistry should not be null"); Validate.notNull(suiteContext.get(), "suiteContext should not be null"); for (Field field : FieldUtils.getAllFields(testCase.getClass())) { JmxInfinispanCacheStatistics annotation = field.getAnnotation(JmxInfinispanCacheStatistics.class); if (annotation == null) { continue; } try { FieldUtils.writeField(field, testCase, getInfinispanCacheStatistics(annotation), true); } catch (IOException | IllegalAccessException | MalformedObjectNameException e) { throw new RuntimeException("Could not set value on field " + field); } } }
Example 4
Source File: TestTwilioAckScriptHandler.java From arcusplatform with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { super.setUp(); builder = buildParameters(null); FieldUtils.writeField(handler, "twilioAccountAuth", "AUTHKEY", true); sig = Base64.encodeToString(HmacUtils.hmacSha1 ("AUTHKEY", TwilioHelper.PROTOCOL_HTTPS + "somehost" + builder.toString())); EasyMock.expect(request.getUri()).andReturn(builder.toString()).anyTimes(); EasyMock.expect(request.getMethod()).andReturn(HttpMethod.GET); EasyMock.expect(request.headers()).andReturn(httpHeaders).anyTimes(); EasyMock.expect(httpHeaders.contains(TwilioHelper.SIGNATURE_HEADER_KEY)).andReturn(true).anyTimes(); EasyMock.expect(httpHeaders.get(TwilioHelper.SIGNATURE_HEADER_KEY)).andReturn(sig).anyTimes(); EasyMock.expect(httpHeaders.get(TwilioHelper.HOST_HEADER_KEY)).andReturn("somehost").anyTimes(); EasyMock.expect(personDAO.findById(personID)).andReturn(person); EasyMock.expect(placeDAO.findById(placeId)).andReturn(place); EasyMock.expect(populationCacheMgr.getPopulationByPlaceId(EasyMock.anyObject(UUID.class))).andReturn(Population.NAME_GENERAL).anyTimes(); }
Example 5
Source File: CommonPermissionCheckingUtilsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Before public void setUp() throws IllegalAccessException { defaultResourceCheckers.map(checkers -> checkers.add(defaultResourceChecker)); FieldUtils.writeField(underTest, "defaultResourceCheckers", defaultResourceCheckers, true); FieldUtils.writeField(underTest, "resourceBasedCrnProviders", resourceBasedCrnProviders, true); lenient().when(defaultResourceChecker.getResourceType()).thenReturn(AuthorizationResourceType.IMAGE_CATALOG); lenient().when(defaultResourceChecker.isDefault(RESOURCE_CRN)).thenReturn(false); lenient().when(defaultResourceChecker.isDefault(DEFAULT_RESOURCE_CRN)).thenReturn(true); lenient().when(defaultResourceChecker.isAllowedAction(AuthorizationResourceAction.DESCRIBE_IMAGE_CATALOG)).thenReturn(true); lenient().when(defaultResourceChecker.getDefaultResourceCrns(any())).thenReturn(CrnsByCategory.newBuilder() .defaultResourceCrns(List.of(DEFAULT_RESOURCE_CRN)) .notDefaultResourceCrns(List.of(RESOURCE_CRN)) .build()); when(umsRightProvider.getResourceType(any())).thenReturn(AuthorizationResourceType.IMAGE_CATALOG); when(umsRightProvider.getRight(eq(AuthorizationResourceAction.DELETE_IMAGE_CATALOG))).thenReturn("environments/deleteImageCatalog"); underTest.init(); }
Example 6
Source File: PulsarJsonTableSinkTest.java From pulsar with Apache License 2.0 | 5 votes |
private PulsarJsonTableSink spySink() throws Exception { ClientConfigurationData clientConfigurationData = new ClientConfigurationData(); clientConfigurationData.setServiceUrl(SERVICE_URL); ProducerConfigurationData producerConfigurationData = new ProducerConfigurationData(); producerConfigurationData.setTopicName(TOPIC_NAME); PulsarJsonTableSink sink = new PulsarJsonTableSink( clientConfigurationData, producerConfigurationData, ROUTING_KEY); FlinkPulsarProducer producer = Mockito.mock(FlinkPulsarProducer.class); PowerMockito.whenNew( FlinkPulsarProducer.class ).withArguments( Mockito.anyString(), Mockito.anyString(), Mockito.any(Authentication.class), Mockito.any(SerializationSchema.class), Mockito.any(PulsarKeyExtractor.class), Mockito.any(PulsarPropertiesExtractor.class) ).thenReturn(producer); FieldUtils.writeField(sink, "fieldNames", fieldNames, true); FieldUtils.writeField(sink, "fieldTypes", typeInformations, true); FieldUtils.writeField(sink, "serializationSchema", Mockito.mock(SerializationSchema.class), true); FieldUtils.writeField(sink, "keyExtractor", Mockito.mock(PulsarKeyExtractor.class), true); FieldUtils.writeField(sink, "propertiesExtractor", Mockito.mock(PulsarPropertiesExtractor.class), true); return sink; }
Example 7
Source File: TestInstrumentMojoTest.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
@BeforeEach public void setUp() throws Exception { fixture = new TestInstrumentMojo(); mavenProject = Mockito.mock(MavenProject.class); Log log = Mockito.mock(Log.class); FieldUtils.writeField(fixture, "project", mavenProject, true); FieldUtils.writeField(fixture, "markerType", MarkerType.NONE, true); FieldUtils.writeField(fixture, "debugMode", false, true); FieldUtils.writeField(fixture, "log", log, true); }
Example 8
Source File: MtlBaseTaskAction.java From atlas with Apache License 2.0 | 5 votes |
protected void setFieldValueByReflection(Task task, String fieldName, Object value) { Field field = FieldUtils.getField(task.getClass(), fieldName, true); if (null == field) { throw new StopExecutionException("The field with name:" + fieldName + " does not existed in class:" + task.getClass().getName()); } try { FieldUtils.writeField(field, task, value, true); } catch (IllegalAccessException e) { throw new StopExecutionException(e.getMessage()); } }
Example 9
Source File: TestTwilioAckScriptHandler.java From arcusplatform with Apache License 2.0 | 5 votes |
@Test public void handleVerifyFailed() throws Exception{ replay(); FieldUtils.writeField(handler, "twilioAccountAuth", "AUTHKEY2", true); TemplatedResponse response = handler.doHandle(request, ctx); assertEquals(HttpResponseStatus.NOT_FOUND,response.getResponseStatus().get()); }
Example 10
Source File: RqueueMessageListenerContainerTest.java From rqueue with Apache License 2.0 | 5 votes |
private RqueueMessageListenerContainer createContainer( RqueueMessageHandler messageHandler, RqueueMessageTemplate rqueueMessageTemplate) throws IllegalAccessException { RqueueMessageListenerContainer container = new RqueueMessageListenerContainer(messageHandler, rqueueMessageTemplate); FieldUtils.writeField( container, "applicationEventPublisher", mock(ApplicationEventPublisher.class), true); FieldUtils.writeField( container, "rqueueMessageMetadataService", mock(RqueueMessageMetadataService.class), true); RqueueConfig rqueueConfig = new RqueueConfig(null, true, 1); FieldUtils.writeField(container, "rqueueConfig", rqueueConfig, true); return container; }
Example 11
Source File: RqueueMessageListenerContainerTest.java From rqueue with Apache License 2.0 | 5 votes |
@Test public void checkDoStopMethodIsCalledWithRunnable() throws Exception { StubMessageSchedulerListenerContainer container = new StubMessageSchedulerListenerContainer(); FieldUtils.writeField( container, "applicationEventPublisher", mock(ApplicationEventPublisher.class), true); CountDownLatch count = new CountDownLatch(1); container.afterPropertiesSet(); container.start(); container.stop(count::countDown); container.destroy(); assertTrue(container.isDestroyMethodIsCalled()); assertEquals(0, count.getCount()); }
Example 12
Source File: RqueueMessageListenerContainerTest.java From rqueue with Apache License 2.0 | 5 votes |
@Test public void checkDoDestroyMethodIsCalled() throws Exception { StubMessageSchedulerListenerContainer container = new StubMessageSchedulerListenerContainer(); FieldUtils.writeField( container, "applicationEventPublisher", mock(ApplicationEventPublisher.class), true); container.afterPropertiesSet(); container.start(); container.stop(); container.destroy(); assertTrue(container.isDestroyMethodIsCalled()); }
Example 13
Source File: RqueueMetricsTest.java From rqueue with Apache License 2.0 | 5 votes |
private RqueueMetrics rqueueMetrics( MeterRegistry meterRegistry, MetricsProperties metricsProperties) throws IllegalAccessException { RqueueMetrics metrics = new RqueueMetrics(template, queueCounter); FieldUtils.writeField(metrics, "meterRegistry", meterRegistry, true); FieldUtils.writeField(metrics, "metricsProperties", metricsProperties, true); return metrics; }
Example 14
Source File: ActionCover.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private <W extends JpaObject, T extends JpaObject> List<T> coverProcessElement(Business business, Process process, WrapCopier<W, T> copier, W w, Class<T> cls) throws Exception { List<T> os = new ArrayList<>(); T _t = business.entityManagerContainer().find(w.getId(), cls); if (null != _t) { copier.copy(w, _t); } else { _t = copier.copy(w); os.add(_t); } FieldUtils.writeField(_t, Agent.process_FIELDNAME, process.getId(), true); return os; }
Example 15
Source File: Maven3DependencyTreeBuilder.java From archiva with Apache License 2.0 | 5 votes |
MavenRepositorySystem initMaven() throws IllegalAccessException { MavenRepositorySystem system = new MavenRepositorySystem( ); DefaultArtifactHandlerManager afm = new DefaultArtifactHandlerManager( ); DefaultRepositoryLayout layout = new DefaultRepositoryLayout( ); FieldUtils.writeField( system, "artifactHandlerManager", afm, true); Map<String, ArtifactRepositoryLayout> map = new HashMap<>( ); map.put( "defaultRepositoryLayout", layout ); FieldUtils.writeField( system, "layouts", map, true); return system; }
Example 16
Source File: RuleCreatorTest.java From support-rulesengine with Apache License 2.0 | 4 votes |
@Test(expected = IOException.class) public void testInitException() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException { FieldUtils.writeField(creator, FIELD_LOC, "foobar", true); creator.init(); }
Example 17
Source File: RqueueMessageListenerContainerTest.java From rqueue with Apache License 2.0 | 4 votes |
@Before public void init() throws IllegalAccessException { FieldUtils.writeField( container, "rqueueMessageMetadataService", mock(RqueueMessageMetadataService.class), true); }
Example 18
Source File: RuleCreatorTest.java From support-rulesengine with Apache License 2.0 | 4 votes |
@Test(expected = IOException.class) public void testCreateDroolRuleIOException() throws IllegalAccessException, TemplateException, IOException { FieldUtils.writeField(creator, FIELD_NAME, "foobar", true); creator.createDroolRule(rule); }
Example 19
Source File: CommandExecutorTest.java From support-rulesengine with Apache License 2.0 | 4 votes |
@Test public void testFireCommandNoClient() throws IllegalAccessException { FieldUtils.writeField(executor, "client", null, true); executor.fireCommand(TEST_DEVICE, TEST_CMD, TEST_BODY); }
Example 20
Source File: FieldUtilsUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenFieldUtilsClass_whenCalledwriteField_thenCorrect() throws IllegalAccessException { FieldUtils.writeField(user, "name", "Julie", true); assertThat(FieldUtils.readField(user, "name", true)).isEqualTo("Julie"); }