Skip to content

Commit

Permalink
HH-76991 remove jdebug, timings and guava, rename properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Khalikov committed Mar 2, 2018
1 parent 32c869c commit 99c8940
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 38 deletions.
24 changes: 7 additions & 17 deletions nab-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
<version>1</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>

<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
Expand Down Expand Up @@ -147,11 +141,6 @@
<artifactId>hh-metrics</artifactId>
<version>0.12</version>
</dependency>
<dependency>
<groupId>ru.hh.jdebug</groupId>
<artifactId>jdebug-addon-jdbc</artifactId>
<version>${jdebug.version}</version>
</dependency>
<!-- MX4J -->
<dependency>
<groupId>mx4j</groupId>
Expand Down Expand Up @@ -191,17 +180,18 @@
</exclusions>
</dependency>

<dependency>
<groupId>ru.hh</groupId>
<artifactId>timings</artifactId>
<version>1.5</version>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.0.7</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion nab-core/src/main/java/ru/hh/nab/core/CoreProdConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CoreProdConfig {

@Bean
FileSettings fileSettings() throws Exception {
Properties properties = fromFilesInSettingsDir("settings.properties", "settings.properties.dev");
Properties properties = fromFilesInSettingsDir("service.properties", "service.properties.dev");
return new FileSettings(properties);
}

Expand Down
30 changes: 18 additions & 12 deletions nab-core/src/main/java/ru/hh/nab/core/util/FileSettings.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ru.hh.nab.core.util;

import com.google.common.base.Strings;

import java.util.ArrayList;
import static java.util.Arrays.asList;
import java.util.List;
import java.util.Properties;
import static org.springframework.util.Assert.hasLength;

public class FileSettings {
private final Properties properties;
Expand Down Expand Up @@ -31,25 +33,29 @@ public Boolean getBoolean(String key) {
}

public Properties getSubProperties(String prefix) {
return getSubProperties(prefix, null);
}

public Properties getSubProperties(String prefix, String newPrefix) {
final String namespacePrefix = Strings.isNullOrEmpty(prefix) ? "" : prefix + ".";
hasLength(prefix, "prefix should not be null or empty");
final Properties subProperties = new Properties();

properties.stringPropertyNames().stream()
.filter(key -> key.startsWith(namespacePrefix))
.filter(key -> key.startsWith(prefix + "."))
.forEach(key -> {
String newKey = Strings.isNullOrEmpty(newPrefix) ? "" : newPrefix + ".";
newKey += prefix.isEmpty() ? key : key.substring(prefix.length() + 1);
String newKey = prefix.isEmpty() ? key : key.substring(prefix.length() + 1);
subProperties.put(newKey, properties.getProperty(key));
});

return subProperties;
}

public FileSettings getSubSettings(String prefix) {
return new FileSettings(getSubProperties(prefix));
}

public List<String> getStringList(String key) {
String value = getString(key);
return value != null ? asList(value.split("[,\\s]+")) : new ArrayList<>();
}

public Properties getProperties() {
Properties propertiesCopy = new Properties();
propertiesCopy.putAll(this.properties);
return propertiesCopy;
}
}
2 changes: 1 addition & 1 deletion nab-core/src/main/resources/shared-logback.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<included>

<property file="${settingsDir}/settings.properties"/>
<property file="${settingsDir}/service.properties"/>
<property scope="context" name="log.dir" value="${log.dir:-logs}"/>
<property scope="context" name="log.immediate.flush" value="${log.immediate.flush:-true}"/>
<property scope="context" name="log.toConsole" value="${log.toConsole:-false}"/>
Expand Down
101 changes: 101 additions & 0 deletions nab-core/src/test/java/ru/hh/nab/core/util/FileSettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package ru.hh.nab.core.util;

import java.util.List;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;

public class FileSettingsTest {
private static FileSettings fileSettings;

@BeforeClass
public static void setUpClass() {
Properties properties = new Properties();
properties.put("strProperty", "value");
properties.put("intProperty1", "0");
properties.put("intProperty2", "123");
properties.put("namespace.boolProperty1", "true");
properties.put("namespace.boolProperty2", "false");
properties.put("listProperty", "value1, value2,value3");

fileSettings = new FileSettings(properties);
}

@Test
public void testGetString() {
assertEquals("value", fileSettings.getString("strProperty"));
assertNull(fileSettings.getString("missingKey"));
}

@Test
public void testGetInteger() {
assertEquals(0, fileSettings.getInteger("intProperty1").intValue());
assertEquals(123, fileSettings.getInteger("intProperty2").intValue());
}

@Test
public void testGetBoolean() {
assertTrue(fileSettings.getBoolean("namespace.boolProperty1"));
assertFalse(fileSettings.getBoolean("namespace.boolProperty2"));
}

@Test
public void testGetSubProperties() {
Properties subProperties = fileSettings.getSubProperties("namespace");
assertEquals(2, subProperties.size());
assertTrue(subProperties.containsKey("boolProperty1"));
assertTrue(subProperties.containsKey("boolProperty2"));
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubPropertiesThrowsExceptionIfPrefixIsEmpty() {
fileSettings.getSubProperties("");
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubPropertiesThrowsExceptionIfPrefixIsNull() {
fileSettings.getSubProperties(null);
}

@Test
public void testGetSubSettings() {
FileSettings subSettings = fileSettings.getSubSettings("namespace");
assertNotNull(subSettings.getString("boolProperty1"));
assertNotNull(subSettings.getString("boolProperty2"));
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubSettingsThrowsExceptionIfPrefixIsEmpty() {
fileSettings.getSubSettings("");
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubSettingsThrowsExceptionIfPrefixIsNull() {
fileSettings.getSubSettings(null);
}

@Test
public void testGetStringList() {
List<String> settings = fileSettings.getStringList("listProperty");
assertEquals(3, settings.size());
assertEquals("value1", settings.get(0));
assertEquals("value2", settings.get(1));
assertEquals("value3", settings.get(2));
}

@Test
public void testGetProperties() {
Properties properties = fileSettings.getProperties();
assertEquals("value", properties.getProperty("strProperty"));

properties.setProperty("strProperty", "newValue");
assertEquals("newValue", properties.getProperty("strProperty"));

assertEquals("value", fileSettings.getString("strProperty"));
}
}
2 changes: 1 addition & 1 deletion nab-testbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
</dependency>

<dependency>
Expand Down
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</modules>

<properties>
<jdebug.version>0.0.23</jdebug.version>
<spring.version>5.0.3.RELEASE</spring.version>
<hibernate.version>5.2.10.Final</hibernate.version>
<junit.version>4.12</junit.version>
</properties>

<dependencyManagement>
Expand All @@ -34,11 +34,6 @@
<artifactId>hh-metrics</artifactId>
<version>0.12</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
Expand Down

0 comments on commit 99c8940

Please sign in to comment.