|
1 | | -package com.microsoft.azure.functions.worker.broker; |
2 | | - |
3 | | -import com.microsoft.azure.functions.rpc.messages.RpcException; |
4 | | -import com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector; |
5 | | -import com.microsoft.azure.functions.worker.WorkerLogManager; |
6 | | -import com.microsoft.azure.functions.worker.binding.BindingDataStore; |
7 | | -import com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource; |
8 | | -import com.microsoft.azure.functions.worker.binding.ExecutionRetryContext; |
9 | | -import com.microsoft.azure.functions.worker.binding.ExecutionTraceContext; |
10 | | -import com.microsoft.azure.functions.worker.resolver.ParameterResolver; |
11 | | -import org.junit.jupiter.api.BeforeEach; |
12 | | -import org.junit.jupiter.api.Test; |
13 | | -import org.junit.jupiter.api.extension.ExtendWith; |
14 | | -import org.mockito.Mock; |
15 | | -import org.mockito.MockedStatic; |
16 | | -import org.mockito.Mockito; |
17 | | -import org.mockito.junit.jupiter.MockitoExtension; |
18 | | - |
19 | | -import java.lang.reflect.Method; |
20 | | -import java.util.ArrayList; |
21 | | -import java.util.HashMap; |
22 | | -import java.util.logging.Logger; |
23 | | - |
24 | | -import static org.junit.jupiter.api.Assertions.*; |
25 | | -import static org.mockito.Mockito.when; |
26 | | - |
27 | | - |
28 | | -@ExtendWith(MockitoExtension.class) |
29 | | -public class ParameterResolverTest { |
30 | | - |
31 | | - private ExecutionContextDataSource executionContextDataSource; |
32 | | - @Mock |
33 | | - private MethodBindInfo methodBindInfo; |
34 | | - |
35 | | - @BeforeEach |
36 | | - public void setup() { |
37 | | - String invocationId = "testInvocationId"; |
38 | | - ExecutionTraceContext traceContext = new ExecutionTraceContext("traceParent", "traceState", new HashMap<>()); |
39 | | - ExecutionRetryContext retryContext = new ExecutionRetryContext(1, 2, RpcException.newBuilder().build()); |
40 | | - String functionName = "ParameterResolverTest"; |
41 | | - BindingDataStore dataStore = new BindingDataStore(); |
42 | | - dataStore.setBindingDefinitions(new HashMap<>()); |
43 | | - try (MockedStatic<WorkerLogManager> workerLogManagerMockedStatic = Mockito.mockStatic(WorkerLogManager.class)) { |
44 | | - workerLogManagerMockedStatic.when(() -> WorkerLogManager.getInvocationLogger(invocationId)) |
45 | | - .thenReturn(Logger.getAnonymousLogger()); |
46 | | - executionContextDataSource = new ExecutionContextDataSource(invocationId, |
47 | | - traceContext, retryContext, functionName, dataStore, methodBindInfo, |
48 | | - this.getClass(), new ArrayList<>(), new FunctionInstanceInjector() { |
49 | | - @Override |
50 | | - public <T> T getInstance(Class<T> functionClass) throws Exception { |
51 | | - return null; |
52 | | - } |
53 | | - }); |
54 | | - } |
55 | | - |
56 | | - } |
57 | | - |
58 | | - @Test |
59 | | - public void testResolveArgumentsHasImplicitOutputTrue() throws Exception { |
60 | | - Method testMethod = this.getClass().getDeclaredMethod("testMethod"); |
61 | | - when(methodBindInfo.hasImplicitOutput()).thenReturn(true); |
62 | | - when(methodBindInfo.getMethod()).thenReturn(testMethod); |
63 | | - when(methodBindInfo.getParams()).thenReturn(new ArrayList<>()); |
64 | | - ParameterResolver.resolveArguments(executionContextDataSource); |
65 | | - assertTrue(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent()); |
66 | | - } |
67 | | - |
68 | | - @Test |
69 | | - public void testResolveArgumentsHasImplicitOutputFalse() throws Exception { |
70 | | - Method testMethod = this.getClass().getDeclaredMethod("testMethod"); |
71 | | - when(methodBindInfo.hasImplicitOutput()).thenReturn(false); |
72 | | - when(methodBindInfo.getMethod()).thenReturn(testMethod); |
73 | | - when(methodBindInfo.getParams()).thenReturn(new ArrayList<>()); |
74 | | - ParameterResolver.resolveArguments(executionContextDataSource); |
75 | | - assertFalse(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent()); |
76 | | - } |
77 | | - |
78 | | - public void testMethod() {} |
79 | | -} |
| 1 | +package com.microsoft.azure.functions.worker.broker; |
| 2 | + |
| 3 | +import com.microsoft.azure.functions.rpc.messages.RpcException; |
| 4 | +import com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector; |
| 5 | +import com.microsoft.azure.functions.worker.WorkerLogManager; |
| 6 | +import com.microsoft.azure.functions.worker.binding.BindingDataStore; |
| 7 | +import com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource; |
| 8 | +import com.microsoft.azure.functions.worker.binding.ExecutionRetryContext; |
| 9 | +import com.microsoft.azure.functions.worker.binding.ExecutionTraceContext; |
| 10 | +import com.microsoft.azure.functions.worker.converter.ParameterConverter; |
| 11 | +import org.junit.jupiter.api.BeforeEach; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 14 | +import org.mockito.Mock; |
| 15 | +import org.mockito.MockedStatic; |
| 16 | +import org.mockito.Mockito; |
| 17 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 18 | + |
| 19 | +import java.lang.reflect.Method; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.logging.Logger; |
| 23 | + |
| 24 | +import static org.junit.jupiter.api.Assertions.*; |
| 25 | +import static org.mockito.Mockito.when; |
| 26 | + |
| 27 | + |
| 28 | +@ExtendWith(MockitoExtension.class) |
| 29 | +public class ParameterConverterTest { |
| 30 | + |
| 31 | + private ExecutionContextDataSource executionContextDataSource; |
| 32 | + @Mock |
| 33 | + private MethodBindInfo methodBindInfo; |
| 34 | + |
| 35 | + @BeforeEach |
| 36 | + public void setup() { |
| 37 | + String invocationId = "testInvocationId"; |
| 38 | + ExecutionTraceContext traceContext = new ExecutionTraceContext("traceParent", "traceState", new HashMap<>()); |
| 39 | + ExecutionRetryContext retryContext = new ExecutionRetryContext(1, 2, RpcException.newBuilder().build()); |
| 40 | + String functionName = "ParameterResolverTest"; |
| 41 | + BindingDataStore dataStore = new BindingDataStore(); |
| 42 | + dataStore.setBindingDefinitions(new HashMap<>()); |
| 43 | + try (MockedStatic<WorkerLogManager> workerLogManagerMockedStatic = Mockito.mockStatic(WorkerLogManager.class)) { |
| 44 | + workerLogManagerMockedStatic.when(() -> WorkerLogManager.getInvocationLogger(invocationId)) |
| 45 | + .thenReturn(Logger.getAnonymousLogger()); |
| 46 | + executionContextDataSource = new ExecutionContextDataSource(invocationId, |
| 47 | + traceContext, retryContext, functionName, dataStore, methodBindInfo, |
| 48 | + this.getClass(), new ArrayList<>(), new FunctionInstanceInjector() { |
| 49 | + @Override |
| 50 | + public <T> T getInstance(Class<T> functionClass) throws Exception { |
| 51 | + return null; |
| 52 | + } |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testResolveArgumentsHasImplicitOutputTrue() throws Exception { |
| 60 | + Method testMethod = this.getClass().getDeclaredMethod("testMethod"); |
| 61 | + when(methodBindInfo.hasImplicitOutput()).thenReturn(true); |
| 62 | + when(methodBindInfo.getMethod()).thenReturn(testMethod); |
| 63 | + when(methodBindInfo.getParams()).thenReturn(new ArrayList<>()); |
| 64 | + ParameterConverter.resolveArguments(executionContextDataSource); |
| 65 | + assertTrue(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent()); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testResolveArgumentsHasImplicitOutputFalse() throws Exception { |
| 70 | + Method testMethod = this.getClass().getDeclaredMethod("testMethod"); |
| 71 | + when(methodBindInfo.hasImplicitOutput()).thenReturn(false); |
| 72 | + when(methodBindInfo.getMethod()).thenReturn(testMethod); |
| 73 | + when(methodBindInfo.getParams()).thenReturn(new ArrayList<>()); |
| 74 | + ParameterConverter.resolveArguments(executionContextDataSource); |
| 75 | + assertFalse(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent()); |
| 76 | + } |
| 77 | + |
| 78 | + public void testMethod() {} |
| 79 | +} |
0 commit comments