ProxyFactory_Test.java (2be43276) ProxyFactory_Test.java (9cbd97ce)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 15 unchanged lines hidden (view full) ---

24package com.sun.star.lib.uno.bridges.java_remote;
25
26import com.sun.star.uno.IQueryInterface;
27import com.sun.star.uno.MappingException;
28import com.sun.star.uno.Type;
29import com.sun.star.uno.UnoRuntime;
30import com.sun.star.uno.XInterface;
31import com.sun.star.uno.XNamingService;
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 15 unchanged lines hidden (view full) ---

24package com.sun.star.lib.uno.bridges.java_remote;
25
26import com.sun.star.uno.IQueryInterface;
27import com.sun.star.uno.MappingException;
28import com.sun.star.uno.Type;
29import com.sun.star.uno.UnoRuntime;
30import com.sun.star.uno.XInterface;
31import com.sun.star.uno.XNamingService;
32import complexlib.ComplexTestCase;
33import java.lang.reflect.InvocationTargetException;
34import java.lang.reflect.Method;
35import java.lang.reflect.UndeclaredThrowableException;
36
32import java.lang.reflect.InvocationTargetException;
33import java.lang.reflect.Method;
34import java.lang.reflect.UndeclaredThrowableException;
35
37public final class ProxyFactory_Test extends ComplexTestCase {
38 public String getTestObjectName() {
39 return getClass().getName();
40 }
36import org.junit.Test;
37import static org.junit.Assert.*;
41
38
42 public String[] getTestMethodNames() {
43 return new String[] { "testQueryInterface", "testExceptionHandling" };
44 }
45
39public final class ProxyFactory_Test {
40 @Test
46 public void testQueryInterface() {
47 TestRequestHandler handler = new TestRequestHandler();
48 Type type = new Type(XNamingService.class);
49 Object proxy = new ProxyFactory(handler, null).create("TestOID", type);
41 public void testQueryInterface() {
42 TestRequestHandler handler = new TestRequestHandler();
43 Type type = new Type(XNamingService.class);
44 Object proxy = new ProxyFactory(handler, null).create("TestOID", type);
50 assure("", proxy == ((IQueryInterface) proxy).queryInterface(type));
51 assure("", proxy == UnoRuntime.queryInterface(type, proxy));
45 assertTrue("", proxy == ((IQueryInterface) proxy).queryInterface(type));
46 assertTrue("", proxy == UnoRuntime.queryInterface(type, proxy));
52 }
53
47 }
48
49 @Test
54 public void testExceptionHandling() throws Exception {
55 TestRequestHandler handler = new TestRequestHandler();
56 Object proxy = new ProxyFactory(handler, null).create(
57 "TestOID", new Type(XNamingService.class));
58 testExceptions(
59 handler,
60 proxy.getClass().getMethod("queryInterface",
61 new Class[] { Type.class }),

--- 23 unchanged lines hidden (view full) ---

85 testExceptionType(method, obj, args, exceptions[i]);
86 }
87 }
88
89 private void testExceptionType(Method method, Object obj, Object[] args,
90 Class exception) throws Exception {
91 try {
92 method.invoke(obj, args);
50 public void testExceptionHandling() throws Exception {
51 TestRequestHandler handler = new TestRequestHandler();
52 Object proxy = new ProxyFactory(handler, null).create(
53 "TestOID", new Type(XNamingService.class));
54 testExceptions(
55 handler,
56 proxy.getClass().getMethod("queryInterface",
57 new Class[] { Type.class }),

--- 23 unchanged lines hidden (view full) ---

81 testExceptionType(method, obj, args, exceptions[i]);
82 }
83 }
84
85 private void testExceptionType(Method method, Object obj, Object[] args,
86 Class exception) throws Exception {
87 try {
88 method.invoke(obj, args);
93 assure("expected exception: " + exception, exception == null);
89 assertTrue("expected exception: " + exception, exception == null);
94 } catch (InvocationTargetException e) {
90 } catch (InvocationTargetException e) {
95 assure("unexpected exception: " + e.getTargetException(),
91 assertTrue("unexpected exception: " + e.getTargetException(),
96 exception != null
97 && exception.isInstance(e.getTargetException()));
98 // TODO check stack trace
99 }
100 }
101
102 private static final class TestRequestHandler implements RequestHandler {
103 public Object sendRequest(String oid, Type type, String operation,

--- 38 unchanged lines hidden ---
92 exception != null
93 && exception.isInstance(e.getTargetException()));
94 // TODO check stack trace
95 }
96 }
97
98 private static final class TestRequestHandler implements RequestHandler {
99 public Object sendRequest(String oid, Type type, String operation,

--- 38 unchanged lines hidden ---