Skip to content

Commit

Permalink
stores upgrades and new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed Dec 31, 2015
1 parent 130ea61 commit da76a02
Show file tree
Hide file tree
Showing 69 changed files with 1,888 additions and 580 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ _This document is currently in progress and is changed very often_

## Getting Started

1 - [Hello World](#hello-world)
<br/>2 - [Integration with Spring Framework](#spring)
<br/>3 - [Feature Flipping through AOP](#aop)
<br/>4 - [Externalize features in JDBC store](#store-jdbc)

<a id="hello-world" name="hello-world"/>
### 1 - Hello world

In this part, we guide you to create a working example from scratch
Expand Down
43 changes: 43 additions & 0 deletions ff4j-aop/src/test/java/org/ff4j/proxy/HiInvocationHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.ff4j.proxy;

/*
* #%L
* ff4j-aop
* %%
* Copyright (C) 2013 - 2015 FF4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class HiInvocationHandler implements InvocationHandler {

private Map < String, Object > target = new HashMap<String, Object>();

/** {@inheritDoc} */
@Override
public Object invoke(Object proxy, Method method, Object[] parameters) throws Throwable {
System.out.println(proxy.getClass().getName());
Object returnObject = method.invoke(target, parameters);

return returnObject;
}


}
28 changes: 28 additions & 0 deletions ff4j-aop/src/test/java/org/ff4j/proxy/HiService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.ff4j.proxy;

/*
* #%L
* ff4j-aop
* %%
* Copyright (C) 2013 - 2015 FF4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


public interface HiService {

void hi();

}
31 changes: 31 additions & 0 deletions ff4j-aop/src/test/java/org/ff4j/proxy/HiService1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.ff4j.proxy;

/*
* #%L
* ff4j-aop
* %%
* Copyright (C) 2013 - 2015 FF4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


public class HiService1 implements HiService {

@Override
public void hi() {
System.out.println("HI 1");
}

}
31 changes: 31 additions & 0 deletions ff4j-aop/src/test/java/org/ff4j/proxy/HiService2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.ff4j.proxy;

/*
* #%L
* ff4j-aop
* %%
* Copyright (C) 2013 - 2015 FF4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


public class HiService2 implements HiService {

@Override
public void hi() {
System.out.println("HI 2");
}

}
39 changes: 39 additions & 0 deletions ff4j-aop/src/test/java/org/ff4j/proxy/NativeProxyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.ff4j.proxy;

/*
* #%L
* ff4j-aop
* %%
* Copyright (C) 2013 - 2015 FF4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


import java.lang.reflect.Proxy;

import org.junit.Ignore;
import org.junit.Test;

public class NativeProxyTest {

@Test
@Ignore
public void testDynamicProxy1() {
HiInvocationHandler hiInvocHandlr = new HiInvocationHandler();
HiService proxy = (HiService) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class[] { HiService.class }, hiInvocHandlr);
proxy.hi();
}

}
31 changes: 28 additions & 3 deletions ff4j-core/src/main/java/org/ff4j/cache/FF4jCacheProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,16 @@ public void setCacheManager(FF4JCacheManager cacheManager) {
// ------------ Cache related method --------------------

/** {@inheritDoc} */
@Override
public boolean isCached() {
return true;
}

/** {@inheritDoc} */
@Override
public String getCacheProvider() {
return cacheManager.getCacheProviderName();
}

/** {@inheritDoc} */
@Override
public String getCachedTargetStore() {
return getTargetFeatureStore().getClass().getCanonicalName();
}
Expand Down Expand Up @@ -340,6 +337,32 @@ public void deleteProperty(String name) {
// even is not present, evict name failed
getCacheManager().evictProperty(name);
}

/** {@inheritDoc} */
@Override
public boolean isEmpty() {
Set < String > pNames = listPropertyNames();
return (pNames != null && pNames.size() > 0);
}

/** {@inheritDoc} */
@Override
public Set<String> listPropertyNames() {

return null;
}

/** {@inheritDoc} */
@Override
public void clear() {
// Cache Operations : As modification, flush cache for this
getCacheManager().clearProperties();
getTargetPropertyStore().clear();

// Cache Operations : As modification, flush cache for this
getCacheManager().clearFeatures();
getTargetFeatureStore().clear();
}

/**
* Setter accessor for attribute 'targetFeatureStore'.
Expand All @@ -359,4 +382,6 @@ public void setTargetPropertyStore(PropertyStore targetPropertyStore) {
this.targetPropertyStore = targetPropertyStore;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @author Cedrick Lunven (@clunven)
*/
public class XmlConfiguration {
public class XmlConfig {

/** Dedicated Parsing. */
private Map <String, Feature > features = new LinkedHashMap<String, Feature>();
Expand Down
16 changes: 11 additions & 5 deletions ff4j-core/src/main/java/org/ff4j/conf/XmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.ff4j.core.FlippingStrategy;
import org.ff4j.property.AbstractProperty;
import org.ff4j.property.Property;
import org.ff4j.utils.MappingUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
Expand Down Expand Up @@ -172,7 +173,7 @@ public final class XmlParser {

/** XML Generation constants. */
private static final String END_FF4J = "</ff4j>\n\n";

/** Document Builder use to parse XML. */
private static DocumentBuilder builder = null;

Expand All @@ -184,11 +185,11 @@ public final class XmlParser {
* @return
* features and properties find within file
*/
public XmlConfiguration parseConfigurationFile(InputStream in) {
public XmlConfig parseConfigurationFile(InputStream in) {
try {

// Object to be build by parsing
XmlConfiguration xmlConf = new XmlConfiguration();
XmlConfig xmlConf = new XmlConfig();

// Load XML as a Document
Document ff4jDocument = getDocumentBuilder().parse(in);
Expand Down Expand Up @@ -346,11 +347,16 @@ private Feature parseFeatureTag(Element featXmlTag) {
String name = attMap.getNamedItem(PROPERTY_PARAMNAME).getNodeValue();
String value = attMap.getNamedItem(PROPERTY_PARAMVALUE).getNodeValue();
AbstractProperty<?> ap = new Property(name, value);

// If specific type defined ?
if (null != attMap.getNamedItem(PROPERTY_PARAMTYPE)) {
String optionalType = attMap.getNamedItem(PROPERTY_PARAMTYPE).getNodeValue();

// Substitution if relevant (e.g. 'int' -> 'org.ff4j.property.PropertyInt')
optionalType = MappingUtil.mapPropertyType(optionalType);

try {
// Construction by dedicated constructor with introspection
// Constructor (String, String) is mandatory in Property interface
Constructor<?> constr = Class.forName(optionalType).getConstructor(String.class, String.class);
ap = (AbstractProperty<?>) constr.newInstance(name, value);
} catch (InstantiationException e) {
Expand Down Expand Up @@ -565,7 +571,7 @@ public InputStream exportAll(Map<String, Feature> mapOfFeatures, Map < String, A
* @throws IOException
* error during marshalling
*/
public InputStream exportAll(XmlConfiguration conf) throws IOException {
public InputStream exportAll(XmlConfig conf) throws IOException {
return exportAll(conf.getFeatures(), conf.getProperties());
}

Expand Down
17 changes: 4 additions & 13 deletions ff4j-core/src/main/java/org/ff4j/core/FeatureStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,11 @@ public interface FeatureStore {
* @return set of group in the store
*/
Set<String> readAllGroups();

/**
* Implementation of Store to get cache.
*
* @return target store
*/
boolean isCached();


/**
* Return false.
* @return
* Empty features set.
*/
String getCacheProvider();

String getCachedTargetStore();
void clear();


}
2 changes: 1 addition & 1 deletion ff4j-core/src/main/java/org/ff4j/property/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Cedrick Lunven (@clunven)
*/
public class Property extends AbstractProperty<String>{
public class Property extends AbstractProperty<String> {

/** serial. */
private static final long serialVersionUID = -7894832435341748278L;
Expand Down
Loading

0 comments on commit da76a02

Please sign in to comment.