Skip to content

Commit

Permalink
excluded classes fixed in Maven and Gradle plugins, improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechhabarta committed Jan 11, 2016
1 parent 4c714a9 commit 6662bce
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<PropertyModel> getProperties() {

@Override
public String toString() {
return "BeanModel{" + "name=" + beanClass + ", properties=" + properties + '}';
return "BeanModel{" + "beanClass=" + beanClass + ", properties=" + properties + '}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ public List<BeanModel> getBeans() {
return beans;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Model{");
sb.append(String.format("%n"));
for (BeanModel bean : beans) {
sb.append(" ");
sb.append(bean);
sb.append(String.format("%n"));
}
sb.append('}');
return sb.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void testReturnedTypes() {
new TypeReference<List<F>>(){}.getType(),
G.class,
new TypeReference<Map<String, H>>(){}.getType(),
I.class
I.class,
J[].class
);
assertHasSameItems(expectedTypes, types);
}
Expand All @@ -53,7 +54,8 @@ public void testWithParsing() {
F.class,
G.class,
H.class,
I.class
I.class,
J.class
);
assertHasSameItems(expectedClasses, classes);
}
Expand All @@ -66,8 +68,12 @@ public void testExcludedResource() {

@Test
public void testExcludedType() {
final List<SourceType<Type>> sourceTypes = new JaxrsApplicationScanner().scanJaxrsApplication(new TestApplication(), Arrays.asList(A.class.getName()));
final List<SourceType<Type>> sourceTypes = new JaxrsApplicationScanner().scanJaxrsApplication(new TestApplication(), Arrays.asList(
A.class.getName(),
J.class.getName()
));
Assert.assertTrue(!getTypes(sourceTypes).contains(A.class));
Assert.assertTrue(getTypes(sourceTypes).contains(J[].class));
}

private List<Type> getTypes(final List<SourceType<Type>> sourceTypes) {
Expand Down Expand Up @@ -153,6 +159,9 @@ public void setI(
I entityI) {
}
@POST
public void setJs(J[] js) {
}
@POST
public void setStandardEntity(byte[] value) {}
@POST
public void setStandardEntity(String value) {}
Expand Down Expand Up @@ -202,5 +211,6 @@ private static class F {}
private static class G {}
private static class H {}
private static class I {}
private static class J {}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

package cz.habarta.typescript.generator;

import com.fasterxml.jackson.core.type.TypeReference;
import cz.habarta.typescript.generator.parser.*;
import java.lang.reflect.Type;
import java.util.*;
import org.junit.*;

Expand All @@ -10,43 +12,62 @@ public class ModelParserTest {

@Test
public void testClassDiscovery1() {
final Model model = parseModel(RootClass1.class, null);
final Model model = parseModel(RootClass1.class);
Assert.assertEquals(2, model.getBeans().size());

}

@Test
public void testClassDiscovery2() {
final Model model = parseModel(RootClass2.class, null);
final Model model = parseModel(RootClass2.class);
Assert.assertEquals(2, model.getBeans().size());
}

@Test
public void testClassDiscovery3() {
final Model model = parseModel(RootClass3.class, null);
final Model model = parseModel(RootClass3.class);
Assert.assertEquals(3, model.getBeans().size());
}

@Test
public void testClassDiscoveryExcludeNodeClassA() {
final Model model = parseModel(RootClass1.class, NodeClassA.class.getName());
Assert.assertEquals(1, model.getBeans().size());
}

@Test
public void testClassDiscoveryExcludeTag() {
final Model model = parseModel(RootClass3.class, Arrays.asList(Tag.class.getName()));
final Model model = parseModel(RootClass3.class, Tag.class.getName());
Assert.assertEquals(2, model.getBeans().size());
}

@Test
public void testClassDiscoveryExcludeNodeClassB() {
final Model model = parseModel(RootClass3.class, Arrays.asList(NodeClassB.class.getName()));
final Model model = parseModel(RootClass3.class, NodeClassB.class.getName());
Assert.assertEquals(1, model.getBeans().size());
}

private Model parseModel(Class<?> rootClass, List<String> excludedClassNames) {
@Test
public void testExcludedInputDirectly() {
final Model model = parseModel(RootClass3.class, RootClass3.class.getName());
Assert.assertEquals(0, model.getBeans().size());
}

@Test
public void testExcludedInputInList() {
final Model model = parseModel(new TypeReference<List<RootClass3>>() {}.getType(), RootClass3.class.getName());
Assert.assertEquals(0, model.getBeans().size());
}

private Model parseModel(Type type, String... excludedClassNames) {
final Settings settings = new Settings();
settings.excludedClassNames = excludedClassNames;
settings.excludedClassNames = Arrays.asList(excludedClassNames);
final ModelParser parser = new Jackson2Parser(settings, new TypeProcessor.Chain(
new ExcludingTypeProcessor(settings.excludedClassNames),
new DefaultTypeProcessor()
));
return parser.parseModel(rootClass);
final Model model = parser.parseModel(type);
return model;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void generate() throws Exception {

// Settings
final Settings settings = new Settings();
settings.excludedClassNames = excludeClasses;
settings.jsonLibrary = jsonLibrary;
settings.namespace = namespace;
settings.module = module;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public void execute() {

// Settings
final Settings settings = new Settings();
settings.excludedClassNames = excludeClasses;
settings.jsonLibrary = jsonLibrary;
settings.namespace = namespace != null ? namespace : moduleName;
settings.module = module;
Expand Down

0 comments on commit 6662bce

Please sign in to comment.