Search in sources :

Example 1 with com.tvd12.ezyfoxserver.socket

use of com.tvd12.ezyfoxserver.socket in project calabash by youngmonkeys.

the class ServerCoreBaseTest method newBeanContext.

protected EzyBeanContext newBeanContext() {
    MongoClient mongoClient = newMongoClient();
    EzyBeanContextBuilder builder = EzyBeanContext.builder().addSingleton("mongoClient", mongoClient).scan("com.tvd12.calabash.local.test.mappersist");
    addAutoImplMongoRepo(builder, mongoClient);
    return builder.build();
}
Also used : MongoClient(com.mongodb.MongoClient) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder)

Example 2 with com.tvd12.ezyfoxserver.socket

use of com.tvd12.ezyfoxserver.socket in project ezyfox-server by youngmonkeys.

the class EzySettingsReaderTest method test.

@Test
public void test() throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance("com.tvd12.ezyfoxserver", getClass().getClassLoader());
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    EzySimpleSettings settings = jaxbUnmarshaller.unmarshal(new StreamSource(inputStream()), EzySimpleSettings.class).getValue();
    System.out.println(settings);
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.testng.annotations.Test)

Example 3 with com.tvd12.ezyfoxserver.socket

use of com.tvd12.ezyfoxserver.socket in project ezyfox-server by youngmonkeys.

the class EzyHandShakeControllerTest method handleSocketSSLButSessionKeyNotNullTest.

@Test
public void handleSocketSSLButSessionKeyNotNullTest() {
    // given
    EzyHandshakeController sut = new EzyHandshakeController();
    byte[] sessionKey = RandomUtil.randomShortAlphabetString().getBytes();
    byte[] encryptedSessionKey = RandomUtil.randomShortAlphabetString().getBytes();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    doAnswer(it -> {
        EzyHandshakeEvent event = it.getArgumentAt(1, EzyHandshakeEvent.class);
        event.setSessionKey(sessionKey);
        event.setEncryptedSessionKey(encryptedSessionKey);
        return null;
    }).when(serverContext).handleEvent(any(EzyEventType.class), any(EzyHandshakeEvent.class));
    EzyHandShakeRequest request = mock(EzyHandShakeRequest.class);
    EzyHandshakeParams params = mock(EzyHandshakeParams.class);
    when(request.getParams()).thenReturn(params);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    when(request.getSession()).thenReturn(session);
    EzyServer server = mock(EzyServer.class);
    EzySettings settings = mock(EzySettings.class);
    EzySocketSetting socketSetting = mock(EzySocketSetting.class);
    when(settings.getSocket()).thenReturn(socketSetting);
    when(socketSetting.isSslActive()).thenReturn(true);
    when(serverContext.getServer()).thenReturn(server);
    when(server.getSettings()).thenReturn(settings);
    String clientId = RandomUtil.randomShortHexString();
    String clientType = RandomUtil.randomShortAlphabetString();
    String clientVersion = RandomUtil.randomShortAlphabetString();
    String reconnectToken = RandomUtil.randomShortHexString();
    KeyPair keyPair = EzyKeysGenerator.builder().build().generate();
    byte[] clientKey = keyPair.getPublic().getEncoded();
    when(params.getClientId()).thenReturn(clientId);
    when(params.getClientKey()).thenReturn(clientKey);
    when(params.getClientType()).thenReturn(clientType);
    when(params.getClientVersion()).thenReturn(clientVersion);
    when(params.getReconnectToken()).thenReturn(reconnectToken);
    when(params.isEnableEncryption()).thenReturn(true);
    // when
    sut.handle(serverContext, request);
    // then
    verify(serverContext, times(1)).handleEvent(any(EzyEventType.class), any(EzyHandshakeEvent.class));
    verify(serverContext, times(1)).send(any(com.tvd12.ezyfoxserver.response.EzyResponse.class), any(EzySession.class), any(boolean.class));
    verify(session, times(1)).setClientId(clientId);
    verify(session, times(1)).setClientKey(clientKey);
    verify(session, times(1)).setClientType(clientType);
    verify(session, times(1)).setClientVersion(clientVersion);
    verify(session, times(1)).setSessionKey(sessionKey);
}
Also used : EzyHandshakeEvent(com.tvd12.ezyfoxserver.event.EzyHandshakeEvent) KeyPair(java.security.KeyPair) EzySocketSetting(com.tvd12.ezyfoxserver.setting.EzySocketSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyHandShakeRequest(com.tvd12.ezyfoxserver.request.EzyHandShakeRequest) EzyHandshakeParams(com.tvd12.ezyfoxserver.request.EzyHandshakeParams) EzyEventType(com.tvd12.ezyfoxserver.constant.EzyEventType) EzyHandshakeController(com.tvd12.ezyfoxserver.controller.EzyHandshakeController) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) Test(org.testng.annotations.Test)

