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
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.tuscany.core.databinding.impl;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.tuscany.api.annotation.DataContext;
import org.apache.tuscany.api.annotation.DataType;
import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.idl.java.JavaServiceContract;
import org.apache.tuscany.spi.model.Operation;
import org.osoa.sca.annotations.Remotable;
import org.w3c.dom.Node;
/**
*
*/
public class DataBindingJavaInterfaceProcessorTestCase extends TestCase {
/**
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* @throws InvalidServiceContractException
*/
public final void testVisitInterface() throws InvalidServiceContractException {
DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor();
JavaServiceContract contract = new JavaServiceContract(MockInterface.class);
Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
Operation<Type> operation = new Operation<Type>("call", null, null, null, false, null);
Operation<Type> operation1 = new Operation<Type>("call1", null, null, null, false, null);
operations.put("call", operation);
operations.put("call1", operation1);
contract.setOperations(operations);
processor.visitInterface(MockInterface.class, null, contract);
Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding());
Assert.assertEquals("element", (String)contract.getMetaData().get("nodeType"));
Assert.assertEquals("org.w3c.dom.Node", contract.getOperations().get("call").getDataBinding());
Assert.assertEquals("xml:string", contract.getOperations().get("call1").getDataBinding());
}
@DataType(name = "org.w3c.dom.Node", context = {@DataContext(key = "nodeType", value = "element")})
@Remotable
public static interface MockInterface {
Node call(Node msg);
@DataType(name = "xml:string")
String call1(String msg);
}
}
|