Search in sources :

Example 1 with FeatureURIManager

use of com.tvd12.ezyhttp.server.core.manager.FeatureURIManager in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method createBeanContext.

protected EzyBeanContext createBeanContext() {
    if (packageToScans.isEmpty()) {
        throw new IllegalStateException("must scan at least one package");
    }
    Set<String> allPackageToScans = new HashSet<>();
    allPackageToScans.add(DEFAULT_PACKAGE_TO_SCAN);
    allPackageToScans.addAll(packageToScans);
    EzyReflection reflection = EzyPackages.scanPackages(allPackageToScans);
    addComponentClassesFromReflection(reflection);
    allPackageToScans.addAll(packageToScans);
    allPackageToScans.addAll(getPackagesToScanFromProviders(reflection));
    reflection = EzyPackages.scanPackages(allPackageToScans);
    Set controllerClasses = reflection.getAnnotatedClasses(Controller.class);
    Set interceptorClases = reflection.getAnnotatedClasses(Interceptor.class);
    Set exceptionHandlerClasses = reflection.getAnnotatedClasses(ExceptionHandler.class);
    Set bodyConverterClasses = reflection.getAnnotatedClasses(BodyConvert.class);
    Set stringConverterClasses = reflection.getAnnotatedClasses(StringConvert.class);
    Set bootstrapClasses = reflection.getAnnotatedClasses(ApplicationBootstrap.class);
    Map<String, Class> serviceClasses = getServiceClasses(reflection);
    EzyPropertiesMap propertiesMap = getPropertiesMap(reflection);
    EzyBeanContext beanContext = newBeanContextBuilder().scan(allPackageToScans).addSingletonClasses(componentClasses).addSingletonClasses(serviceClasses).addSingletonClasses(controllerClasses).addSingletonClasses(interceptorClases).addSingletonClasses(exceptionHandlerClasses).addSingletonClasses(bodyConverterClasses).addSingletonClasses(stringConverterClasses).addSingletonClasses(bootstrapClasses).propertiesMap(propertiesMap).addSingleton("systemObjectMapper", objectMapper).addSingleton("componentManager", componentManager).addSingleton("requestHandlerManager", requestHandlerManager).addSingleton("featureURIManager", requestHandlerManager.getFeatureURIManager()).addSingleton("requestURIManager", requestHandlerManager.getRequestURIManager()).addAllClasses(EzyPackages.scanPackage(DEFAULT_PACKAGE_TO_SCAN)).build();
    setComponentProperties(beanContext);
    registerComponents(beanContext);
    addRequestHandlers(beanContext);
    addResourceRequestHandlers(beanContext);
    addExceptionHandlers();
    return beanContext;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection) EzyPropertiesMap(com.tvd12.ezyfox.bean.EzyPropertiesMap) HashSet(java.util.HashSet)

Example 2 with FeatureURIManager

use of com.tvd12.ezyhttp.server.core.manager.FeatureURIManager in project ezyhttp by youngmonkeys.

the class RequestHandlerManagerTest method test.

@Test
public void test() {
    // given
    RequestHandlerManager sut = new RequestHandlerManager();
    RequestHandler requestHandler = mock(RequestHandler.class);
    RequestURI requestURI = new RequestURI(HttpMethod.GET, "/get", RequestURIMeta.builder().api(true).authenticated(true).management(true).resource(true).payment(true).feature("hello.world").resourceFullPath("/").build());
    sut.addHandler(requestURI, requestHandler);
    // when
    FeatureURIManager featureURIManager = sut.getFeatureURIManager();
    // then
    Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get"), "hello.world");
    Asserts.assertEquals(featureURIManager.getFeatureByURI(HttpMethod.GET, "/get/"), "hello.world");
}
Also used : RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) FeatureURIManager(com.tvd12.ezyhttp.server.core.manager.FeatureURIManager) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) Test(org.testng.annotations.Test)

Example 3 with FeatureURIManager

use of com.tvd12.ezyhttp.server.core.manager.FeatureURIManager in project ezyhttp by youngmonkeys.

the class FeatureURIManagerTest method test.

@Test
public void test() {
    // given
    FeatureURIManager sut = new FeatureURIManager();
    sut.addFeatureURI("hello", HttpMethod.GET, "/a");
    sut.addFeatureURI("hello", HttpMethod.POST, "/a");
    sut.addFeatureURI("hello", HttpMethod.POST, "/b");
    sut.addFeatureURI("world", HttpMethod.PUT, "/c");
    // when
    Asserts.assertEquals(sut.getFeatures(), Sets.newHashSet("hello", "world"), false);
    Asserts.assertEquals(sut.getFeatureByURI(HttpMethod.GET, "/a"), "hello");
    Asserts.assertEquals(sut.getFeatureByURI(HttpMethod.PUT, "/c"), "world");
    Asserts.assertNull(sut.getFeatureByURI(HttpMethod.TRACE, "I don't know"));
    Asserts.assertEquals(sut.getURIsByFeature("hello"), EzyMapBuilder.mapBuilder().put("/a", Sets.newHashSet(HttpMethod.GET, HttpMethod.POST)).put("/b", Collections.singletonList(HttpMethod.POST)).build(), false);
    Asserts.assertEquals(sut.getFeatureByURIMap(), EzyMapBuilder.mapBuilder().put("/a", EzyMapBuilder.mapBuilder().put(HttpMethod.GET, "hello").put(HttpMethod.POST, "hello").build()).put("/b", EzyMapBuilder.mapBuilder().put(HttpMethod.POST, "hello").build()).put("/c", EzyMapBuilder.mapBuilder().put(HttpMethod.PUT, "world").build()).build());
    Asserts.assertEquals(sut.getURIsByFeatureMap(), EzyMapBuilder.mapBuilder().put("hello", EzyMapBuilder.mapBuilder().put("/a", Sets.newHashSet(HttpMethod.GET, HttpMethod.POST)).put("/b", Sets.newHashSet(HttpMethod.POST)).build()).put("world", EzyMapBuilder.mapBuilder().put("/c", Sets.newHashSet(HttpMethod.PUT)).build()).build(), false);
}
Also used : FeatureURIManager(com.tvd12.ezyhttp.server.core.manager.FeatureURIManager) Test(org.testng.annotations.Test)

Aggregations

FeatureURIManager (com.tvd12.ezyhttp.server.core.manager.FeatureURIManager)2 Test (org.testng.annotations.Test)2 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzyPropertiesMap (com.tvd12.ezyfox.bean.EzyPropertiesMap)1 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)1 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)1 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)1 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1