mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
以2.2.1.BUILD-SNAPSHOT 为基准,适配Greenwich版本的Spring Cloud
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.autoconfigure;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* {@link DubboServiceRegistrationAutoConfiguration} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class DubboServiceRegistrationAutoConfigurationTest {
|
||||
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@link AbstractHttpRequestMatcher} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public abstract class AbstractHttpRequestMatcherTest<T extends AbstractHttpRequestMatcher> {
|
||||
|
||||
@Test
|
||||
public abstract void testEqualsAndHashCode();
|
||||
|
||||
@Test
|
||||
public abstract void testGetContent();
|
||||
|
||||
@Test
|
||||
public abstract void testGetToStringInfix();
|
||||
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* {@link AbstractMediaTypeExpression} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public abstract class AbstractMediaTypeExpressionTest<T extends AbstractMediaTypeExpression> {
|
||||
|
||||
protected T createExpression(String expression) {
|
||||
ResolvableType resolvableType = ResolvableType
|
||||
.forType(getClass().getGenericSuperclass());
|
||||
Class<T> firstGenericType = (Class<T>) resolvableType.resolveGeneric(0);
|
||||
Constructor<T> constructor = null;
|
||||
try {
|
||||
constructor = firstGenericType.getDeclaredConstructor(String.class);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return BeanUtils.instantiateClass(constructor, expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMediaTypeAndNegated() {
|
||||
// Normal
|
||||
AbstractMediaTypeExpression expression = createExpression(
|
||||
MediaType.APPLICATION_JSON_VALUE);
|
||||
Assert.assertEquals(MediaType.APPLICATION_JSON, expression.getMediaType());
|
||||
Assert.assertFalse(expression.isNegated());
|
||||
|
||||
// Negated
|
||||
expression = createExpression("!" + MediaType.APPLICATION_JSON_VALUE);
|
||||
Assert.assertEquals(MediaType.APPLICATION_JSON, expression.getMediaType());
|
||||
Assert.assertTrue(expression.isNegated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
Assert.assertEquals(createExpression(MediaType.APPLICATION_JSON_VALUE),
|
||||
createExpression(MediaType.APPLICATION_JSON_VALUE));
|
||||
Assert.assertEquals(createExpression(MediaType.APPLICATION_JSON_VALUE).hashCode(),
|
||||
createExpression(MediaType.APPLICATION_JSON_VALUE).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTo() {
|
||||
Assert.assertEquals(0, createExpression(MediaType.APPLICATION_JSON_VALUE)
|
||||
.compareTo(createExpression(MediaType.APPLICATION_JSON_VALUE)));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
/**
|
||||
* {@link AbstractNameValueExpression} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public abstract class AbstractNameValueExpressionTest<T extends AbstractNameValueExpression> {
|
||||
|
||||
protected T createExpression(String expression) {
|
||||
ResolvableType resolvableType = ResolvableType
|
||||
.forType(getClass().getGenericSuperclass());
|
||||
Class<T> firstGenericType = (Class<T>) resolvableType.resolveGeneric(0);
|
||||
Constructor<T> constructor = null;
|
||||
try {
|
||||
constructor = firstGenericType.getDeclaredConstructor(String.class);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return BeanUtils.instantiateClass(constructor, expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNameAndValue() {
|
||||
// Normal Name and value
|
||||
AbstractNameValueExpression expression = createExpression("a=1");
|
||||
Assert.assertEquals("a", expression.getName());
|
||||
Assert.assertFalse(expression.isNegated());
|
||||
|
||||
expression = createExpression("a=1");
|
||||
Assert.assertEquals("a", expression.getName());
|
||||
Assert.assertEquals("1", expression.getValue());
|
||||
Assert.assertFalse(expression.isNegated());
|
||||
|
||||
// Negated Name
|
||||
expression = createExpression("!a");
|
||||
Assert.assertEquals("a", expression.getName());
|
||||
Assert.assertTrue(expression.isNegated());
|
||||
|
||||
expression = createExpression("a!=1");
|
||||
Assert.assertEquals("a", expression.getName());
|
||||
Assert.assertEquals("1", expression.getValue());
|
||||
Assert.assertTrue(expression.isNegated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
Assert.assertEquals(createExpression("a"), createExpression("a"));
|
||||
Assert.assertEquals(createExpression("a").hashCode(),
|
||||
createExpression("a").hashCode());
|
||||
Assert.assertEquals(createExpression("a=1"), createExpression("a = 1 "));
|
||||
Assert.assertEquals(createExpression("a=1").hashCode(),
|
||||
createExpression("a = 1 ").hashCode());
|
||||
Assert.assertNotEquals(createExpression("a"), createExpression("b"));
|
||||
Assert.assertNotEquals(createExpression("a").hashCode(),
|
||||
createExpression("b").hashCode());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* {@link ConsumeMediaTypeExpression} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class ConsumeMediaTypeExpressionTest
|
||||
extends AbstractMediaTypeExpressionTest<ConsumeMediaTypeExpression> {
|
||||
|
||||
@Test
|
||||
public void testMatch() {
|
||||
ConsumeMediaTypeExpression expression = createExpression(MediaType.ALL_VALUE);
|
||||
|
||||
Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON));
|
||||
|
||||
expression = createExpression(MediaType.APPLICATION_JSON_VALUE);
|
||||
Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON));
|
||||
|
||||
expression = createExpression(MediaType.APPLICATION_JSON_VALUE + ";q=0.7");
|
||||
Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON));
|
||||
|
||||
expression = createExpression(MediaType.TEXT_HTML_VALUE);
|
||||
Assert.assertFalse(expression.match(MediaType.APPLICATION_JSON));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
|
||||
import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder;
|
||||
|
||||
/**
|
||||
* {@link HeaderExpression} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class HeaderExpressionTest
|
||||
extends AbstractNameValueExpressionTest<HeaderExpression> {
|
||||
|
||||
@Test
|
||||
public void testIsCaseSensitiveName() {
|
||||
Assert.assertFalse(createExpression("a=1").isCaseSensitiveName());
|
||||
Assert.assertFalse(createExpression("a=!1").isCaseSensitiveName());
|
||||
Assert.assertFalse(createExpression("b=1").isCaseSensitiveName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatch() {
|
||||
|
||||
HeaderExpression expression = createExpression("a=1");
|
||||
HttpRequest request = builder().build();
|
||||
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().header("a", "").build();
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().header("a", "2").build();
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().header("", "1").build();
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().header("a", "1").build();
|
||||
Assert.assertTrue(expression.match(request));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
/**
|
||||
* {@link HttpRequestMethodsMatcher} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class HttpRequestMethodsMatcherTest
|
||||
extends AbstractHttpRequestMatcherTest<HttpRequestMethodsMatcher> {
|
||||
|
||||
HttpRequestMethodsMatcher matcher = new HttpRequestMethodsMatcher("GET");
|
||||
|
||||
@Override
|
||||
public void testEqualsAndHashCode() {
|
||||
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpMethod.GET)),
|
||||
matcher.getMethods());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testGetContent() {
|
||||
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpMethod.GET)),
|
||||
matcher.getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testGetToStringInfix() {
|
||||
Assert.assertEquals(" || ", matcher.getToStringInfix());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
|
||||
/**
|
||||
* {@link HttpRequestParamsMatcher} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class HttpRequestParamsMatcherTest {
|
||||
|
||||
// @Test
|
||||
// public void testGetParams() {
|
||||
//
|
||||
// HttpRequestParamsMatcher matcher = new HttpRequestParamsMatcher(
|
||||
// "a ",
|
||||
// "a =1",
|
||||
// "b = 2",
|
||||
// "b = 3 ",
|
||||
// " c = 4 ",
|
||||
// " d"
|
||||
// );
|
||||
//
|
||||
// Map<String, List<String>> params = matcher.getParams();
|
||||
// Assert.assertEquals(4, params.size());
|
||||
// Assert.assertTrue(params.containsKey("a"));
|
||||
// Assert.assertTrue(params.containsKey("b"));
|
||||
// Assert.assertTrue(params.containsKey("c"));
|
||||
// Assert.assertTrue(params.containsKey("d"));
|
||||
// Assert.assertFalse(params.containsKey("e"));
|
||||
//
|
||||
// List<String> values = params.get("a");
|
||||
// Assert.assertEquals(2, values.size());
|
||||
// Assert.assertEquals("", values.get(0));
|
||||
// Assert.assertEquals("1", values.get(1));
|
||||
//
|
||||
// values = params.get("b");
|
||||
// Assert.assertEquals(2, values.size());
|
||||
// Assert.assertEquals("2", values.get(0));
|
||||
// Assert.assertEquals("3", values.get(1));
|
||||
//
|
||||
// values = params.get("c");
|
||||
// Assert.assertEquals(1, values.size());
|
||||
// Assert.assertEquals("4", values.get(0));
|
||||
//
|
||||
// values = params.get("d");
|
||||
// Assert.assertEquals(1, values.size());
|
||||
// Assert.assertEquals("", values.get(0));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
|
||||
HttpRequestParamsMatcher matcher = new HttpRequestParamsMatcher("a ", "a = 1");
|
||||
|
||||
MockClientHttpRequest request = new MockClientHttpRequest();
|
||||
|
||||
request.setURI(URI.create("http://dummy/?a"));
|
||||
Assert.assertTrue(matcher.match(request));
|
||||
request.setURI(URI.create("http://dummy/?a&a=1"));
|
||||
Assert.assertTrue(matcher.match(request));
|
||||
|
||||
matcher = new HttpRequestParamsMatcher("a ", "a =1", "b", "b=2");
|
||||
request.setURI(URI.create("http://dummy/?a&a=1&b"));
|
||||
Assert.assertTrue(matcher.match(request));
|
||||
request.setURI(URI.create("http://dummy/?a&a=1&b&b=2"));
|
||||
Assert.assertTrue(matcher.match(request));
|
||||
|
||||
matcher = new HttpRequestParamsMatcher("a ", "a =1", "b", "b=2", "b = 3 ");
|
||||
request.setURI(URI.create("http://dummy/?a&a=1&b&b=2&b=3"));
|
||||
Assert.assertTrue(matcher.match(request));
|
||||
|
||||
request.setURI(URI.create("http://dummy/?d=1"));
|
||||
Assert.assertFalse(matcher.match(request));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
|
||||
import static com.alibaba.cloud.dubbo.http.DefaultHttpRequest.builder;
|
||||
|
||||
/**
|
||||
* {@link ParamExpression} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class ParamExpressionTest
|
||||
extends AbstractNameValueExpressionTest<ParamExpression> {
|
||||
|
||||
@Test
|
||||
public void testIsCaseSensitiveName() {
|
||||
Assert.assertTrue(createExpression("a=1").isCaseSensitiveName());
|
||||
Assert.assertTrue(createExpression("a=!1").isCaseSensitiveName());
|
||||
Assert.assertTrue(createExpression("b=1").isCaseSensitiveName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatch() {
|
||||
|
||||
ParamExpression expression = createExpression("a=1");
|
||||
HttpRequest request = builder().build();
|
||||
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().param("a", "").build();
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().param("a", "2").build();
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().param("", "1").build();
|
||||
Assert.assertFalse(expression.match(request));
|
||||
|
||||
request = builder().param("a", "1").build();
|
||||
Assert.assertTrue(expression.match(request));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.matcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* {@link ProduceMediaTypeExpression} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class ProduceMediaTypeExpressionTest
|
||||
extends AbstractMediaTypeExpressionTest<ProduceMediaTypeExpression> {
|
||||
|
||||
@Test
|
||||
public void testMatch() {
|
||||
ProduceMediaTypeExpression expression = createExpression(
|
||||
MediaType.APPLICATION_JSON_VALUE);
|
||||
Assert.assertTrue(expression.match(
|
||||
Arrays.asList(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON)));
|
||||
|
||||
expression = createExpression(MediaType.APPLICATION_JSON_VALUE);
|
||||
Assert.assertFalse(expression.match(Arrays.asList(MediaType.APPLICATION_XML)));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.http.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@link HttpUtils} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class HttpUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testEncodeAndDecode() {
|
||||
|
||||
String whitespace = " ";
|
||||
|
||||
String encodedValue = HttpUtils.encode(" ");
|
||||
|
||||
String decodedValue = HttpUtils.decode(encodedValue);
|
||||
|
||||
Assert.assertEquals(whitespace, decodedValue);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.metadata;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* {@link RequestMetadata} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class RequestMetadataTest {
|
||||
|
||||
private String method = "GET";
|
||||
|
||||
private String url = "/param";
|
||||
|
||||
private Set<String> paramNames = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
|
||||
|
||||
private Set<String> headerNames = new LinkedHashSet<>(Arrays.asList("d", "e", "f"));
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCodeAndCompareTo() {
|
||||
|
||||
RequestMetadata metadata = new RequestMetadata();
|
||||
RequestMetadata metadata2 = new RequestMetadata();
|
||||
|
||||
Assert.assertEquals(metadata, metadata2);
|
||||
Assert.assertEquals(metadata.hashCode(), metadata2.hashCode());
|
||||
|
||||
metadata.setMethod(method);
|
||||
metadata2.setMethod(method);
|
||||
|
||||
Assert.assertEquals(metadata, metadata2);
|
||||
Assert.assertEquals(metadata.hashCode(), metadata2.hashCode());
|
||||
|
||||
metadata.setPath(url);
|
||||
metadata2.setPath(url);
|
||||
|
||||
Assert.assertEquals(metadata, metadata2);
|
||||
Assert.assertEquals(metadata.hashCode(), metadata2.hashCode());
|
||||
|
||||
metadata.addParam("a", "1").addParam("b", "2").addParam("c", "3");
|
||||
metadata2.addParam("a", "1a").addParam("b", "2b").addParam("c", "3c");
|
||||
|
||||
Assert.assertEquals(metadata, metadata2);
|
||||
Assert.assertEquals(metadata.hashCode(), metadata2.hashCode());
|
||||
|
||||
metadata.addHeader("d", "1").addHeader("e", "2").addHeader("f", "3");
|
||||
metadata2.addHeader("d", "1").addHeader("e", "2");
|
||||
|
||||
Assert.assertNotEquals(metadata, metadata2);
|
||||
Assert.assertNotEquals(metadata.hashCode(), metadata2.hashCode());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testBestMatch() {
|
||||
//
|
||||
// NavigableMap<RequestMetadata, RequestMetadata> requestMetadataMap = new
|
||||
// TreeMap<>();
|
||||
//
|
||||
// RequestMetadata metadata = new RequestMetadata();
|
||||
// metadata.setMethod(method);
|
||||
//
|
||||
// RequestMetadata metadata1 = new RequestMetadata();
|
||||
// metadata1.setMethod(method);
|
||||
// metadata1.setPath(url);
|
||||
//
|
||||
// RequestMetadata metadata2 = new RequestMetadata();
|
||||
// metadata2.setMethod(method);
|
||||
// metadata2.setPath(url);
|
||||
// metadata2.setParams(paramNames);
|
||||
//
|
||||
// RequestMetadata metadata3 = new RequestMetadata();
|
||||
// metadata3.setMethod(method);
|
||||
// metadata3.setPath(url);
|
||||
// metadata3.setParams(paramNames);
|
||||
// metadata3.setHeaders(headerNames);
|
||||
//
|
||||
// requestMetadataMap.put(metadata, metadata);
|
||||
// requestMetadataMap.put(metadata1, metadata1);
|
||||
// requestMetadataMap.put(metadata2, metadata2);
|
||||
// requestMetadataMap.put(metadata3, metadata3);
|
||||
//
|
||||
// RequestMetadata result = getBestMatch(requestMetadataMap, metadata);
|
||||
// Assert.assertEquals(result, metadata);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, metadata1);
|
||||
// Assert.assertEquals(result, metadata1);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, metadata2);
|
||||
// Assert.assertEquals(result, metadata2);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, metadata3);
|
||||
// Assert.assertEquals(result, metadata3);
|
||||
//
|
||||
// // REDO
|
||||
// requestMetadataMap.clear();
|
||||
//
|
||||
// requestMetadataMap.put(metadata1, metadata1);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, metadata2);
|
||||
// Assert.assertEquals(metadata1, result);
|
||||
//
|
||||
// requestMetadataMap.put(metadata2, metadata2);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, metadata3);
|
||||
// Assert.assertEquals(metadata2, result);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, new RequestMetadata());
|
||||
// Assert.assertNull(result);
|
||||
//
|
||||
// result = getBestMatch(requestMetadataMap, metadata);
|
||||
// Assert.assertNull(result);
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 com.alibaba.cloud.dubbo.metadata.resolver;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.cloud.dubbo.annotation.DubboTransported;
|
||||
import com.alibaba.cloud.dubbo.metadata.DubboTransportedMethodMetadata;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
/**
|
||||
* {@link DubboTransportedMethodMetadataResolver} Test.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class DubboTransportedMethodMetadataResolverTest {
|
||||
|
||||
private DubboTransportedMethodMetadataResolver resolver;
|
||||
|
||||
private MockEnvironment environment;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
environment = new MockEnvironment();
|
||||
resolver = new DubboTransportedMethodMetadataResolver(environment,
|
||||
new SpringMvcContract());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolve() {
|
||||
Set<DubboTransportedMethodMetadata> metadataSet = resolver
|
||||
.resolveDubboTransportedMethodMetadataSet(TestDefaultService.class);
|
||||
Assert.assertEquals(1, metadataSet.size());
|
||||
}
|
||||
|
||||
@DubboTransported
|
||||
interface TestDefaultService {
|
||||
|
||||
String test(String message);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
dubbo:
|
||||
scan:
|
||||
base-packages: com.alibaba.cloud.dubbo.service
|
||||
protocols:
|
||||
dubbo:
|
||||
name: dubbo
|
||||
port: 12345
|
||||
rest:
|
||||
name: rest
|
||||
port: 8081
|
||||
server: netty
|
||||
registry:
|
||||
address: spring-cloud://nacos
|
||||
|
||||
feign:
|
||||
hystrix:
|
||||
enabled: true
|
||||
|
||||
server:
|
||||
port: 8080
|
@@ -0,0 +1,47 @@
|
||||
spring:
|
||||
application:
|
||||
name: spring-cloud-alibaba-dubbo
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
config:
|
||||
server-addr: 127.0.0.1:8848
|
||||
zookeeper:
|
||||
enabled: false
|
||||
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
eureka:
|
||||
client:
|
||||
enabled: false
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: eureka
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
enabled: false
|
||||
register-enabled: false
|
||||
|
||||
eureka:
|
||||
client:
|
||||
enabled: true
|
||||
service-url:
|
||||
defaultZone: http://localhost:9090/eureka/
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: zookeeper
|
||||
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
enabled: false
|
||||
register-enabled: false
|
||||
|
||||
zookeeper:
|
||||
enabled: true
|
||||
connect-string: localhost:2181
|
Reference in New Issue
Block a user