Example 4 with com.tvd12.ezyfoxserver.socket

use of com.tvd12.ezyfoxserver.socket in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntryTest method scanPackages.

@Test
public void scanPackages() {
    // given
    EzyAppContext appContext = mock(EzyAppContext.class);
    ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyApplication application = mock(EzyApplication.class);
    EzyAppUserManager appUserManager = mock(EzyAppUserManager.class);
    EzyAppSetup appSetup = mock(EzyAppSetup.class);
    EzyAppSetting appSetting = mock(EzyAppSetting.class);
    when(application.getSetting()).thenReturn(appSetting);
    InternalAppEntry sut = new InternalAppEntry();
    // when
    when(appContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
    when(appContext.getParent()).thenReturn(zoneContext);
    when(zoneContext.getParent()).thenReturn(serverContext);
    when(appContext.getApp()).thenReturn(application);
    when(application.getUserManager()).thenReturn(appUserManager);
    when(appContext.get(EzyAppSetup.class)).thenReturn(appSetup);
    sut.config(appContext);
    // then
    EzyBeanContext beanContext = sut.beanContext;
    MongoConfig mongoConfig = (MongoConfig) beanContext.getBean(MongoConfig.class);
    Set<String> expectedPackages = Sets.newHashSet(EzySupportConstants.DEFAULT_PACKAGE_TO_SCAN, "com.tvd12.ezyfoxserver.support.v120.test.entry");
    Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);
    Singleton singleton = (Singleton) beanContext.getBean(Singleton.class);
    Asserts.assertNotNull(singleton);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyAppSetup(com.tvd12.ezyfoxserver.command.EzyAppSetup) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzySingleton(com.tvd12.ezyfox.bean.annotation.EzySingleton) Test(org.testng.annotations.Test)

Example 5 with com.tvd12.ezyfoxserver.socket

use of com.tvd12.ezyfoxserver.socket in project ezyfox-server by youngmonkeys.

the class EzySimpleXmlReaderTest method test2.

@Test(expectedExceptions = { IllegalArgumentException.class })
public void test2() {
    EzyXmlReader reader = EzySimpleXmlMapper.builder().contextPath("com.tvd12.ezyfoxserver.mapping").classLoader(getClass().getClassLoader()).build();
    reader.read(new File("pom.xml"), ClassB.class);
}
Also used : EzyXmlReader(com.tvd12.ezyfox.mapping.jaxb.EzyXmlReader) File(java.io.File) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)9 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)8 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)3 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)3 MongoClient (com.mongodb.MongoClient)2 EzySingleton (com.tvd12.ezyfox.bean.annotation.EzySingleton)2 EzyBindingContext (com.tvd12.ezyfox.binding.EzyBindingContext)2 EzyXmlReader (com.tvd12.ezyfox.mapping.jaxb.EzyXmlReader)2 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)2 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)2 ApplicationContext (com.tvd12.ezyhttp.server.core.ApplicationContext)2 ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)2 ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HomeController (com.tvd12.example.reactive.HomeController)1 RxHomeController (com.tvd12.example.reactive.RxHomeController)1 HomeData (com.tvd12.example.reactive.data.HomeData)1 BookService (com.tvd12.example.spring_core.service.BookService)1