1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package fr.ifremer.isisfish.entity;
27
28 import java.lang.reflect.Method;
29 import java.lang.reflect.Modifier;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.nuiton.topia.TopiaException;
36 import org.nuiton.topia.persistence.TopiaEntity;
37
38 import fr.ifremer.isisfish.IsisFishDAOHelper;
39 import fr.ifremer.isisfish.IsisFishDAOHelper.IsisFishEntityEnum;
40 import fr.ifremer.isisfish.entities.Equation;
41
42
43
44
45
46
47
48
49
50
51 public class PersistenceConventionTest {
52
53
54 private static final Log log = LogFactory.getLog(PersistenceConventionTest.class);
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @Test
69 public void testEquationSetterName() throws TopiaException, SecurityException, NoSuchMethodException {
70
71 for (IsisFishEntityEnum entityEnum : IsisFishDAOHelper.IsisFishEntityEnum.values()) {
72 Class<? extends TopiaEntity> entity = entityEnum.getImplementation();
73
74 if (log.isDebugEnabled()) {
75 log.debug("Testing convention on : " + entity);
76 }
77
78 for (Method method : entity.getMethods()) {
79 Class<?> returnType = method.getReturnType();
80
81
82 if (returnType.isAssignableFrom(Equation.class)) {
83 String methodName = method.getName();
84 methodName = methodName.replaceFirst("g", "s") + "Content";
85
86 try {
87 Method methodSet = entity.getMethod(methodName, String.class);
88
89 Assert.assertTrue("Method " + entity.getName() + "#" +
90 methodName + "(" + String.class.getName() + ") is not accessible", Modifier.isPublic(methodSet.getModifiers()));
91 }
92 catch (NoSuchMethodException ex) {
93 Assert.fail("Method " + entity.getName() + "#" +
94 methodName + "(" + String.class.getName() + ") not found");
95 }
96 }
97 }
98 }
99 }
100 }