Skip to content

Commit

Permalink
svn merge -c1539385 ^/tiles/framework/branches/TILES_3_0_X .
Browse files Browse the repository at this point in the history
> TILES-573 – Tiles.xml definitions not reloaded when using expressions
> Contribution from Eric B.


git-svn-id: https://svn.apache.org/repos/asf/tiles/framework/trunk@1539386 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
michaelsembwever committed Nov 6, 2013
1 parent 480a883 commit dde1b90
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ protected Definition getDefinitionFromResolver(String name,
* @return The loaded definitions.
* @since 2.1.0
*/
protected synchronized Map<String, Definition> checkAndloadDefinitions(
Locale customizationKey) {
protected synchronized Map<String, Definition> checkAndloadDefinitions(Locale customizationKey) {
if (checkRefresh && refreshRequired()) {
locale2definitionMap.clear();
definitionResolver.clearPatternPaths(customizationKey);
}
loadDefinitions(customizationKey);
return locale2definitionMap.get(customizationKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,17 @@ private Definition searchAndResolveDefinition(

return d;
}


/**
* Used to clear all entries in the localePatternPaths for a specific locale. Necessary when reloading definition
* files to ensure that the list is cleared first
*
* @param customizationKey
*/
@Override
public void clearPatternPaths(T customizationKey) {
if (localePatternPaths.get(customizationKey) != null)
localePatternPaths.get(customizationKey).clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,12 @@ Map<String, Definition> storeDefinitionPatterns(Map<String, Definition> localeDe
* @since 2.2.0
*/
Definition resolveDefinition(String name, T customizationKey);

/**
* Used to clear all entries in the localePatternPaths for a specific locale. Necessary when reloading definition
* files to ensure that the list is cleared first
*
* @param customizationKey
*/
public void clearPatternPaths(T customizationKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,60 +40,70 @@
*/
public class AbstractPatternDefinitionResolverTest {

private DefinitionPatternMatcher firstMatcher;
private DefinitionPatternMatcher thirdMatcher;

private final PatternDefinitionResolver<Integer> resolver = new AbstractPatternDefinitionResolver<Integer>() {
@Override
protected Map<String, Definition> addDefinitionsAsPatternMatchers(
List<DefinitionPatternMatcher> matchers,
Map<String, Definition> defsMap) {

if (defsMap.containsKey("first")) {
matchers.add(firstMatcher);
}
if (defsMap.containsKey("third")) {
matchers.add(thirdMatcher);
}
Map<String, Definition> retValue = new HashMap<String, Definition>(defsMap);
retValue.remove("first");
retValue.remove("third");
return retValue;
}
};

/**
* Test method for
* {@link BasicPatternDefinitionResolver#resolveDefinition(String, Object)}.
*/
@Test
public void testResolveDefinition() {
final DefinitionPatternMatcher firstMatcher = createMock(DefinitionPatternMatcher.class);
final DefinitionPatternMatcher thirdMatcher = createMock(DefinitionPatternMatcher.class);

Definition firstDefinition = new Definition("first", (Attribute) null,
null);
Definition secondDefinition = new Definition("second",
(Attribute) null, null);
Definition thirdDefinition = new Definition("third", (Attribute) null,
null);

Definition firstTransformedDefinition = new Definition(
"firstTransformed", (Attribute) null, null);
Definition thirdTransformedDefinition = new Definition(
"thirdTransformed", (Attribute) null, null);

expect(firstMatcher.createDefinition("firstTransformed")).andReturn(
firstTransformedDefinition);
expect(firstMatcher.createDefinition("secondTransformed")).andReturn(
null);
expect(firstMatcher.createDefinition("thirdTransformed")).andReturn(
null);
expect(thirdMatcher.createDefinition("thirdTransformed")).andReturn(
thirdTransformedDefinition).times(2);
expect(thirdMatcher.createDefinition("firstTransformed")).andReturn(
null);
expect(thirdMatcher.createDefinition("secondTransformed")).andReturn(
null).times(2);
testResolveDefinitionImpl();
}

/**
* Test method for
* {@link BasicPatternDefinitionResolver#clearPatternPaths(Object)}.
*/
@Test
public void testClearPatternPaths() {
testResolveDefinitionImpl();
resolver.clearPatternPaths(1);
resolver.clearPatternPaths(2);
testResolveDefinitionImpl();
}

private void testResolveDefinitionImpl() {

firstMatcher = createMock(DefinitionPatternMatcher.class);
thirdMatcher = createMock(DefinitionPatternMatcher.class);

Definition firstDefinition = new Definition("first", (Attribute) null, null);
Definition secondDefinition = new Definition("second", (Attribute) null, null);
Definition thirdDefinition = new Definition("third", (Attribute) null, null);

Definition firstTransformedDefinition = new Definition("firstTransformed", (Attribute) null, null);
Definition thirdTransformedDefinition = new Definition("thirdTransformed", (Attribute) null, null);

expect(firstMatcher.createDefinition("firstTransformed")).andReturn(firstTransformedDefinition);
expect(firstMatcher.createDefinition("secondTransformed")).andReturn(null);
expect(firstMatcher.createDefinition("thirdTransformed")).andReturn(null);
expect(thirdMatcher.createDefinition("thirdTransformed")).andReturn(thirdTransformedDefinition).times(2);
expect(thirdMatcher.createDefinition("firstTransformed")).andReturn(null);
expect(thirdMatcher.createDefinition("secondTransformed")).andReturn(null).times(2);

replay(firstMatcher, thirdMatcher);
PatternDefinitionResolver<Integer> resolver = new AbstractPatternDefinitionResolver<Integer>() {

@Override
protected Map<String, Definition> addDefinitionsAsPatternMatchers(
List<DefinitionPatternMatcher> matchers,
Map<String, Definition> defsMap) {
if (defsMap.containsKey("first")) {
matchers.add(firstMatcher);
}
if (defsMap.containsKey("third")) {
matchers.add(thirdMatcher);
}
Map<String, Definition> retValue = new HashMap<String, Definition>(defsMap);
retValue.remove("first");
retValue.remove("third");
return retValue;
}

};
Map<String, Definition> localeDefsMap = new LinkedHashMap<String, Definition>();
localeDefsMap.put("first", firstDefinition);
localeDefsMap.put("second", secondDefinition);
Expand Down

0 comments on commit dde1b90

Please sign in to comment.