blob: 87c12db9bf9511a4d9c94f797f81ad17e0fc931a (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package org.apache.tuscany.persistence.datasource;
import javax.sql.DataSource;
import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
import org.apache.tuscany.spi.model.ComponentType;
import junit.framework.TestCase;
/**
* @version $Rev$ $Date$
*/
public class DSComponentTypeLoaderTestCase extends TestCase {
public void testIntrospection() throws Exception {
DSComponentTypeLoader loader = new DSComponentTypeLoader(null);
DataSourceImplementation implementation = new DataSourceImplementation();
implementation.setProviderName(Foo.class.getName());
implementation.setClassLoader(getClass().getClassLoader());
loader.load(implementation, null);
ComponentType<?, ?, ?> type = implementation.getComponentType();
assertEquals(2, type.getProperties().size());
assertNull(type.getProperties().get("object"));
Object bar = type.getProperties().get("bar");
assertEquals(String.class, ((JavaMappedProperty) bar).getJavaType());
Object baz = type.getProperties().get("baz");
assertEquals(Integer.TYPE, ((JavaMappedProperty) baz).getJavaType());
assertEquals(1, type.getServices().size());
assertEquals(DataSource.class, type.getServices().get("DataSource").getServiceContract().getInterfaceClass());
}
public void testOverloadedMethod() throws Exception {
DSComponentTypeLoader loader = new DSComponentTypeLoader(null);
DataSourceImplementation implementation = new DataSourceImplementation();
implementation.setProviderName(BadFoo.class.getName());
implementation.setClassLoader(getClass().getClassLoader());
try {
loader.load(implementation, null);
fail();
} catch (AmbiguousPropertyException e) {
// expected
}
}
public class Foo {
private String bar;
private int baz;
private Foo object;
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
public int getBaz() {
return baz;
}
public void setBaz(int baz) {
this.baz = baz;
}
public Foo getObject() {
return object;
}
public void setObject(Foo object) {
this.object = object;
}
}
public class BadFoo {
public void setBar(String bar) {
}
public void setBar(Object bar) {
}
}
}
|