1 | package com.framsticks.model; |
---|
2 | |
---|
3 | import java.io.InputStream; |
---|
4 | |
---|
5 | import org.testng.annotations.DataProvider; |
---|
6 | import org.testng.annotations.Test; |
---|
7 | |
---|
8 | import com.framsticks.params.FramsClass; |
---|
9 | import com.framsticks.params.ReflectionAccess; |
---|
10 | import com.framsticks.params.Source; |
---|
11 | import com.framsticks.params.ValueParam; |
---|
12 | import com.framsticks.parsers.FileSource; |
---|
13 | import com.framsticks.parsers.Loaders; |
---|
14 | import com.framsticks.test.TestConfiguration; |
---|
15 | |
---|
16 | import static org.fest.assertions.Assertions.*; |
---|
17 | import static com.framsticks.params.ParamsUtil.getParam; |
---|
18 | |
---|
19 | @Test |
---|
20 | public class ModelPackageTest extends TestConfiguration { |
---|
21 | |
---|
22 | @Test(dataProvider = "classesList") |
---|
23 | public void testFramsClass(Class<?> javaClass, String name, int paramCount, Object[][] paramsTests) throws InstantiationException, IllegalAccessException { |
---|
24 | String filename = "/info/" + name + ".info"; |
---|
25 | InputStream stream = ModelPackage.class.getResourceAsStream(filename); |
---|
26 | assertThat(stream).describedAs("stream " + filename).isNotNull(); |
---|
27 | |
---|
28 | Source source = new FileSource(stream, filename); |
---|
29 | |
---|
30 | assertThat(source.isClosed()).isFalse(); |
---|
31 | FramsClass framsClass = Loaders.loadFramsClass(source); |
---|
32 | assertThat(framsClass).isNotNull(); |
---|
33 | |
---|
34 | assertThat(framsClass.getParamCount()).isEqualTo(paramCount); |
---|
35 | ReflectionAccess access = new ReflectionAccess(javaClass, framsClass); |
---|
36 | Object object = javaClass.newInstance(); |
---|
37 | access.select(object); |
---|
38 | |
---|
39 | if (paramsTests != null) { |
---|
40 | for (Object[] args : paramsTests) { |
---|
41 | String paramName = (String )args[0]; |
---|
42 | Object defaultValue = args[1]; |
---|
43 | |
---|
44 | ValueParam param = getParam(framsClass, paramName, ValueParam.class); |
---|
45 | assertThat(param.getDef(Object.class)).isEqualTo(defaultValue); |
---|
46 | |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | @DataProvider |
---|
52 | public Object[][] classesList() { |
---|
53 | return new Object[][] { |
---|
54 | { MechPart.class, "MechPart", 20 , null}, |
---|
55 | { Joint.class, "Joint", 16 , null}, |
---|
56 | { MechJoint.class, "MechJoint", 10 , null}, |
---|
57 | { Neuro.class, "Neuro", 21, null}, |
---|
58 | { NeuroDefinition.class, "NeuroDef", 9, null}, |
---|
59 | { Part.class, "Part", 18, new Object[][] {{"m", 1.0}}}, |
---|
60 | // { Model.class, "Model", null}, |
---|
61 | { Creature.class, "Creature", 64, null}, |
---|
62 | { Genotype.class, "Genotype", 37, null}, |
---|
63 | { World.class, "World", 10, null} |
---|
64 | }; |
---|
65 | } |
---|
66 | } |
---|