Skip to content

Commit

Permalink
Creating the test exposing wisdom-framework#564 in the cleanest way
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel committed Nov 16, 2016
1 parent 08f3d23 commit 8dbb55b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
*/
package org.wisdom.source.ast.util;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.expr.MemberValuePair;
import static java.util.Collections.singleton;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static java.util.Collections.singleton;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.expr.MemberValuePair;
import com.github.javaparser.ast.visitor.GenericVisitorAdapter;

/**
* A set of function that helps to extract various entity from the javaparser AST.
Expand All @@ -50,6 +51,8 @@ private ExtractUtil(){
* @return string version of the node value.
*/
public static String asString(Node node){
// return node.accept(new GenericVisitorAdapter<String, String>() {
// }, "");
String string = node.toString();

if("\"\"".equals(string)){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* #%L
* Wisdom-Framework
* %%
* Copyright (C) 2013 - 2015 Wisdom Framework
* %%
* 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%
*/
package controller;

import org.wisdom.api.DefaultController;
import org.wisdom.api.annotations.Route;
import org.wisdom.api.http.HttpMethod;
import org.wisdom.api.http.Result;

/**
* A controller referencing uri through a constant
*/
public class ControllerReferencingConstant extends DefaultController {
public static final String URI = "/constant";

@Route(method= HttpMethod.GET, uri=URI)
public Result get() {
return ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ public void testControllerUsingPath() throws IOException, ParseException {

}

@Test
public void testReferencingConstant() throws IOException, ParseException {
File file = new File("src/test/java/controller/ControllerReferencingConstant.java");
final CompilationUnit declaration = JavaParser.parse(file);
ControllerModel model = new ControllerModel();
visitor.visit(declaration, model);

final Collection<ControllerRouteModel> routes = (Collection<ControllerRouteModel>) model.getRoutes().get("/constant");
assertThat(routes).isNotNull();
assertThat(routes).hasSize(1);

for (ControllerRouteModel route : routes) {
assertThat(route.getHttpMethod().name()).isEqualToIgnoringCase(route.getMethodName());
assertThat(route.getParams()).isEmpty();
assertThat(route.getPath()).isEqualToIgnoringCase("/constant");
}
}

private ControllerRouteModel getModelByPath(ControllerModel model, String name) {
for (ControllerRouteModel route : (Collection<ControllerRouteModel>) model.getRoutesAsMultiMap().values()) {
if (route.getPath().equals(name)) {
Expand Down

0 comments on commit 8dbb55b

Please sign in to comment.