-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
124 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...a/uk/gov/justice/services/core/featurecontrol/local/ClasspathLocalFeatureFileLocator.java
This file was deleted.
Oops, something went wrong.
33 changes: 25 additions & 8 deletions
33
.../main/java/uk/gov/justice/services/core/featurecontrol/local/LocalFeatureFileLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,45 @@ | ||
package uk.gov.justice.services.core.featurecontrol.local; | ||
|
||
import static java.lang.String.format; | ||
import static java.util.Optional.empty; | ||
import static java.util.Optional.of; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.Optional; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
|
||
public class LocalFeatureFileLocator { | ||
|
||
public static final String FEATURE_CONTROL_FILE_NAME = "feature-control.yaml"; | ||
|
||
@Inject | ||
private ClasspathLocalFeatureFileLocator classpathLocalFeatureFileLocator; | ||
private WildflyDeploymentDirectoryLocator wildflyDeploymentDirectoryLocator; | ||
|
||
@Inject | ||
private FileToUrlConverter fileToUrlConverter; | ||
|
||
@Inject | ||
private WildflyDeploymentDirLocalFeatureFileLocator wildflyDeploymentDirLocalFeatureFileLocator; | ||
private Logger logger; | ||
|
||
public Optional<URL> findLocalFeatureFileLocation(final String featureControlFileName) { | ||
|
||
final File deploymentDirectory = wildflyDeploymentDirectoryLocator.getDeploymentDirectory().toFile(); | ||
|
||
public Optional<URL> findLocalFeatureFileLocation() { | ||
if (deploymentDirectory.exists()) { | ||
|
||
final Optional<URL> classpathUrl = classpathLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME); | ||
final File file = new File(deploymentDirectory, featureControlFileName); | ||
|
||
if (classpathUrl.isPresent()) { | ||
return classpathUrl; | ||
if (file.exists()) { | ||
logger.warn(format("Feature control file found in wildfly deployment directory: '%s'", file.getAbsolutePath())); | ||
return of(fileToUrlConverter.toUrl(file)); | ||
} | ||
} else { | ||
logger.error(format("wildfly deployment dir '%s; does not exist", deploymentDirectory.getAbsolutePath())); | ||
} | ||
|
||
return wildflyDeploymentDirLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME); | ||
return empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
...stice/services/core/featurecontrol/local/WildflyDeploymentDirLocalFeatureFileLocator.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...src/main/java/uk/gov/justice/services/core/featurecontrol/remote/AzureFeatureFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package uk.gov.justice.services.core.featurecontrol.remote; | ||
|
||
import uk.gov.justice.services.core.featurecontrol.domain.Feature; | ||
|
||
import java.util.List; | ||
|
||
public interface AzureFeatureFetcher { | ||
|
||
List<Feature> fetchFeatures(); | ||
} |
21 changes: 21 additions & 0 deletions
21
...n/java/uk/gov/justice/services/core/featurecontrol/remote/DefaultAzureFeatureFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package uk.gov.justice.services.core.featurecontrol.remote; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import uk.gov.justice.services.core.featurecontrol.domain.Feature; | ||
|
||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Default; | ||
|
||
@Default | ||
@ApplicationScoped | ||
public class DefaultAzureFeatureFetcher implements AzureFeatureFetcher { | ||
|
||
@Override | ||
public List<Feature> fetchFeatures() { | ||
|
||
return emptyList(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ain/java/uk/gov/justice/services/core/featurecontrol/remote/DummyAzureFeatureFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package uk.gov.justice.services.core.featurecontrol.remote; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import uk.gov.justice.services.core.featurecontrol.domain.Feature; | ||
|
||
import java.util.List; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.inject.Alternative; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Alternative | ||
@Priority(100) | ||
public class DummyAzureFeatureFetcher implements AzureFeatureFetcher { | ||
|
||
@Override | ||
public List<Feature> fetchFeatures() { | ||
|
||
return emptyList(); | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
.../gov/justice/services/core/featurecontrol/local/ClasspathLocalFeatureFileLocatorTest.java
This file was deleted.
Oops, something went wrong.
66 changes: 33 additions & 33 deletions
66
...t/java/uk/gov/justice/services/core/featurecontrol/local/LocalFeatureFileLocatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,83 @@ | ||
package uk.gov.justice.services.core.featurecontrol.local; | ||
|
||
import static java.util.Optional.empty; | ||
import static java.util.Optional.of; | ||
import static java.nio.file.Paths.get; | ||
import static org.hamcrest.CoreMatchers.endsWith; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.verifyZeroInteractions; | ||
import static org.mockito.Mockito.when; | ||
import static uk.gov.justice.services.core.featurecontrol.local.LocalFeatureFileLocator.FEATURE_CONTROL_FILE_NAME; | ||
import static uk.gov.justice.services.core.featurecontrol.local.LocalFeatureStore.FEATURE_CONTROL_FILE_NAME; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.slf4j.Logger; | ||
|
||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class LocalFeatureFileLocatorTest { | ||
|
||
@Spy | ||
private FileToUrlConverter fileToUrlConverter = new FileToUrlConverter(); | ||
|
||
@Mock | ||
private ClasspathLocalFeatureFileLocator classpathLocalFeatureFileLocator; | ||
private WildflyDeploymentDirectoryLocator wildflyDeploymentDirectoryLocator; | ||
|
||
@Mock | ||
private WildflyDeploymentDirLocalFeatureFileLocator wildflyDeploymentDirLocalFeatureFileLocator; | ||
private Logger logger; | ||
|
||
@InjectMocks | ||
private LocalFeatureFileLocator localFeatureFileLocator; | ||
|
||
@Test | ||
public void shouldReturnTheFileLocationFromTheClasspathIfItExists() throws Exception { | ||
public void shouldGetTheUrlOfAFileInTheWildflyDeploymentDirectory() throws Exception { | ||
|
||
final URL classpathUrl = aRealUrlBecauseWeCannotMockTheDamnThings(); | ||
when(classpathLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME)).thenReturn(of(classpathUrl)); | ||
final Path aDirectory = directoryOfFileOnClasspath(FEATURE_CONTROL_FILE_NAME); | ||
when(wildflyDeploymentDirectoryLocator.getDeploymentDirectory()).thenReturn(aDirectory); | ||
|
||
final Optional<URL> localFeatureFileLocation = localFeatureFileLocator.findLocalFeatureFileLocation(); | ||
final Optional<URL> localFeatureFileLocation = localFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME); | ||
|
||
if (localFeatureFileLocation.isPresent()) { | ||
assertThat(localFeatureFileLocation.get(), is(classpathUrl)); | ||
assertThat(localFeatureFileLocation.get().getFile(), endsWith("/" + FEATURE_CONTROL_FILE_NAME)); | ||
} else { | ||
fail(); | ||
} | ||
|
||
verifyZeroInteractions(wildflyDeploymentDirLocalFeatureFileLocator); | ||
} | ||
|
||
@Test | ||
public void shouldReturnTheFileLocationFromWildflyDeploymentDirectoryIfTheClasspathFileDoesNotExists() throws Exception { | ||
public void shouldReturnEmptyIfTheFileCannotBeFoundInTheWildflyDeploymentDirectory() throws Exception { | ||
|
||
final Optional<URL> classpathUrl = empty(); | ||
final Path aDirectory = directoryOfFileOnClasspath("json/envelope.json"); | ||
when(wildflyDeploymentDirectoryLocator.getDeploymentDirectory()).thenReturn(aDirectory); | ||
|
||
final URL wildflyDeploymentDirUrl = aRealUrlBecauseWeCannotMockTheDamnThings(); | ||
when(classpathLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME)).thenReturn(classpathUrl); | ||
when(wildflyDeploymentDirLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME)).thenReturn(of(wildflyDeploymentDirUrl)); | ||
final Optional<URL> localFeatureFileLocation = localFeatureFileLocator.findLocalFeatureFileLocation(); | ||
final Optional<URL> localFeatureFileLocation = localFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME); | ||
|
||
if (localFeatureFileLocation.isPresent()) { | ||
assertThat(localFeatureFileLocation.get(), is(wildflyDeploymentDirUrl)); | ||
} else { | ||
fail(); | ||
} | ||
assertThat(localFeatureFileLocation.isPresent(), is(false)); | ||
} | ||
|
||
@Test | ||
public void shouldReturnEmptyIfNotFoundOnClasspathNorWildflyDeploymentDirectory() throws Exception { | ||
public void shouldReturnEmptyIfTheWildflyDeploymentDirectoryDoesNotExist() throws Exception { | ||
|
||
when(classpathLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME)).thenReturn(empty()); | ||
when(wildflyDeploymentDirLocalFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME)).thenReturn(empty()); | ||
final Path aDirectory = get("/this/directory-does-not-exist"); | ||
when(wildflyDeploymentDirectoryLocator.getDeploymentDirectory()).thenReturn(aDirectory); | ||
|
||
assertThat(localFeatureFileLocator.findLocalFeatureFileLocation().isPresent(), is(false)); | ||
final Optional<URL> localFeatureFileLocation = localFeatureFileLocator.findLocalFeatureFileLocation(FEATURE_CONTROL_FILE_NAME); | ||
|
||
assertThat(localFeatureFileLocation.isPresent(), is(false)); | ||
} | ||
|
||
private URL aRealUrlBecauseWeCannotMockTheDamnThings() { | ||
final URL url = getClass().getClassLoader().getResource("feature-control.yaml"); | ||
assertThat(url, is(notNullValue())); | ||
return url; | ||
private Path directoryOfFileOnClasspath(final String fileOnClasspath) throws URISyntaxException { | ||
|
||
final URL localFeatureFileLocation = getClass().getClassLoader().getResource(fileOnClasspath); | ||
|
||
return get(localFeatureFileLocation.toURI()).getParent().toAbsolutePath(); | ||
} | ||
} |
Oops, something went wrong.