Migrate from junit4 to junit5 (#692)
* migrate to junit5 * update pom.xml file * remove lenient stub - correct assertions order * move java version log to function load request handler
This commit is contained in:
Родитель
86e4db1ce8
Коммит
3d297240ed
24
pom.xml
24
pom.xml
|
@ -23,6 +23,8 @@
|
|||
<azure.functions.java.core.library.version>1.2.0</azure.functions.java.core.library.version>
|
||||
<azure.functions.java.spi>1.0.0</azure.functions.java.spi>
|
||||
<azure.functions.java.library.version>2.2.0</azure.functions.java.library.version>
|
||||
<jupiter.version>5.9.1</jupiter.version>
|
||||
<mockito-core.version>4.11.0</mockito-core.version>
|
||||
</properties>
|
||||
<licenses>
|
||||
<license>
|
||||
|
@ -67,12 +69,6 @@
|
|||
<artifactId>azure-functions-java-spi</artifactId>
|
||||
<version>${azure.functions.java.spi}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure.functions</groupId>
|
||||
<artifactId>azure-functions-java-library</artifactId>
|
||||
<version>${azure.functions.java.library.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
|
@ -114,15 +110,21 @@
|
|||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<groupId>com.microsoft.azure.functions</groupId>
|
||||
<artifactId>azure-functions-java-library</artifactId>
|
||||
<version>${azure.functions.java.library.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>4.6.1</version>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>${mockito-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -3,11 +3,13 @@ package com.microsoft.azure.functions.worker.handler;
|
|||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.microsoft.azure.functions.worker.Util;
|
||||
import com.microsoft.azure.functions.worker.WorkerLogManager;
|
||||
import com.microsoft.azure.functions.worker.broker.*;
|
||||
import com.microsoft.azure.functions.worker.description.*;
|
||||
import com.microsoft.azure.functions.rpc.messages.*;
|
||||
|
||||
|
||||
public class FunctionLoadRequestHandler extends MessageHandler<FunctionLoadRequest, FunctionLoadResponse.Builder> {
|
||||
public FunctionLoadRequestHandler(JavaFunctionBroker broker) {
|
||||
super(StreamingMessage::getFunctionLoadRequest,
|
||||
|
@ -20,7 +22,7 @@ public class FunctionLoadRequestHandler extends MessageHandler<FunctionLoadReque
|
|||
|
||||
@Override
|
||||
String execute(FunctionLoadRequest request, FunctionLoadResponse.Builder response) throws Exception {
|
||||
WorkerLogManager.getSystemLogger().log(Level.INFO, "FunctionLoadRequest received by the Java worker");
|
||||
WorkerLogManager.getSystemLogger().log(Level.INFO, "FunctionLoadRequest received by the Java worker, Java version - " + Util.getJavaVersion());
|
||||
final RpcFunctionMetadata metadata = request.getMetadata();
|
||||
final FunctionMethodDescriptor descriptor = createFunctionDescriptor(request.getFunctionId(), metadata);
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import com.microsoft.azure.functions.worker.*;
|
|||
import com.microsoft.azure.functions.worker.broker.*;
|
||||
import com.microsoft.azure.functions.rpc.messages.*;
|
||||
|
||||
import static com.microsoft.azure.functions.worker.Util.getJavaVersion;
|
||||
|
||||
public class InvocationRequestHandler extends MessageHandler<InvocationRequest, InvocationResponse.Builder> {
|
||||
public InvocationRequestHandler(JavaFunctionBroker broker) {
|
||||
super(StreamingMessage::getInvocationRequest,
|
||||
|
@ -25,7 +23,6 @@ public class InvocationRequestHandler extends MessageHandler<InvocationRequest,
|
|||
|
||||
@Override
|
||||
String execute(InvocationRequest request, InvocationResponse.Builder response) throws Exception {
|
||||
WorkerLogManager.getSystemLogger().log(Level.INFO, "Java version - " + getJavaVersion());
|
||||
WorkerLogManager.getSystemLogger().log(Level.INFO, "InvocationRequest received by the Java worker");
|
||||
final String functionId = request.getFunctionId();
|
||||
final String invocationId = request.getInvocationId();
|
||||
|
|
|
@ -51,12 +51,6 @@ public class DefaultClassLoaderProvider implements ClassLoaderProvider {
|
|||
addUrlToSystemClassLoader(url);
|
||||
}
|
||||
|
||||
public static boolean isUrlPointingToAFile(URL url) throws UnsupportedEncodingException {
|
||||
String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8");
|
||||
File file = new File(decodedPath);
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
private void addUrlToSystemClassLoader(URL url) throws IOException {
|
||||
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||
Class<?> sysclass = URLClassLoader.class;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.microsoft.azure.functions.worker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UtilTests {
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class UtilTest {
|
||||
|
||||
@Test
|
||||
public void isTrueNull() {
|
|
@ -1,18 +1,18 @@
|
|||
package com.microsoft.azure.functions.worker.binding.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcByteArrayDataSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RpcByteArrayDataSourceTests {
|
||||
public class RpcByteArrayDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void rpcByteArrayDataSource_To_byteArray() {
|
||||
|
@ -26,7 +26,7 @@ public class RpcByteArrayDataSourceTests {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
byte[] actualBytes = (byte[]) actualArg.getValue();
|
||||
String actualString = new String(actualBytes);
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,7 +41,7 @@ public class RpcByteArrayDataSourceTests {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
Byte[] actualBytes = (Byte[]) actualArg.getValue();
|
||||
String actualString = new String(ArrayUtils.toPrimitive(actualBytes));
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -58,7 +58,7 @@ public class RpcByteArrayDataSourceTests {
|
|||
TestBlobData.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
TestBlobData actualBlobData = (TestBlobData) actualArg.getValue();
|
||||
assertEquals(actualBlobData.blobText, testBlobData.blobText);
|
||||
assertEquals(testBlobData.blobText, actualBlobData.blobText);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,7 +73,7 @@ public class RpcByteArrayDataSourceTests {
|
|||
String.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
String actualBlobData = (String) actualArg.getValue();
|
||||
assertEquals(actualBlobData, expectedString);
|
||||
assertEquals(expectedString, actualBlobData);
|
||||
}
|
||||
|
||||
public static class TestBlobData {
|
|
@ -8,16 +8,14 @@ import com.microsoft.azure.functions.rpc.messages.CollectionBytes.Builder;
|
|||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RpcCollectionByteArrayDataSourceTest {
|
||||
@Test
|
||||
|
@ -41,7 +39,7 @@ public class RpcCollectionByteArrayDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
byte[][] actualBytes = (byte[][]) actualArg.getValue();
|
||||
String actualString = new String(actualBytes[0]);
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -65,7 +63,7 @@ public class RpcCollectionByteArrayDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
Byte[][] actualBytes = (Byte[][]) actualArg.getValue();
|
||||
String actualString = new String(ArrayUtils.toPrimitive(actualBytes[0]));
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,7 +87,7 @@ public class RpcCollectionByteArrayDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<byte[]> actualBytes = (List) actualArg.getValue();
|
||||
String actualString = new String(actualBytes.get(0));
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -113,7 +111,7 @@ public class RpcCollectionByteArrayDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<byte[]> actualBytes = (List) actualArg.getValue();
|
||||
String actualString = new String(actualBytes.get(0));
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -137,7 +135,7 @@ public class RpcCollectionByteArrayDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Byte[]> actualBytes = (List) actualArg.getValue();
|
||||
String actualString = new String(ArrayUtils.toPrimitive(actualBytes.get(0)));
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -161,7 +159,7 @@ public class RpcCollectionByteArrayDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<byte[]> actualBytes = (List) actualArg.getValue();
|
||||
String actualString = new String(actualBytes.get(0));
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ import com.microsoft.azure.functions.rpc.messages.CollectionDouble;
|
|||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource;
|
||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RpcCollectionDoubleDataSourceTest {
|
||||
@Test
|
||||
|
@ -34,7 +34,7 @@ public class RpcCollectionDoubleDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
Double[] actualDoublegArray = (Double[]) actualArg.getValue();
|
||||
Double actualDouble = actualDoublegArray[0];
|
||||
assertEquals(actualDouble, expectedDouble);
|
||||
assertEquals(expectedDouble, actualDouble);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,7 +56,7 @@ public class RpcCollectionDoubleDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
double[] actualDoubleArray = (double[]) actualArg.getValue();
|
||||
double actualDouble = actualDoubleArray[0];
|
||||
assertEquals("" + actualDouble, "" + expectedDouble);
|
||||
assertEquals(expectedDouble, actualDouble);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -78,7 +78,7 @@ public class RpcCollectionDoubleDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Double> actualDoubleList = (List) actualArg.getValue();
|
||||
Double actualLong = actualDoubleList.get(0);
|
||||
assertEquals(actualLong, expectedDouble);
|
||||
assertEquals(expectedDouble, actualLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -100,7 +100,7 @@ public class RpcCollectionDoubleDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Double> actualDoubleList = (List) actualArg.getValue();
|
||||
Double actualLong = actualDoubleList.get(0);
|
||||
assertEquals(actualLong, expectedDouble);
|
||||
assertEquals(expectedDouble, actualLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -122,7 +122,7 @@ public class RpcCollectionDoubleDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Double> actualDoubleList = (List) actualArg.getValue();
|
||||
Double actualLong = actualDoubleList.get(0);
|
||||
assertEquals(actualLong, expectedDouble);
|
||||
assertEquals(expectedDouble, actualLong);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ import com.microsoft.azure.functions.rpc.messages.CollectionSInt64.Builder;
|
|||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcCollectionLongDataSource;
|
||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RpcCollectionLongDataSourceTest{
|
||||
@Test
|
||||
|
@ -34,7 +34,7 @@ public class RpcCollectionLongDataSourceTest{
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
Long[] actualLongArray = (Long[]) actualArg.getValue();
|
||||
Long actualLong = actualLongArray[0];
|
||||
assertEquals(actualLong, expectedLong);
|
||||
assertEquals(expectedLong, actualLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,7 +56,7 @@ public class RpcCollectionLongDataSourceTest{
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
long[] actualLongArray = (long[]) actualArg.getValue();
|
||||
Long actualLong = actualLongArray[0];
|
||||
assertEquals(actualLong, expectedLong);
|
||||
assertEquals(expectedLong, actualLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -78,7 +78,7 @@ public class RpcCollectionLongDataSourceTest{
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Long> actualLongList = (List) actualArg.getValue();
|
||||
Long actualLong = actualLongList.get(0);
|
||||
assertEquals(actualLong, expectedLong);
|
||||
assertEquals(expectedLong, actualLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -101,7 +101,7 @@ public class RpcCollectionLongDataSourceTest{
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Long> actualLongList = (List) actualArg.getValue();
|
||||
Long actualLong = actualLongList.get(0);
|
||||
assertEquals(actualLong, expectedLong);
|
||||
assertEquals(expectedLong, actualLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -124,6 +124,6 @@ public class RpcCollectionLongDataSourceTest{
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<Long> actualLongList = (List) actualArg.getValue();
|
||||
Long actualLong = actualLongList.get(0);
|
||||
assertEquals(actualLong, expectedLong);
|
||||
assertEquals(expectedLong, actualLong);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ import com.microsoft.azure.functions.rpc.messages.CollectionString;
|
|||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcCollectionStringDataSource;
|
||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RpcCollectionStringDataSourceTest {
|
||||
@Test
|
||||
|
@ -34,7 +34,7 @@ public class RpcCollectionStringDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
String[] actualStringArray = (String[]) actualArg.getValue();
|
||||
String actualString = actualStringArray[0];
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,7 +56,7 @@ public class RpcCollectionStringDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<String> actualStringList = (List) actualArg.getValue();
|
||||
String actualString = actualStringList.get(0);
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -78,7 +78,7 @@ public class RpcCollectionStringDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<String> actualStringList = (List) actualArg.getValue();
|
||||
String actualString = actualStringList.get(0);
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -100,10 +100,6 @@ public class RpcCollectionStringDataSourceTest {
|
|||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<String> actualStringList = (List) actualArg.getValue();
|
||||
String actualString = actualStringList.get(0);
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
package com.microsoft.azure.functions.worker.binding.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
import org.junit.Test;
|
||||
import com.microsoft.azure.functions.HttpRequestMessage;
|
||||
import com.microsoft.azure.functions.HttpStatus;
|
||||
import com.microsoft.azure.functions.rpc.messages.RpcHttp;
|
||||
import com.microsoft.azure.functions.rpc.messages.TypedData;
|
||||
import com.microsoft.azure.functions.worker.binding.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RpcHttpRequestDataSourceTests {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
public class RpcHttpRequestDataSourceTest {
|
||||
|
||||
public void HttpRequestStringBody(HttpRequestMessage<String> request) {
|
||||
}
|
||||
|
@ -52,7 +54,7 @@ public class RpcHttpRequestDataSourceTests {
|
|||
parameters[0].getParameterizedType());
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
HttpRequestMessage<?> requestMsg = (HttpRequestMessage<?>) actualArg.getValue();
|
||||
assertEquals(requestMsg.getBody().toString(), "testStringBody");
|
||||
assertEquals( "testStringBody", requestMsg.getBody().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -88,12 +90,12 @@ public class RpcHttpRequestDataSourceTests {
|
|||
HttpRequestMessage<?> requestMsg = (HttpRequestMessage<?>) actualArg.getValue();
|
||||
byte[] actualBytes = (byte[])requestMsg.getBody();
|
||||
String actualString = new String (actualBytes);
|
||||
assertEquals(actualString, expectedString);
|
||||
assertEquals(expectedString, actualString);
|
||||
}
|
||||
|
||||
private Method getFunctionMethod(String methodName) {
|
||||
RpcHttpRequestDataSourceTests httpDataSourceTests = new RpcHttpRequestDataSourceTests();
|
||||
Class<? extends RpcHttpRequestDataSourceTests> httpDataSourceTestsClass = httpDataSourceTests
|
||||
RpcHttpRequestDataSourceTest httpDataSourceTests = new RpcHttpRequestDataSourceTest();
|
||||
Class<? extends RpcHttpRequestDataSourceTest> httpDataSourceTestsClass = httpDataSourceTests
|
||||
.getClass();
|
||||
Method[] methods = httpDataSourceTestsClass.getMethods();
|
||||
Method functionMethod = null;
|
|
@ -1,16 +1,16 @@
|
|||
package com.microsoft.azure.functions.worker.binding.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.util.Optional;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcIntegerDataSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RpcIntegerDataSourceTests {
|
||||
public class RpcIntegerDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void rpcIntegerDataSource_To_Integer() {
|
|
@ -0,0 +1,170 @@
|
|||
package com.microsoft.azure.functions.worker.binding.tests;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcJsonDataSource;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcStringDataSource;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class RpcStringDataSourceTest {
|
||||
|
||||
public static class TestPOJO {
|
||||
public Integer id;
|
||||
public String name;
|
||||
public String description;
|
||||
}
|
||||
|
||||
public void FunctionWithPOJOListInput(ArrayList<TestPOJO> items) {
|
||||
}
|
||||
|
||||
public void FunctionWithStringListInput(List<String> items) {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcStringDataSource_To_String() {
|
||||
String sourceKey = "testString";
|
||||
String inputString = "Test String";
|
||||
RpcStringDataSource stringData = new RpcStringDataSource(sourceKey, inputString);
|
||||
BindingData bindingData = new BindingData(inputString);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
assertEquals(bindingData.getValue(), actualArg.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringDataSource_To_String() {
|
||||
String sourceKey = "testStringJson";
|
||||
String jsonInString = "{\"id\":7500 , \"testname\":\"joe\"}";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInString);
|
||||
BindingData bindingData = new BindingData(jsonInString);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
assertEquals(bindingData.getValue(), actualArg.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcStringArrayDataSource_To_StringArray() {
|
||||
String sourceKey = "testStringArray";
|
||||
String jsonInStringArray = "[\"item1\", \"item2\"]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String[].class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
String[] convertedData = (String[]) actualArg.getValue();
|
||||
assertTrue(convertedData.length == 2);
|
||||
assertTrue(convertedData[0].contains("item1"));
|
||||
assertTrue(convertedData[1].contains("item2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_POJOArray() {
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, TestPOJO[].class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
TestPOJO[] convertedData = (TestPOJO[]) actualArg.getValue();
|
||||
assertTrue(convertedData.length == 2);
|
||||
assertTrue(convertedData[0].id == 7500);
|
||||
assertEquals("joe", convertedData[0].name);
|
||||
assertTrue(convertedData[1].id == 7501);
|
||||
assertEquals("joe", convertedData[1].name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_StringArray() {
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String[].class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
String[] convertedData = (String[]) actualArg.getValue();
|
||||
assertTrue(convertedData.length == 2);
|
||||
assertTrue(convertedData[0].contains("7500"));
|
||||
assertTrue(convertedData[1].contains("7501"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_StringList() {
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
|
||||
Type paramType = getParameterType("FunctionWithStringListInput");
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, paramType);
|
||||
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<String> convertedData = (List<String>) actualArg.getValue();
|
||||
assertTrue(convertedData.size() == 2);
|
||||
assertTrue(convertedData.get(0).contains("7500"));
|
||||
assertTrue(convertedData.get(1).contains("7501"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringDataSource_To_POJO() {
|
||||
String sourceKey = "testStringJson";
|
||||
String jsonInStringArray = "{\"id\":7500, \"name\":\"joe\"}";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, TestPOJO.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
TestPOJO convertedData = (TestPOJO) actualArg.getValue();
|
||||
assertTrue(convertedData.id == 7500);
|
||||
assertEquals("joe", convertedData.name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_POJOList() throws NoSuchMethodException, SecurityException {
|
||||
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
|
||||
Type paramType = getParameterType("FunctionWithPOJOListInput");
|
||||
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, paramType);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<TestPOJO> convertedData = (List<TestPOJO>) actualArg.getValue();
|
||||
assertTrue(convertedData.size() == 2);
|
||||
assertTrue(convertedData.get(0).id == 7500);
|
||||
assertEquals("joe", convertedData.get(0).name);
|
||||
assertTrue(convertedData.get(1).id == 7501);
|
||||
assertEquals("joe", convertedData.get(1).name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcStringStringDataSource_To_POJO_Throws() {
|
||||
Assertions.assertThrows(JsonSyntaxException.class, () -> {
|
||||
String sourceKey = "testString";
|
||||
String testString = "item1";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, testString);
|
||||
stringData.computeByName(sourceKey, TestPOJO.class);
|
||||
});
|
||||
}
|
||||
|
||||
private static Type getParameterType(String functionName) {
|
||||
RpcStringDataSourceTest stringDataSourceTests = new RpcStringDataSourceTest();
|
||||
Class<? extends RpcStringDataSourceTest> stringDataSourceTestsClass = stringDataSourceTests.getClass();
|
||||
Method[] methods = stringDataSourceTestsClass.getMethods();
|
||||
Method functionWithStringListInputMethod = null;
|
||||
for (Method method : methods) {
|
||||
if (method.getName() == functionName) {
|
||||
functionWithStringListInputMethod = method;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Parameter[] parameters = functionWithStringListInputMethod.getParameters();
|
||||
return parameters[0].getParameterizedType();
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
package com.microsoft.azure.functions.worker.binding.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.microsoft.azure.functions.worker.binding.BindingData;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcJsonDataSource;
|
||||
import com.microsoft.azure.functions.worker.binding.RpcStringDataSource;
|
||||
|
||||
public class RpcStringDataSourceTests {
|
||||
|
||||
public static class TestPOJO {
|
||||
public Integer id;
|
||||
public String name;
|
||||
public String description;
|
||||
}
|
||||
|
||||
public void FunctionWithPOJOListInput(ArrayList<TestPOJO> items) {
|
||||
}
|
||||
|
||||
public void FunctionWithStringListInput(List<String> items) {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcStringDataSource_To_String() {
|
||||
String sourceKey = "testString";
|
||||
String inputString = "Test String";
|
||||
RpcStringDataSource stringData = new RpcStringDataSource(sourceKey, inputString);
|
||||
BindingData bindingData = new BindingData(inputString);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
assertEquals(bindingData.getValue(), actualArg.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringDataSource_To_String() {
|
||||
String sourceKey = "testStringJson";
|
||||
String jsonInString = "{\"id\":7500 , \"testname\":\"joe\"}";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInString);
|
||||
BindingData bindingData = new BindingData(jsonInString);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
assertEquals(bindingData.getValue(), actualArg.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcStringArrayDataSource_To_StringArray() {
|
||||
String sourceKey = "testStringArray";
|
||||
String jsonInStringArray = "[\"item1\", \"item2\"]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String[].class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
String[] convertedData = (String[]) actualArg.getValue();
|
||||
assertTrue(convertedData.length == 2);
|
||||
assertTrue(convertedData[0].contains("item1"));
|
||||
assertTrue(convertedData[1].contains("item2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_POJOArray() {
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, TestPOJO[].class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
TestPOJO[] convertedData = (TestPOJO[]) actualArg.getValue();
|
||||
assertTrue(convertedData.length == 2);
|
||||
assertTrue(convertedData[0].id == 7500);
|
||||
assertEquals(convertedData[0].name, "joe");
|
||||
assertTrue(convertedData[1].id == 7501);
|
||||
assertEquals(convertedData[1].name, "joe");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_StringArray() {
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, String[].class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
String[] convertedData = (String[]) actualArg.getValue();
|
||||
assertTrue(convertedData.length == 2);
|
||||
assertTrue(convertedData[0].contains("7500"));
|
||||
assertTrue(convertedData[1].contains("7501"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_StringList() {
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
|
||||
Type paramType = getParameterType("FunctionWithStringListInput");
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey,paramType);
|
||||
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<String> convertedData = (List<String>) actualArg.getValue();
|
||||
assertTrue(convertedData.size() == 2);
|
||||
assertTrue(convertedData.get(0).contains("7500"));
|
||||
assertTrue(convertedData.get(1).contains("7501"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringDataSource_To_POJO() {
|
||||
String sourceKey = "testStringJson";
|
||||
String jsonInStringArray = "{\"id\":7500, \"name\":\"joe\"}";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey, TestPOJO.class);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
TestPOJO convertedData = (TestPOJO) actualArg.getValue();
|
||||
assertTrue(convertedData.id == 7500);
|
||||
assertEquals(convertedData.name, "joe");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcJsonStringArrayDataSource_To_POJOList() throws NoSuchMethodException, SecurityException {
|
||||
|
||||
String sourceKey = "testStringJsonArray";
|
||||
String jsonInStringArray = "[{\"id\":7500, \"name\":\"joe\"}, {\"id\":7501 , \"name\":\"joe\"}]";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, jsonInStringArray);
|
||||
|
||||
Type paramType = getParameterType("FunctionWithPOJOListInput");
|
||||
|
||||
Optional<BindingData> actualBindingData = stringData.computeByName(sourceKey,paramType);
|
||||
BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new);
|
||||
List<TestPOJO> convertedData = (List<TestPOJO>) actualArg.getValue();
|
||||
assertTrue(convertedData.size() == 2);
|
||||
assertTrue(convertedData.get(0).id == 7500);
|
||||
assertEquals(convertedData.get(0).name, "joe");
|
||||
assertTrue(convertedData.get(1).id == 7501);
|
||||
assertEquals(convertedData.get(1).name, "joe");
|
||||
}
|
||||
|
||||
@Test(expected = JsonSyntaxException.class)
|
||||
public void rpcStringStringDataSource_To_POJO_Throws() {
|
||||
String sourceKey = "testString";
|
||||
String testString = "item1";
|
||||
RpcJsonDataSource stringData = new RpcJsonDataSource(sourceKey, testString);
|
||||
stringData.computeByName(sourceKey, TestPOJO.class);
|
||||
}
|
||||
|
||||
private static Type getParameterType(String functionName) {
|
||||
RpcStringDataSourceTests stringDataSourceTests = new RpcStringDataSourceTests();
|
||||
Class<? extends RpcStringDataSourceTests> stringDataSourceTestsClass = stringDataSourceTests.getClass();
|
||||
Method[] methods = stringDataSourceTestsClass.getMethods();
|
||||
Method functionWithStringListInputMethod = null;
|
||||
for (Method method : methods) {
|
||||
if (method.getName() == functionName) {
|
||||
functionWithStringListInputMethod = method;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Parameter[] parameters = functionWithStringListInputMethod.getParameters();
|
||||
return parameters[0].getParameterizedType();
|
||||
}
|
||||
}
|
|
@ -4,20 +4,18 @@ import com.microsoft.azure.functions.rpc.messages.InvocationRequest;
|
|||
import com.microsoft.azure.functions.rpc.messages.ParameterBinding;
|
||||
import com.microsoft.azure.functions.rpc.messages.TypedData;
|
||||
import com.microsoft.azure.functions.worker.reflect.DefaultClassLoaderProvider;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class JavaFunctionBrokerTest {
|
||||
@Mock InvocationRequest request;
|
||||
@Mock ParameterBinding binding;
|
||||
|
@ -36,19 +34,24 @@ public class JavaFunctionBrokerTest {
|
|||
|
||||
@Test
|
||||
public void getTriggerMetadataMap_success() throws Exception {
|
||||
String expectedData = "http {\n method: \"GET\"\n url: \"https://localhost:5001/api/HttpExample?name=ushio\"\n headers {\n key: \"cache-control\"\n value: \"max-age=0\"\n }\n headers {\n key: \"connection\"\n value: \"Keep-Alive\"\n }\n headers {\n key: \"accept\"\n value: \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\"\n }\n headers {\n key: \"accept-encoding\"\n value: \"gzip, deflate, br\"\n }\n headers {\n key: \"accept-language\"\n value: \"en-US,ja;q=0.8,en-GB;q=0.5,en;q=0.3\"\n }\n headers {\n key: \"host\"\n value: \"localhost:5001\"\n }\n headers {\n key: \"user-agent\"\n value: \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041\"\n }\n headers {\n key: \"upgrade-insecure-requests\"\n value: \"1\"\n }\n query {\n key: \"name\"\n value: \"ushio\"\n }\n identities {\n name_claim_type {\n value: \"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\"\n }\n role_claim_type {\n value: \"http://schemas.microsoft.com/ws/2008/06/identity/claims/role\"\n }\n }\n}\n";
|
||||
String expectedName = "req";
|
||||
String reqValue = "http {\n method: \"GET\"\n url: \"https://localhost:5001/api/HttpExample?name=ushio\"\n headers {\n key: \"cache-control\"\n value: \"max-age=0\"\n }\n headers {\n key: \"connection\"\n value: \"Keep-Alive\"\n }\n headers {\n key: \"accept\"\n value: \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\"\n }\n headers {\n key: \"accept-encoding\"\n value: \"gzip, deflate, br\"\n }\n headers {\n key: \"accept-language\"\n value: \"en-US,ja;q=0.8,en-GB;q=0.5,en;q=0.3\"\n }\n headers {\n key: \"host\"\n value: \"localhost:5001\"\n }\n headers {\n key: \"user-agent\"\n value: \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041\"\n }\n headers {\n key: \"upgrade-insecure-requests\"\n value: \"1\"\n }\n query {\n key: \"name\"\n value: \"ushio\"\n }\n identities {\n name_claim_type {\n value: \"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\"\n }\n role_claim_type {\n value: \"http://schemas.microsoft.com/ws/2008/06/identity/claims/role\"\n }\n }\n}\n";
|
||||
String reqName = "req";
|
||||
String nameValue = "string: \"John\"\n";
|
||||
String queryValue = "json: \"{\"name\":\"ushio\"}\"";
|
||||
String headersValue = "json: \"{\"Cache-Control\":\"max-age=0\",\"Connection\":\"Keep-Alive\",\"Accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\"Accept-Encoding\":\"gzip, deflate, br\",\"Accept-Language\":\"en-US,ja;q=0.8,en-GB;q=0.5,en;q=0.3\",\"Host\":\"localhost:5001\",\"User-Agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041\",\"Upgrade-Insecure-Requests\":\"1\"}\"";
|
||||
String sysValue = "json: \"{\"MethodName\":\"HttpExample\",\"UtcNow\":\"2020-04-30T15:26:57.281277Z\",\"RandGuid\":\"cd332c4a-df9e-415a-acd4-973994072e46\"}\"";
|
||||
|
||||
|
||||
when(bindingData.hasHttp()).thenReturn(true);
|
||||
when(bindingData.getString()).thenReturn(expectedData);
|
||||
when(binding.getName()).thenReturn(expectedName);
|
||||
when(bindingData.getString()).thenReturn(reqValue);
|
||||
when(binding.getName()).thenReturn(reqName);
|
||||
when(binding.getData()).thenReturn(bindingData);
|
||||
when(request.getInputDataList()).thenReturn(Arrays.asList(binding));
|
||||
|
||||
lenient().when(name.getString()).thenReturn("string: \"John\"\n");
|
||||
lenient().when(query.getString()).thenReturn("json: \"{\"name\":\"ushio\"}\"");
|
||||
lenient().when(headers.getString()).thenReturn("json: \"{\"Cache-Control\":\"max-age=0\",\"Connection\":\"Keep-Alive\",\"Accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\"Accept-Encoding\":\"gzip, deflate, br\",\"Accept-Language\":\"en-US,ja;q=0.8,en-GB;q=0.5,en;q=0.3\",\"Host\":\"localhost:5001\",\"User-Agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041\",\"Upgrade-Insecure-Requests\":\"1\"}\"");
|
||||
lenient().when(sys.getString()).thenReturn("json: \"{\"MethodName\":\"HttpExample\",\"UtcNow\":\"2020-04-30T15:26:57.281277Z\",\"RandGuid\":\"cd332c4a-df9e-415a-acd4-973994072e46\"}\"");
|
||||
when(name.getString()).thenReturn(nameValue);
|
||||
when(query.getString()).thenReturn(queryValue);
|
||||
when(headers.getString()).thenReturn(headersValue);
|
||||
when(sys.getString()).thenReturn(sysValue);
|
||||
|
||||
Map<String,TypedData> triggerMetadata = new HashMap<String, TypedData>();
|
||||
triggerMetadata.put("name", name);
|
||||
|
@ -59,31 +62,40 @@ public class JavaFunctionBrokerTest {
|
|||
|
||||
JavaFunctionBroker broker = new JavaFunctionBroker(new DefaultClassLoaderProvider());
|
||||
Map<String, TypedData> actualTriggerMetadata = broker.getTriggerMetadataMap(request);
|
||||
TypedData actual = actualTriggerMetadata.get("$request");
|
||||
assertEquals(actual.getString(), expectedData);
|
||||
TypedData actual2 = actualTriggerMetadata.get(expectedName);
|
||||
assertEquals(actual2.getString(), expectedData);
|
||||
assertEquals(reqValue, actualTriggerMetadata.get("$request").getString());
|
||||
assertEquals(reqValue, actualTriggerMetadata.get(reqName).getString());
|
||||
assertEquals(nameValue, actualTriggerMetadata.get("name").getString());
|
||||
assertEquals(queryValue, actualTriggerMetadata.get("Query").getString());
|
||||
assertEquals(headersValue, actualTriggerMetadata.get("Headers").getString());
|
||||
assertEquals(sysValue, actualTriggerMetadata.get("sys").getString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTriggerMetadataMap_ignored() throws Exception {
|
||||
String data = "string: \"hello queue\"\n";
|
||||
String name = "msg";
|
||||
String msgValue = "string: \"hello queue\"\n";
|
||||
String msgName = "msg";
|
||||
String queueTriggerValue = "string: \"hello queue\"\n";
|
||||
String dequeueCountValue = "json: \"1\"\n";
|
||||
String expirationTimeValue = "json: \"\"2020-05-08T17:47:22+00:00\"\n";
|
||||
String idValue = "string: \"e4f4a332-df80-41a1-8ecd-c2f7fba91f28\"\n";
|
||||
String insertionTimeValue = "json: \"\"2020-05-01T17:47:22+00:00\"\n";
|
||||
String nextVisibleTimeValue = "json: \"\"2020-05-01T17:57:22+00:00\"\n";
|
||||
String popReceiptValue = "string: \"oJCJGfnt1wgBAAAA\"\n";
|
||||
String sysValue = "json: \"{\"MethodName\":\"QueueProcessor\",\"UtcNow\":\"2020-05-01T17:47:29.2664174Z\",\"RandGuid\":\"7f67ac1c-b7b0-43f5-a51a-73af321d7d9f\"}\n";
|
||||
|
||||
|
||||
when(bindingData.hasHttp()).thenReturn(false);
|
||||
lenient().when(bindingData.getString()).thenReturn(data);
|
||||
lenient().when(binding.getName()).thenReturn(name);
|
||||
when(binding.getData()).thenReturn(bindingData);
|
||||
when(request.getInputDataList()).thenReturn(Arrays.asList(binding));
|
||||
|
||||
lenient().when(queueTrigger.getString()).thenReturn("string: \"hello queue\"\n");
|
||||
lenient().when(dequeueCount.getString()).thenReturn("json: \"1\"\n");
|
||||
lenient().when(expirationTime.getString()).thenReturn("json: \"\"2020-05-08T17:47:22+00:00\"\n");
|
||||
lenient().when(id.getString()).thenReturn("string: \"e4f4a332-df80-41a1-8ecd-c2f7fba91f28\"\n");
|
||||
lenient().when(insertionTime.getString()).thenReturn("json: \"\"2020-05-01T17:47:22+00:00\"\n");
|
||||
lenient().when(nextVisibleTime.getString()).thenReturn("json: \"\"2020-05-01T17:57:22+00:00\"\n");
|
||||
lenient().when(popReceipt.getString()).thenReturn("string: \"oJCJGfnt1wgBAAAA\"\n");
|
||||
lenient().when(sys.getString()).thenReturn( "json: \"{\"MethodName\":\"QueueProcessor\",\"UtcNow\":\"2020-05-01T17:47:29.2664174Z\",\"RandGuid\":\"7f67ac1c-b7b0-43f5-a51a-73af321d7d9f\"}\n");
|
||||
when(queueTrigger.getString()).thenReturn(queueTriggerValue);
|
||||
when(dequeueCount.getString()).thenReturn(dequeueCountValue);
|
||||
when(expirationTime.getString()).thenReturn(expirationTimeValue);
|
||||
when(id.getString()).thenReturn(idValue);
|
||||
when(insertionTime.getString()).thenReturn(insertionTimeValue);
|
||||
when(nextVisibleTime.getString()).thenReturn(nextVisibleTimeValue);
|
||||
when(popReceipt.getString()).thenReturn(popReceiptValue);
|
||||
when(sys.getString()).thenReturn(sysValue);
|
||||
|
||||
Map<String,TypedData> triggerMetadata = new HashMap<String, TypedData>();
|
||||
triggerMetadata.put("QueueTrigger", queueTrigger);
|
||||
|
@ -101,5 +113,14 @@ public class JavaFunctionBrokerTest {
|
|||
Map<String, TypedData> actualTriggerMetadata = broker.getTriggerMetadataMap(request);
|
||||
// In case of non-http request, it will not modify the triggerMetadata
|
||||
assertEquals(expectedCount, actualTriggerMetadata.size());
|
||||
assertNull(actualTriggerMetadata.get(msgName));
|
||||
assertEquals(queueTriggerValue, actualTriggerMetadata.get("QueueTrigger").getString());
|
||||
assertEquals(dequeueCountValue, actualTriggerMetadata.get("DequeueCount").getString());
|
||||
assertEquals(expirationTimeValue, actualTriggerMetadata.get("ExpirationTime").getString());
|
||||
assertEquals(idValue, actualTriggerMetadata.get("Id").getString());
|
||||
assertEquals(insertionTimeValue, actualTriggerMetadata.get("InsertionTime").getString());
|
||||
assertEquals(nextVisibleTimeValue, actualTriggerMetadata.get("NextVisibleTime").getString());
|
||||
assertEquals(popReceiptValue, actualTriggerMetadata.get("PopReceipt").getString());
|
||||
assertEquals(sysValue, actualTriggerMetadata.get("sys").getString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
package com.microsoft.azure.functions.worker.broker.tests;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.microsoft.azure.functions.*;
|
||||
import com.microsoft.azure.functions.annotation.*;
|
||||
import com.microsoft.azure.functions.worker.binding.tests.RpcHttpRequestDataSourceTests;
|
||||
import com.microsoft.azure.functions.worker.broker.CoreTypeResolver;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.microsoft.azure.functions.worker.broker.CoreTypeResolver.getRuntimeClass;
|
||||
import static com.microsoft.azure.functions.worker.broker.CoreTypeResolver.isValidOutputType;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CoreTypeResolverTests {
|
||||
public class CoreTypeResolverTest {
|
||||
|
||||
public void CustomBinding_Valid(
|
||||
@HttpTrigger(name = "req", methods = { HttpMethod.GET,
|
||||
|
@ -125,7 +123,7 @@ public class CoreTypeResolverTests {
|
|||
}
|
||||
|
||||
private Type returnTypeOf(String type) throws NoSuchMethodException {
|
||||
Method m = CoreTypeResolverTests.class.getDeclaredMethod(type);
|
||||
Method m = CoreTypeResolverTest.class.getDeclaredMethod(type);
|
||||
m.setAccessible(true);
|
||||
return m.getGenericReturnType();
|
||||
}
|
||||
|
@ -153,8 +151,8 @@ public class CoreTypeResolverTests {
|
|||
}
|
||||
|
||||
private Method getFunctionMethod(String methodName) {
|
||||
CoreTypeResolverTests coreTypeResolverTests = new CoreTypeResolverTests();
|
||||
Class<? extends CoreTypeResolverTests> testsClass = coreTypeResolverTests.getClass();
|
||||
CoreTypeResolverTest coreTypeResolverTest = new CoreTypeResolverTest();
|
||||
Class<? extends CoreTypeResolverTest> testsClass = coreTypeResolverTest.getClass();
|
||||
Method[] methods = testsClass.getMethods();
|
||||
Method functionMethod = null;
|
||||
for (Method method : methods) {
|
|
@ -0,0 +1,75 @@
|
|||
package com.microsoft.azure.functions.worker.broker.tests;
|
||||
|
||||
import java.util.*;
|
||||
import com.microsoft.azure.functions.rpc.messages.*;
|
||||
import com.microsoft.azure.functions.worker.broker.*;
|
||||
import com.microsoft.azure.functions.worker.description.*;
|
||||
import com.microsoft.azure.functions.worker.reflect.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class FunctionDefinitionTest {
|
||||
|
||||
@Test
|
||||
public void functionMethodLoadSucceeds_8() throws Exception {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
assertNotNull(functionDefinition.getCandidate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionMethod_doesnotexist_LoadFails_8() throws Exception {
|
||||
assertThrows(NoSuchMethodException.class, () -> {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger1","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger1","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionMethod_DuplicateAnnotations_LoadFails_8() throws Exception {
|
||||
assertThrows(UnsupportedOperationException.class, () -> {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTriggerOverload","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTriggerOverload","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionMethodLoadSucceeds_11() throws Exception {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
System.setProperty("java.specification.version", "11");
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
assertNotNull(functionDefinition.getCandidate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionMethod_doesnotexist_LoadFails_11() throws Exception {
|
||||
assertThrows(NoSuchMethodException.class, () -> {
|
||||
System.setProperty("java.specification.version", "11");
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger1","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger1","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionMethod_DuplicateAnnotations_LoadFails_11() throws Exception {
|
||||
assertThrows(UnsupportedOperationException.class, () -> {
|
||||
System.setProperty("java.specification.version", "11");
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTriggerOverload","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTriggerOverload","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package com.microsoft.azure.functions.worker.broker.tests;
|
||||
|
||||
import org.junit.*;
|
||||
import java.util.*;
|
||||
import com.microsoft.azure.functions.rpc.messages.*;
|
||||
import com.microsoft.azure.functions.worker.broker.*;
|
||||
import com.microsoft.azure.functions.worker.description.*;
|
||||
import com.microsoft.azure.functions.worker.reflect.*;
|
||||
import static junit.framework.TestCase.*;
|
||||
|
||||
|
||||
public class FunctionDefinitionTests {
|
||||
|
||||
@Test
|
||||
public void functionMethodLoadSucceeds_8() throws Exception {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
assertNotNull(functionDefinition.getCandidate());
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchMethodException.class)
|
||||
public void functionMethod_doesnotexist_LoadFails_8() throws Exception {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger1","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger1","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void functionMethod_DuplicateAnnotations_LoadFails_8() throws Exception {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTriggerOverload","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTriggerOverload","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionMethodLoadSucceeds_11() throws Exception {
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
System.setProperty("java.specification.version", "11");
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
assertNotNull(functionDefinition.getCandidate());
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchMethodException.class)
|
||||
public void functionMethod_doesnotexist_LoadFails_11() throws Exception {
|
||||
System.setProperty("java.specification.version", "11");
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTrigger1","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTrigger1","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void functionMethod_DuplicateAnnotations_LoadFails_11() throws Exception {
|
||||
System.setProperty("java.specification.version", "11");
|
||||
FunctionMethodDescriptor descriptor = new FunctionMethodDescriptor("testid", "TestHttpTriggerOverload","com.microsoft.azure.functions.worker.broker.tests.TestFunctionsClass.TestHttpTriggerOverload","TestFunctionsClass.jar");
|
||||
Map<String, BindingInfo> bindings = new HashMap<>();
|
||||
bindings.put("$return", BindingInfo.newBuilder().setDirection(BindingInfo.Direction.out).build());
|
||||
FunctionDefinition functionDefinition = new FunctionDefinition(descriptor, bindings, new FactoryClassLoader().createClassLoaderProvider());
|
||||
}
|
||||
}
|
|
@ -2,31 +2,21 @@ package com.microsoft.azure.functions.worker.functional.tests;
|
|||
|
||||
import com.microsoft.azure.functions.rpc.messages.*;
|
||||
import com.microsoft.azure.functions.worker.test.utilities.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class SimpleParamReturnTest extends FunctionsTestBase {
|
||||
|
||||
@Parameters
|
||||
public static Object[] data() {
|
||||
return new Object[] { "test String" };
|
||||
}
|
||||
|
||||
@Parameter
|
||||
public String stringInput;
|
||||
private static String stringReturnValue;
|
||||
|
||||
public String ReturnStringFunction() {
|
||||
return stringReturnValue;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringData() throws Exception {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"test String"})
|
||||
public void testStringData(String stringInput) throws Exception {
|
||||
stringReturnValue = stringInput;
|
||||
System.setProperty("azure.functions.worker.java.skip.testing", "true");
|
||||
try (FunctionsTestHost host = new FunctionsTestHost()) {
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
package com.microsoft.azure.functions.worker.handler.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.microsoft.azure.functions.worker.broker.JavaFunctionBroker;
|
||||
import com.microsoft.azure.functions.worker.handler.FunctionEnvironmentReloadRequestHandler;
|
||||
import com.microsoft.azure.functions.worker.reflect.DefaultClassLoaderProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FunctionEnvironmentReloadRequestHandlerTests {
|
||||
public class FunctionEnvironmentReloadRequestHandlerTest {
|
||||
|
||||
@Test
|
||||
public void SetEnv_Succeeds() throws Exception {
|
||||
|
@ -30,7 +27,7 @@ public class FunctionEnvironmentReloadRequestHandlerTests {
|
|||
envHandler.setEnv(newEnvVariables);
|
||||
testSetting = System.getenv("testSetting");
|
||||
assertNotNull(testSetting);
|
||||
assertEquals(testSetting, "testSettingValue");
|
||||
assertEquals( "testSettingValue", testSetting);
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,45 +0,0 @@
|
|||
package com.microsoft.azure.functions.worker.reflect.tests;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.*;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import com.microsoft.azure.functions.worker.reflect.DefaultClassLoaderProvider;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class DefaultClassLoaderProviderTests {
|
||||
|
||||
@Parameters
|
||||
public static Object[] data() {
|
||||
return new Object[] { "nospace.txt", "with space.txt" };
|
||||
}
|
||||
|
||||
@Parameter
|
||||
public String filePath;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder testFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void isUrlPointingToAFile_Returns_True() throws IOException {
|
||||
File createdFile = testFolder.newFile(filePath);
|
||||
boolean fileExists = DefaultClassLoaderProvider.isUrlPointingToAFile(createdFile.toURI().toURL());
|
||||
assertTrue(fileExists);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUrlPointingToAFile_False() throws IOException {
|
||||
String dummyFile = "filedoesnotexist.txt";
|
||||
URL jarUrl = new File(dummyFile).toURI().toURL();
|
||||
boolean fileExists = DefaultClassLoaderProvider.isUrlPointingToAFile(jarUrl);
|
||||
assertFalse(fileExists);
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
package com.microsoft.azure.functions.worker.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import com.microsoft.azure.functions.TraceContext;
|
||||
import com.microsoft.azure.functions.worker.binding.ExecutionTraceContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExecutionTraceContextTests {
|
||||
public class ExecutionTraceContextTest {
|
||||
|
||||
@Test
|
||||
public void TraceContext_test_getAndset_nonEmpty() {
|
Загрузка…
Ссылка в новой задаче