This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
b1d35d8
commit 0ca5238
Showing
19 changed files
with
404 additions
and
0 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
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>raml-jaxrs</artifactId> | ||
<groupId>uk.gov.justice</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>raml-io</artifactId> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.raml</groupId> | ||
<artifactId>raml-parser</artifactId> | ||
<version>0.8.12</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>19.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.trajano.commons</groupId> | ||
<artifactId>commons-testing</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
43 changes: 43 additions & 0 deletions
43
raml-io/src/main/java/uk/gov/justice/raml/io/FileTreeResolver.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,43 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import com.google.common.io.Files; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* | ||
* Created by jcooke on 01/02/16. | ||
* | ||
*/ | ||
public class FileTreeResolver { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FileTreeResolver.class); | ||
|
||
/** | ||
* | ||
* returns a list of Paths to files found under searchDirectory where the file name matches the supplied | ||
* regex pattern. | ||
* | ||
* @param searchDirectory | ||
* @param pattern | ||
* @return | ||
*/ | ||
public List<Path> load(File searchDirectory, Pattern pattern) { | ||
|
||
LOGGER.debug("Loading files from : " + searchDirectory.getAbsolutePath()); | ||
|
||
return Files.fileTreeTraverser() | ||
.breadthFirstTraversal(searchDirectory) | ||
.toList() | ||
.stream() | ||
.filter(s -> pattern.matcher(s.getPath()).matches()) | ||
.map(File::toPath) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
raml-io/src/main/java/uk/gov/justice/raml/io/TierImportPattern.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,15 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Created by jcooke on 27/01/16. | ||
*/ | ||
public final class TierImportPattern { | ||
|
||
public static final Pattern ALL = Pattern.compile(".*\\.raml"); | ||
|
||
private TierImportPattern(){ | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
raml-io/src/test/java/uk/gov/justice/raml/io/FileTreeResolverTest.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,32 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import org.junit.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Created by jcooke on 05/02/16. | ||
*/ | ||
public class FileTreeResolverTest { | ||
|
||
|
||
@Test | ||
public void testValidateSyntax() throws Exception { | ||
|
||
FileTreeResolver fileTreeResolver = new FileTreeResolver(); | ||
|
||
List<Path> results = fileTreeResolver.load(TestRaml.getTestRamlDirectory(), TierImportPattern.ALL); | ||
|
||
results.stream() | ||
.forEach(path -> System.out.println(path)); | ||
|
||
assertNotNull(results.get(0)); | ||
|
||
assertTrue(results.size() == 2); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
raml-io/src/test/java/uk/gov/justice/raml/io/TestRaml.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,31 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Created by jcooke on 01/02/16. | ||
*/ | ||
public class TestRaml { | ||
|
||
private TestRaml() {} | ||
|
||
public static File getTestRamlDirectory() { | ||
|
||
return new File("src/test/resources/raml/"); | ||
|
||
} | ||
|
||
|
||
public static File getTestNoRamlDirectory() { | ||
|
||
return new File("src/test/resources/noraml/"); | ||
|
||
} | ||
|
||
|
||
public static File getTestInvalidRamlDirectory() { | ||
|
||
return new File("src/test/resources/invalidraml/"); | ||
|
||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
raml-io/src/test/java/uk/gov/justice/raml/io/TierImportPatternTest.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,22 @@ | ||
package uk.gov.justice.raml.io; | ||
|
||
import org.junit.Test; | ||
|
||
import static net.trajano.commons.testing.UtilityClassTestUtil.assertUtilityClassWellDefined; | ||
|
||
/** | ||
* Created by jcooke on 15/02/16. | ||
*/ | ||
public class TierImportPatternTest { | ||
|
||
/** | ||
* Tests the private constructor & that class is well defined. | ||
* http://www.trajano.net/2013/04/covering-utility-classes/ | ||
* https://github.com/trajano/commons-testing | ||
*/ | ||
@Test | ||
public void isUtilityClassWellDefined() { | ||
assertUtilityClassWellDefined(TierImportPattern.class); | ||
} | ||
|
||
} |
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,9 @@ | ||
# Set root logger level to DEBUG and its only appender to A1. | ||
log4j.rootLogger=INFO, A1 | ||
|
||
# A1 is set to be a ConsoleAppender. | ||
log4j.appender.A1=org.apache.log4j.ConsoleAppender | ||
|
||
# A1 uses PatternLayout. | ||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n |
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,15 @@ | ||
#%RAML 0.8 | ||
title: Example | ||
baseUri: http://localhost:8080/ | ||
version: v0.1 | ||
mediaType: application/json | ||
protocols: [ HTTP, HTTPS ] | ||
|
||
/test: | ||
description: | | ||
Post to this entry point to create a test | ||
post: | ||
headers: | ||
Content-Type: | ||
type: string | ||
example: application/json |
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,15 @@ | ||
#%RAML 0.8 | ||
title: Example | ||
baseUri: http://localhost:8080/ | ||
version: v0.1 | ||
mediaType: application/json | ||
protocols: [ HTTP, HTTPS ] | ||
|
||
/test: | ||
description: | | ||
Post to this entry point to create a test | ||
post: | ||
headers: | ||
Content-Type: | ||
type: string | ||
example: application/json |
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 @@ | ||
A test file which is not raml. |
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>raml-jaxrs</artifactId> | ||
<groupId>uk.gov.justice</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>raml-parser</artifactId> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.raml</groupId> | ||
<artifactId>raml-parser</artifactId> | ||
<version>0.8.12</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<artifactId>raml-io</artifactId> | ||
<groupId>uk.gov.justice</groupId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
41 changes: 41 additions & 0 deletions
41
raml-parser/src/main/java/uk/gov/justice/raml/io/files/parser/RamlFileParser.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,41 @@ | ||
package uk.gov.justice.raml.io.files.parser; | ||
|
||
import org.raml.model.Raml; | ||
import org.raml.parser.loader.FileResourceLoader; | ||
import org.raml.parser.visitor.RamlDocumentBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Takes a list of file paths and loads the files and parses them into a @code List<raml> | ||
* | ||
* Created by jcooke on 27/01/16. | ||
*/ | ||
public class RamlFileParser { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(RamlFileParser.class); | ||
|
||
public RamlFileParser() { | ||
|
||
LOGGER.debug("RamlLoader created"); | ||
|
||
} | ||
|
||
public List<Raml> loadRaml(List<Path> ramlURIs) { | ||
|
||
|
||
return ramlURIs | ||
.stream() | ||
.map(aFile -> { | ||
LOGGER.info(new StringBuilder().append("Loading file ").append(aFile).toString()); | ||
|
||
return new RamlDocumentBuilder(new FileResourceLoader(aFile.toFile().getParent())).build(aFile.toFile().getName()); | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
raml-parser/src/test/java/uk/gov/justice/raml/io/files/parser/RamlFileParserTest.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,35 @@ | ||
package uk.gov.justice.raml.io.files.parser; | ||
|
||
import org.junit.Test; | ||
import org.raml.model.Raml; | ||
import uk.gov.justice.raml.io.FileTreeResolver; | ||
import uk.gov.justice.raml.io.TierImportPattern; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Created by jcooke on 08/03/16. | ||
*/ | ||
public class RamlFileParserTest { | ||
|
||
@Test | ||
public void testLoadRaml() throws Exception { | ||
|
||
FileTreeResolver fileTreeResolver = new FileTreeResolver(); | ||
|
||
List<Path> paths = fileTreeResolver.load(TestRaml.getTestRamlDirectory(), TierImportPattern.ALL); | ||
|
||
RamlFileParser ramlLoader = new RamlFileParser(); | ||
|
||
List<Raml> ramls = ramlLoader.loadRaml(paths); | ||
|
||
assertNotNull(ramls.get(0)); | ||
assertTrue(ramls.size() == 2); | ||
assertTrue(ramls.get(1) instanceof Raml); | ||
|
||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
raml-parser/src/test/java/uk/gov/justice/raml/io/files/parser/TestRaml.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,31 @@ | ||
package uk.gov.justice.raml.io.files.parser; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Created by jcooke on 01/02/16. | ||
*/ | ||
public class TestRaml { | ||
|
||
private TestRaml() {} | ||
|
||
public static File getTestRamlDirectory() { | ||
|
||
return new File("src/test/resources/raml/"); | ||
|
||
} | ||
|
||
|
||
public static File getTestNoRamlDirectory() { | ||
|
||
return new File("src/test/resources/noraml/"); | ||
|
||
} | ||
|
||
|
||
public static File getTestInvalidRamlDirectory() { | ||
|
||
return new File("src/test/resources/invalidraml/"); | ||
|
||
} | ||
} |
Oops, something went wrong.