From 383c7f01c26988efb9f7fdbbad03821fffd97c93 Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Sat, 21 Nov 2015 16:44:22 -0600 Subject: [PATCH] hibernate 5 update module names clean up hibernate config and commonize testng.xml accessIT EmbeddedIT groovy tests fix build warnings fix plugin versions reuse pom inheritance and minimize global pom properties rebase fix comment skip install minimize logs new container installing libaio1 mysql service options --- .travis.yml | 6 +- elide-core/pom.xml | 36 +- .../coerce/converters/FromMapConverter.java | 5 +- .../elide-datastore-hibernate/pom.xml | 14 +- .../elide/core/filter/HQLFilterOperation.java | 2 +- .../elide-datastore-hibernate3/README.md | 1 - .../elide-datastore-hibernate3/pom.xml | 24 +- .../HibernateDataStoreSupplier.java | 25 +- .../hibernate3}/usertypes/JsonType.java | 3 +- .../test/java/example/AddressFragment.java | 2 +- .../src/test/java/example/Person.java | 3 +- .../elide-datastore-hibernate3/testng.xml | 19 - .../elide-datastore-hibernate5/pom.xml | 66 +- .../hibernate5/PersistenceStore.java | 10 +- .../hibernate5/security/CriteriaCheck.java | 5 + ...r.java => HibernateDataStoreSupplier.java} | 27 +- .../hibernate5/HibernateStoreTest.java | 11 - .../hibernate5/tests/FilteredIT.java | 40 + .../hibernate5}/usertypes/JsonType.java | 3 +- .../test/java/example/AddressFragment.java | 21 + .../src/test/java/example/Person.java | 43 ++ .../elide-datastore-inmemorydb/README.md | 1 - .../elide-datastore-inmemorydb/pom.xml | 16 +- .../elide-datastore-multiplex/pom.xml | 35 +- elide-datastore/pom.xml | 11 +- elide-datastore/testng.xml | 39 + .../elide-hibernate3-mysql-example/pom.xml | 31 +- .../elide-persistence-mysql-example/pom.xml | 42 +- elide-example/pom.xml | 13 +- elide-integration-tests/pom.xml | 33 +- .../com/yahoo/elide/tests/FilterIT.groovy | 702 ++++++++++++++++++ .../com/yahoo/elide/tests/ShareableIT.groovy | 443 +++++++++++ .../com/yahoo/elide/tests/UserTypeIT.groovy | 6 +- .../java/com/yahoo/elide/tests/AccessIT.java | 36 + .../com/yahoo/elide/tests/EmbeddedIT.java | 79 ++ .../src/test/resources/hibernate.cfg.xml | 31 +- pom.xml | 177 +++-- 37 files changed, 1680 insertions(+), 381 deletions(-) rename {elide-integration-tests/src/test/java-hibernate3 => elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3}/usertypes/JsonType.java (98%) rename {elide-integration-tests => elide-datastore/elide-datastore-hibernate3}/src/test/java/example/AddressFragment.java (87%) rename {elide-integration-tests => elide-datastore/elide-datastore-hibernate3}/src/test/java/example/Person.java (90%) delete mode 100644 elide-datastore/elide-datastore-hibernate3/testng.xml rename elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/{Hibernate5DataStoreSupplier.java => HibernateDataStoreSupplier.java} (65%) delete mode 100644 elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateStoreTest.java create mode 100644 elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/tests/FilteredIT.java rename {elide-integration-tests/src/test/java-hibernate5 => elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5}/usertypes/JsonType.java (98%) create mode 100644 elide-datastore/elide-datastore-hibernate5/src/test/java/example/AddressFragment.java create mode 100644 elide-datastore/elide-datastore-hibernate5/src/test/java/example/Person.java create mode 100644 elide-datastore/testng.xml create mode 100644 elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/FilterIT.groovy create mode 100644 elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/ShareableIT.groovy create mode 100644 elide-integration-tests/src/test/java/com/yahoo/elide/tests/AccessIT.java create mode 100644 elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIT.java diff --git a/.travis.yml b/.travis.yml index 43d7f984d9..7175d03449 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,15 +9,17 @@ global: - secure: VV+uJlBgXRCUSj3+khXnKvbrB0bxtay3yovKAchTT83Y6+iXUAgp3b7EA1QjT0l3Hz88Y+EAVuiZqwzFRidbZwbgApaxYMJKWjHTmr+VsXXJp29J1tyGtXR1K+DUG0HO/jiRCxMVythB68BnNMIXfprpmsLFpXhKMPf41fzMaAtqSYrPdJkNvEzBDhu5hIPG9apyEcpIZNhtfwnk18DntyGFC3OVAKzEma51s0tS6NeXiZNzTvc9j0d4Fr8vyWGclAp1XKMjWzpvfRyB2EFto076V+8tJ5E3czJjJs12SDwOvEdzYeCpGk3VWboiz9DuZn41IdTLYy89OmcIooZQHViMwiatcqqHREEbuuUWZLYMEh1bUHZHRWQf2AnUScDfJB1QUKVR8mbkSr5DXto4FIsHpqofoBloDveaXkWC735DqOPwbIwe2owGZfkQv19vPpVvF3e2LyFn1vf8blR3wFBItKKZyvBTbrIVM/YxuTDfswDVlhEgHTeet0TQSy4yEoMxGTHsfk8Ykc2B0JDheWH5zhhZBdozmV5TFbM50PXjLqfqWVDD+WqzGVer1Sokfv6MMERoWKvb/LEyKO4Eq3aHgXyy2GoRQHfUh9qOOvBnNpHbtacL+NzfggLZ1Ut97QIbEoWb3VPx6lbNKxiiC4DbwR7nnc92zNJM5YU6Dog= - secure: SSqm3fI2slK6qcmfeRiWvQJ8kNd5VQD6wSkFM5NMCo7Uvo3peNNwCDiTpWMN6nNuM4LSJJhgGwDLZeIlRF4i74xgWpDznjZ4AoqgG1QeIjg/4Xdy+szz0+BiTdUhQnRsaKHfUoky4wm+Jrix1rYgz/eED6uiOHmgLWywD4+BEBHN37N5N6/vT7ELkxi/jzXWOunMA12Y6F+LFcw4A87qM94iFws94C0BEqfWRqaXYPZoQ7v5Yw7TilJuPGiL6pcdWyh5ObfAhIbHhhxmIvaMFWV7HGoB1rC2T/E/GQynKU/l1uQHTf/rNK70uUTCKz3usl28AnVsnyhjg7+Ivk22Z0pSnZtLw1TJT5prPdX+Cas8NEElk6zSS/h3lMmQuGZk8T6FmsqkDx3tkFiJqgxvbgGLZBMgYdm87OCzrM55ZTlxBOYErQQgFrevJ2oJV98Pb4DNCPx5uu/CVCbR+d1kZ6b91rabzjl+a3yiz10vnaO00dyW1gR1P0KHZiRactdds2jLsxBhr3MFDymZD7W+WhuI4RtP2/bsQQ1dnLIvWm+JYmDvr09/7k1uX7WCm9AkMb0u1gW19WYQT1Qct3hFfvKIbgv3gTNJz2+Alu3mqeIpSkmtdtGjVMij3/0OBdYBNC+BfaR4IQVnIbvyu0HmjtJgRji2TO/U7rCUKjOrm6c= + - MAVEN_OPTS="-XX:MaxPermSize=2g -Xmx4g" + - JAVA_OPTS="-XX:MaxPermSize=2g -Xmx4g" branches: only: - master - "/^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+/" - # build steps before_install: - sudo apt-get install libaio1 - script: mvn verify + install: true + script: mvn clean verify after_success: - test "${TRAVIS_PULL_REQUEST}" == "false" && test "${TRAVIS_TAG}" != "" && mvn deploy --settings travis/settings.xml # before_deploy: cat travis/bintray_template.json | sed s/\$\{TRAVIS_TAG\}/${TRAVIS_TAG}/g > travis/release.json diff --git a/elide-core/pom.xml b/elide-core/pom.xml index c7980b0767..2fa9074a99 100644 --- a/elide-core/pom.xml +++ b/elide-core/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-core jar - Elide Core + Elide: Core Elide Core https://github.com/yahoo/elide @@ -25,6 +25,11 @@ + + Yahoo! Inc. + http://www.yahoo.com + + Yahoo Inc. @@ -38,11 +43,6 @@ HEAD - - 2.4.0-b32 - 1.1.3 - - org.projectlombok @@ -52,11 +52,6 @@ com.google.guava guava - - org.glassfish.hk2 - hk2-api - ${version.hk2} - org.antlr antlr4-runtime @@ -118,13 +113,11 @@ ch.qos.logback logback-classic - ${version.logback} test ch.qos.logback logback-core - ${version.logback} test @@ -150,7 +143,6 @@ org.codehaus.groovy groovy-all - ${groovy.version} test @@ -186,18 +178,6 @@ org.apache.maven.plugins maven-checkstyle-plugin - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - org.codehaus.gmaven gmaven-plugin @@ -215,8 +195,4 @@ - - Yahoo! Inc. - http://www.yahoo.com/ - diff --git a/elide-core/src/main/java/com/yahoo/elide/utils/coerce/converters/FromMapConverter.java b/elide-core/src/main/java/com/yahoo/elide/utils/coerce/converters/FromMapConverter.java index 260698c8b1..9186fc24b2 100644 --- a/elide-core/src/main/java/com/yahoo/elide/utils/coerce/converters/FromMapConverter.java +++ b/elide-core/src/main/java/com/yahoo/elide/utils/coerce/converters/FromMapConverter.java @@ -9,11 +9,12 @@ import org.apache.commons.beanutils.Converter; /** - * Uses Jackson to Convert from Map to target object + * Uses Jackson to Convert from Map to target object. */ public class FromMapConverter implements Converter { /** - * Convert value to Enum + * Convert value to Enum. + * * @param cls class to convert to * @param value value to convert * @param diff --git a/elide-datastore/elide-datastore-hibernate/pom.xml b/elide-datastore/elide-datastore-hibernate/pom.xml index e10f13de32..351040a8a8 100644 --- a/elide-datastore/elide-datastore-hibernate/pom.xml +++ b/elide-datastore/elide-datastore-hibernate/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-datastore-hibernate jar - Elide Hibernate Common + Elide Data Store: Hibernate Common Common files for Elide Data Store Hibernate3 and Hibernate5 https://github.com/yahoo/elide @@ -70,22 +70,10 @@ - - org.apache.maven.plugins - maven-compiler-plugin - org.apache.maven.plugins maven-checkstyle-plugin - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - diff --git a/elide-datastore/elide-datastore-hibernate/src/main/java/com/yahoo/elide/core/filter/HQLFilterOperation.java b/elide-datastore/elide-datastore-hibernate/src/main/java/com/yahoo/elide/core/filter/HQLFilterOperation.java index ccfcfb551c..197d8a86db 100644 --- a/elide-datastore/elide-datastore-hibernate/src/main/java/com/yahoo/elide/core/filter/HQLFilterOperation.java +++ b/elide-datastore/elide-datastore-hibernate/src/main/java/com/yahoo/elide/core/filter/HQLFilterOperation.java @@ -10,7 +10,7 @@ import java.util.Set; /** - * FilterOperation that creates Hibernate query language fragments + * FilterOperation that creates Hibernate query language fragments. */ public class HQLFilterOperation implements FilterOperation { @Override diff --git a/elide-datastore/elide-datastore-hibernate3/README.md b/elide-datastore/elide-datastore-hibernate3/README.md index 58d5a35c85..61c6b65891 100644 --- a/elide-datastore/elide-datastore-hibernate3/README.md +++ b/elide-datastore/elide-datastore-hibernate3/README.md @@ -2,4 +2,3 @@ elide-datastore-hibernate3 ========================== [![Dependency Status](https://www.versioneye.com/user/projects/5621504036d0ab0019000901/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5621504036d0ab0019000901) - diff --git a/elide-datastore/elide-datastore-hibernate3/pom.xml b/elide-datastore/elide-datastore-hibernate3/pom.xml index 5180db8b5b..9557d03c7f 100644 --- a/elide-datastore/elide-datastore-hibernate3/pom.xml +++ b/elide-datastore/elide-datastore-hibernate3/pom.xml @@ -8,8 +8,8 @@ 4.0.0 elide-datastore-hibernate3 jar - Elide Hibernate3 Data Store - Elide Data Store for Hibernate3 support + Elide Data Store: Hibernate 3 + Elide Data Store for Hibernate 3 support https://github.com/yahoo/elide com.yahoo.elide @@ -56,17 +56,19 @@ com.yahoo.elide elide-datastore-hibernate - 1.0.0.9-SNAPSHOT + 1.0.0.10-SNAPSHOT test-jar test com.yahoo.elide elide-integration-tests - 1.0.0.9-SNAPSHOT + 1.0.0.10-SNAPSHOT test-jar test + + org.hibernate hibernate-core @@ -101,7 +103,7 @@ 2.6.3 - + org.testng testng @@ -156,22 +158,10 @@ org.apache.maven.plugins maven-surefire-plugin - - org.apache.maven.plugins - maven-compiler-plugin - org.apache.maven.plugins maven-checkstyle-plugin - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - diff --git a/elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/HibernateDataStoreSupplier.java b/elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/HibernateDataStoreSupplier.java index 31ffe0b5d9..a03090fecb 100644 --- a/elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/HibernateDataStoreSupplier.java +++ b/elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/HibernateDataStoreSupplier.java @@ -14,26 +14,25 @@ import org.hibernate.cfg.Environment; import org.hibernate.tool.hbm2ddl.SchemaExport; -import java.util.function.Supplier; - import javax.persistence.Entity; +import java.util.function.Supplier; /** - * Supplier of Hibernate5 Data Store. + * Supplier of Hibernate 3 Data Store. */ public class HibernateDataStoreSupplier implements Supplier { @Override public DataStore get() { // method to force class initialization - Configuration c = new Configuration(); - + Configuration configuration = new Configuration(); try { - ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class).forEach(c::addAnnotatedClass); + ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class) + .forEach(configuration::addAnnotatedClass); } catch (MappingException e) { throw new RuntimeException(e); } - SessionFactory sessionFactory = c.configure("hibernate.cfg.xml") + SessionFactory sessionFactory = configuration.configure("hibernate.cfg.xml") .setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread") .setProperty(Environment.URL, "jdbc:mysql://localhost:" + System.getProperty("mysql.port", "3306") + "/root") @@ -41,13 +40,13 @@ public DataStore get() { .setProperty(Environment.PASS, "root") .buildSessionFactory(); - // create Example tables from beans - SchemaExport se = new SchemaExport(c).setHaltOnError(true); - se.drop(false, true); - se.execute(false, true, false, true); + // create example tables from beans + SchemaExport schemaExport = new SchemaExport(configuration).setHaltOnError(true); + schemaExport.drop(false, true); + schemaExport.execute(false, true, false, true); - if (se.getExceptions().size() != 0) { - throw new RuntimeException("" + se.getExceptions()); + if (!schemaExport.getExceptions().isEmpty()) { + throw new RuntimeException("" + schemaExport.getExceptions()); } return new HibernateStore(sessionFactory); diff --git a/elide-integration-tests/src/test/java-hibernate3/usertypes/JsonType.java b/elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/usertypes/JsonType.java similarity index 98% rename from elide-integration-tests/src/test/java-hibernate3/usertypes/JsonType.java rename to elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/usertypes/JsonType.java index 3e5283e827..30595ed69b 100644 --- a/elide-integration-tests/src/test/java-hibernate3/usertypes/JsonType.java +++ b/elide-datastore/elide-datastore-hibernate3/src/test/java/com/yahoo/elide/datastores/hibernate3/usertypes/JsonType.java @@ -4,7 +4,7 @@ * See LICENSE file in project root for terms. */ -package usertypes; +package com.yahoo.elide.datastores.hibernate3.usertypes; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,7 +21,6 @@ import java.util.Objects; import java.util.Properties; - /** * JsonType serializes an object to json string and vice versa */ diff --git a/elide-integration-tests/src/test/java/example/AddressFragment.java b/elide-datastore/elide-datastore-hibernate3/src/test/java/example/AddressFragment.java similarity index 87% rename from elide-integration-tests/src/test/java/example/AddressFragment.java rename to elide-datastore/elide-datastore-hibernate3/src/test/java/example/AddressFragment.java index 1ce96ba13d..9c3c9e4a6e 100644 --- a/elide-integration-tests/src/test/java/example/AddressFragment.java +++ b/elide-datastore/elide-datastore-hibernate3/src/test/java/example/AddressFragment.java @@ -5,8 +5,8 @@ */ package example; +import com.yahoo.elide.datastores.hibernate3.usertypes.JsonType; import org.hibernate.annotations.TypeDef; -import usertypes.JsonType; @TypeDef(typeClass = JsonType.class, name = "json") public class AddressFragment { diff --git a/elide-integration-tests/src/test/java/example/Person.java b/elide-datastore/elide-datastore-hibernate3/src/test/java/example/Person.java similarity index 90% rename from elide-integration-tests/src/test/java/example/Person.java rename to elide-datastore/elide-datastore-hibernate3/src/test/java/example/Person.java index 078ce33d38..fe4c14182c 100644 --- a/elide-integration-tests/src/test/java/example/Person.java +++ b/elide-datastore/elide-datastore-hibernate3/src/test/java/example/Person.java @@ -15,7 +15,6 @@ import javax.persistence.Entity; import javax.persistence.Id; - @Entity @Include(rootLevel = true) public class Person { @@ -35,7 +34,7 @@ public long getId() { } @Column(name = "address", columnDefinition = "TEXT") - @Type(type = "usertypes.JsonType", parameters = { + @Type(type = "com.yahoo.elide.datastores.hibernate3.usertypes.JsonType", parameters = { @Parameter(name = "class", value = "example.AddressFragment") }) public AddressFragment getAddress() { diff --git a/elide-datastore/elide-datastore-hibernate3/testng.xml b/elide-datastore/elide-datastore-hibernate3/testng.xml deleted file mode 100644 index 9638b25bd3..0000000000 --- a/elide-datastore/elide-datastore-hibernate3/testng.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/elide-datastore/elide-datastore-hibernate5/pom.xml b/elide-datastore/elide-datastore-hibernate5/pom.xml index 1c15cf3c13..90c95ab9aa 100644 --- a/elide-datastore/elide-datastore-hibernate5/pom.xml +++ b/elide-datastore/elide-datastore-hibernate5/pom.xml @@ -8,8 +8,8 @@ 4.0.0 elide-datastore-hibernate5 jar - Elide Hibernate5 Data Store - Elide Data Store for Hibernate5 support + Elide Data Store: Hibernate 5 + Elide Data Store for Hibernate 5 support https://github.com/yahoo/elide com.yahoo.elide @@ -38,7 +38,12 @@ HEAD + + com.yahoo.elide.datastores.hibernate5.HibernateDataStoreSupplier + + + com.yahoo.elide elide-core @@ -48,13 +53,22 @@ elide-datastore-hibernate 1.0.0.10-SNAPSHOT + + com.yahoo.elide + elide-datastore-hibernate + 1.0.0.10-SNAPSHOT + test-jar + test + com.yahoo.elide elide-integration-tests - 1.0.0.9-SNAPSHOT + 1.0.0.10-SNAPSHOT test-jar test + + org.hibernate hibernate-core @@ -88,27 +102,65 @@ jackson-datatype-hibernate5 2.6.3 - + + org.testng testng test + + com.jayway.restassured + rest-assured + test + + + org.glassfish.jersey.containers + jersey-container-servlet + test + + + org.hibernate + hibernate-validator + test + + + mysql + mysql-connector-java + test + + + org.eclipse.jetty + jetty-webapp + test + + + org.codehaus.mojo + build-helper-maven-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + + + com.jcabi + jcabi-mysql-maven-plugin + org.apache.maven.plugins - maven-compiler-plugin + maven-failsafe-plugin org.apache.maven.plugins - maven-source-plugin + maven-surefire-plugin org.apache.maven.plugins - maven-javadoc-plugin + maven-checkstyle-plugin diff --git a/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/PersistenceStore.java b/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/PersistenceStore.java index 89faa8d943..96a5e2e77d 100644 --- a/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/PersistenceStore.java +++ b/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/PersistenceStore.java @@ -1,3 +1,8 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ package com.yahoo.elide.datastores.hibernate5; import com.google.common.base.Preconditions; @@ -13,7 +18,7 @@ import java.io.Serializable; /** - * Manager for javax.persistence compatible db resource + * Manager for javax.persistence compatible db resource. */ public class PersistenceStore implements DataStore { private final EntityManagerFactory entityManagerFactory; @@ -35,6 +40,9 @@ public DataStoreTransaction beginTransaction() { return new PersistenceTransaction(entityManagerFactory.createEntityManager()); } + /** + * The type Persistence transaction. + */ public class PersistenceTransaction implements DataStoreTransaction { private final EntityManager entityManager; diff --git a/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/security/CriteriaCheck.java b/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/security/CriteriaCheck.java index ecafebd578..d8e2e4f171 100644 --- a/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/security/CriteriaCheck.java +++ b/elide-datastore/elide-datastore-hibernate5/src/main/java/com/yahoo/elide/datastores/hibernate5/security/CriteriaCheck.java @@ -12,10 +12,15 @@ /** * Extends Check to support Hibernate Criteria to limit SQL query responses. + * * @param Type of record for Check */ public interface CriteriaCheck extends Check { /** + * Gets criterion. + * + * @param requestScope the request scope + * @return the criterion * @see org.hibernate.criterion.Restrictions */ Criterion getCriterion(RequestScope requestScope); diff --git a/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/Hibernate5DataStoreSupplier.java b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateDataStoreSupplier.java similarity index 65% rename from elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/Hibernate5DataStoreSupplier.java rename to elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateDataStoreSupplier.java index d9855afeb4..20337537ee 100644 --- a/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/Hibernate5DataStoreSupplier.java +++ b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateDataStoreSupplier.java @@ -15,18 +15,17 @@ import org.hibernate.cfg.Environment; import org.hibernate.tool.hbm2ddl.SchemaExport; -import java.util.function.Supplier; - import javax.persistence.Entity; +import java.util.function.Supplier; /** - * Supplier of Hibernate5 Data Store. + * Supplier of Hibernate 5 Data Store. */ -public class Hibernate5DataStoreSupplier implements Supplier { +public class HibernateDataStoreSupplier implements Supplier { @Override public DataStore get() { // method to force class initialization - MetadataSources metadata = new MetadataSources( + MetadataSources metadataSources = new MetadataSources( new StandardServiceRegistryBuilder() .configure("hibernate.cfg.xml") .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread") @@ -38,22 +37,22 @@ public DataStore get() { try { ClassScanner.getAnnotatedClasses(Parent.class.getPackage(), Entity.class) - .forEach(metadata::addAnnotatedClass); + .forEach(metadataSources::addAnnotatedClass); } catch (MappingException e) { throw new RuntimeException(e); } - MetadataImplementor metadataImpl = (MetadataImplementor) metadata.buildMetadata(); + MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata(); - // create Example tables from beans - SchemaExport export = new SchemaExport(metadataImpl); //.setHaltOnError(true); - export.drop(false, true); - export.execute(false, true, false, true); + // create example tables from beans + SchemaExport schemaExport = new SchemaExport(metadataImplementor); //.setHaltOnError(true); + schemaExport.drop(false, true); + schemaExport.execute(false, true, false, true); - if (export.getExceptions().size() != 0) { - throw new RuntimeException("" + export.getExceptions()); + if (!schemaExport.getExceptions().isEmpty()) { + throw new RuntimeException("" + schemaExport.getExceptions()); } - return new HibernateStore(metadataImpl.buildSessionFactory()); + return new HibernateStore(metadataImplementor.buildSessionFactory()); } } diff --git a/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateStoreTest.java b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateStoreTest.java deleted file mode 100644 index 2485820c81..0000000000 --- a/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/HibernateStoreTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.yahoo.elide.datastores.hibernate5; - -import org.testng.annotations.Test; - -public class HibernateStoreTest { - // TODO: Create tests for our manager - @Test - public void todo() { - System.err.println("Still need to write tests for hibernate3 manager!"); - } -} diff --git a/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/tests/FilteredIT.java b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/tests/FilteredIT.java new file mode 100644 index 0000000000..c87c068065 --- /dev/null +++ b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/tests/FilteredIT.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package com.yahoo.elide.datastores.hibernate5.tests; + +import com.yahoo.elide.core.DataStoreTransaction; +import com.yahoo.elide.initialization.AbstractIntegrationTestInitializer; +import com.yahoo.elide.utils.JsonParser; +import example.Filtered; +import org.apache.http.HttpStatus; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import static com.jayway.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +public class FilteredIT extends AbstractIntegrationTestInitializer { + private final JsonParser jsonParser = new JsonParser(); + + @BeforeTest + public static void setup() { + DataStoreTransaction tx = dataStore.beginTransaction(); + + tx.save(tx.createObject(Filtered.class)); + tx.save(tx.createObject(Filtered.class)); + tx.save(tx.createObject(Filtered.class)); + + tx.commit(); + } + + @Test + public void testFiltered() throws Exception { + String expected = jsonParser.getJson("/ResourceIT/testFiltered.json"); + + given().when().get("/filtered").then().statusCode(HttpStatus.SC_OK) + .body(equalTo(expected)); + } +} diff --git a/elide-integration-tests/src/test/java-hibernate5/usertypes/JsonType.java b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/usertypes/JsonType.java similarity index 98% rename from elide-integration-tests/src/test/java-hibernate5/usertypes/JsonType.java rename to elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/usertypes/JsonType.java index 56561a336c..a6a4bcf65b 100644 --- a/elide-integration-tests/src/test/java-hibernate5/usertypes/JsonType.java +++ b/elide-datastore/elide-datastore-hibernate5/src/test/java/com/yahoo/elide/datastores/hibernate5/usertypes/JsonType.java @@ -4,7 +4,7 @@ * See LICENSE file in project root for terms. */ -package usertypes; +package com.yahoo.elide.datastores.hibernate5.usertypes; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -22,7 +22,6 @@ import java.util.Objects; import java.util.Properties; - /** * JsonType serializes an object to json string and vice versa */ diff --git a/elide-datastore/elide-datastore-hibernate5/src/test/java/example/AddressFragment.java b/elide-datastore/elide-datastore-hibernate5/src/test/java/example/AddressFragment.java new file mode 100644 index 0000000000..c4e8e2b288 --- /dev/null +++ b/elide-datastore/elide-datastore-hibernate5/src/test/java/example/AddressFragment.java @@ -0,0 +1,21 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package example; + +import com.yahoo.elide.datastores.hibernate5.usertypes.JsonType; +import org.hibernate.annotations.TypeDef; + +@TypeDef(typeClass = JsonType.class, name = "json") +public class AddressFragment { + public String street; + public String state; + public ZipCode zip; + + public class ZipCode { + public String zip; + public String plusFour; + } +} diff --git a/elide-datastore/elide-datastore-hibernate5/src/test/java/example/Person.java b/elide-datastore/elide-datastore-hibernate5/src/test/java/example/Person.java new file mode 100644 index 0000000000..11d33e26d0 --- /dev/null +++ b/elide-datastore/elide-datastore-hibernate5/src/test/java/example/Person.java @@ -0,0 +1,43 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package example; + +import com.yahoo.elide.annotation.Include; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.Type; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +@Include(rootLevel = true) +public class Person { + @Setter + private long id; + + @Setter + @Getter + private String name; + + @Setter + private AddressFragment address; + + @Id + public long getId() { + return id; + } + + @Column(name = "address", columnDefinition = "TEXT") + @Type(type = "com.yahoo.elide.datastores.hibernate5.usertypes.JsonType", parameters = { + @Parameter(name = "class", value = "example.AddressFragment") + }) + public AddressFragment getAddress() { + return address; + } +} diff --git a/elide-datastore/elide-datastore-inmemorydb/README.md b/elide-datastore/elide-datastore-inmemorydb/README.md index 6f73310ca9..c73f9b2537 100644 --- a/elide-datastore/elide-datastore-inmemorydb/README.md +++ b/elide-datastore/elide-datastore-inmemorydb/README.md @@ -2,4 +2,3 @@ elide-datastore-inmemorydb ========================== [![Dependency Status](https://www.versioneye.com/user/projects/5621504136d0ab0021000a1e/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5621504136d0ab0021000a1e) - diff --git a/elide-datastore/elide-datastore-inmemorydb/pom.xml b/elide-datastore/elide-datastore-inmemorydb/pom.xml index 97cf04bc16..951ce3c8b6 100644 --- a/elide-datastore/elide-datastore-inmemorydb/pom.xml +++ b/elide-datastore/elide-datastore-inmemorydb/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-datastore-inmemorydb jar - Elide In-Memory Data Store + Elide Data Store: In-Memory Elide data store for a demonstrative in-memory datastore support https://github.com/yahoo/elide @@ -46,7 +46,7 @@ com.yahoo.elide elide-integration-tests - 1.0.0.9-SNAPSHOT + 1.0.0.10-SNAPSHOT test-jar test @@ -86,22 +86,10 @@ - - org.apache.maven.plugins - maven-compiler-plugin - org.apache.maven.plugins maven-checkstyle-plugin - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - diff --git a/elide-datastore/elide-datastore-multiplex/pom.xml b/elide-datastore/elide-datastore-multiplex/pom.xml index 4a59d5fb0b..a6ec1faa6a 100644 --- a/elide-datastore/elide-datastore-multiplex/pom.xml +++ b/elide-datastore/elide-datastore-multiplex/pom.xml @@ -4,8 +4,8 @@ 4.0.0 elide-datastore-multiplex jar - Elide Multiplex Database Manager - Elide entity manager for multiple database support + Elide Data Store: Multiplex Library + Elide entity manager for multiple data store support https://github.com/yahoo/elide com.yahoo.elide @@ -34,15 +34,18 @@ HEAD - - 1.1.3 - - + com.yahoo.elide elide-core + + com.yahoo.elide + elide-datastore-inmemorydb + 1.0.0.10-SNAPSHOT + test + javax.persistence @@ -61,44 +64,24 @@ mockito-core test - - com.yahoo.elide - elide-datastore-inmemorydb - 1.0.0.10-SNAPSHOT - test - ch.qos.logback logback-classic - ${version.logback} test ch.qos.logback logback-core - ${version.logback} test - - org.apache.maven.plugins - maven-compiler-plugin - org.apache.maven.plugins maven-checkstyle-plugin - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - diff --git a/elide-datastore/pom.xml b/elide-datastore/pom.xml index 51c27d6323..4f2bd740c2 100644 --- a/elide-datastore/pom.xml +++ b/elide-datastore/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-datastore-parent-pom pom - Elide Data Store Parent Pom + Elide Data Store: Parent Pom Parent pom for data stores https://github.com/yahoo/elide @@ -40,7 +40,6 @@ ${project.basedir}/../.. - 2.7.0 ${project.build.directory}/mysql-data @@ -59,12 +58,6 @@ elide-core 1.0.0.10-SNAPSHOT - - com.jayway.restassured - rest-assured - ${version.restassured} - test - org.hibernate hibernate-validator @@ -185,7 +178,7 @@ ${dataStoreSupplier} - testng.xml + ${project.basedir}/../testng.xml diff --git a/elide-datastore/testng.xml b/elide-datastore/testng.xml new file mode 100644 index 0000000000..20c68146bc --- /dev/null +++ b/elide-datastore/testng.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/elide-example/elide-hibernate3-mysql-example/pom.xml b/elide-example/elide-hibernate3-mysql-example/pom.xml index 3ff065cc47..0fe847117b 100644 --- a/elide-example/elide-hibernate3-mysql-example/pom.xml +++ b/elide-example/elide-hibernate3-mysql-example/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-hibernate3-mysql-example jar - Elide Hibernate 3 MySQL Example + Elide Example: Hibernate 3 API with MySQL Elide example using Hibernate 3 and MySQL com.yahoo.elide @@ -17,38 +17,30 @@ - 1.0.0.10-SNAPSHOT - 9.3.5.v20151012 - 1.7.12 - 2.3 - 1.8 - ${project.build.directory}/mysql-data - + com.yahoo.elide elide-core - ${version.elide} + 1.0.0.10-SNAPSHOT com.yahoo.elide elide-datastore-hibernate3 - ${version.elide} + 1.0.0.10-SNAPSHOT org.eclipse.jetty jetty-server - ${version.jetty} org.eclipse.jetty jetty-servlet - ${version.jetty} @@ -61,21 +53,18 @@ jersey-container-jetty-servlet RELEASE - + org.slf4j slf4j-api - ${version.slf4j} org.apache.logging.log4j log4j-slf4j-impl - ${version.log4j} org.apache.logging.log4j log4j-core - ${version.log4j} @@ -109,16 +98,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - ${version.jdk} - ${version.jdk} - ${version.jdk} - - org.apache.maven.plugins maven-jar-plugin diff --git a/elide-example/elide-persistence-mysql-example/pom.xml b/elide-example/elide-persistence-mysql-example/pom.xml index 1357495a7e..f46387efcb 100644 --- a/elide-example/elide-persistence-mysql-example/pom.xml +++ b/elide-example/elide-persistence-mysql-example/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-persistence-mysql-example jar - Elide Persistence MySQL Example + Elide Example: Persistence API with MySQL Elide example using javax.persistence and MySQL com.yahoo.elide @@ -17,18 +17,11 @@ - 1.0.0.10-SNAPSHOT - 9.3.5.v20151012 - 1.7.12 - 2.3 - 1.8 - - 2.4.1 ${project.build.directory}/mysql-data - + com.yahoo.elide elide-core @@ -37,19 +30,17 @@ com.yahoo.elide elide-datastore-hibernate5 - ${version.elide} + 1.0.0.10-SNAPSHOT org.eclipse.jetty jetty-server - ${version.jetty} org.eclipse.jetty jetty-servlet - ${version.jetty} @@ -62,21 +53,18 @@ jersey-container-jetty-servlet RELEASE - + org.slf4j slf4j-api - ${version.slf4j} org.apache.logging.log4j log4j-slf4j-impl - ${version.log4j} org.apache.logging.log4j log4j-core - ${version.log4j} @@ -111,39 +99,17 @@ com.jayway.restassured rest-assured - ${version.restassured} test com.jayway.restassured json-schema-validator - ${version.restassured} test - - - jackson-databind - com.fasterxml.jackson.core - - - jsr305 - com.google.code.findbugs - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - ${version.jdk} - ${version.jdk} - ${version.jdk} - - org.apache.maven.plugins maven-jar-plugin diff --git a/elide-example/pom.xml b/elide-example/pom.xml index 9fdfdc8ec5..38ed2574a1 100644 --- a/elide-example/pom.xml +++ b/elide-example/pom.xml @@ -8,7 +8,7 @@ 4.0.0 elide-example-parent-pom pom - Elide Example Parent Pom + Elide Example: Parent Pom Parent pom for various examples of Elide use https://github.com/yahoo/elide @@ -40,6 +40,7 @@ ${project.basedir}/../.. + 2.4.1 @@ -49,6 +50,16 @@ elide-core 1.0.0.10-SNAPSHOT + + org.apache.logging.log4j + log4j-slf4j-impl + ${version.log4j} + + + org.apache.logging.log4j + log4j-core + ${version.log4j} + diff --git a/elide-integration-tests/pom.xml b/elide-integration-tests/pom.xml index e9def373ec..e1b2f93370 100644 --- a/elide-integration-tests/pom.xml +++ b/elide-integration-tests/pom.xml @@ -8,8 +8,8 @@ 4.0.0 elide-integration-tests jar - Elide Integration Tests - Integration test suite for Elide + Elide: Integration Test Library + Integration tests to be executed with each data store com.yahoo.elide elide-parent-pom @@ -24,11 +24,6 @@ - - 1.1.3 - 2.7.0 - - @@ -36,11 +31,6 @@ elide-core 1.0.0.10-SNAPSHOT - - - - - org.projectlombok @@ -99,24 +89,12 @@ com.jayway.restassured rest-assured - ${version.restassured} test com.jayway.restassured json-schema-validator - ${version.restassured} test - - - jackson-databind - com.fasterxml.jackson.core - - - jsr305 - com.google.code.findbugs - - @@ -128,13 +106,11 @@ ch.qos.logback logback-classic - ${version.logback} test ch.qos.logback logback-core - ${version.logback} test @@ -146,7 +122,6 @@ org.codehaus.groovy groovy-all - ${groovy.version} test @@ -167,10 +142,6 @@ org.apache.maven.plugins maven-surefire-plugin - - org.apache.maven.plugins - maven-compiler-plugin - org.apache.maven.plugins diff --git a/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/FilterIT.groovy b/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/FilterIT.groovy new file mode 100644 index 0000000000..826c6f5ca6 --- /dev/null +++ b/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/FilterIT.groovy @@ -0,0 +1,702 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package com.yahoo.elide.tests +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.jayway.restassured.RestAssured +import com.yahoo.elide.core.HttpStatus +import com.yahoo.elide.initialization.AbstractIntegrationTestInitializer +import org.testng.Assert +import org.testng.annotations.BeforeTest +import org.testng.annotations.Test +/** + * Tests for Filters + */ +class FilterIT extends AbstractIntegrationTestInitializer { + private final ObjectMapper mapper = new ObjectMapper() + + private JsonNode books = null + private JsonNode authors = null + private String asimovId = null + private JsonNode asimovBooks = null + private String nullNedId = null + private JsonNode nullNedBooks = null + + @BeforeTest + public void setup() { + RestAssured + .given() + .contentType("application/vnd.api+json; ext=jsonpatch") + .accept("application/vnd.api+json; ext=jsonpatch") + .body(''' + [ + { + "op": "add", + "path": "/author", + "value": { + "id": "12345678-1234-1234-1234-1234567890ab", + "type": "author", + "attributes": { + "name": "Ernest Hemingway" + }, + "relationships": { + "books": { + "data": [ + { + "type": "book", + "id": "12345678-1234-1234-1234-1234567890ac" + }, + { + "type": "book", + "id": "12345678-1234-1234-1234-1234567890ad" + } + ] + } + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345678-1234-1234-1234-1234567890ac", + "attributes": { + "title": "The Old Man and the Sea", + "genre": "Literary Fiction", + "language": "English" + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345678-1234-1234-1234-1234567890ad", + "attributes": { + "title": "For Whom the Bell Tolls", + "genre": "Literary Fiction", + "language": "English" + } + } + } + ] + ''') + .patch("/") + + RestAssured + .given() + .contentType("application/vnd.api+json; ext=jsonpatch") + .accept("application/vnd.api+json; ext=jsonpatch") + .body(''' + [ + { + "op": "add", + "path": "/author", + "value": { + "id": "12345679-1234-1234-1234-1234567890ab", + "type": "author", + "attributes": { + "name": "Orson Scott Card" + }, + "relationships": { + "books": { + "data": [ + { + "type": "book", + "id": "12345679-1234-1234-1234-1234567890ac" + } + ] + } + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345679-1234-1234-1234-1234567890ac", + "attributes": { + "title": "Enders Game", + "genre": "Science Fiction", + "language": "English" + } + } + } + ] + ''') + .patch("/") + + RestAssured + .given() + .contentType("application/vnd.api+json; ext=jsonpatch") + .accept("application/vnd.api+json; ext=jsonpatch") + .body(''' + [ + { + "op": "add", + "path": "/author", + "value": { + "id": "12345680-1234-1234-1234-1234567890ab", + "type": "author", + "attributes": { + "name": "Isaac Asimov" + }, + "relationships": { + "books": { + "data": [ + { + "type": "book", + "id": "12345680-1234-1234-1234-1234567890ac" + }, + { + "type": "book", + "id": "12345680-1234-1234-1234-1234567890ad" + } + ] + } + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345680-1234-1234-1234-1234567890ac", + "attributes": { + "title": "Foundation", + "genre": "Science Fiction", + "language": "English" + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345680-1234-1234-1234-1234567890ad", + "attributes": { + "title": "The Roman Republic", + "genre": "History", + "language": "English" + } + } + } + ] + ''') + .patch("/") + + RestAssured + .given() + .contentType("application/vnd.api+json; ext=jsonpatch") + .accept("application/vnd.api+json; ext=jsonpatch") + .body(''' + [ + { + "op": "add", + "path": "/author", + "value": { + "id": "12345681-1234-1234-1234-1234567890ab", + "type": "author", + "attributes": { + "name": "Null Ned" + }, + "relationships": { + "books": { + "data": [ + { + "type": "book", + "id": "12345681-1234-1234-1234-1234567890ac" + }, + { + "type": "book", + "id": "12345681-1234-1234-1234-1234567890ad" + } + ] + } + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345681-1234-1234-1234-1234567890ac", + "attributes": { + "title": "Life with Null Ned", + "language": "English" + } + } + }, + { + "op": "add", + "path": "/book", + "value": { + "type": "book", + "id": "12345681-1234-1234-1234-1234567890ad", + "attributes": { + "title": "Life with Null Ned 2", + "genre": "Not Null", + "language": "English" + } + } + } + ] + ''') + .patch("/") + + books = mapper.readTree(RestAssured.get("/book").asString()) + authors = mapper.readTree(RestAssured.get("/author").asString()) + + for (JsonNode author : authors.get("data")) { + if (author.get("attributes").get("name").asText() == "Isaac Asimov") { + asimovId = author.get("id").asText() + } + + if (author.get("attributes").get("name").asText() == "Null Ned") { + nullNedId = author.get("id").asText() + } + } + + Assert.assertNotNull(asimovId) + Assert.assertNotNull(nullNedId) + + asimovBooks = mapper.readTree(RestAssured.get("/author/${asimovId}/books").asString()) + nullNedBooks = mapper.readTree(RestAssured.get("/author/${nullNedId}/books").asString()) + } + + @Test + public void testRootFilterInvalidField() { + RestAssured + .get("/book?filter[book.name]=Ignored") + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST) + } + + @Test + public void testRootFilterInvalidEntity() { + RestAssured + .get("/book?filter[bank.title]=Ignored") + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST) + } + + @Test + public void testRootInvalidOperator() { + RestAssured + .get("/book?filter[bank.title][invalid]=Ignored") + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST) + } + + @Test + public void testFilterInvalidField() { + RestAssured + .get("/author/3/book?filter[book.name]=Ignored") + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST) + } + + @Test + public void testFilterInvalidEntity() { + RestAssured + .get("/author/3/book?filter[bank.title]=Ignored") + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST) + } + + @Test + public void testInvalidOperator() { + RestAssured + .get("/author/3/book?filter[book.title][invalid]=Ignored") + .then() + .statusCode(HttpStatus.SC_BAD_REQUEST) + } + + @Test + public void testRootFilterImplicitSingle() { + int scienceFictionBookCount = 0 + for (JsonNode node : books.get("data")) { + if (node.get("attributes").get("genre").asText().equals("Science Fiction")) { + scienceFictionBookCount += 1 + } + } + + Assert.assertTrue(scienceFictionBookCount > 0) + + def scienceFictionBooks = mapper.readTree( + RestAssured.get("/book?filter[book.genre]=Science Fiction").asString()) + + Assert.assertEquals(scienceFictionBookCount, scienceFictionBooks.get("data").size()) + } + + @Test + public void testRootFilterInSingle() { + int literaryFictionBookCount = 0 + for (JsonNode node : books.get("data")) { + if (node.get("attributes").get("genre").asText().equals("Literary Fiction")) { + literaryFictionBookCount += 1 + } + } + + Assert.assertTrue(literaryFictionBookCount > 0) + + def literaryFictionBooks = mapper.readTree( + RestAssured.get("/book?filter[book.genre][in]=Literary Fiction").asString()) + + Assert.assertEquals(literaryFictionBookCount, literaryFictionBooks.get("data").size()) + } + + @Test + public void testRootFilterNotInSingle() { + int nonLiteraryFictionBookCount = 0 + for (JsonNode node : books.get("data")) { + if (!node.get("attributes").get("genre").isNull() + && !node.get("attributes").get("genre").asText().equals("Literary Fiction")) { + nonLiteraryFictionBookCount += 1 + } + } + + Assert.assertTrue(nonLiteraryFictionBookCount > 0) + + def nonLiteraryFictionBooks = mapper.readTree( + RestAssured.get("/book?filter[book.genre][not]=Literary Fiction").asString()) + + Assert.assertEquals(nonLiteraryFictionBookCount, nonLiteraryFictionBooks.get("data").size()) + } + + @Test + public void testRootFilterNotInMultiple() { + int nonFictionBookCount = 0 + for (JsonNode node : books.get("data")) { + if (!node.get("attributes").get("genre").isNull() + && !node.get("attributes").get("genre").asText().equals("Literary Fiction") + && !node.get("attributes").get("genre").asText().equals("Science Fiction")) { + nonFictionBookCount += 1 + } + } + + Assert.assertTrue(nonFictionBookCount > 0) + + def nonFictionBooks = mapper.readTree( + RestAssured.get("/book?filter[book.genre][not]=Literary Fiction,Science Fiction").asString()) + + Assert.assertEquals(nonFictionBookCount, nonFictionBooks.get("data").size()) + } + + @Test + public void testRootFilterInMultipleSingle() { + int literaryAndScienceFictionBookCount = 0 + for (JsonNode node : books.get("data")) { + if (node.get("attributes").get("genre").asText().equals("Literary Fiction") + || node.get("attributes").get("genre").asText().equals("Science Fiction")) { + literaryAndScienceFictionBookCount += 1 + } + } + + Assert.assertTrue(literaryAndScienceFictionBookCount > 0) + + def literaryAndScienceFictionBooks = mapper.readTree( + RestAssured.get("/book?filter[book.genre][in]=Literary Fiction,Science Fiction").asString()) + + Assert.assertEquals(literaryAndScienceFictionBookCount, literaryAndScienceFictionBooks.get("data").size()) + } + + @Test + public void testRootFilterPostfix() { + int genreEndsWithFictionBookCount = 0 + for (JsonNode node : books.get("data")) { + if (node.get("attributes").get("genre").asText().endsWith("Fiction")) { + genreEndsWithFictionBookCount += 1 + } + } + + Assert.assertTrue(genreEndsWithFictionBookCount > 0) + + def genreEndsWithFictionBooks = mapper.readTree( + RestAssured.get("/book?filter[book.genre][postfix]=Fiction").asString()) + + Assert.assertEquals(genreEndsWithFictionBookCount, genreEndsWithFictionBooks.get("data").size()) + } + + @Test + public void testRootFilterPrefix() { + int titleStartsWithTheBookCount = 0 + for (JsonNode node : books.get("data")) { + if (node.get("attributes").get("title").asText().startsWith("The")) { + titleStartsWithTheBookCount += 1 + } + } + + Assert.assertTrue(titleStartsWithTheBookCount > 0) + + def titleStartsWithTheBooks = mapper.readTree( + RestAssured.get("/book?filter[book.title][prefix]=The").asString()) + + Assert.assertEquals(titleStartsWithTheBookCount, titleStartsWithTheBooks.get("data").size()) + } + + @Test + public void testRootFilterInfix() { + int titleContainsTheBookCount = 0 + for (JsonNode node : books.get("data")) { + if (node.get("attributes").get("title").asText().toLowerCase().contains("the")) { + titleContainsTheBookCount += 1 + } + } + + Assert.assertTrue(titleContainsTheBookCount > 0) + + def titleContainsTheBooks = mapper.readTree( + RestAssured.get("/book?filter[book.title][infix]=the").asString()) + + Assert.assertEquals(titleContainsTheBookCount, titleContainsTheBooks.get("data").size()) + } + + @Test + public void testRootFilterWithInclude() { + def authorIdsOfLiteraryFiction = [] as Set + + for (JsonNode book : books.get("data")) { + if (book.get("attributes").get("genre").asText() == "Literary Fiction") { + for (JsonNode author : book.get("relationships").get("authors").get("data")) { + authorIdsOfLiteraryFiction.add(author.get("id").asText()) + } + } + } + + Assert.assertTrue(authorIdsOfLiteraryFiction.size() > 0) + + def result = mapper.readTree( + RestAssured.get("/book?include=authors&filter[book.genre]=Literary Fiction").asString()) + + for (JsonNode author : result.get("included")) { + Assert.assertTrue(authorIdsOfLiteraryFiction.contains(author.get("id").asText())) + } + } + + @Test + public void testRootFilterIsNull() { + def bookIdsWithNullGenre = [] as Set + + for (JsonNode book : books.get("data")) { + if (book.get("attributes").get("genre").isNull()) { + bookIdsWithNullGenre.add(book.get("id")) + } + } + + Assert.assertTrue(bookIdsWithNullGenre.size() > 0) + + def result = mapper.readTree( + RestAssured.get("/book?filter[book.genre][isnull]").asString()) + + Assert.assertEquals(result.get("data").size(), bookIdsWithNullGenre.size()) + + for (JsonNode book : result.get("data")) { + Assert.assertTrue(book.get("attributes").get("genre").isNull()) + Assert.assertTrue(bookIdsWithNullGenre.contains(book.get("id"))) + } + } + + @Test + public void testRootFilterIsNotNull() { + def bookIdsWithNonNullGenre = [] as Set + + for (JsonNode book : books.get("data")) { + if (!book.get("attributes").get("genre").isNull()) { + bookIdsWithNonNullGenre.add(book.get("id")) + } + } + + Assert.assertTrue(bookIdsWithNonNullGenre.size() > 0) + + def result = mapper.readTree( + RestAssured.get("/book?filter[book.genre][notnull]").asString()) + + Assert.assertEquals(result.get("data").size(), bookIdsWithNonNullGenre.size()) + + for (JsonNode book : result.get("data")) { + Assert.assertTrue(!book.get("attributes").get("genre").isNull()) + Assert.assertTrue(bookIdsWithNonNullGenre.contains(book.get("id"))) + } + } + + @Test + public void testNonRootFilterImplicitSingle() { + int asimovScienceFictionBookCount = 0 + for (JsonNode node : asimovBooks.get("data")) { + if (node.get("attributes").get("genre").asText().equals("Science Fiction")) { + asimovScienceFictionBookCount += 1 + } + } + + Assert.assertTrue(asimovScienceFictionBookCount > 0) + + def asimovScienceFictionBooks = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?filter[book.genre]=Science Fiction").asString()) + + Assert.assertEquals(asimovScienceFictionBookCount, asimovScienceFictionBooks.get("data").size()) + } + + @Test + public void testNonRootFilterInSingle() { + int asimovHistoryBookCount = 0 + for (JsonNode node : asimovBooks.get("data")) { + if (node.get("attributes").get("genre").asText().equals("History")) { + asimovHistoryBookCount += 1 + } + } + + Assert.assertTrue(asimovHistoryBookCount > 0) + + def asimovHistoryBooks = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?filter[book.genre]=History").asString()) + + Assert.assertEquals(asimovHistoryBookCount, asimovHistoryBooks.get("data").size()) + } + + @Test + public void testNonRootFilterNotInSingle() { + int nonHistoryBookCount = 0 + for (JsonNode node : asimovBooks.get("data")) { + if (!node.get("attributes").get("genre").isNull() + && !node.get("attributes").get("genre").asText().equals("History")) { + nonHistoryBookCount += 1 + } + } + + Assert.assertTrue(nonHistoryBookCount > 0) + + def nonHistoryBooks = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?filter[book.genre][not]=History").asString()) + + Assert.assertEquals(nonHistoryBookCount, nonHistoryBooks.get("data").size()) + } + + @Test + public void testNonRootFilterPostfix() { + int genreEndsWithFictionBookCount = 0 + for (JsonNode node : asimovBooks.get("data")) { + if (node.get("attributes").get("genre").asText().endsWith("Fiction")) { + genreEndsWithFictionBookCount += 1 + } + } + + Assert.assertTrue(genreEndsWithFictionBookCount > 0) + + def genreEndsWithFictionBooks = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?filter[book.genre][postfix]=Fiction").asString()) + + Assert.assertEquals(genreEndsWithFictionBookCount, genreEndsWithFictionBooks.get("data").size()) + } + + @Test + public void testNonRootFilterPrefix() { + int titleStartsWithTheBookCount = 0 + for (JsonNode node : asimovBooks.get("data")) { + if (node.get("attributes").get("title").asText().startsWith("The")) { + titleStartsWithTheBookCount += 1 + } + } + + Assert.assertTrue(titleStartsWithTheBookCount > 0) + + def titleStartsWithTheBooks = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?filter[book.title][prefix]=The").asString()) + + Assert.assertEquals(titleStartsWithTheBookCount, titleStartsWithTheBooks.get("data").size()) + } + + @Test + public void testNonRootFilterInfix() { + int titleContainsTheBookCount = 0 + for (JsonNode node : asimovBooks.get("data")) { + if (node.get("attributes").get("title").asText().toLowerCase().contains("the")) { + titleContainsTheBookCount += 1 + } + } + + Assert.assertTrue(titleContainsTheBookCount > 0) + + def titleContainsTheBooks = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?filter[book.title][infix]=the").asString()) + + Assert.assertEquals(titleContainsTheBookCount, titleContainsTheBooks.get("data").size()) + } + + @Test + public void testNonRootFilterWithInclude() { + def authorIdsOfScienceFiction = [] as Set + + for (JsonNode book : asimovBooks.get("data")) { + if (book.get("attributes").get("genre").asText() == "Science Fiction") { + for (JsonNode author : book.get("relationships").get("authors").get("data")) { + authorIdsOfScienceFiction.add(author.get("id").asText()) + } + } + } + + Assert.assertTrue(authorIdsOfScienceFiction.size() > 0) + + def result = mapper.readTree( + RestAssured.get("/author/${asimovId}/books?include=authors&filter[book.genre]=Science Fiction").asString()) + + for (JsonNode author : result.get("included")) { + Assert.assertTrue(authorIdsOfScienceFiction.contains(author.get("id").asText())) + } + } + + @Test + public void testNonRootFilterIsNull() { + def bookIdsWithNullGenre = [] as Set + + for (JsonNode book : nullNedBooks.get("data")) { + if (book.get("attributes").get("genre").isNull()) { + bookIdsWithNullGenre.add(book.get("id")) + } + } + + Assert.assertTrue(bookIdsWithNullGenre.size() > 0) + + def result = mapper.readTree( + RestAssured.get("/author/${nullNedId}/books?filter[book.genre][isnull]").asString()) + + Assert.assertEquals(result.get("data").size(), bookIdsWithNullGenre.size()) + + for (JsonNode book : result.get("data")) { + Assert.assertTrue(book.get("attributes").get("genre").isNull()) + Assert.assertTrue(bookIdsWithNullGenre.contains(book.get("id"))) + } + } + + @Test + public void testNonRootFilterIsNotNull() { + def bookIdsWithNonNullGenre = [] as Set + + for (JsonNode book : nullNedBooks.get("data")) { + if (!book.get("attributes").get("genre").isNull()) { + bookIdsWithNonNullGenre.add(book.get("id")) + } + } + + Assert.assertTrue(bookIdsWithNonNullGenre.size() > 0) + + def result = mapper.readTree( + RestAssured.get("/author/${nullNedId}/books?filter[book.genre][notnull]").asString()) + + Assert.assertEquals(result.get("data").size(), bookIdsWithNonNullGenre.size()) + + for (JsonNode book : result.get("data")) { + Assert.assertTrue(!book.get("attributes").get("genre").isNull()) + Assert.assertTrue(bookIdsWithNonNullGenre.contains(book.get("id"))) + } + } +} diff --git a/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/ShareableIT.groovy b/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/ShareableIT.groovy new file mode 100644 index 0000000000..fe957b3b92 --- /dev/null +++ b/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/ShareableIT.groovy @@ -0,0 +1,443 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package com.yahoo.elide.tests +import com.fasterxml.jackson.databind.ObjectMapper +import com.yahoo.elide.core.HttpStatus +import com.yahoo.elide.initialization.AbstractIntegrationTestInitializer +import org.testng.Assert +import org.testng.annotations.Test + +import static com.jayway.restassured.RestAssured.given +/** + * @AShareable annotation integration tests + */ +class ShareableIT extends AbstractIntegrationTestInitializer { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testUnshareableForbiddenAccess() { + // Create container + def container = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "container" + } + }''') + .post("/container") + container.then().statusCode(HttpStatus.SC_CREATED) + def containerJson = mapper.readTree(container.asString()) + + // Create unshareable + def unshareable = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "unshareable" + } + } + ''') + .post("/unshareable") + unshareable.then().statusCode(HttpStatus.SC_CREATED) + def unshareableJson = mapper.readTree(unshareable.asString()) + + // Fail to add unshareable to container's unshareables (unshareable is not shareable) + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "unshareable", + "id": ${unshareableJson['data']['id']} + } + } + """) + .patch("/container/${containerJson['data']['id'].asText()}/relationships/unshareables") + .then() + .statusCode(HttpStatus.SC_FORBIDDEN) + + // Fail to replace container's unshareables collection (unshareable is not shareable) + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "unshareable", + "id": ${unshareableJson['data']['id']} + } + } + """) + .post("/container/${containerJson['data']['id'].asText()}/relationships/unshareables") + .then() + .statusCode(HttpStatus.SC_FORBIDDEN) + + // Fail to update unshareable's container (container is not shareable) + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "container", + "id": ${containerJson['data']['id']} + } + } + """) + .patch("/unshareable/${unshareableJson['data']['id'].asText()}/relationships/container") + .then() + .statusCode(HttpStatus.SC_FORBIDDEN) + + // Fail to set unshareable's container (container is not shareable) + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "container", + "id": ${containerJson['data']['id']} + } + } + """) + .post("/unshareable/${unshareableJson['data']['id'].asText()}/relationships/container") + .then() + .statusCode(HttpStatus.SC_FORBIDDEN) + } + + @Test + public void testShareableForbiddenAccess() { + // Create container + def container = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "container" + } + }''') + .post("/container") + container.then().statusCode(HttpStatus.SC_CREATED) + def containerJson = mapper.readTree(container.asString()) + + // Create shareable + def shareable = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "shareable" + } + } + ''') + .post("/shareable") + shareable.then().statusCode(HttpStatus.SC_CREATED) + def shareableJson = mapper.readTree(shareable.asString()) + + // Fail to update shareable's container (container is not shareable) + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "container", + "id": ${containerJson['data']['id']} + } + } + """) + .patch("/shareable/${shareableJson['data']['id'].asText()}/relationships/container") + .then() + .statusCode(HttpStatus.SC_FORBIDDEN) + + // Fail to set shareable's container (container is not shareable) + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "container", + "id": ${containerJson['data']['id']} + } + } + """) + .post("/shareable/${shareableJson['data']['id'].asText()}/relationships/container") + .then() + .statusCode(HttpStatus.SC_FORBIDDEN) + } + + @Test + public void testShareablePost() { + // Create container + def container = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "container" + } + }''') + .post("/container") + container.then().statusCode(HttpStatus.SC_CREATED) + def containerJson = mapper.readTree(container.asString()) + + // Create shareable + def shareable = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "shareable" + } + } + ''') + .post("/shareable") + shareable.then().statusCode(HttpStatus.SC_CREATED) + def shareableJson = mapper.readTree(shareable.asString()) + + // Add shareable to container's shareables + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "shareable", + "id": ${shareableJson['data']['id']} + } + } + """) + .post("/container/${containerJson['data']['id'].asText()}/relationships/shareables") + .then() + .statusCode(HttpStatus.SC_NO_CONTENT) + + def result = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .get("/container/${containerJson['data']['id'].asText()}") + result.then().statusCode(HttpStatus.SC_OK) + + def resultJson = mapper.readTree(result.asString()) + Assert.assertEquals(resultJson['data']['relationships']['shareables'].size(), 1) + } + + @Test + public void testShareablePatch() { + // Create container + def container = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "container" + } + }''') + .post("/container") + container.then().statusCode(HttpStatus.SC_CREATED) + def containerJson = mapper.readTree(container.asString()) + + // Create shareable + def shareable = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(''' + { + "data": { + "type": "shareable" + } + } + ''') + .post("/shareable") + shareable.then().statusCode(HttpStatus.SC_CREATED) + def shareableJson = mapper.readTree(shareable.asString()) + + // Add shareable to container's shareables + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data": { + "type": "shareable", + "id": ${shareableJson['data']['id']} + } + } + """) + .patch("/container/${containerJson['data']['id'].asText()}/relationships/shareables") + .then() + .statusCode(HttpStatus.SC_NO_CONTENT) + + def result = given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .get("/container/${containerJson['data']['id'].asText()}") + result.then().statusCode(HttpStatus.SC_OK) + + def resultJson = mapper.readTree(result.asString()) + Assert.assertEquals(resultJson['data']['relationships']['shareables'].size(), 1) + } + + @Test + public void testCreateContainerAndUnshareables() { + def patchResponse = given() + .contentType("application/vnd.api+json; ext=jsonpatch") + .accept("application/vnd.api+json; ext=jsonpatch") + .body(""" + [ + { + "op": "add", + "path": "/container", + "value": { + "id": "12345678-1234-1234-1234-1234567890ab", + "type": "container", + "relationships": { + "unshareables": { + "data": [ + { + "type": "unshareable", + "id": "12345678-1234-1234-1234-1234567890ac" + }, + { + "type": "unshareable", + "id": "12345678-1234-1234-1234-1234567890ad" + } + ] + } + } + } + }, + { + "op": "add", + "path": "/unshareable", + "value": { + "type": "unshareable", + "id": "12345678-1234-1234-1234-1234567890ac" + } + }, + { + "op": "add", + "path": "/unshareable", + "value": { + "type": "unshareable", + "id": "12345678-1234-1234-1234-1234567890ad" + } + } + ] + """) + .patch("/") + patchResponse.then().statusCode(HttpStatus.SC_OK) + + def patchJson = mapper.readTree(patchResponse.asString()) + + // Should have 3 results, 1st is container, 2nd and 3rd are unshareables + Assert.assertEquals(patchJson.size(), 3) + Assert.assertEquals(patchJson[0]["data"]["type"].asText(), "container") + Assert.assertEquals(patchJson[1]["data"]["type"].asText(), "unshareable") + Assert.assertEquals(patchJson[2]["data"]["type"].asText(), "unshareable") + + // Container should have 2 unshareables + Assert.assertEquals(patchJson[0]["data"]["relationships"]["unshareables"]["data"].size(), 2) + } + + @Test + public void testCreateContainerAndShareables() { + def patchResponse = given() + .contentType("application/vnd.api+json; ext=jsonpatch") + .accept("application/vnd.api+json; ext=jsonpatch") + .body(""" + [ + { + "op": "add", + "path": "/container", + "value": { + "id": "12345678-1234-1234-1234-1234567890ab", + "type": "container", + "relationships": { + "shareables": { + "data": [ + { + "type": "shareable", + "id": "12345678-1234-1234-1234-1234567890ac" + }, + { + "type": "shareable", + "id": "12345678-1234-1234-1234-1234567890ad" + } + ] + } + } + } + }, + { + "op": "add", + "path": "/shareable", + "value": { + "type": "shareable", + "id": "12345678-1234-1234-1234-1234567890ac" + } + }, + { + "op": "add", + "path": "/shareable", + "value": { + "type": "shareable", + "id": "12345678-1234-1234-1234-1234567890ad" + } + } + ] + """) + .patch("/") + patchResponse.then().statusCode(HttpStatus.SC_OK) + + def patchJson = mapper.readTree(patchResponse.asString()) + + // Should have 3 results, 1st is container, 2nd and 3rd are shareables + Assert.assertEquals(patchJson.size(), 3) + Assert.assertEquals(patchJson[0]["data"]["type"].asText(), "container") + Assert.assertEquals(patchJson[1]["data"]["type"].asText(), "shareable") + Assert.assertEquals(patchJson[2]["data"]["type"].asText(), "shareable") + + // Container should have 2 shareables + Assert.assertEquals(patchJson[0]["data"]["relationships"]["shareables"]["data"].size(), 2) + } + + + @Test(priority = 3) + public void addUnsharedRelationship() { + given() + .contentType("application/vnd.api+json") + .accept("application/vnd.api+json") + .body(""" + { + "data":{ + "type":"right", + "relationships":{ + "one2one":{ + "data":{ + "type":"left", + "id":"1" + } + } + } + } + } + """) + .post("/left/1/one2many") + .then() + .statusCode(HttpStatus.SC_CREATED); + } +} diff --git a/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/UserTypeIT.groovy b/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/UserTypeIT.groovy index 7691f28122..278c8fc10e 100644 --- a/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/UserTypeIT.groovy +++ b/elide-integration-tests/src/test/groovy/com/yahoo/elide/tests/UserTypeIT.groovy @@ -4,17 +4,15 @@ * See LICENSE file in project root for terms. */ package com.yahoo.elide.tests - import com.yahoo.elide.core.HttpStatus -import com.yahoo.elide.datastores.AHibernateTest +import com.yahoo.elide.initialization.AbstractIntegrationTestInitializer import org.testng.annotations.Test import static com.jayway.restassured.RestAssured.given - /** * Tests for UserType */ -class UserTypeIT extends AHibernateTest { +class UserTypeIT extends AbstractIntegrationTestInitializer { @Test public void testUserTypePost() { diff --git a/elide-integration-tests/src/test/java/com/yahoo/elide/tests/AccessIT.java b/elide-integration-tests/src/test/java/com/yahoo/elide/tests/AccessIT.java new file mode 100644 index 0000000000..e400e696d9 --- /dev/null +++ b/elide-integration-tests/src/test/java/com/yahoo/elide/tests/AccessIT.java @@ -0,0 +1,36 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package com.yahoo.elide.tests; + +import com.yahoo.elide.core.DataStoreTransaction; +import com.yahoo.elide.initialization.AbstractIntegrationTestInitializer; +import example.Parent; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.HashSet; + +/** + * Simple integration tests to verify session and access. + */ +public class AccessIT extends AbstractIntegrationTestInitializer { + @Test + public void verifySession() throws IOException { + try (DataStoreTransaction tx = dataStore.beginTransaction()) { + tx.commit(); + } + } + + @Test + public void accessParentBean() { + DataStoreTransaction tx = dataStore.beginTransaction(); + Parent parent = new Parent(); + parent.setChildren(new HashSet<>()); + parent.setSpouses(new HashSet<>()); + tx.save(parent); + tx.commit(); + } +} diff --git a/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIT.java b/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIT.java new file mode 100644 index 0000000000..c680ba5066 --- /dev/null +++ b/elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIT.java @@ -0,0 +1,79 @@ +/* + * Copyright 2015, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package com.yahoo.elide.tests; + +import com.google.common.collect.ImmutableSet; +import com.yahoo.elide.core.DataStoreTransaction; +import com.yahoo.elide.core.EntityDictionary; +import com.yahoo.elide.core.HttpStatus; +import com.yahoo.elide.initialization.AbstractIntegrationTestInitializer; +import com.yahoo.elide.jsonapi.JsonApiMapper; +import com.yahoo.elide.utils.JsonParser; +import example.Embedded; +import example.Left; +import example.Right; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.io.IOException; + +import static com.jayway.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +/** + * Integration test for embedded collections. + */ +public class EmbeddedIT extends AbstractIntegrationTestInitializer { + private final JsonParser jsonParser = new JsonParser(); + private final JsonApiMapper mapper; + + public EmbeddedIT() { + /* There is no good way to get the dictionary from Elide */ + EntityDictionary empty = new EntityDictionary(); + + /* Empty dictionary is OK provided the OBJECT_MAPPER is used for reading only */ + mapper = new JsonApiMapper(empty); + } + + @BeforeTest + public static void setup() throws IOException { + DataStoreTransaction tx = dataStore.beginTransaction(); + Embedded embedded = new Embedded(); // id 1 + embedded.setSegmentIds(ImmutableSet.of(3L, 4L, 5L)); + + tx.save(embedded); + + Left left = new Left(); + Right right = new Right(); + + left.setOne2one(right); + right.setOne2one(left); + + tx.save(left); + tx.save(right); + + tx.commit(); + } + + @Test + void testEmbedded() { + String expected = jsonParser.getJson("/EmbeddedIT/testEmbedded.json"); + + given().when().get("/embedded/1").then().statusCode(HttpStatus.SC_OK).body(equalTo(expected)); + } + + @Test + void testOne2One() { + String expected = jsonParser.getJson("/EmbeddedIT/testOne2One.json"); + + String response = + given().when().get("/right/1") + .then().statusCode(HttpStatus.SC_OK) + .extract().body().asString(); + + assertEqualDocuments(response, expected); + } +} diff --git a/elide-integration-tests/src/test/resources/hibernate.cfg.xml b/elide-integration-tests/src/test/resources/hibernate.cfg.xml index c4b88f4367..e1fb9de958 100644 --- a/elide-integration-tests/src/test/resources/hibernate.cfg.xml +++ b/elide-integration-tests/src/test/resources/hibernate.cfg.xml @@ -13,47 +13,22 @@ - - com.mysql.jdbc.Driver - + com.mysql.jdbc.Driver - - org.hibernate.dialect.MySQL5InnoDBDialect - + org.hibernate.dialect.MySQL5InnoDBDialect 50 50 true - - org.hibernate.transaction.JDBCTransactionFactory - + org.hibernate.transaction.JDBCTransactionFactory false false true - - - com.flurry.hibernate.memcached.MultiSchemaMemcachedCacheProvider - - com.flurry.hibernate.memcached.MultiSchemaStrategy - com.flurry.hibernate.cache.FlurryHibernateSchemaRegistry - - localhost:11211 - 3600 - true false - - 1 - 25 - 1800 - 50 - 1 - 150 - /* ping */ select 1 - thread diff --git a/pom.xml b/pom.xml index 8578a7bdf9..a92bec46cd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ elide-parent-pom 1.0.0.10-SNAPSHOT pom - Elide Parent Pom + Elide: Parent Pom Parent pom for Elide project https://github.com/yahoo/elide @@ -56,6 +56,10 @@ HEAD + + 3.0.0 + + true 1.8 @@ -66,15 +70,9 @@ UTF-8 - 1.7.12 - 9.3.5.v20151012 - 2.22.1 - - - 2.17 - 6.12 - 2.19 - 2.4.5 + 1.1.3 + 9.3.6.v20151106 + 2.7.0 ${project.basedir}/.. @@ -95,7 +93,7 @@ org.slf4j slf4j-api - ${version.slf4j} + 1.7.13 com.google.guava @@ -117,12 +115,34 @@ commons-lang3 3.4 + + org.eclipse.jetty + jetty-server + ${version.jetty} + + + org.eclipse.jetty + jetty-servlet + ${version.jetty} + + + ch.qos.logback + logback-classic + ${version.logback} + test + + + ch.qos.logback + logback-core + ${version.logback} + test + org.glassfish.jersey.containers jersey-container-servlet - ${version.jersey} + 2.22.1 test @@ -152,15 +172,37 @@ org.mockito mockito-core - 2.0.13-beta + 2.0.31-beta test org.codehaus.groovy groovy-all - ${groovy.version} + 2.4.5 test + + com.jayway.restassured + rest-assured + ${version.restassured} + test + + + com.jayway.restassured + json-schema-validator + ${version.restassured} + test + + + jackson-databind + com.fasterxml.jackson.core + + + jsr305 + com.google.code.findbugs + + + @@ -170,12 +212,12 @@ org.apache.maven.plugins maven-surefire-plugin - ${surefire.plugin.version} + 2.19 org.apache.maven.plugins maven-checkstyle-plugin - ${maven.checkstyle.plugin.version} + 2.17 validate @@ -202,66 +244,20 @@ com.puppycrawl.tools checkstyle - ${checkstyle.version} + 6.12.1 compile - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - ${source.jdk.version} - ${target.jdk.version} - true - true - true - ${project.build.sourceEncoding} - - org.apache.maven.plugins maven-deploy-plugin 2.8.2 - - maven-release-plugin - 2.5.3 - - - org.apache.maven.scm - maven-scm-provider-gitexe - 1.9.4 - - - - @{project.version} - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - + maven-jar-plugin + 2.6 org.codehaus.gmaven @@ -283,7 +279,58 @@ + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + ${source.jdk.version} + ${target.jdk.version} + true + true + true + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins maven-release-plugin + 2.5.3 + + + org.apache.maven.scm + maven-scm-provider-gitexe + 1.9.4 + + + + @{project.version} +