blob: 23dac171e8557ae5a2bc37cbf092739ea8fee5cb [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.server;
import static org.apache.datasketches.server.SketchConstants.DEFAULT_PORT;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.io.IOException;
import java.util.Objects;
import org.testng.annotations.Test;
public class SketchServerConfigTest {
@Test
public void invalidFile() {
try {
new SketchServerConfig("fileDoesNotExist");
fail();
} catch (final IOException e) {
// expected
}
}
@Test
public void parseTestConfig() {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
final SketchServerConfig serverConf =
new SketchServerConfig(Objects.requireNonNull(classLoader.getResource("test_config.json")).getFile());
assertEquals(serverConf.getSketchList().size(), 15);
assertEquals(serverConf.getPort(), 8080);
} catch (final IOException e) {
fail();
}
}
@Test
public void parseJsonArrayConfig() {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
final SketchServerConfig serverConf =
new SketchServerConfig(Objects.requireNonNull(classLoader.getResource("array_config.json")).getFile());
assertEquals(serverConf.getSketchList().size(), 2);
assertEquals(serverConf.getPort(), DEFAULT_PORT);
} catch (final IOException e) {
fail();
}
}
}