Skip to content

Commit

Permalink
Merge pull request #29 from aol/rest-annotation-issue
Browse files Browse the repository at this point in the history
fix for #28
  • Loading branch information
johnmcclean committed Jun 26, 2015
2 parents e08d3ed + af4eafd commit ed13bb1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.58
version=0.59
1 change: 1 addition & 0 deletions micro-core/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test=hello world
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public class ConfigurableModule implements Module{

private final List<Class> restResourceClasses;
private final List<Class> restAnnotationClasses;
private final List<Class> defaultResources;
private final List<ServletContextListener> listeners;
private final List<ServletRequestListener> requestListeners;
Expand Down Expand Up @@ -78,6 +79,13 @@ public List<Class> getRestResourceClasses() {

return Module.super.getRestResourceClasses();
}
@Override
public List<Class> getRestAnnotationClasses() {
if(restAnnotationClasses!=null)
return ImmutableList.copyOf(Iterables.concat(restAnnotationClasses, extract(() -> Module.super.getRestAnnotationClasses())));

return Module.super.getRestAnnotationClasses();
}

@Override
public List<Class> getDefaultResources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;

import com.aol.micro.server.config.Config;
import com.aol.micro.server.config.ConfigAccessor;
import com.google.common.collect.Lists;

@Configuration
public class PropertyFileConfig {

private final Logger logger = LoggerFactory.getLogger(getClass());

public PropertyFileConfig(){

}
public PropertyFileConfig(boolean set){
if(set)
new Config().set(); //make sure config instance is set
}
@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() throws IOException {

Expand Down Expand Up @@ -53,7 +60,7 @@ public Properties propertyFactory() throws IOException {
private List<Resource> loadPropertyResource() {
List<Resource> resources = Lists.newArrayList();
loadProperties().ifPresent(it -> resources.add(it));

String instancePropertyFileName = new ConfigAccessor().get().getInstancePropertiesName();

URL instanceResource = getClass().getClassLoader().getResource(instancePropertyFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.aol.micro.server.MicroserverApp;
import com.aol.micro.server.config.Config;
import com.aol.micro.server.config.Microserver;
import com.aol.micro.server.spring.properties.PropertyFileConfig;
import com.aol.micro.server.testing.RestAgent;

@Microserver
Expand Down Expand Up @@ -42,6 +46,13 @@ public void runAppAndBasicTest() throws InterruptedException, ExecutionException

}

@Test
public void loadProperties() throws IOException{

Properties props = new PropertyFileConfig(true).propertyFactory() ;
assertThat(props.getProperty("test"),is("hello world"));
}



}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package app.async.com.aol.micro.server;

import java.io.IOException;
import java.util.Properties;

import com.aol.micro.server.MicroserverApp;
import com.aol.micro.server.config.Config;
import com.aol.micro.server.spring.properties.PropertyFileConfig;

public class Simple {

public static void main(String[] args){
public static void main(String[] args) throws IOException{

new MicroserverApp(()->"test-app").run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -20,6 +21,7 @@
import org.junit.Before;
import org.junit.Test;

import com.aol.micro.server.auto.discovery.Rest;
import com.aol.micro.server.auto.discovery.RestResource;
import com.aol.micro.server.servers.model.ServerData;
import com.aol.micro.server.web.filter.QueryIPRetriever;
Expand All @@ -39,6 +41,7 @@ public class ConfigurableModuleTest {
private List<ServletRequestListener> requestListeners;
private String providers;
private List<Class> resourceClasses;
private List<Class> resourceAnnotationClasses;
private Map<String, Servlet> servlets;
private Set<Class> springConfigurationClasses;
private List<String> defaultJaxRsPackages;
Expand All @@ -58,6 +61,7 @@ public void setup(){
providers = "providers2";
Module m = () -> "hello";
resourceClasses =new ArrayList<>();
resourceAnnotationClasses = Arrays.asList(Rest.class);
servlets = new HashMap<>();
springConfigurationClasses = ImmutableSet.of(this.getClass());

Expand Down Expand Up @@ -107,6 +111,19 @@ public void testGetRestResourceClasses() {
public void testGetRestResourceClassesUnchanged() {
assertThat(unchanged.getRestResourceClasses(),is(m.getRestResourceClasses()));
}
@Test
public void testGetRestAnnotationClassesResetAll() {
assertThat(module.withResetAll(true).getRestAnnotationClasses(),is(resourceAnnotationClasses));
}
@Test
public void testGetRestAnnotationClasses() {
assertThat(module.getRestAnnotationClasses(),hasItem(Rest.class));
}

@Test
public void testGetRestAnnotationClassesUnchanged() {
assertThat(unchanged.getRestAnnotationClasses(),is(m.getRestAnnotationClasses()));
}

@Test
public void testGetDefaultResourcesReset() {
Expand Down Expand Up @@ -225,7 +242,10 @@ public void testGetSpringConfigurationClassesUnchanged() {




@Test
public void testWithResourceAnnotationClasses() {
assertThat(unchanged.withRestAnnotationClasses(this.resourceClasses).getRestAnnotationClasses(),is(module.getRestAnnotationClasses()));
}

@Test
public void testWithResourceClasses() {
Expand Down

0 comments on commit ed13bb1

Please sign in to comment.