Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support env variables in report manager #325

Merged
merged 8 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to AET will be documented in this file.
- [PR-291](https://github.com/Cognifide/aet/pull/291) Updated nu.validator version from 15.6.29 to 17.11.1
- [PR-298](https://github.com/Cognifide/aet/pull/298) Filtering accessibility errors by markup CSS ([#214](https://github.com/Cognifide/aet/issues/214))
- [PR-296](https://github.com/Cognifide/aet/pull/296) Status Code Comparator now checks range 400-600 by default, parameters validation added
- [PR-325](https://github.com/Cognifide/aet/pull/325) Support env variables in report manager

## Version 2.1.6

Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.18.0</version>
<scope>test</scope>
</dependency>

<!-- findbugs -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
18 changes: 18 additions & 0 deletions rest-endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.cognifide.aet.rest.helpers;

import com.cognifide.aet.rest.helpers.configuration.ReportConfigurationManagerConf;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.Designate;
Expand All @@ -24,14 +26,19 @@
@Designate(ocd = ReportConfigurationManagerConf.class)
public class ReportConfigurationManager {

ReportConfigurationManagerConf config;
private static final String REPORT_DOMAIN_ENV = "REPORT_DOMAIN";

private String reportDomain;

@Activate
public void activate(ReportConfigurationManagerConf config) {
this.config = config;
reportDomain = Optional.ofNullable(config.reportDomain())
.filter(StringUtils::isNotBlank)
.orElseGet(() -> Optional.ofNullable(System.getenv(REPORT_DOMAIN_ENV))
.orElse(ReportConfigurationManagerConf.DEFAULT_REPORT_DOMAIN));
}

public String getReportDomain() {
return config.reportDomain();
return reportDomain;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

@AttributeDefinition(
name = REPORT_DOMAIN_PROPERTY_NAME,
description = "Report application domain",
description = "Report application domain that is printed at the end of processing suite. "
+ "If not provided here, env variable REPORT_DOMAIN will be used instead or value will "
+ "fallback to the default: " + DEFAULT_REPORT_DOMAIN,
type = AttributeType.STRING)
String reportDomain() default DEFAULT_REPORT_DOMAIN;
String reportDomain() default "";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed 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 com.cognifide.aet.rest.helpers;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;

import com.cognifide.aet.rest.helpers.configuration.ReportConfigurationManagerConf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ReportConfigurationManagerTest {

@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();

@Mock
private ReportConfigurationManagerConf config;

@Test
public void activate_whenNoReportDomainSettingProvided_expectDefaultValue() {
final ReportConfigurationManager manager = new ReportConfigurationManager();
when(config.reportDomain()).thenReturn("");
manager.activate(config);
assertThat(manager.getReportDomain(), is("http://aet-vagrant"));
}

@Test
public void activate_whenOnlyOsgiConfigProvided_expectConfiguredValue() {
final ReportConfigurationManager manager = new ReportConfigurationManager();
when(config.reportDomain()).thenReturn("http://custom-report-domain");
manager.activate(config);
assertThat(manager.getReportDomain(), is("http://custom-report-domain"));
}

@Test
public void activate_whenOnlyEnvConfigProvided_expectConfiguredValue() {
environmentVariables.set("REPORT_DOMAIN", "http://env-set-domain");
final ReportConfigurationManager manager = new ReportConfigurationManager();
when(config.reportDomain()).thenReturn("");
manager.activate(config);
assertThat(manager.getReportDomain(), is("http://env-set-domain"));
}

@Test
public void activate_whenOsgiAndEnvConfigProvided_expectOsgiConfigValue() {
environmentVariables.set("REPORT_DOMAIN", "http://env-set-domain");
final ReportConfigurationManager manager = new ReportConfigurationManager();
when(config.reportDomain()).thenReturn("http://custom-report-domain");
manager.activate(config);
assertThat(manager.getReportDomain(), is("http://custom-report-domain"));
}
}