youngmonkeys / ezyfox-server

A socket server (include SSL) supports realtime application, realtime game, MMORPG, messaging, chat and streaming data with TCP, UDP and Websocket
Apache License 2.0
569 stars 98 forks source link

Lỗi không add packages to scan #68

Closed tvd12 closed 3 years ago

tvd12 commented 3 years ago

Nguyên nhân

Các file bị ảnh hưởng

  1. EzySimpleAppEntry
  2. EzySimplePluginEntry

Cách fix

package com.tvd12.ezyfoxserver.support.v120.test.entry;

import java.util.Set;

import org.testng.annotations.Test;

import com.tvd12.ezyfox.bean.EzyBeanContext;
import com.tvd12.ezyfox.bean.EzyPackagesToScanAware;
import com.tvd12.ezyfox.bean.annotation.EzySingleton;
import com.tvd12.ezyfox.collect.Sets;
import com.tvd12.ezyfoxserver.context.EzyAppContext;
import com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry;
import com.tvd12.test.assertion.Asserts;

import static org.mockito.Mockito.*;

import lombok.Setter;

public class EzySimpleAppEntryTest {

    @Test
    public void scanPacakges() {
        // given
        EzyAppContext appContext = mock(EzyAppContext.class);

        InternalAppEntry sut = new InternalAppEntry();

        // when
        sut.config(appContext);

        // then
        EzyBeanContext beanContext = sut.beanContext;
        MongoConfig mongoConfig = beanContext.getBeanCast(MongoConfig.class);

        Set<String> expectedPackages = Sets.newHashSet(
            "com.tvd12.ezyfoxserver.support.v120.test.entry"
        );
        Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);

        Singleton singleton = beanContext.getBeanCast(Singleton.class);
        Asserts.assertNotNull(singleton);
    }

    @EzySingleton
    public static class Singleton {
    }

    @Setter
    public static class MongoConfig implements EzyPackagesToScanAware {
        public Set<String> packagesToScan;
    }

    private static class InternalAppEntry extends EzySimpleAppEntry {

        public EzyBeanContext beanContext;

        @Override
        protected String[] getScanablePackages() {
            return new String[] {"com.tvd12.ezyfoxserver.support.v120.test.entry"};
        }

        @Override
        protected void postConfig(EzyAppContext context, EzyBeanContext beanContext) {
            this.beanContext = beanContext;
        }
    }

}

Quy trình