Repository: incubator-streams Updated Branches: refs/heads/master 348963471 -> 4f100f3a2
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/4f100f3a/streams-schemas/streams-schema-activitystreams/src/test/java/org/w3c/activitystreams/test/SchemaValidationTest.java ---------------------------------------------------------------------- diff --git a/streams-schemas/streams-schema-activitystreams/src/test/java/org/w3c/activitystreams/test/SchemaValidationTest.java b/streams-schemas/streams-schema-activitystreams/src/test/java/org/w3c/activitystreams/test/SchemaValidationTest.java new file mode 100644 index 0000000..8f22450 --- /dev/null +++ b/streams-schemas/streams-schema-activitystreams/src/test/java/org/w3c/activitystreams/test/SchemaValidationTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.w3c.activitystreams.test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.networknt.schema.JsonSchema; +import com.networknt.schema.JsonSchemaFactory; +import com.networknt.schema.ValidationMessage; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Set; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class SchemaValidationTest { + + private final static Logger LOGGER = LoggerFactory.getLogger(SchemaValidationTest.class); + + private final static ObjectMapper MAPPER = new ObjectMapper(); + + /** + * Tests that activities matching core-ex* can be parsed by apache streams + * + * @throws Exception + */ + @Test + public void validateToSchema() throws Exception { + + JsonSchemaFactory factory = new JsonSchemaFactory(); + + InputStream testActivityFolderStream = SchemaValidationTest.class.getClassLoader() + .getResourceAsStream("activities"); + List<String> files = IOUtils.readLines(testActivityFolderStream, Charsets.UTF_8); + + for (String file : files) { + if( !file.startsWith(".") ) { + + LOGGER.info("Test File: activities/" + file); + String testFileString = new String(Files.readAllBytes(Paths.get("target/test-classes/activities/" + file))); + LOGGER.info("Test Document JSON: " + testFileString); + JsonNode testNode = MAPPER.readValue(testFileString, ObjectNode.class); + LOGGER.info("Test Document Object:" + testNode); + LOGGER.info("Test Schema File: " + "target/classes/verbs/" + file); + String testSchemaString = new String(Files.readAllBytes(Paths.get("target/classes/verbs/" + file))); + LOGGER.info("Test Schema JSON: " + testSchemaString); + JsonNode testSchemaNode = MAPPER.readValue(testFileString, ObjectNode.class); + LOGGER.info("Test Schema Object:" + testSchemaNode); + JsonSchema testSchema = factory.getSchema(testSchemaNode); + LOGGER.info("Test Schema:" + testSchema); + + Set<ValidationMessage> errors = testSchema.validate(testNode); + assertThat(errors.size(), is(0)); + + } + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/4f100f3a/streams-util/pom.xml ---------------------------------------------------------------------- diff --git a/streams-util/pom.xml b/streams-util/pom.xml index 4e1c849..ecf7dc3 100644 --- a/streams-util/pom.xml +++ b/streams-util/pom.xml @@ -54,16 +54,6 @@ <artifactId>joda-time</artifactId> </dependency> <dependency> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-core</artifactId> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> @@ -73,18 +63,22 @@ <version>2.1.2</version> </dependency> <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-schema-activitystreams</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <type>jar</type> + <groupId>org.jsonschema2pojo</groupId> + <artifactId>jsonschema2pojo-core</artifactId> + <version>${jsonschema2pojo.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.streams</groupId> <artifactId>streams-schema-activitystreams</artifactId> <version>${project.version}</version> <scope>test</scope> - <type>test-jar</type> + <type>jar</type> </dependency> <dependency> <groupId>org.apache.streams</groupId> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/4f100f3a/streams-util/src/test/java/org/apache/streams/util/schema/test/SchemaStoreTest.java ---------------------------------------------------------------------- diff --git a/streams-util/src/test/java/org/apache/streams/util/schema/test/SchemaStoreTest.java b/streams-util/src/test/java/org/apache/streams/util/schema/test/SchemaStoreTest.java index a030bd5..1dce654 100644 --- a/streams-util/src/test/java/org/apache/streams/util/schema/test/SchemaStoreTest.java +++ b/streams-util/src/test/java/org/apache/streams/util/schema/test/SchemaStoreTest.java @@ -60,9 +60,6 @@ public class SchemaStoreTest { assert( schemaStore.getById(schemaStore.getByUri(file.toURI()).get().getId()).isPresent()); Schema collection = schemaStore.getByUri(file.toURI()).get(); assert( collection.getParent() == null ); - assert( schemaStore.getById( - URI.create("http://streams.incubator.apache.org/site/latest/streams-project/streams-schemas/object.json#" - )).isPresent()); } @Test @@ -75,10 +72,10 @@ public class SchemaStoreTest { assert( schemaStore.getById(schemaStore.getByUri(file.toURI()).get().getId()).isPresent()); Schema update = schemaStore.getByUri(file.toURI()).get(); assert( update.getParent() != null ); - assert( update.getParent().getId().getScheme().equals("http")); - assert( update.getParent().getId().getHost().equals("streams.incubator.apache.org")); - assert( update.getParent().getId().getPath().startsWith("/site/latest/streams-project/streams-schemas")); - assert( update.getParent().getId().getPath().endsWith("activity.json")); + File parentFile = new File("target/test-classes/activitystreams-schemas/activity.json"); + Schema parent = schemaStore.getByUri(parentFile.toURI()).get(); + assert( parent != null ); + assert( update.getParentURI().equals(parent.getURI())); } // test create from messed up URI http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/4f100f3a/streams-verbs/pom.xml ---------------------------------------------------------------------- diff --git a/streams-verbs/pom.xml b/streams-verbs/pom.xml index 26d2860..c8f2865 100644 --- a/streams-verbs/pom.xml +++ b/streams-verbs/pom.xml @@ -33,13 +33,6 @@ <dependencies> <dependency> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-core</artifactId> - <type>jar</type> - <scope>compile</scope> - </dependency> - - <dependency> <groupId>org.apache.streams</groupId> <artifactId>streams-pojo</artifactId> </dependency> @@ -135,6 +128,25 @@ </testResources> <plugins> <plugin> + <groupId>org.apache.streams.plugins</groupId> + <artifactId>streams-plugin-pojo</artifactId> + <version>${project.version}</version> + <configuration> + <sourcePaths> + <sourcePath>${project.basedir}/src/main/jsonschema</sourcePath> + </sourcePaths> + <targetDirectory>${project.basedir}/target/generated-sources/pojo</targetDirectory> + <targetPackage>org.apache.streams.verbs</targetPackage> + </configuration> + <executions> + <execution> + <goals> + <goal>generate-sources</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> @@ -146,35 +158,13 @@ </goals> <configuration> <sources> - <source>target/generated-sources/jsonschema2pojo</source> + <source>target/generated-sources/pojo</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-maven-plugin</artifactId> - <configuration> - <addCompileSourceRoot>true</addCompileSourceRoot> - <generateBuilders>true</generateBuilders> - <sourcePaths> - <sourcePath>${project.basedir}/src/main/jsonschema</sourcePath> - </sourcePaths> - <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory> - <targetPackage>org.apache.streams.verbs</targetPackage> - <useLongIntegers>true</useLongIntegers> - <useJodaDates>true</useJodaDates> - </configuration> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <configuration> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/4f100f3a/streams-verbs/src/test/java/org/apache/streams/verbs/ObjectCombinationSpecificOrderingTest.java ---------------------------------------------------------------------- diff --git a/streams-verbs/src/test/java/org/apache/streams/verbs/ObjectCombinationSpecificOrderingTest.java b/streams-verbs/src/test/java/org/apache/streams/verbs/ObjectCombinationSpecificOrderingTest.java index 81adc59..3162aa0 100644 --- a/streams-verbs/src/test/java/org/apache/streams/verbs/ObjectCombinationSpecificOrderingTest.java +++ b/streams-verbs/src/test/java/org/apache/streams/verbs/ObjectCombinationSpecificOrderingTest.java @@ -20,7 +20,7 @@ package org.apache.streams.verbs; import org.apache.streams.pojo.json.Activity; -import org.apache.streams.pojo.json.Actor; +import org.apache.streams.pojo.json.ActivityObject; import org.apache.streams.pojo.json.Provider; import org.junit.Test; @@ -32,7 +32,7 @@ public class ObjectCombinationSpecificOrderingTest { @Test public void compareMatchCountTest() { - Actor actor = new Actor(); + ActivityObject actor = new ActivityObject(); actor.setObjectType("actor"); Activity activity = new Activity().withActor(actor); ObjectCombination combination1 = new ObjectCombination(); http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/4f100f3a/streams-verbs/src/test/java/org/apache/streams/verbs/VerbDefinitionTemplateTest.java ---------------------------------------------------------------------- diff --git a/streams-verbs/src/test/java/org/apache/streams/verbs/VerbDefinitionTemplateTest.java b/streams-verbs/src/test/java/org/apache/streams/verbs/VerbDefinitionTemplateTest.java index f59cc36..eeb61f7 100644 --- a/streams-verbs/src/test/java/org/apache/streams/verbs/VerbDefinitionTemplateTest.java +++ b/streams-verbs/src/test/java/org/apache/streams/verbs/VerbDefinitionTemplateTest.java @@ -22,7 +22,6 @@ package org.apache.streams.verbs; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.streams.pojo.json.Activity; import org.apache.streams.pojo.json.ActivityObject; -import org.apache.streams.pojo.json.Actor; import org.apache.streams.pojo.json.Provider; import org.junit.Test; @@ -50,7 +49,7 @@ public class VerbDefinitionTemplateTest { */ @Test public void testTopField() throws Exception { - Actor actor = new Actor(); + ActivityObject actor = new ActivityObject(); actor.setObjectType("page"); actor.setDisplayName("Paige"); Provider provider = new Provider();
