Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public abstract class AbstractContextRefreshedEventListener<T, A extends Annotat

private ApplicationContext context;

private final Boolean isDiscoveryLocalMode;

/**
* multiple namespace support.
*/
Expand Down Expand Up @@ -139,7 +137,6 @@ public AbstractContextRefreshedEventListener(final ShenyuClientConfig clientConf
this.ipAndPort = props.getProperty(ShenyuClientConstants.IP_PORT);
this.host = props.getProperty(ShenyuClientConstants.HOST);
this.port = props.getProperty(ShenyuClientConstants.PORT);
this.isDiscoveryLocalMode = Boolean.valueOf(props.getProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY));
publisher.start(shenyuClientRegisterRepository);
}

Expand All @@ -153,6 +150,9 @@ public void onApplicationEvent(@NonNull final ContextRefreshedEvent event) {
if (!registered.compareAndSet(false, true)) {
return;
}
String discoveryMode = context.getEnvironment()
.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE);
boolean isDiscoveryLocalMode = ShenyuClientConstants.DISCOVERY_LOCAL_MODE.equals(discoveryMode);
if (isDiscoveryLocalMode) {
List<String> namespaceIds = this.getNamespace();
namespaceIds.forEach(namespaceId -> publisher.publishEvent(buildURIRegisterDTO(context, beans, namespaceId)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private void init() {
results.put("springMvcClientTestBean3", springMvcClientTestBean3);
results.put("springMvcClientTestBean4", springMvcClientTestBean4);
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
when(applicationContext.getEnvironment()).thenReturn(env);
when(env.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local");
contextRefreshedEvent = new ContextRefreshedEvent(applicationContext);
ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class);
Assert.assertThrows(ShenyuClientIllegalArgumentException.class, () -> new SpringMvcClientEventListener(shenyuClientConfig, mock(ShenyuClientRegisterRepository.class), env));
Expand Down Expand Up @@ -182,12 +184,12 @@ public void testOnBuildApiSuperPath() {
SpringMvcClientEventListener springMvcClientEventListener = buildSpringMvcClientEventListener(false, false);

Assertions.assertEquals("/order", springMvcClientEventListener.buildApiSuperPath(
SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path");
SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path");

when(env.getProperty("spring.mvc.servlet.path")).thenReturn("/servlet-path");
when(env.getProperty("server.servlet.context-path")).thenReturn("/servlet-context-path");
Assertions.assertEquals("/servlet-context-path/servlet-path/order", springMvcClientEventListener.buildApiSuperPath(
SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path");
SpringMvcClientTestBean.class, AnnotatedElementUtils.findMergedAnnotation(SpringMvcClientTestBean.class, ShenyuSpringMvcClient.class)), "super-path");
registerUtilsMockedStatic.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shenyu.client.tars;

import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
import org.apache.shenyu.client.core.enums.RpcTypeEnum;
import org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
import org.apache.shenyu.client.core.register.ShenyuClientRegisterRepository;
Expand All @@ -38,6 +39,7 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.Environment;

import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -68,6 +70,9 @@ public final class TarsServiceBeanPostProcessorTest {
@Mock
private ApplicationContext applicationContext;

@Mock
private Environment env;

private ContextRefreshedEvent contextRefreshedEvent;

@BeforeEach
Expand All @@ -77,6 +82,8 @@ public void init() {
results.put("tarsDemoService2", tarsDemoService2);
results.put("tarsDemoService3", tarsDemoService3);
when(applicationContext.getBeansWithAnnotation(any())).thenReturn(results);
when(applicationContext.getEnvironment()).thenReturn(env);
when(env.getProperty("shenyu.discovery.type", ShenyuClientConstants.DISCOVERY_LOCAL_MODE)).thenReturn("local");
contextRefreshedEvent = new ContextRefreshedEvent(applicationContext);

ShenyuClientConfig shenyuClientConfig = mock(ShenyuClientConfig.class);
Expand Down
Loading