2015-07-06 18:35:31 +02:00
|
|
|
/*
|
2018-04-27 20:17:47 +02:00
|
|
|
* Copyright (c) 2012-2018 The original author or authors
|
2015-07-06 18:35:31 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
|
* and Apache License v2.0 which accompanies this distribution.
|
|
|
|
|
*
|
|
|
|
|
* The Eclipse Public License is available at
|
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
*
|
|
|
|
|
* The Apache License v2.0 is available at
|
|
|
|
|
* http://www.opensource.org/licenses/apache2.0.php
|
|
|
|
|
*
|
|
|
|
|
* You may elect to redistribute this code under either of these licenses.
|
|
|
|
|
*/
|
2017-02-01 16:10:44 +01:00
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.server;
|
2015-07-06 18:35:31 +02:00
|
|
|
|
2015-12-08 14:04:35 +01:00
|
|
|
import io.moquette.BrokerConstants;
|
2015-11-20 20:54:27 +01:00
|
|
|
import io.moquette.server.config.IConfig;
|
|
|
|
|
import io.moquette.server.config.MemoryConfig;
|
2017-02-14 17:23:04 +01:00
|
|
|
import io.moquette.spi.impl.subscriptions.Topic;
|
2017-03-25 16:05:45 +01:00
|
|
|
import io.moquette.persistence.MemoryMessagesStore;
|
|
|
|
|
import io.moquette.persistence.MemoryStorageService;
|
|
|
|
|
import io.moquette.persistence.MemorySessionStore;
|
2015-12-13 16:42:04 +01:00
|
|
|
import io.moquette.spi.security.IAuthenticator;
|
2018-08-12 15:50:22 +02:00
|
|
|
import io.moquette.spi.security.IAuthorizatorPolicy;
|
2015-07-06 18:35:31 +02:00
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
2018-08-12 15:50:22 +02:00
|
|
|
public class ConfigurationClassLoaderTest implements IAuthenticator, IAuthorizatorPolicy {
|
2017-02-01 16:10:44 +01:00
|
|
|
|
2015-07-06 18:35:31 +02:00
|
|
|
Server m_server;
|
2015-08-22 15:35:11 +02:00
|
|
|
IConfig m_config;
|
2017-02-01 16:10:44 +01:00
|
|
|
|
2015-07-06 18:35:31 +02:00
|
|
|
protected void startServer(Properties props) throws IOException {
|
2015-08-22 15:35:11 +02:00
|
|
|
m_server = new Server();
|
|
|
|
|
m_config = new MemoryConfig(props);
|
|
|
|
|
m_server.startServer(m_config);
|
2015-07-06 18:35:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
|
m_server.stopServer();
|
|
|
|
|
}
|
2017-02-01 16:10:44 +01:00
|
|
|
|
2015-07-06 18:35:31 +02:00
|
|
|
@Test
|
|
|
|
|
public void loadAuthenticator() throws Exception {
|
2016-05-18 00:09:40 +02:00
|
|
|
Properties props = new Properties(IntegrationUtils.prepareTestProperties());
|
2016-12-31 16:06:18 +01:00
|
|
|
props.setProperty(BrokerConstants.AUTHENTICATOR_CLASS_NAME, getClass().getName());
|
2015-07-06 18:35:31 +02:00
|
|
|
startServer(props);
|
|
|
|
|
assertTrue(true);
|
|
|
|
|
}
|
2017-02-01 16:10:44 +01:00
|
|
|
|
2015-07-06 18:35:31 +02:00
|
|
|
@Test
|
|
|
|
|
public void loadAuthorizator() throws Exception {
|
2016-05-18 00:09:40 +02:00
|
|
|
Properties props = new Properties(IntegrationUtils.prepareTestProperties());
|
2016-12-31 16:06:18 +01:00
|
|
|
props.setProperty(BrokerConstants.AUTHORIZATOR_CLASS_NAME, getClass().getName());
|
2015-07-06 18:35:31 +02:00
|
|
|
startServer(props);
|
|
|
|
|
assertTrue(true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 18:06:03 +01:00
|
|
|
@Test
|
|
|
|
|
public void loadStorage() throws Exception {
|
|
|
|
|
Properties props = new Properties(IntegrationUtils.prepareTestProperties());
|
|
|
|
|
props.setProperty(BrokerConstants.STORAGE_CLASS_NAME, MemoryStorageService.class.getName());
|
|
|
|
|
|
|
|
|
|
startServer(props);
|
|
|
|
|
assertTrue(m_server.getProcessor().getMessagesStore() instanceof MemoryMessagesStore);
|
|
|
|
|
assertTrue(m_server.getProcessor().getSessionsStore() instanceof MemorySessionStore);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-06 18:35:31 +02:00
|
|
|
@Override
|
2016-06-26 10:01:15 -04:00
|
|
|
public boolean checkValid(String clientID, String username, byte[] password) {
|
2015-07-06 18:35:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-02-14 17:23:04 +01:00
|
|
|
public boolean canWrite(Topic topic, String user, String client) {
|
2015-07-06 18:35:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-02-14 17:23:04 +01:00
|
|
|
public boolean canRead(Topic topic, String user, String client) {
|
2015-07-06 18:35:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2017-02-01 16:10:44 +01:00
|
|
|
|
2015-07-06 18:35:31 +02:00
|
|
|
}
|