/** {@inheritDoc} */ @Override public Property<?> readProperty(String name, Property<?> defaultValue) { return target.readProperty(name, defaultValue); }
/** {@inheritDoc} */ public Property<?> readProperty(String name) { return target.readProperty(name); }
/** * Read property in Store * * @param featureID * target feature ID * @return target feature. */ public Property<?> getProperty(String propertyName) { return getPropertiesStore().readProperty(propertyName); }
/** TDD. */ @Test(expected = IllegalArgumentException.class) public void readKOempty() { // Given testedStore.readProperty(""); }
/** TDD. */ @Test(expected = IllegalArgumentException.class) public void readKOnull() { // Given testedStore.readProperty(null); }
private Property<?> readProperty(Field field, String propertyName, boolean required) { if (!ff4j.getPropertiesStore().existProperty(propertyName)) { if (required) { throw new IllegalArgumentException("Cannot autowiring field '" + field.getName() + "' with FF4J property as" + " target property has not been found"); } else { logger.warn("Property '" + propertyName + "' has not been found but not required"); return null; } } return ff4j.getPropertiesStore().readProperty(propertyName); }
/** {@inheritDoc} */ @Override public Object getProperty(String key) { return ff4jStore().readProperty(key).getValue(); }
/** * Allows to retrieve feature by its id. * * @param featId * target feature identifier * @return feature is exist */ @GET @RolesAllowed({ROLE_READ}) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Read information about a Property", response=PropertyApiBean.class) @ApiResponses({ @ApiResponse(code = 200, message= "Information about features"), @ApiResponse(code = 404, message= "Property not found") }) public Response read(@PathParam("name") String name) { if (!ff4j.getPropertiesStore().existProperty(name)) { String errMsg = new PropertyNotFoundException(name).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } return Response.ok(new PropertyApiBean(ff4j.getPropertiesStore().readProperty(name))).build(); }
/** * The read will raise PropertyNotFound if not exist, null could be cast in any type. * * @param key * current property name * @return * property value */ private Object getValue(String key) { Util.assertHasLength(key); return ff4jStore().readProperty(key).asString(); }
/** TDD. */ @Test(expected = PropertyNotFoundException.class) public void readKOnotExist() { // Given Assert.assertFalse(testedStore.existProperty(INVALID)); // When testedStore.readProperty(INVALID); }
public PropertyApiBean getProperty(String propertyName) { propertyValidator.assertPropertyExist(propertyName); return new PropertyApiBean(ff4j.getPropertiesStore().readProperty(propertyName)); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void setProperty(String key, Object value) { if (!ff4jStore.existProperty(key)) { addProperty(key, value); } Property<Object> ap = (Property<Object>) ff4jStore().readProperty(key); ap.setValue(String.valueOf(value)); ff4jStore().updateProperty(ap); }
@Test public void valueFixed() { // When-Then Assert.assertTrue(testedStore.existProperty("a")); Assert.assertEquals("AMER", testedStore.readProperty("a").getValue()); }
/** {@inheritDoc} */ @Override public Property<?> readProperty(String name) { Property<?> fp = getCacheManager().getProperty(name); // not in cache but may has been created from now if (null == fp) { fp = getTargetPropertyStore().readProperty(name); getCacheManager().putProperty(fp); } return fp; }
/** {@inheritDoc} */ @Override public Property<?> readProperty(String name, Property<?> defaultValue) { Property<?> fp = getCacheManager().getProperty(name); // Not in cache but may has been created from now // Or in cache but with different value that default if (null == fp) { fp = getTargetPropertyStore().readProperty(name, defaultValue); getCacheManager().putProperty(fp); } return fp; }
/** TDD. */ @Test public void updateOK() { // Given testedStore.createProperty(new PropertyLogLevel(UPDATE_OK, LogLevel.ERROR)); // When testedStore.updateProperty(UPDATE_OK, "INFO"); // Then Assert.assertEquals(LogLevel.INFO, testedStore.readProperty(UPDATE_OK).getValue()); }
/** TDD. */ @Test public void updateOKProperties() { // Given testedStore.createProperty(new PropertyLogLevel("logX", LogLevel.ERROR)); // When PropertyLogLevel pll = new PropertyLogLevel("logX", LogLevel.INFO); testedStore.updateProperty(pll); // Then Assert.assertEquals(LogLevel.INFO, testedStore.readProperty("logX").getValue()); }
/** {@inheritDoc} */ @Override public void updateProperty(String name, String newValue) { // Retrieve the full object from its name Property<?> fp = getTargetPropertyStore().readProperty(name); fp.setValueFromString(newValue); // Update value in target store getTargetPropertyStore().updateProperty(fp); // Remove from cache old value getCacheManager().evictProperty(fp.getName()); // Add new value in the cache getCacheManager().putProperty(fp); }
@Test public void readOKFixed() { // Given testedStore.createProperty(new PropertyLogLevel(READ_OK_FIXED, LogLevel.ERROR)); // When Property<?> log = testedStore.readProperty(READ_OK_FIXED); // Then Assert.assertNotNull(log); Assert.assertNotNull(log.getName()); Assert.assertEquals(READ_OK_FIXED, log.getName()); Assert.assertEquals(LogLevel.ERROR, log.getValue()); Assert.assertEquals("ERROR", log.asString()); Assert.assertNotNull(log.getFixedValues()); }
@Test public void readOK() { // Given testedStore.createProperty(new PropertyString("toto", "ff4j")); // When Property<?> ap = testedStore.readProperty("toto"); // Then Assert.assertNotNull(ap); Assert.assertNotNull(ap.getName()); Assert.assertEquals("toto", ap.getName()); Assert.assertEquals("ff4j", ap.getValue()); Assert.assertEquals("ff4j", ap.asString()); Assert.assertNull(ap.getFixedValues()); }