Skip to content

Commit

Permalink
Merged in COM-115 (pull request #3)
Browse files Browse the repository at this point in the history
COM-115 - Доработки по результатам статического анализа кода

Approved-by: Stanislav Doroshin <stanislav.doroshin@bsc-ideas.com>
  • Loading branch information
MAKAR1031 committed Feb 27, 2018
2 parents 137653d + e92bbd1 commit 37d7391
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
14 changes: 12 additions & 2 deletions src/main/java/ru/bsc/wiremock/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
* Created by smakarov
* 13.02.2018 11:15
*/
public interface Constants {
String VELOCITY_PROPERTIES = "/velocity.properties";
public enum Constants {
VELOCITY_PROPERTIES("/velocity.properties");

private final String value;

Constants(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void contextInitialized(ServletContextEvent sce) {

Properties properties = new Properties();
String wireMockMappingPath = "";
try (final InputStream stream = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES)) {
try (final InputStream stream = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES.getValue())) {
properties.load(stream);
wireMockMappingPath = properties.getProperty("wiremock.mapping.path");
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@
*
*/
class BscMappingSaver implements MappingsSaver {
private final Logger logger = LoggerFactory.getLogger(BscMappingSaver.class);
private final Logger log = LoggerFactory.getLogger(BscMappingSaver.class);

private final String mappingPath;
private final SimpleDateFormat dateFormat;

BscMappingSaver() {
Properties properties = new Properties();
try (final InputStream stream = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES)) {
try (final InputStream stream = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES.getValue())) {
properties.load(stream);
} catch (IOException e) {
logger.error("Error while loading properties", e);
log.error("Error while loading properties", e);
}
mappingPath = properties.getProperty("wiremock.mapping.path");
dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS", Locale.ENGLISH);
}

@Override
public void save(List<StubMapping> stubMappings) {
File mappingActual = new File(mappingPath + "/mappings/");
File newName = new File(mappingPath + "/mappings_" + dateFormat.format(Calendar.getInstance().getTime()) + "/");
boolean isRenamed = mappingActual.renameTo(newName);
if (isRenamed) {
log.info("File {} is renamed", mappingActual);
} else {
log.warn("File {} not renamed", mappingActual);
}

try {
File mappingActual = new File(mappingPath + "/mappings/");
//noinspection ResultOfMethodCallIgnored
mappingActual.renameTo(new File(mappingPath + "/mappings_" + dateFormat.format(Calendar.getInstance().getTime()) + "/"));
for (StubMapping stubMapping: stubMappings) {
String fileName = "";
if (stubMapping.getRequest().getUrl() != null) {
Expand All @@ -59,23 +65,23 @@ public void save(List<StubMapping> stubMappings) {
Files.write(stubMapping.toString(), new File(file, stubMapping.getUuid() + ".json"), Charsets.UTF_8);
}
} catch (IOException e) {
logger.error("Error while save subMapping list", e);
log.error("Error while save subMapping list", e);
}
logger.info("Save list: {}", stubMappings.toString());
log.info("Save list: {}", stubMappings.toString());
}

@Override
public void save(StubMapping stubMapping) {
logger.info("Save one: {}", stubMapping.toString());
log.info("Save one: {}", stubMapping.toString());
}

@Override
public void remove(StubMapping stubMapping) {
logger.info("Remove: {}", stubMapping.toString());
log.info("Remove: {}", stubMapping.toString());
}

@Override
public void removeAll() {
logger.info("Remove all");
log.info("Remove all");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public <T extends Extension> Map<String, T> extensionsOfType(Class<T> extensionT

// VelocityResponseTransformer configuration
Properties properties = new Properties();
try (final InputStream stream = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES)) {
try (final InputStream stream = this.getClass().getResourceAsStream(VELOCITY_PROPERTIES.getValue())) {
properties.load(stream);
} catch (IOException e) {
logger.error("Error while loading properties", e);
Expand Down

0 comments on commit 37d7391

Please sign in to comment.