Search in sources :

Example 1 with AuthDataSubscriber

use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.

the class ZookeeperSyncDataServiceTest method testWatchAppAuthWhenInit.

@Test
public void testWatchAppAuthWhenInit() {
    final List<AppAuthData> subscribeList = new ArrayList<>(1);
    AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {

        @Override
        public void onSubscribe(final AppAuthData appAuthData) {
            subscribeList.add(appAuthData);
        }

        @Override
        public void unSubscribe(final AppAuthData appAuthData) {
        }
    };
    syncDataService = new ZookeeperSyncDataService(zkClient, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
    assertThat(subscribeList.size(), is(1));
}
Also used : AuthDataSubscriber(org.apache.shenyu.sync.data.api.AuthDataSubscriber) AppAuthData(org.apache.shenyu.common.dto.AppAuthData) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with AuthDataSubscriber

use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.

the class ZookeeperSyncDataServiceTest method testWatchAppAuthWhenDataDeleted.

@Test
public void testWatchAppAuthWhenDataDeleted() throws Exception {
    final List<AppAuthData> unSubscribeList = new ArrayList<>(1);
    AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {

        @Override
        public void onSubscribe(final AppAuthData appAuthData) {
        }

        @Override
        public void unSubscribe(final AppAuthData appAuthData) {
            unSubscribeList.add(appAuthData);
        }
    };
    syncDataService = new ZookeeperSyncDataService(zkClient, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
    ArgumentCaptor<IZkDataListener> captor = ArgumentCaptor.forClass(IZkDataListener.class);
    verify(zkClient).subscribeDataChanges(eq(MOCK_APP_AUTH_PATH), captor.capture());
    captor.getValue().handleDataDeleted(MOCK_APP_AUTH_PATH);
    assertThat(unSubscribeList.size(), is(1));
    assertThat(unSubscribeList.get(0).getAppKey(), is(MOCK_APP_AUTH_KEY));
}
Also used : AuthDataSubscriber(org.apache.shenyu.sync.data.api.AuthDataSubscriber) AppAuthData(org.apache.shenyu.common.dto.AppAuthData) ArrayList(java.util.ArrayList) IZkDataListener(org.I0Itec.zkclient.IZkDataListener) Test(org.junit.jupiter.api.Test)

Example 3 with AuthDataSubscriber

use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.

the class NacosCacheHandlerTest method testUpdateAuthMap.

@Test
public void testUpdateAuthMap() throws NacosException {
    String mockAppKey = "MOCK_APP_KEY";
    String mockAppKey2 = "MOCK_APP_KEY2";
    String mockAppSecret = "MOCK_APP_SECRET";
    AppAuthData appAuthData = AppAuthData.builder().appKey(mockAppKey).appSecret(mockAppSecret).enabled(true).build();
    AppAuthData appAuthData2 = AppAuthData.builder().appKey(mockAppKey2).appSecret(mockAppSecret).enabled(true).build();
    changeAuthData(ImmutableList.of(appAuthData, appAuthData2));
    String appAuthDataParam = GsonUtils.getInstance().toJson(ImmutableMap.of(mockAppKey2, appAuthData2, mockAppKey, appAuthData));
    final CountDownLatch latch = new CountDownLatch(2);
    final List<AppAuthData> subscribeList = new ArrayList<>();
    final List<AppAuthData> unsubscribeList = new ArrayList<>();
    AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {

        @Override
        public void onSubscribe(final AppAuthData appAuthData) {
            subscribeList.add(appAuthData);
            latch.countDown();
        }

        @Override
        public void unSubscribe(final AppAuthData appAuthData) {
            unsubscribeList.add(appAuthData);
            latch.countDown();
        }
    };
    nacosCacheHandlerService = new NacosCacheHandler(configService, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
    nacosCacheHandlerService.updateAuthMap(appAuthDataParam);
    assertEquals(2, subscribeList.size());
    assertEquals(2, unsubscribeList.size());
    assertEquals(configService.getConfig(AUTH_DATA_ID, GROUP, 100), GsonUtils.getInstance().toJson(ImmutableMap.of(mockAppKey2, appAuthData2, mockAppKey, appAuthData)));
}
Also used : AuthDataSubscriber(org.apache.shenyu.sync.data.api.AuthDataSubscriber) AppAuthData(org.apache.shenyu.common.dto.AppAuthData) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 4 with AuthDataSubscriber

use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.

the class NacosCacheHandlerTest method testWatcherData.

@Test
public void testWatcherData() throws NacosException {
    String mockAppKey = "MOCK_APP_KEY";
    String mockAppKey2 = "MOCK_APP_KEY2";
    String mockAppSecret = "MOCK_APP_SECRET";
    AppAuthData appAuthData = AppAuthData.builder().appKey(mockAppKey).appSecret(mockAppSecret).enabled(true).build();
    AppAuthData appAuthData2 = AppAuthData.builder().appKey(mockAppKey2).appSecret(mockAppSecret).enabled(true).build();
    changeAuthData(ImmutableList.of(appAuthData, appAuthData2));
    final CountDownLatch latch = new CountDownLatch(2);
    AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {

        @Override
        public void onSubscribe(final AppAuthData appAuthData) {
            latch.countDown();
        }

        @Override
        public void unSubscribe(final AppAuthData appAuthData) {
            latch.countDown();
        }
    };
    nacosCacheHandlerService = new NacosCacheHandler(configService, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
    NacosCacheHandler.OnChange oc = nacosCacheHandlerService::updateAuthMap;
    nacosCacheHandlerService.watcherData(AUTH_DATA_ID, oc);
}
Also used : AuthDataSubscriber(org.apache.shenyu.sync.data.api.AuthDataSubscriber) AppAuthData(org.apache.shenyu.common.dto.AppAuthData) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 5 with AuthDataSubscriber

use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.

the class AppAuthDataRefreshTest method buildMockAppAuthDataRefresh.

private AppAuthDataRefresh buildMockAppAuthDataRefresh() {
    List<AuthDataSubscriber> authDataSubscribers = new ArrayList<>();
    authDataSubscribers.add(new AuthDataSubscriber() {

        @Override
        public void onSubscribe(final AppAuthData appAuthData) {
        }

        @Override
        public void unSubscribe(final AppAuthData appAuthData) {
        }
    });
    return new AppAuthDataRefresh(authDataSubscribers);
}
Also used : AuthDataSubscriber(org.apache.shenyu.sync.data.api.AuthDataSubscriber) AppAuthData(org.apache.shenyu.common.dto.AppAuthData) ArrayList(java.util.ArrayList)

Aggregations

AuthDataSubscriber (org.apache.shenyu.sync.data.api.AuthDataSubscriber)9 AppAuthData (org.apache.shenyu.common.dto.AppAuthData)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 CountDownLatch (java.util.concurrent.CountDownLatch)2 IZkDataListener (org.I0Itec.zkclient.IZkDataListener)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 ResponseTemplateTransformer (com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer)1 MetaDataSubscriber (org.apache.shenyu.sync.data.api.MetaDataSubscriber)1 PluginDataSubscriber (org.apache.shenyu.sync.data.api.PluginDataSubscriber)1 HttpConfig (org.apache.shenyu.sync.data.http.config.HttpConfig)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1