diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md deleted file mode 100644 index f59ed788..00000000 --- a/.github/ISSUE_TEMPLATE/custom.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -name: Custom issue template -about: Describe this issue template's purpose here. - ---- - -**Your issue may already be reported! Please search before creating a new one.** - -## Expected Behavior -* placeholder - -## Current Behavior -* placeholder - -## Possible Solution -* placeholder - -## Steps to Reproduce (for bugs) -* step-1 -* step-2 -* ... - -## Snapshot Code for Reproduce -```java -@SpringBootApplication -public class Application { - public static void main(String... args) { - SpringApplication.run(Application.class, args); - } -} -``` - -## Branch -* placeholder - -## Your Environment -* Version used: -* Operating System and version (desktop or mobile): -* SDK version: diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ea66cf52..00000000 --- a/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -.idea* -target/* -*.patch -*.iml - -**/target - -#Eclipse generated files -.classpath -.project -.settings/ -/.apt_generated/ -/.apt_generated_tests/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 37f2385b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: java -jdk: - - openjdk8 - -before_script: - # - wget http://www-us.apache.org/dist/tinkerpop/3.3.4/apache-tinkerpop-gremlin-server-3.3.4-bin.zip - # - unzip apache-tinkerpop-gremlin-server-3.3.4-bin.zip > /dev/null - # - cp -v config/gremlin-server-ci.yaml apache-tinkerpop-gremlin-server-3.3.4/conf/ - # - cp -v config/gremlin-server-ci.properties apache-tinkerpop-gremlin-server-3.3.4/conf/ - # - apache-tinkerpop-gremlin-server-3.3.4/bin/ - - tar -zvxf package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz - - apache-tinkerpop-gremlin-server-minimal-3.3.4/bin/gremlin-server.sh conf/gremlin-server-ci.yaml & - - sleep 10 - -script: - - set -o pipefail - - mvn clean -P full-test cobertura:cobertura-integration-test | grep -v "DEBUG" - -after_success: - - bash <(curl -s https://codecov.io/bash) - diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 65c8a42b..00000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1 +0,0 @@ -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 2a452f74..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,44 +0,0 @@ -# How to Build and Contribute -Below are guidelines for building and code contribution. - -## Prerequisites -- JDK 1.8 and above -- [Maven](http://maven.apache.org/) 3.0 and above - -## Build from source -To build the project, run maven commands. - -```bash -git clone https://github.com/Microsoft/azure-spring-boot.git -cd azure-spring-boot -mvn clean install -``` - -## Test - -- Run unit tests -```bash -mvn clean install -``` - -- [Run integration tests]() - -- Skip test execution -```bash -mvn clean install -DskipTests -``` - -## Version management -Developing version naming convention is like `0.1.0-SNAPSHOT`. Release version naming convention is like `2.0.0`. Please don't update version if no release plan. - -## CI -[Travis](https://travis-ci.org/Microsoft/spring-data-gremlin) -[Codecov](https://codecov.io/gh/Microsoft/spring-data-gremlin) -[Codacy](https://app.codacy.com/project/Incarnation-p-lee/spring-data-gremlin/dashboard) - -## Contribution -Code contribution is welcome. To contribute to existing code or add a new starter, please make sure below check list is checked. -- [ ] Build pass. Checkstyle and findbugs is enabled by default. Please check [checkstyle.xml](config/checkstyle.xml) to learn detailed checkstyle configuration. -- [ ] Documents are updated to align with code. -- [ ] New starter must have sample folder containing sample code and corresponding readme file. -- [ ] Keep Code coverage for repository >= 90%. Code coverage check is not enabled, as you may need to split feature code and test code in different PR. diff --git a/DESIGN.md b/DESIGN.md deleted file mode 100644 index f06e8e58..00000000 --- a/DESIGN.md +++ /dev/null @@ -1,93 +0,0 @@ -# Spring Data Gremlin Design - -### Orientation - -Gremlin is a functional, data-flow language that enables users to succinctly express complex -traversals on (or queries of) their application's property graph. It hides the details of backend -database implementation (like azure cosmosdb support Graph API). - -Apache Tinkerpop gremlin java driver allows you to launch gremlin query, but it is not easy to -get familiar with gremlin syntax. You have to generate all gremlin queries by yourself as following. - -```java - static final String[] gremlinQueries = new String[] { - "g.V().drop()", - "g.addV('person').property('id', '1').property('name', 'pli').property('age', 31)", - "g.addV('person').property('id', '4').property('name', 'incarnation').property('age', 27)", - "g.addV('software').property('id', '2').property('name', 'spring-boot-sample').property('lang', 'java')", - "g.V('1').addE('created').to(g.V('2')).property('weight', 0.8)", - "g.V('1').addE('contributed').to(g.V('2')).property('weight', 0.1)", - "g.V('4').addE('contributed').to(g.V('2')).property('weight', 0.4)" - }; -``` - -We'd like to make things easier by hiding the process of mapping Java instance to graph database -persistent entity, with the help of spring-data-commons. - -### From Users' View -How do users use graph db? They can use gremlin driver to generate the query literal in Java class instance. -It's not impossible but yet isn't easy. We want to figure out a more Spring natural way by leveraging -Spring annotations to map Java instance to database entity. - -### From Graph database View -As we know, there may be some concept like `Vertex`, `Edge` and `Graph` when we talk about -graph. Naturally the object instance needs to be mapped to one and the only one of these -element in graph. Simply we add some annotations to reach this. - -```java - @Vertex // maps an Object to a Vertex - @VertexSet // maps a set of Vertex in Graph - @Edge // maps an Object to an Edge - @EdgeSet // maps to a set of Edge in Graph - @EdgeFrom // maps to the head Vertex of an Edge - @EdgeTo // maps to the tail Vertex of an Edge - @Graph // maps to an Object to a Graph -``` - -### CRUD based query -The `@GremlinRepository` extends `@CrudReposiotry` is providing basic queries, like insert, -save, find, delete and count. Let's take insert as example to the details of implementation. - -##### Some Constrictions -* Gremlin describes the `Vertex` and `Edge` in a flat layout, with fixed property `id`, `label`, -and any other properties organized as key-value pair. -* Gremlin properties name must be `String`, and values can be `Number`, `Boolean` and `String`. -* No nested structure in `Vertex` and `Edge`. -* `Edge` is directed. - -##### GremlinSource -Before we start to insert a `Vertex` instance to database, we need one abstract layer into -isolate the dependency between instance and entity in database. We define one class to -represent all instance stored in database. This class not only needs to hold all information from -instance object, but also has the flat structure like entity in database. It is the bridge between -instance in java and persistent entity in database. Here we call it `GremlinSource`. - -With the above constriction of gremlin, `GremlinSource` has field `id` and `label` for mapping, -and keep all other fields into one `Map`. When we try to insert a instance from -java to `GremlinSource`, we perform a **WRITE** operation and convert the instance to a `GremlinSource`. -Operation **WRITE** will convert all the data of one instance to `GremlinSource`, and take care of -`id` or `@Id` field. - -The `GremlinSourceWriter` converts Java instance to `GremlinSource`. - -##### GremlinResult -There must be one **READ** operation for retrieving instance from database entity. For example, -the `find` query will return the persistent data from database with the type `Result`, provided -by apache SDK. For insulating the dependency between instance and `Result`, just like what we do -in **WRITE**. We also use `GremlinSource` as the bridge from `Result` to instance. Simply there -are two steps after query from database. First the `Result` from database will be converted to -`GremlinSource`. And then the `GremlinSource` will be converted to Java instance, just like what -we do in **WRITE** operation. - -The `GremlinResultReader` converts `Result` to `GremlinSource`. -The `GremlinSourceReader` converts `GremlinSource` to Java instance. - -##### GremlinScript -GremlinScript will generate the query based on `GremlinSource`. It converts the data like -`id`, `label` and `properites` into gremlin query literal Strings. For type `String`, `Number` -and `Boolean`, the query will store them as primitive types (supported by gremlin). And any -other type of instance field will be converted to Json-like `String` except type `Date`, it will -be converted to milliSeconds and stored as `Number`. Then the gremlin client will execute the query -to access database. - -The `GremlinScriptLiteral` generates literal query based on `GremlinSource`. diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1168078c..00000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,17 +0,0 @@ -## Description -A few sentences describing the overall goals of the pull request's commits. - -## Related PRs -List related PRs against other branches: - -branch | PR ------- | ------ -other_pr_production | [link]() -other_pr_master | [link]() - -## Todos -- [ ] Tests -- [ ] Documentation - -## Steps to Test -Steps to test code change diff --git a/README.md b/README.md index 914af6b4..67d25a24 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ :exclamation::exclamation::exclamation: -We are in the process of **deprecating** Spring Data Gremlin. We recommend using [azure-spring-boot-starter-cosmos](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/spring/azure-spring-boot-starter-cosmos) or [Spring Data Azure Cosmos DB v3 for SQL API](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-spring-v3) instead. +We have **deprecated** Spring Data Gremlin. We recommend using [azure-spring-boot-starter-cosmos](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/spring/azure-spring-boot-starter-cosmos) or [Spring Data Azure Cosmos DB v3 for SQL API](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-java-spring-v3) instead. diff --git a/config/checkstyle.xml b/config/checkstyle.xml deleted file mode 100644 index 60739459..00000000 --- a/config/checkstyle.xml +++ /dev/null @@ -1,296 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/findbugs-exclude.xml b/config/findbugs-exclude.xml deleted file mode 100644 index 24f08b48..00000000 --- a/config/findbugs-exclude.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/config/gremlin-server-ci.properties b/config/gremlin-server-ci.properties deleted file mode 100644 index 65cd869d..00000000 --- a/config/gremlin-server-ci.properties +++ /dev/null @@ -1,2 +0,0 @@ -gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph -gremlin.tinkergraph.vertexIdManager=ANY diff --git a/config/gremlin-server-ci.yaml b/config/gremlin-server-ci.yaml deleted file mode 100644 index d7947fba..00000000 --- a/config/gremlin-server-ci.yaml +++ /dev/null @@ -1,19 +0,0 @@ -host: localhost -port: 8889 -gremlinPool: 8 -threadPoolWorker: 8 -scriptEvaluationTimeout: 30000 -channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer -graphs: { graph: conf/gremlin-server-ci.properties } - -scriptEngines: { - gremlin-groovy: { - plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}, - org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/empty-sample.groovy]}}}} - -serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }} -ssl: { enabled: false } - diff --git a/examples/LICENSE b/examples/LICENSE deleted file mode 100644 index c96a6d29..00000000 --- a/examples/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 Pan Li - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/examples/example/pom.xml b/examples/example/pom.xml deleted file mode 100644 index 77e3f833..00000000 --- a/examples/example/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - 4.0.0 - - spring-data-gremlin-example - Spring Data gremlin - Example - - - com.microsoft.spring.data.gremlin.examples - spring-data-gremlin-examples - 0.0.1.BUILD-SNAPSHOT - ../pom.xml - - - - - org.springframework.boot - spring-boot - - - - org.springframework.boot - spring-boot-autoconfigure - - - - diff --git a/examples/example/src/main/java/example/springdata/gremlin/Application.java b/examples/example/src/main/java/example/springdata/gremlin/Application.java deleted file mode 100644 index 80a900c5..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/Application.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.gremlin; - -import com.microsoft.spring.data.gremlin.common.GremlinFactory; -import example.springdata.gremlin.domain.Network; -import example.springdata.gremlin.domain.Person; -import example.springdata.gremlin.domain.Relation; -import example.springdata.gremlin.repository.NetworkRepository; -import example.springdata.gremlin.repository.PersonRepository; -import example.springdata.gremlin.repository.RelationRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -@SpringBootApplication -public class Application { - - private static final String PERSON_ID = "89757"; - private static final String PERSON_ID_0 = "0123456789"; - private static final String PERSON_ID_1 = "666666"; - private static final String PERSON_NAME = "person-name"; - private static final String PERSON_NAME_0 = "person-No.0"; - private static final String PERSON_NAME_1 = "person-No.1"; - private static final String PERSON_AGE = "4"; - private static final String PERSON_AGE_0 = "18"; - private static final String PERSON_AGE_1 = "27"; - - private static final String RELATION_ID = "2333"; - private static final String RELATION_NAME = "brother"; - - private final Person person = new Person(PERSON_ID, PERSON_NAME, PERSON_AGE); - private final Person person0 = new Person(PERSON_ID_0, PERSON_NAME_0, PERSON_AGE_0); - private final Person person1 = new Person(PERSON_ID_1, PERSON_NAME_1, PERSON_AGE_1); - private final Relation relation = new Relation(RELATION_ID, RELATION_NAME, person0, person1); - private final Network network = new Network(); - - @Autowired - private PersonRepository personRepo; - - @Autowired - private RelationRepository relationRepo; - - @Autowired - private NetworkRepository networkRepo; - - @Autowired - private GremlinFactory factory; - - public static void main(String... args) { - SpringApplication.run(Application.class, args); - } - - @PostConstruct - public void setup() { - this.networkRepo.deleteAll(); - - this.network.getEdges().add(this.relation); - this.network.getVertexes().add(this.person); - this.network.getVertexes().add(this.person0); - this.network.getVertexes().add(this.person1); - - this.networkRepo.save(this.network); - } -} diff --git a/examples/example/src/main/java/example/springdata/gremlin/config/GremlinProperties.java b/examples/example/src/main/java/example/springdata/gremlin/config/GremlinProperties.java deleted file mode 100644 index a0ceac28..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/config/GremlinProperties.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package example.springdata.gremlin.config; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import org.apache.tinkerpop.gremlin.driver.ser.Serializers; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -@ConfigurationProperties("gremlin") -public class GremlinProperties { - private String endpoint; - - private int port; - - private String username; - - private String password; - - private boolean sslEnabled; - - private boolean telemetryAllowed = true; - - private String serializer = Serializers.GRAPHSON.toString(); - - private int maxContentLength; -} diff --git a/examples/example/src/main/java/example/springdata/gremlin/config/UserRepositoryConfiguration.java b/examples/example/src/main/java/example/springdata/gremlin/config/UserRepositoryConfiguration.java deleted file mode 100644 index af62141f..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/config/UserRepositoryConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2014-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.gremlin.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -import com.microsoft.spring.data.gremlin.common.GremlinConfig; -import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; -import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; - - -@Configuration -@EnableGremlinRepositories(basePackages = "example.springdata.gremlin.repository") -@EnableConfigurationProperties(GremlinProperties.class) -@PropertySource("classpath:application.yml") -public class UserRepositoryConfiguration extends AbstractGremlinConfiguration { - - @Autowired - private GremlinProperties gremlinProps; - - @Override - public GremlinConfig getGremlinConfig() { - return new GremlinConfig( - gremlinProps.getEndpoint(), - gremlinProps.getPort(), - gremlinProps.getUsername(), - gremlinProps.getPassword(), - gremlinProps.isSslEnabled(), - gremlinProps.isTelemetryAllowed(), - gremlinProps.getSerializer(), - gremlinProps.getMaxContentLength() - ); - } -} diff --git a/examples/example/src/main/java/example/springdata/gremlin/domain/Network.java b/examples/example/src/main/java/example/springdata/gremlin/domain/Network.java deleted file mode 100644 index 0f5c87c3..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/domain/Network.java +++ /dev/null @@ -1,30 +0,0 @@ -package example.springdata.gremlin.domain; - -import com.microsoft.spring.data.gremlin.annotation.EdgeSet; -import com.microsoft.spring.data.gremlin.annotation.Graph; -import com.microsoft.spring.data.gremlin.annotation.VertexSet; -import lombok.Getter; -import org.springframework.data.annotation.Id; - -import java.util.ArrayList; -import java.util.List; - -@Graph -public class Network { - - @Id - private String id; - - public Network() { - this.edges = new ArrayList(); - this.vertexes = new ArrayList(); - } - - @EdgeSet - @Getter - private List edges; - - @VertexSet - @Getter - private List vertexes; -} diff --git a/examples/example/src/main/java/example/springdata/gremlin/domain/Person.java b/examples/example/src/main/java/example/springdata/gremlin/domain/Person.java deleted file mode 100644 index 60a88210..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/domain/Person.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.gremlin.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -@Data -@Vertex -@AllArgsConstructor -@NoArgsConstructor -public class Person { - - @Id - private String id; - - private String name; - - private String age; -} - diff --git a/examples/example/src/main/java/example/springdata/gremlin/domain/Relation.java b/examples/example/src/main/java/example/springdata/gremlin/domain/Relation.java deleted file mode 100644 index f0ce7f15..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/domain/Relation.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package example.springdata.gremlin.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - - -@Data -@Edge -@AllArgsConstructor -@NoArgsConstructor -public class Relation { - - @Id - private String id; - - private String name; - - @EdgeFrom - private Person personFrom; - - @EdgeTo - private Person personTo; -} - diff --git a/examples/example/src/main/java/example/springdata/gremlin/repository/NetworkRepository.java b/examples/example/src/main/java/example/springdata/gremlin/repository/NetworkRepository.java deleted file mode 100644 index 0fcff995..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/repository/NetworkRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package example.springdata.gremlin.repository; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import example.springdata.gremlin.domain.Network; -import org.springframework.stereotype.Repository; - -@Repository -public interface NetworkRepository extends GremlinRepository { -} - diff --git a/examples/example/src/main/java/example/springdata/gremlin/repository/PersonRepository.java b/examples/example/src/main/java/example/springdata/gremlin/repository/PersonRepository.java deleted file mode 100644 index dfe80716..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/repository/PersonRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package example.springdata.gremlin.repository; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import example.springdata.gremlin.domain.Person; -import org.springframework.data.rest.webmvc.RepositoryRestController; -import org.springframework.stereotype.Repository; - - -@Repository -@RepositoryRestController -public interface PersonRepository extends GremlinRepository { -} - diff --git a/examples/example/src/main/java/example/springdata/gremlin/repository/RelationRepository.java b/examples/example/src/main/java/example/springdata/gremlin/repository/RelationRepository.java deleted file mode 100644 index a0a6e3af..00000000 --- a/examples/example/src/main/java/example/springdata/gremlin/repository/RelationRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package example.springdata.gremlin.repository; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import example.springdata.gremlin.domain.Relation; -import org.springframework.stereotype.Repository; - -@Repository -public interface RelationRepository extends GremlinRepository { -} - diff --git a/examples/example/src/main/resources/application.yml b/examples/example/src/main/resources/application.yml deleted file mode 100644 index 7f669352..00000000 --- a/examples/example/src/main/resources/application.yml +++ /dev/null @@ -1,8 +0,0 @@ -gremlin: - endpoint: localhost - port: 8889 - username: your-username - password: your-password - sslEnabled: false - telemetryAllowed: true - maxContentLength: 1000 diff --git a/examples/example/src/test/java/example/springdata/gremlin/GremlinRepositoryIntegrationTest.java b/examples/example/src/test/java/example/springdata/gremlin/GremlinRepositoryIntegrationTest.java deleted file mode 100644 index cd18fe4b..00000000 --- a/examples/example/src/test/java/example/springdata/gremlin/GremlinRepositoryIntegrationTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.gremlin; - -import example.springdata.gremlin.domain.Network; -import example.springdata.gremlin.domain.Person; -import example.springdata.gremlin.domain.Relation; -import example.springdata.gremlin.repository.NetworkRepository; -import example.springdata.gremlin.repository.PersonRepository; -import example.springdata.gremlin.repository.RelationRepository; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Optional; - -@SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = RepositoryConfiguration.class) -public class GremlinRepositoryIntegrationTest { - private static final String PERSON_ID = "89757"; - private static final String PERSON_ID_0 = "0123456789"; - private static final String PERSON_ID_1 = "666666"; - private static final String PERSON_NAME = "person-name"; - private static final String PERSON_NAME_0 = "person-No.0"; - private static final String PERSON_NAME_1 = "person-No.1"; - private static final String PERSON_AGE = "4"; - private static final String PERSON_AGE_0 = "18"; - private static final String PERSON_AGE_1 = "27"; - - private static final String RELATION_ID = "2333"; - private static final String RELATION_NAME = "brother"; - - private final Person person = new Person(PERSON_ID, PERSON_NAME, PERSON_AGE); - private final Person person0 = new Person(PERSON_ID_0, PERSON_NAME_0, PERSON_AGE_0); - private final Person person1 = new Person(PERSON_ID_1, PERSON_NAME_1, PERSON_AGE_1); - private final Relation relation = new Relation(RELATION_ID, RELATION_NAME, person0, person1); - private final Network network = new Network(); - - @Autowired - private PersonRepository personRepo; - - @Autowired - private RelationRepository relationRepo; - - @Autowired - private NetworkRepository networkRepo; - - @Before - public void setup() { - this.networkRepo.deleteAll(); - } - - @After - public void cleanup() { - this.networkRepo.deleteAll(); - } - - @Test - public void testRepository() { - this.network.getVertexes().add(this.person); - this.network.getVertexes().add(this.person0); - this.network.getVertexes().add(this.person1); - this.network.getEdges().add(this.relation); - - this.networkRepo.save(this.network); - - final Optional personOptional = this.personRepo.findById(this.person.getId()); - Assert.assertTrue(personOptional.isPresent()); - - final Person personFound = personOptional.get(); - Assert.assertEquals(personFound.getId(), this.person.getId()); - Assert.assertEquals(personFound.getName(), this.person.getName()); - Assert.assertEquals(personFound.getAge(), this.person.getAge()); - - final Optional relationOptional = this.relationRepo.findById(this.relation.getId()); - Assert.assertTrue(relationOptional.isPresent()); - - final Relation relationFound = relationOptional.get(); - - Assert.assertEquals(relationFound.getId(), this.relation.getId()); - Assert.assertEquals(relationFound.getName(), this.relation.getName()); - } -} - diff --git a/examples/example/src/test/java/example/springdata/gremlin/RepositoryConfiguration.java b/examples/example/src/test/java/example/springdata/gremlin/RepositoryConfiguration.java deleted file mode 100644 index b99dfe13..00000000 --- a/examples/example/src/test/java/example/springdata/gremlin/RepositoryConfiguration.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.gremlin; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -import com.microsoft.spring.data.gremlin.common.GremlinConfig; -import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; -import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; - -import example.springdata.gremlin.config.GremlinProperties; - - -@Configuration -@EnableGremlinRepositories(basePackages = "example.springdata.gremlin.repository") -@EnableConfigurationProperties(GremlinProperties.class) -@PropertySource("classpath:application.yml") -public class RepositoryConfiguration extends AbstractGremlinConfiguration { - - @Autowired - private GremlinProperties gremlinProps; - - @Override - public GremlinConfig getGremlinConfig() { - return new GremlinConfig( - gremlinProps.getEndpoint(), - gremlinProps.getPort(), - gremlinProps.getUsername(), - gremlinProps.getPassword(), - gremlinProps.isSslEnabled(), - gremlinProps.isTelemetryAllowed(), - gremlinProps.getSerializer(), - gremlinProps.getMaxContentLength() - ); - } -} diff --git a/examples/example/src/test/resources/application.yml b/examples/example/src/test/resources/application.yml deleted file mode 100644 index 85d68b1b..00000000 --- a/examples/example/src/test/resources/application.yml +++ /dev/null @@ -1,7 +0,0 @@ -gremlin: - endpoint: your-endpoint.gremlin.cosmosdb.azure.com - port: 443 - username: your-username - password: your-password - sslEnabled: false - telemetryAllowed: true diff --git a/examples/pom.xml b/examples/pom.xml deleted file mode 100644 index 4311e5e7..00000000 --- a/examples/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - - com.microsoft.spring.data.gremlin.examples - spring-data-gremlin-examples - 0.0.1.BUILD-SNAPSHOT - pom - - - org.springframework.boot - spring-boot-starter-parent - 2.3.0.RELEASE - - - - - UTF-8 - - - Spring Data gremlin - Examples - Sample projects for Spring Data gremlin - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.projectlombok - lombok - provided - - - - org.springframework.data - spring-data-commons - - - - org.springframework.boot - spring-boot-starter-data-rest - - - - com.microsoft.spring.data.gremlin - spring-data-gremlin - 2.3.0 - - - - - example - web-service - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/examples/web-service/pom.xml b/examples/web-service/pom.xml deleted file mode 100644 index 2d94838b..00000000 --- a/examples/web-service/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - 4.0.0 - - spring-data-gremlin-web-service - Spring Data gremlin - Web Service - - - com.microsoft.spring.data.gremlin.examples - spring-data-gremlin-examples - 0.0.1.BUILD-SNAPSHOT - ../pom.xml - - - - - org.springframework.boot - spring-boot - - - - org.springframework.boot - spring-boot-autoconfigure - - - - org.springframework.boot - spring-boot-starter-web - - - - com.jayway.jsonpath - json-path - - - - - diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/Application.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/Application.java deleted file mode 100644 index 77dd3867..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/Application.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package web.service.springdata.gremlin; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } -} diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/config/GremlinProperties.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/config/GremlinProperties.java deleted file mode 100644 index e1105518..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/config/GremlinProperties.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package web.service.springdata.gremlin.config; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import org.apache.tinkerpop.gremlin.driver.ser.Serializers; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -@ConfigurationProperties("gremlin") -public class GremlinProperties { - private String endpoint; - - private int port; - - private String username; - - private String password; - - private boolean sslEnabled; - - private boolean telemetryAllowed = true; - - private String serializer = Serializers.GRAPHSON.toString(); - - private int maxContentLength; -} diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/config/UserRepositoryConfiguration.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/config/UserRepositoryConfiguration.java deleted file mode 100644 index 1956b17d..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/config/UserRepositoryConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2014-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package web.service.springdata.gremlin.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -import com.microsoft.spring.data.gremlin.common.GremlinConfig; -import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; -import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; - - -@Configuration -@EnableGremlinRepositories(basePackages = "web.service.springdata.gremlin.repository") -@EnableConfigurationProperties(GremlinProperties.class) -@PropertySource("classpath:application.yml") -public class UserRepositoryConfiguration extends AbstractGremlinConfiguration { - - @Autowired - private GremlinProperties gremlinProps; - - @Override - public GremlinConfig getGremlinConfig() { - return new GremlinConfig( - gremlinProps.getEndpoint(), - gremlinProps.getPort(), - gremlinProps.getUsername(), - gremlinProps.getPassword(), - gremlinProps.isSslEnabled(), - gremlinProps.isTelemetryAllowed(), - gremlinProps.getSerializer(), - gremlinProps.getMaxContentLength() - ); - } -} diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/MicroService.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/MicroService.java deleted file mode 100644 index 32ef2b6b..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/MicroService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package web.service.springdata.gremlin.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -import java.util.HashMap; -import java.util.Map; - -@Data -@Vertex -@AllArgsConstructor -@NoArgsConstructor -public class MicroService { - - @Id - private String id; - - private Map properties = new HashMap<>(); -} - diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/ServicesDataFlow.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/ServicesDataFlow.java deleted file mode 100644 index b35cd889..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/ServicesDataFlow.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package web.service.springdata.gremlin.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -import java.util.HashMap; -import java.util.Map; - - -@Data -@Edge -@AllArgsConstructor -@NoArgsConstructor -public class ServicesDataFlow { - - @Id - private String id; - - @EdgeFrom - private MicroService serviceFrom; - - @EdgeTo - private MicroService serviceTo; - - private Map properties = new HashMap<>(); -} - diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/SpringCloudServiceNetwork.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/SpringCloudServiceNetwork.java deleted file mode 100644 index e808c78d..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/domain/SpringCloudServiceNetwork.java +++ /dev/null @@ -1,27 +0,0 @@ -package web.service.springdata.gremlin.domain; - -import com.microsoft.spring.data.gremlin.annotation.EdgeSet; -import com.microsoft.spring.data.gremlin.annotation.Graph; -import com.microsoft.spring.data.gremlin.annotation.VertexSet; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -import java.util.ArrayList; -import java.util.List; - -@Graph -@NoArgsConstructor -public class SpringCloudServiceNetwork { - - @Id - private String id; - - @EdgeSet - @Getter - private List edges = new ArrayList<>(); - - @VertexSet - @Getter - private List vertexes = new ArrayList<>(); -} diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/MicroServiceRepository.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/MicroServiceRepository.java deleted file mode 100644 index 34361597..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/MicroServiceRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package web.service.springdata.gremlin.repository; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; -import web.service.springdata.gremlin.domain.MicroService; - -@Repository -public interface MicroServiceRepository extends GremlinRepository { -} - diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/ServicesDataFlowRepository.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/ServicesDataFlowRepository.java deleted file mode 100644 index dd940594..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/ServicesDataFlowRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package web.service.springdata.gremlin.repository; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; -import web.service.springdata.gremlin.domain.ServicesDataFlow; - -@Repository -public interface ServicesDataFlowRepository extends GremlinRepository { -} - diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/SpringCloudServiceNetworkRepository.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/SpringCloudServiceNetworkRepository.java deleted file mode 100644 index 18fa6859..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/repository/SpringCloudServiceNetworkRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package web.service.springdata.gremlin.repository; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; -import web.service.springdata.gremlin.domain.SpringCloudServiceNetwork; - -@Repository -public interface SpringCloudServiceNetworkRepository extends GremlinRepository { -} - diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/web/Controller/WebController.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/web/Controller/WebController.java deleted file mode 100644 index 0b6c6bc9..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/web/Controller/WebController.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package web.service.springdata.gremlin.web.Controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import web.service.springdata.gremlin.domain.MicroService; -import web.service.springdata.gremlin.domain.ServicesDataFlow; -import web.service.springdata.gremlin.repository.MicroServiceRepository; -import web.service.springdata.gremlin.repository.ServicesDataFlowRepository; -import web.service.springdata.gremlin.web.domain.Greeting; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; - -@RestController -public class WebController { - - @Autowired - private MicroServiceRepository microServiceRepo; - - @Autowired - private ServicesDataFlowRepository dataFlowRepo; - - private final AtomicLong counter = new AtomicLong(); - - @RequestMapping(value = "/greeting", method = RequestMethod.GET) - public Greeting greeting() { - return new Greeting(String.valueOf(this.counter.incrementAndGet()), "Greetings to User."); - } - - @RequestMapping(value = "/services/{id}", method = RequestMethod.GET) - public MicroService getService(@PathVariable String id) { - - final Optional foundService = this.microServiceRepo.findById(id); - - return foundService.orElse(null); - } - - @RequestMapping(value = "/services/{id}", method = RequestMethod.PUT) - public MicroService putService(@PathVariable String id, @RequestBody MicroService service) { - - if (!service.getId().equals(id)) { - service.setId(id); - } - - this.microServiceRepo.save(service); - - return service; - } - - @RequestMapping(value = "/services/{id}", method = RequestMethod.DELETE) - public void deleteService(@PathVariable String id) { - this.microServiceRepo.deleteById(id); - } - - @RequestMapping(value = "/services/", method = RequestMethod.DELETE) - public void deleteService(@RequestBody MicroService service) { - this.microServiceRepo.delete(service); - } - - @RequestMapping(value = "/services/all", method = RequestMethod.DELETE) - public void deleteServicesAll() { - this.microServiceRepo.deleteAll(); - } - - @RequestMapping(value = "/services/", method = RequestMethod.PUT) - public MicroService putService(@RequestBody MicroService service) { - - this.microServiceRepo.save(service); - - return service; - } - - @RequestMapping(value = "/services/", method = RequestMethod.GET) - public List getServiceList() { - return (List) this.microServiceRepo.findAll(MicroService.class); - } - - @RequestMapping(value = "/services/create/{id}", method = RequestMethod.PUT) - public MicroService createService(@PathVariable String id, @RequestBody MicroService service) { - return this.putService(id, service); - } - - @RequestMapping(value = "/services/create/", method = RequestMethod.PUT) - public MicroService createService(@RequestBody MicroService service) { - return this.putService(service); - } - - @RequestMapping(value = "/dataflow/{id}", method = RequestMethod.GET) - public ServicesDataFlow getServicesDataFlow(@PathVariable String id) { - - final Optional foundDataFlow = this.dataFlowRepo.findById(id); - - return foundDataFlow.orElse(null); - } - - @RequestMapping(value = "/dataflow/{id}", method = RequestMethod.PUT) - public ServicesDataFlow putServicesDataFlow(@PathVariable String id, @RequestBody ServicesDataFlow dataFlow) { - - if (!dataFlow.getId().equals(id)) { - dataFlow.setId(id); - } - - this.dataFlowRepo.save(dataFlow); - - return dataFlow; - } - - @RequestMapping(value = "/dataflow/", method = RequestMethod.PUT) - public ServicesDataFlow putServicesDataFlow(@RequestBody ServicesDataFlow dataFlow) { - - this.dataFlowRepo.save(dataFlow); - - return dataFlow; - } - - @RequestMapping(value = "/dataflow/", method = RequestMethod.GET) - public List getServicesDataFlowList() { - return (List) this.dataFlowRepo.findAll(ServicesDataFlow.class); - } -} diff --git a/examples/web-service/src/main/java/web/service/springdata/gremlin/web/domain/Greeting.java b/examples/web-service/src/main/java/web/service/springdata/gremlin/web/domain/Greeting.java deleted file mode 100644 index 5ecb4c43..00000000 --- a/examples/web-service/src/main/java/web/service/springdata/gremlin/web/domain/Greeting.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package web.service.springdata.gremlin.web.domain; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -public class Greeting { - - @Getter - private String id; - - @Getter - private String content; -} diff --git a/examples/web-service/src/main/resources/application.yml b/examples/web-service/src/main/resources/application.yml deleted file mode 100644 index 02b63c2d..00000000 --- a/examples/web-service/src/main/resources/application.yml +++ /dev/null @@ -1,8 +0,0 @@ -gremlin: - endpoint: your-endpoint.gremlin.cosmosdb.azure.com - port: 443 - username: your-username - password: your-password - sslEnabled: false - telemetryAllowed: true - maxContentLength: 1000 diff --git a/package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz b/package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz deleted file mode 100644 index e2b7f019..00000000 Binary files a/package/apache-tinkerpop-gremlin-server-minimal-3.3.4.tar.gz and /dev/null differ diff --git a/pom.xml b/pom.xml deleted file mode 100644 index eda63054..00000000 --- a/pom.xml +++ /dev/null @@ -1,326 +0,0 @@ - - - 4.0.0 - - com.microsoft.spring.data.gremlin - spring-data-gremlin - 2.3.1-SNAPSHOT - - Spring Data Gremlin - Gremlin support for Spring Data - https://github.com/Microsoft/spring-data-gremlin - - - - MIT - https://github.com/Microsoft/spring-data-gremlin/blob/master/LICENSE - repo - - - - - scm:git:git://github.com:Microsoft/spring-data-gremlin.git - scm:git:ssh://github.com:Microsoft/spring-data-gremlin.git - https://github.com/Microsoft/spring-data-gremlin/tree/master - - - - - incarnation-p-lee - Pan Li - panli@microsoft.com - - - - - 1.8 - 1.8 - UTF-8 - - 5.2.6.RELEASE - 2.3.0.RELEASE - 2.3.0.RELEASE - - 3.2.4 - 3.7 - 1.16.18 - 2.8.9 - 2.10.0.pr1 - - true - - - - - - org.springframework - spring-framework-bom - ${spring.springframework.version} - pom - import - - - - - - - - org.springframework - spring-core - - - commons-logging - commons-logging - - - - - - - org.springframework - spring-web - - - - - org.springframework - spring-tx - - - - - org.springframework.data - spring-data-commons - ${spring.data.version} - - - - - org.apache.tinkerpop - gremlin-driver - ${org.apache.tinkerpop.gremlin.driver.version} - - - - - org.apache.commons - commons-lang3 - ${apache.commons.lang3.version} - - - - - org.springframework - spring-context - - - - - org.mockito - mockito-core - ${mockito.core.version} - test - - - - - org.springframework.boot - spring-boot-starter-test - ${spring.boot.test.version} - test - - - - - org.projectlombok - lombok - ${org.projectlombok.version} - provided - - - - - com.fasterxml.jackson.core - jackson-databind - ${fasterxml.jackson.version} - - - - - - - src/main/resources - true - - META-INF/project.properties - telemetry.config - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - validate - validate - - ${project.basedir}/config/checkstyle.xml - UTF-8 - true - true - true - true - - - check - - - - - false - - true - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.5 - - Max - Low - true - ${project.build.directory}/findbugs - - ${project.basedir}/config/findbugs-exclude.xml - - - - org.apache.ant - ant - 1.9.15 - - - - - compile - - check - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.20 - - ${skip.integration.tests} - - - - - integration-test - verify - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - - html - xml - - - false - 65 - 65 - - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - private - false - - - - attach-javadocs - - jar - - - -Xdoclint:none - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.0.2 - - - - true - true - - - - - - - - - - full-test - - full-test - false - - - - - release - - - release - - - - - diff --git a/script/integration-test-setup.sh b/script/integration-test-setup.sh deleted file mode 100644 index 99e7e331..00000000 --- a/script/integration-test-setup.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -cat << EOF - -gremlin.endpoint=localhost -gremlin.port=9889 -gremlin.username="anonymous" -gremlin.password="anonymous" -gremlin.sslEnabled=false - -EOF - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/Edge.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/Edge.java deleted file mode 100644 index 721aa5c9..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/Edge.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import com.microsoft.spring.data.gremlin.common.Constants; -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the class as edge in graph, with one optional label(String). - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Edge { - /** - * The label(gremlin reserved) of given Edge, can add Edge by label. - * @return class name if not specify. - */ - String label() default Constants.DEFAULT_EDGE_LABEL; -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeFrom.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeFrom.java deleted file mode 100644 index 07602a96..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeFrom.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the field as source of one edge. - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface EdgeFrom { -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeSet.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeSet.java deleted file mode 100644 index 98c79ff5..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeSet.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the field as EdgeSet of graph. - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface EdgeSet { -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeTo.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeTo.java deleted file mode 100644 index 303f57e1..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/EdgeTo.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the field as target of one edge. - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface EdgeTo { -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/GeneratedValue.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/GeneratedValue.java deleted file mode 100644 index 2203eeed..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/GeneratedValue.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Specifies that a field's value is to be generated (and not explicitly specified in the domain object). - * This annotation should only be used on an id field. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface GeneratedValue { - -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/Graph.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/Graph.java deleted file mode 100644 index 323935c8..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/Graph.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import com.microsoft.spring.data.gremlin.common.Constants; -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the domain class as graph, with one optional collection(String). - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface Graph { - /** - * The collection of given Graph. - * @return class name if not specify. - */ - String collection() default Constants.DEFAULT_COLLECTION_NAME; -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/Vertex.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/Vertex.java deleted file mode 100644 index 14834643..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/Vertex.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import com.microsoft.spring.data.gremlin.common.Constants; -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the class as vertex in graph, with one optional label(String). - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface Vertex { - /** - * The label(gremlin reserved) of given Vertex, can add Vertex by label. - * @return class name if not specify. - */ - String label() default Constants.DEFAULT_VERTEX_LABEL; -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/annotation/VertexSet.java b/src/main/java/com/microsoft/spring/data/gremlin/annotation/VertexSet.java deleted file mode 100644 index f6015107..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/annotation/VertexSet.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import org.springframework.data.annotation.Persistent; - -import java.lang.annotation.*; - -/** - * Specifies the field as VertexSet of graph. - */ -@Persistent -@Inherited -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface VertexSet { -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/common/Constants.java b/src/main/java/com/microsoft/spring/data/gremlin/common/Constants.java deleted file mode 100644 index 418c1997..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/common/Constants.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class Constants { - - public static final String PROPERTY_ID = "id"; - public static final String PROPERTY_LABEL = "label"; - public static final String PROPERTY_TYPE = "type"; - public static final String PROPERTY_VALUE = "value"; - public static final String PROPERTY_PROPERTIES = "properties"; - public static final String PROPERTY_INV = "inV"; - public static final String PROPERTY_OUTV = "outV"; - - public static final String RESULT_TYPE_VERTEX = "vertex"; - public static final String RESULT_TYPE_EDGE = "edge"; - - public static final String DEFAULT_VERTEX_LABEL = ""; - public static final String DEFAULT_EDGE_LABEL = ""; - public static final String DEFAULT_COLLECTION_NAME = ""; - public static final int DEFAULT_ENDPOINT_PORT = 443; - public static final String DEFAULT_REPOSITORY_IMPLEMENT_POSTFIX = "Impl"; - - public static final String GREMLIN_MODULE_NAME = "Gremlin"; - public static final String GREMLIN_MODULE_PREFIX = "gremlin"; - public static final String GREMLIN_MAPPING_CONTEXT = "gremlinMappingContext"; - - public static final String GREMLIN_PRIMITIVE_GRAPH = "g"; - public static final String GREMLIN_PRIMITIVE_INVOKE = "."; - public static final String GREMLIN_PRIMITIVE_DROP = "drop()"; - - public static final String GREMLIN_PRIMITIVE_EDGE_ALL = "E()"; - - public static final String GREMLIN_PRIMITIVE_VERTEX_ALL = "V()"; - - public static final String GREMLIN_PRIMITIVE_HAS_STRING = "has('%s', '%s')"; - public static final String GREMLIN_PRIMITIVE_HAS_NUMBER = "has('%s', %d)"; - public static final String GREMLIN_PRIMITIVE_HAS_BOOLEAN = "has('%s', %b)"; - - public static final String GREMLIN_PRIMITIVE_PROPERTY_STRING = "property('%s', '%s')"; - public static final String GREMLIN_PRIMITIVE_PROPERTY_NUMBER = "property('%s', %d)"; - public static final String GREMLIN_PRIMITIVE_PROPERTY_BOOLEAN = "property('%s', %b)"; - - public static final String GREMLIN_PRIMITIVE_AND = "and()"; - public static final String GREMLIN_PRIMITIVE_OR = "or()"; - public static final String GREMLIN_PRIMITIVE_WHERE = "where(%s)"; - - public static final String GREMLIN_QUERY_BARRIER = "barrier"; - - public static final String GREMLIN_PRIMITIVE_VALUES = "values('%s')"; - public static final String GREMLIN_PRIMITIVE_IS = "is(%s)"; - public static final String GREMLIN_PRIMITIVE_GT = "gt(%d)"; - public static final String GREMLIN_PRIMITIVE_LT = "lt(%d)"; - public static final String GREMLIN_PRIMITIVE_BETWEEN = "between(%d, %d)"; - - public static final String GREMLIN_PRIMITIVE_IS_GT = String.format(GREMLIN_PRIMITIVE_IS, GREMLIN_PRIMITIVE_GT); - public static final String GREMLIN_PRIMITIVE_IS_LT = String.format(GREMLIN_PRIMITIVE_IS, GREMLIN_PRIMITIVE_LT); - public static final String GREMLIN_PRIMITIVE_IS_BETWEEN = String.format( - GREMLIN_PRIMITIVE_IS, - GREMLIN_PRIMITIVE_BETWEEN - ); - - public static final String GREMLIN_SCRIPT_EDGE_ALL = String.join(GREMLIN_PRIMITIVE_INVOKE, - GREMLIN_PRIMITIVE_GRAPH, - GREMLIN_PRIMITIVE_EDGE_ALL - ); - - public static final String GREMLIN_SCRIPT_VERTEX_ALL = String.join(GREMLIN_PRIMITIVE_INVOKE, - GREMLIN_PRIMITIVE_GRAPH, - GREMLIN_PRIMITIVE_VERTEX_ALL - ); - - public static final String GREMLIN_SCRIPT_EDGE_DROP_ALL = String.join(GREMLIN_PRIMITIVE_INVOKE, - GREMLIN_PRIMITIVE_GRAPH, - GREMLIN_PRIMITIVE_EDGE_ALL, - GREMLIN_PRIMITIVE_DROP - ); - - public static final String GREMLIN_SCRIPT_VERTEX_DROP_ALL = String.join(GREMLIN_PRIMITIVE_INVOKE, - GREMLIN_PRIMITIVE_GRAPH, - GREMLIN_PRIMITIVE_VERTEX_ALL, - GREMLIN_PRIMITIVE_DROP - ); - - public static final String GREMLIN_PROPERTY_CLASSNAME = "_classname"; - - public static final int DEFAULT_MAX_CONTENT_LENGTH = 65536; - -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinConfig.java b/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinConfig.java deleted file mode 100644 index 5a9b62b8..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import org.apache.tinkerpop.gremlin.driver.ser.Serializers; - -@Getter -@Setter -@Builder(builderMethodName = "defaultBuilder") -@AllArgsConstructor(access = AccessLevel.PUBLIC) -public class GremlinConfig { - private String endpoint; - - private int port; - - private String username; - - private String password; - - private boolean sslEnabled; - - private boolean telemetryAllowed; - - private String serializer; - - private int maxContentLength; - - - public static GremlinConfigBuilder builder(String endpoint, String username, String password) { - return defaultBuilder() - .endpoint(endpoint) - .username(username) - .password(password) - .port(Constants.DEFAULT_ENDPOINT_PORT) - .sslEnabled(true) - .serializer(Serializers.GRAPHSON.toString()) - .telemetryAllowed(true); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinEntityType.java b/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinEntityType.java deleted file mode 100644 index c70df8b4..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinEntityType.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import org.springframework.lang.NonNull; - -import java.util.function.Supplier; - -public enum GremlinEntityType { - - VERTEX(GremlinSourceVertex::new), - EDGE(GremlinSourceEdge::new), - GRAPH(GremlinSourceGraph::new); - - private Supplier creator; - - GremlinEntityType(@NonNull Supplier creator) { - this.creator = creator; - } - - public GremlinSource createGremlinSource() { - return this.creator.get(); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinFactory.java b/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinFactory.java deleted file mode 100644 index df7357d2..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.exception.GremlinIllegalConfigurationException; -import com.microsoft.spring.data.gremlin.telemetry.TelemetrySender; -import org.apache.tinkerpop.gremlin.driver.Client; -import org.apache.tinkerpop.gremlin.driver.Cluster; -import org.apache.tinkerpop.gremlin.driver.ser.Serializers; -import org.springframework.lang.NonNull; - -import javax.annotation.PostConstruct; - -public class GremlinFactory { - - private Cluster gremlinCluster; - - private GremlinConfig gremlinConfig; - - public GremlinFactory(@NonNull GremlinConfig gremlinConfig) { - final int port = gremlinConfig.getPort(); - if (port <= 0 || port > 65535) { - gremlinConfig.setPort(Constants.DEFAULT_ENDPOINT_PORT); - } - - final int maxContentLength = gremlinConfig.getMaxContentLength(); - if (maxContentLength <= 0) { - gremlinConfig.setMaxContentLength(Constants.DEFAULT_MAX_CONTENT_LENGTH); - } - - this.gremlinConfig = gremlinConfig; - } - - private Cluster createGremlinCluster() throws GremlinIllegalConfigurationException { - final Cluster cluster; - - try { - cluster = Cluster.build(this.gremlinConfig.getEndpoint()) - .serializer(Serializers.valueOf(this.gremlinConfig.getSerializer()).simpleInstance()) - .credentials(this.gremlinConfig.getUsername(), this.gremlinConfig.getPassword()) - .enableSsl(this.gremlinConfig.isSslEnabled()) - .maxContentLength(this.gremlinConfig.getMaxContentLength()) - .port(this.gremlinConfig.getPort()) - .create(); - } catch (IllegalArgumentException e) { - throw new GremlinIllegalConfigurationException("Invalid configuration of Gremlin", e); - } - - return cluster; - } - - public Client getGremlinClient() { - - if (this.gremlinCluster == null) { - this.gremlinCluster = this.createGremlinCluster(); - } - - return this.gremlinCluster.connect(); - } - - @PostConstruct - private void sendTelemetry() { - - if (gremlinConfig.isTelemetryAllowed()) { - final TelemetrySender sender = new TelemetrySender(); - - sender.send(this.getClass().getSimpleName()); - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinUtils.java b/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinUtils.java deleted file mode 100644 index d172bcec..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/common/GremlinUtils.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.exception.GremlinIllegalConfigurationException; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.repository.support.GremlinEntityInformation; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.tinkerpop.shaded.jackson.databind.MapperFeature; -import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; -import org.springframework.data.annotation.Id; -import org.springframework.lang.NonNull; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import static com.microsoft.spring.data.gremlin.common.Constants.GREMLIN_QUERY_BARRIER; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class GremlinUtils { - - private static final ObjectMapper mapper = new ObjectMapper(); - - static { - mapper.configure(MapperFeature.AUTO_DETECT_FIELDS, false); - } - - public static ObjectMapper getObjectMapper() { - return mapper; - } - - public static T createInstance(@NonNull Class type) { - final T instance; - - try { - instance = type.newInstance(); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException("can not access type constructor", e); - } catch (InstantiationException e) { - throw new IllegalArgumentException("failed to create instance of given type", e); - } - - return instance; - } - - public static Field getIdField(@NonNull Class domainClass) { - final Field idField; - final List idFields = FieldUtils.getFieldsListWithAnnotation(domainClass, Id.class); - final List generatedValueFields = - FieldUtils.getFieldsListWithAnnotation(domainClass, GeneratedValue.class); - - if (generatedValueFields.size() > 1) { - throw new GremlinIllegalConfigurationException("Only one field, the id field, can have the optional " - + "@GeneratedValue annotation!"); - } - - if (idFields.isEmpty()) { - idField = ReflectionUtils.findField(domainClass, Constants.PROPERTY_ID); - } else if (idFields.size() == 1) { - idField = idFields.get(0); - } else { - throw new GremlinInvalidEntityIdFieldException("only one @Id field is allowed"); - } - - if (idField == null) { - throw new GremlinInvalidEntityIdFieldException("no field named id in class"); - } else if (idField.getType() != String.class - && idField.getType() != Long.class && idField.getType() != Integer.class) { - throw new GremlinInvalidEntityIdFieldException("the type of @Id/id field should be String/Integer/Long"); - } - - if (generatedValueFields.size() == 1 && !generatedValueFields.get(0).equals(idField)) { - throw new GremlinIllegalConfigurationException("Only the id field can have the optional " - + "@GeneratedValue annotation!"); - } - - return idField; - } - - public static long timeToMilliSeconds(@NonNull Object time) { - if (time instanceof Date) { - return ((Date) time).getTime(); - } else { - throw new UnsupportedOperationException("Unsupported time type"); - } - } - - public static long toPrimitiveLong(@NonNull Object object) { - if (object instanceof Date) { - return timeToMilliSeconds(object); - } else if (object instanceof Integer) { - return (long) (int) object; - } else if (object instanceof Long) { - return (long) object; - } else { - throw new UnsupportedOperationException("Unsupported object type to long"); - } - } - - public static GremlinSource toGremlinSource(@NonNull Class domainClass) { - return new GremlinEntityInformation<>(domainClass).createGremlinSource(); - } - - public static List> toParallelQueryList(@NonNull List queries) { - final List> parallelQueries = new ArrayList<>(); - List parallelQuery = new ArrayList<>(); - - for (final String query : queries) { - if (query.equals(GREMLIN_QUERY_BARRIER)) { - parallelQueries.add(parallelQuery); - parallelQuery = new ArrayList<>(); - } else { - parallelQuery.add(query); - } - } - - parallelQueries.add(parallelQuery); - - return parallelQueries; - } - - public static Class toEntityClass(@NonNull String className) { - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - throw new GremlinUnexpectedSourceTypeException("failed to retrieve class: " + className, e); - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfiguration.java b/src/main/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfiguration.java deleted file mode 100644 index b7fec52a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.config; - -import com.microsoft.spring.data.gremlin.common.GremlinConfig; -import com.microsoft.spring.data.gremlin.common.GremlinFactory; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.query.GremlinTemplate; -import org.springframework.context.annotation.Bean; - -public abstract class AbstractGremlinConfiguration extends GremlinConfigurationSupport { - - public abstract GremlinConfig getGremlinConfig(); - - @Bean - public GremlinFactory gremlinFactory() { - return new GremlinFactory(getGremlinConfig()); - } - - @Bean - public MappingGremlinConverter mappingGremlinConverter() throws ClassNotFoundException { - return new MappingGremlinConverter(gremlinMappingContext()); - } - - @Bean - public GremlinTemplate gremlinTemplate(GremlinFactory factory) throws ClassNotFoundException { - return new GremlinTemplate(factory, mappingGremlinConverter()); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupport.java b/src/main/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupport.java deleted file mode 100644 index 32eeeb80..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupport.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.config; - -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.core.type.filter.AnnotationTypeFilter; -import org.springframework.data.annotation.Persistent; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public abstract class GremlinConfigurationSupport { - - protected Collection getMappingBasePackages() { - final Package basePackage = this.getClass().getPackage(); - - return Collections.singleton(basePackage == null ? null : basePackage.getName()); - } - - protected Set> scanEntities(@NonNull String basePackage) throws ClassNotFoundException { - if (!StringUtils.hasText(basePackage)) { - return Collections.emptySet(); - } - - final Set> entitySet = new HashSet<>(); - final ClassPathScanningCandidateComponentProvider provider = - new ClassPathScanningCandidateComponentProvider(false); - - provider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); - - for (final BeanDefinition candidate : provider.findCandidateComponents(basePackage)) { - final String className = candidate.getBeanClassName(); - Assert.notNull(GremlinConfigurationSupport.class.getClassLoader(), "Class loader cannot be null"); - - entitySet.add(ClassUtils.forName(className, GremlinConfigurationSupport.class.getClassLoader())); - } - - return entitySet; - } - - protected Set> getInitialEntitySet() throws ClassNotFoundException { - final Set> entitySet = new HashSet<>(); - - for (final String basePackage : this.getMappingBasePackages()) { - entitySet.addAll(this.scanEntities(basePackage)); - } - - return entitySet; - } - - @Bean - public GremlinMappingContext gremlinMappingContext() throws ClassNotFoundException { - final GremlinMappingContext context = new GremlinMappingContext(); - - context.setInitialEntitySet(this.getInitialEntitySet()); - - return context; - } - -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/MappingGremlinConverter.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/MappingGremlinConverter.java deleted file mode 100644 index 07c9a75c..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/MappingGremlinConverter.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.core.convert.ConversionService; -import org.springframework.core.convert.support.GenericConversionService; -import org.springframework.data.convert.EntityConverter; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.PersistentPropertyAccessor; -import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentProperty; - -public class MappingGremlinConverter - implements EntityConverter, GremlinPersistentProperty, Object, GremlinSource>, - ApplicationContextAware { - - protected final MappingContext, GremlinPersistentProperty> mappingContext; - protected GenericConversionService conversionService; - private ApplicationContext applicationContext; - - public MappingGremlinConverter( - MappingContext, GremlinPersistentProperty> context) { - - this.mappingContext = context; - this.conversionService = new GenericConversionService(); - } - - public ApplicationContext getApplicationContext() { - return this.applicationContext; - } - - @Override - public MappingContext, GremlinPersistentProperty> getMappingContext() { - return this.mappingContext; - } - - @Override - public void setApplicationContext(ApplicationContext context) { - this.applicationContext = context; - } - - @Override - public ConversionService getConversionService() { - return this.conversionService; - } - - @Override - public T read(Class domainClass, @NonNull GremlinSource source) { - @SuppressWarnings("unchecked") final GremlinSource gremlinSource = (GremlinSource) source; - - return gremlinSource.doGremlinSourceRead(domainClass, this); - } - - @Override - public void write(@NonNull Object domain, @NonNull GremlinSource source) { - source.doGremlinSourceWrite(domain, this); - } - - public ConvertingPropertyAccessor getPropertyAccessor(@NonNull Object domain) { - final GremlinPersistentEntity persistentEntity = this.getPersistentEntity(domain.getClass()); - Assert.notNull(persistentEntity, "persistentEntity should not be null"); - - final PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(domain); - - return new ConvertingPropertyAccessor(accessor, this.conversionService); - } - - public GremlinPersistentEntity getPersistentEntity(@NonNull Class domainClass) { - return mappingContext.getPersistentEntity(domainClass); - } - - private String getIdFieldName(@NonNull Object domain) { - return GremlinUtils.getIdField(domain.getClass()).getName(); - } - - private Object getFieldValue(@NonNull Object domain, @NonNull String fieldName) { - final ConvertingPropertyAccessor accessor = this.getPropertyAccessor(domain); - final GremlinPersistentEntity persistentEntity = this.getPersistentEntity(domain.getClass()); - final PersistentProperty property = persistentEntity.getPersistentProperty(fieldName); - - return property != null ? accessor.getProperty(property) : null; - } - - public Object getIdFieldValue(@NonNull Object domain) { - return this.getFieldValue(domain, this.getIdFieldName(domain)); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/AbstractGremlinResultReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/AbstractGremlinResultReader.java deleted file mode 100644 index 1b7881b1..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/AbstractGremlinResultReader.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.result; - -import com.microsoft.spring.data.gremlin.common.Constants; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import lombok.NoArgsConstructor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.Map; - -@NoArgsConstructor -// TODO: seems only for Vertex. -public abstract class AbstractGremlinResultReader { - - /** - * properties's organization is a little complicated. - *

- * properties is LinkedHashMap - * K is String - * V is ArrayList - * T is LinkedHashMap - */ - private Object readProperty(@NonNull Object value) { - Assert.isInstanceOf(ArrayList.class, value, "should be instance of ArrayList"); - - @SuppressWarnings("unchecked") final ArrayList> mapList - = (ArrayList>) value; - - Assert.isTrue(mapList.size() == 1, "should be only 1 element in ArrayList"); - - return mapList.get(0).get(Constants.PROPERTY_VALUE); - } - - protected void readResultProperties(@NonNull Map properties, @NonNull GremlinSource source) { - source.getProperties().clear(); - properties.forEach((key, value) -> source.setProperty(key, this.readProperty(value))); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultEdgeReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultEdgeReader.java deleted file mode 100644 index a0d3341d..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultEdgeReader.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.result; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.apache.tinkerpop.gremlin.driver.Result; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Map; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; - -@NoArgsConstructor -public class GremlinResultEdgeReader extends AbstractGremlinResultReader implements GremlinResultsReader { - - private void readProperties(@NonNull GremlinSource source, @Nullable Map map) { - if (map != null) { - @SuppressWarnings("unchecked") final Map properties = (Map) map; - - properties.forEach(source::setProperty); - } - } - - private void validate(List results, GremlinSource source) { - Assert.notNull(results, "Results should not be null."); - Assert.notNull(source, "GremlinSource should not be null."); - Assert.isTrue(results.size() == 1, "Edge should contain only one result."); - - final Result result = results.get(0); - - Assert.isInstanceOf(Map.class, result.getObject(), "should be one instance of Map"); - - @SuppressWarnings("unchecked") final Map map = (Map) result.getObject(); - - Assert.isTrue(map.containsKey(PROPERTY_ID), "should contain id property"); - Assert.isTrue(map.containsKey(PROPERTY_LABEL), "should contain label property"); - Assert.isTrue(map.containsKey(PROPERTY_TYPE), "should contain type property"); - Assert.isTrue(map.containsKey(PROPERTY_INV), "should contain inV property"); - Assert.isTrue(map.containsKey(PROPERTY_OUTV), "should contain outV property"); - Assert.isTrue(map.get(PROPERTY_TYPE).equals(RESULT_TYPE_EDGE), "must be vertex type"); - } - - @Override - @SuppressWarnings("unchecked") - public void read(@NonNull List results, @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("Should be instance of GremlinSourceEdge"); - } - - validate(results, source); - - final GremlinSourceEdge sourceEdge = (GremlinSourceEdge) source; - final Map map = (Map) results.get(0).getObject(); - - this.readProperties(source, (Map) map.get(PROPERTY_PROPERTIES)); - - final String className = source.getProperties().get(GREMLIN_PROPERTY_CLASSNAME).toString(); - - sourceEdge.setIdField(GremlinUtils.getIdField(GremlinUtils.toEntityClass(className))); - sourceEdge.setId(map.get(PROPERTY_ID)); - sourceEdge.setLabel(map.get(PROPERTY_LABEL).toString()); - sourceEdge.setVertexIdFrom(map.get(PROPERTY_OUTV)); - sourceEdge.setVertexIdTo(map.get(PROPERTY_INV)); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultVertexReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultVertexReader.java deleted file mode 100644 index 10e8795e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultVertexReader.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.result; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import lombok.NoArgsConstructor; -import org.apache.tinkerpop.gremlin.driver.Result; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Map; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; - -@NoArgsConstructor -public class GremlinResultVertexReader extends AbstractGremlinResultReader implements GremlinResultsReader { - - private void validate(List results, GremlinSource source) { - Assert.notNull(results, "Results should not be null."); - Assert.notNull(source, "GremlinSource should not be null."); - Assert.isTrue(results.size() == 1, "Vertex should contain only one result."); - - final Result result = results.get(0); - - Assert.isInstanceOf(Map.class, result.getObject(), "should be one instance of Map"); - - @SuppressWarnings("unchecked") final Map map = (Map) result.getObject(); - - Assert.isTrue(map.containsKey(PROPERTY_ID), "should contain id property"); - Assert.isTrue(map.containsKey(PROPERTY_LABEL), "should contain label property"); - Assert.isTrue(map.containsKey(PROPERTY_TYPE), "should contain type property"); - Assert.isTrue(map.containsKey(PROPERTY_PROPERTIES), "should contain properties property"); - Assert.isTrue(map.get(PROPERTY_TYPE).equals(RESULT_TYPE_VERTEX), "must be vertex type"); - - Assert.isInstanceOf(Map.class, map.get(PROPERTY_PROPERTIES), "should be one instance of Map"); - } - - @Override - @SuppressWarnings("unchecked") - public void read(@NonNull List results, @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("Should be instance of GremlinSourceVertex"); - } - - validate(results, source); - - final Map map = (Map) results.get(0).getObject(); - final Map properties = (Map) map.get(PROPERTY_PROPERTIES); - - super.readResultProperties(properties, source); - - final String className = source.getProperties().get(GREMLIN_PROPERTY_CLASSNAME).toString(); - - source.setIdField(GremlinUtils.getIdField(GremlinUtils.toEntityClass(className))); - source.setId(map.get(PROPERTY_ID)); - source.setLabel(map.get(PROPERTY_LABEL).toString()); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsGraphReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsGraphReader.java deleted file mode 100644 index 8ef2d18a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsGraphReader.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.result; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import org.apache.tinkerpop.gremlin.driver.Result; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Map; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; -import static java.util.Collections.singletonList; - -public class GremlinResultsGraphReader extends AbstractGremlinResultReader implements GremlinResultsReader { - - private final GremlinResultVertexReader vertexResultReader; - private final GremlinResultEdgeReader edgeResultReader; - - public GremlinResultsGraphReader() { - vertexResultReader = new GremlinResultVertexReader(); - edgeResultReader = new GremlinResultEdgeReader(); - } - - @Override - public void read(@NonNull List results, @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceGraph)) { - throw new GremlinUnexpectedSourceTypeException("Should be instance of GremlinSourceGraph"); - } - - final GremlinSourceGraph graphSource = (GremlinSourceGraph) source; - - graphSource.getVertexSet().clear(); - graphSource.getEdgeSet().clear(); - - results.stream().map(this::processResult).forEach(graphSource::addGremlinSource); - } - - private GremlinSource processResult(Result result) { - final GremlinSource source; - final Object obj = result.getObject(); - - Assert.isInstanceOf(Map.class, obj, "should be an instance of Map"); - @SuppressWarnings("unchecked") final Map map = (Map) result.getObject(); - - Assert.isTrue(map.containsKey(PROPERTY_TYPE), "should contain a type property"); - final String type = (String) map.get(PROPERTY_TYPE); - - switch (type) { - case RESULT_TYPE_VERTEX: - source = new GremlinSourceVertex(); - vertexResultReader.read(singletonList(result), source); - break; - case RESULT_TYPE_EDGE: - source = new GremlinSourceEdge(); - edgeResultReader.read(singletonList(result), source); - break; - default: - throw new GremlinUnexpectedEntityTypeException("Unexpected result type: " + type); - } - - return source; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsReader.java deleted file mode 100644 index 93145ee6..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultsReader.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.result; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import org.apache.tinkerpop.gremlin.driver.Result; - -import java.util.List; - -public interface GremlinResultsReader { - /** - * Read the Gremlin returned Results to GremlinSource. - */ - void read(List results, GremlinSource source); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteral.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteral.java deleted file mode 100644 index 70f84f04..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteral.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import lombok.NonNull; -import org.apache.tinkerpop.shaded.jackson.core.JsonProcessingException; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; -import java.util.*; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; - -public abstract class AbstractGremlinScriptLiteral { - - protected static String generateEntityWithRequiredId(@NonNull Object id, GremlinEntityType type) { - Assert.isTrue(type == GremlinEntityType.EDGE || type == GremlinEntityType.VERTEX, "should be edge/vertex type"); - - final String prefix = (type == GremlinEntityType.VERTEX) ? "V" : "E"; - - if (id instanceof String) { - return prefix + String.format("('%s')", (String) id); - } else if (id instanceof Integer) { - return prefix + String.format("(%d)", (Integer) id); - } else if (id instanceof Long) { - return prefix + String.format("(%d)", (Long) id); - } - - throw new GremlinInvalidEntityIdFieldException("Only String/Integer/Long of id is supported"); - } - - protected static String generatePropertyWithRequiredId(@NonNull Object id) { - if (id instanceof String) { - return String.format("property(id, '%s')", (String) id); - } else if (id instanceof Integer) { - return String.format("property(id, %d)", (Integer) id); - } else if (id instanceof Long) { - return String.format("property(id, %d)", (Long) id); - } - - throw new GremlinInvalidEntityIdFieldException("Only String/Integer/Long of id is supported"); - } - - protected static String generateAsWithAlias(@NonNull String alias) { - return String.format("as('%s')", alias); - } - - protected static String generateAddEntityWithLabel(@NonNull String label, GremlinEntityType type) { - Assert.isTrue(type == GremlinEntityType.EDGE || type == GremlinEntityType.VERTEX, "should be edge/vertex type"); - - final String prefix = (type == GremlinEntityType.VERTEX) ? "addV" : "addE"; - - return prefix + String.format("('%s')", label); - } - - protected static List completeScript(@NonNull List scriptList) { - return Collections.singletonList(String.join(GREMLIN_PRIMITIVE_INVOKE, scriptList)); - } - - public static String generateHasLabel(@NonNull String label) { - return String.format("has(label, '%s')", label); - } - - public static String generateHasId(@NonNull Object id) { - if (id instanceof String) { - return String.format("hasId('%s')", id); - } else if (id instanceof Integer) { - return String.format("hasId(%d)", (Integer) id); - } else if (id instanceof Long) { - return String.format("hasId(%d)", (Long) id); - } else { - throw new GremlinInvalidEntityIdFieldException("the type of @Id/id field should be String/Integer/Long"); - } - } - - public static String generateHasId(@NonNull Object id, @NonNull Field idFiled) { - if (!idFiled.isAnnotationPresent(GeneratedValue.class)) { - return generateHasId(id); - } else if (id instanceof String) { - return String.format("hasId('%s')", id); - } else if (id instanceof Integer) { - return String.format("hasId(%dL)", (Integer) id); - } else if (id instanceof Long) { - return String.format("hasId(%dL)", (Long) id); - } else { - throw new GremlinInvalidEntityIdFieldException("the type of @Id/id field should be String/Integer/Long"); - } - } - - private static String generateProperty(@NonNull String name, @NonNull String value) { - return String.format(GREMLIN_PRIMITIVE_PROPERTY_STRING, name, value); - } - - private static String generateProperty(@NonNull String name, @NonNull Integer value) { - return String.format(GREMLIN_PRIMITIVE_PROPERTY_NUMBER, name, value); - } - - private static String generateProperty(@NonNull String name, @NonNull Boolean value) { - return String.format(GREMLIN_PRIMITIVE_PROPERTY_BOOLEAN, name, value); - } - - private static String generateProperty(@NonNull String name, @NonNull Long value) { - return String.format(GREMLIN_PRIMITIVE_PROPERTY_NUMBER, name, value); - } - - private static String generateProperty(@NonNull String name, @NonNull Object value) { - if (value instanceof Integer) { - return generateProperty(name, (Integer) value); - } else if (value instanceof Boolean) { - return generateProperty(name, (Boolean) value); - } else if (value instanceof String) { - return generateProperty(name, (String) value); - } else if (value instanceof Date) { - return generateProperty(name, GremlinUtils.timeToMilliSeconds(value)); - } else { - final String propertyScript; - - try { - propertyScript = generateProperty(name, GremlinUtils.getObjectMapper().writeValueAsString(value)); - } catch (JsonProcessingException e) { - throw new GremlinUnexpectedEntityTypeException("Failed to write object to String", e); - } - - return propertyScript; - } - } - - protected static List generateProperties(@NonNull final Map properties) { - final List scripts = new ArrayList<>(); - - properties.entrySet().stream().filter(e -> e.getValue() != null) - .forEach(e -> scripts.add(generateProperty(e.getKey(), e.getValue()))); - - return scripts; - } - - private static String generateHas(@NonNull String name, @NonNull Integer value) { - return String.format(GREMLIN_PRIMITIVE_HAS_NUMBER, name, value); - } - - private static String generateHas(@NonNull String name, @NonNull Boolean value) { - return String.format(GREMLIN_PRIMITIVE_HAS_BOOLEAN, name, value); - } - - private static String generateHas(@NonNull String name, @NonNull String value) { - return String.format(GREMLIN_PRIMITIVE_HAS_STRING, name, value); - } - - private static String generateHas(@NonNull String name, @NonNull Long value) { - return String.format(GREMLIN_PRIMITIVE_HAS_NUMBER, name, value); - } - - // TODO: should move to query method part. - public static String generateHas(@NonNull String name, @NonNull Object value) { - - if (value instanceof Integer) { - return generateHas(name, (Integer) value); - } else if (value instanceof Boolean) { - return generateHas(name, (Boolean) value); - } else if (value instanceof String) { - return generateHas(name, (String) value); - } else if (value instanceof Date) { - return generateHas(name, GremlinUtils.timeToMilliSeconds(value)); - } else { - final String hasScript; - - try { - hasScript = generateHas(name, GremlinUtils.getObjectMapper().writeValueAsString(value)); - } catch (JsonProcessingException e) { - throw new GremlinUnexpectedEntityTypeException("Failed to write object to String", e); - } - - return hasScript; - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteral.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteral.java deleted file mode 100644 index cd49fd69..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteral.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; - -import java.util.List; - -/** - * Provider interface to generate different query to gremlin server. - * The scripts return queries in steps, organized by List. - */ -public interface GremlinScriptLiteral { - /** - * Generate the insert query from source (Vertex, Edge or Graph). - */ - List generateInsertScript(GremlinSource source); - - /** - * Generate the deleteAll query from source (Vertex, Edge or Graph). - */ - List generateDeleteAllScript(); - - /** - * Generate the deleteAll By Domain Class query from source (Vertex, Edge or Graph). - */ - List generateDeleteAllByClassScript(GremlinSource source); - - /** - * Generate the findById query from source (Vertex, Edge). - */ - List generateFindByIdScript(GremlinSource source); - - /** - * Generate the update query from source (Vertex, Edge or Graph). - */ - List generateUpdateScript(GremlinSource source); - - /** - * Generate the findAll query from source (Vertex, Edge or Graph). - */ - List generateFindAllScript(GremlinSource source); - - /** - * Generate the DeleteById query from source (Vertex, Edge or Graph). - */ - List generateDeleteByIdScript(GremlinSource source); - - /** - * Generate the Count query from Source (Vertex, Edge) - */ - List generateCountScript(GremlinSource source); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralEdge.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralEdge.java deleted file mode 100644 index ab331b00..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralEdge.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; -import static com.microsoft.spring.data.gremlin.common.GremlinEntityType.EDGE; -import static com.microsoft.spring.data.gremlin.common.GremlinEntityType.VERTEX; - -@NoArgsConstructor -public class GremlinScriptLiteralEdge extends AbstractGremlinScriptLiteral implements GremlinScriptLiteral { - - private static final String FROM_ALIAS = "from"; - private static final String TO_ALIAS = "to"; - - private String generateEdgeDirection(@NonNull String from, @NonNull String to) { - return String.format("from('%s').to('%s')", from, to); - } - - @Override - @SuppressWarnings("unchecked") - public List generateInsertScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - final GremlinSourceEdge sourceEdge = (GremlinSourceEdge) source; - final List scriptList = new ArrayList<>(); - - scriptList.add(GREMLIN_PRIMITIVE_GRAPH); // g - scriptList.add(generateEntityWithRequiredId(sourceEdge.getVertexIdFrom(), VERTEX)); // V(id) - scriptList.add(generateAsWithAlias(FROM_ALIAS)); // from('from') - scriptList.add(generateEntityWithRequiredId(sourceEdge.getVertexIdTo(), VERTEX)); // V(id) - scriptList.add(generateAsWithAlias(TO_ALIAS)); // to('to') - scriptList.add(generateAddEntityWithLabel(sourceEdge.getLabel(), EDGE)); // addE(label) - scriptList.add(generateEdgeDirection(FROM_ALIAS, TO_ALIAS)); // from('from').to('to') - - source.getId().ifPresent(id -> scriptList.add(generatePropertyWithRequiredId(id))); // property(id, xxx) - - scriptList.addAll(generateProperties(source.getProperties())); - - return completeScript(scriptList); - } - - @Override - public List generateDeleteAllScript() { - return Collections.singletonList(GREMLIN_SCRIPT_EDGE_DROP_ALL); - } - - @Override - public List generateDeleteAllByClassScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_EDGE_ALL, // E() - generateHasLabel(source.getLabel()), // has(label, 'label') - GREMLIN_PRIMITIVE_DROP // drop() - ); - - return completeScript(scriptList); - } - - @Override - public List generateFindByIdScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - Assert.isTrue(source.getId().isPresent(), "GremlinSource should contain id."); - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_EDGE_ALL, // E() - generateHasId(source.getId().get(), source.getIdField()) // hasId(xxx) - ); - - return completeScript(scriptList); - } - - @Override - @SuppressWarnings("unchecked") - public List generateUpdateScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - final List scriptList = new ArrayList<>(); - - Assert.isTrue(source.getId().isPresent(), "GremlinSource should contain id."); - - scriptList.add(GREMLIN_PRIMITIVE_GRAPH); // g - scriptList.add(generateEntityWithRequiredId(source.getId().get(), EDGE)); // E(id) - - scriptList.addAll(generateProperties(source.getProperties())); - - return completeScript(scriptList); - } - - @Override - public List generateFindAllScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - final String className = source.getProperties().get(GREMLIN_PROPERTY_CLASSNAME).toString(); - Assert.notNull(className, "GremlinSource should contain predefined className"); - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_EDGE_ALL, // E() - generateHasLabel(source.getLabel()), // has(label, 'label') - generateHas(GREMLIN_PROPERTY_CLASSNAME, className) // has(_classname, 'xxxxxx') - ); - - return completeScript(scriptList); - } - - @Override - public List generateDeleteByIdScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - Assert.isTrue(source.getId().isPresent(), "GremlinSource should contain id."); - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_EDGE_ALL, // E() - generateHasId(source.getId().get(), source.getIdField()), // hasId(xxx) - GREMLIN_PRIMITIVE_DROP // drop() - ); - - return completeScript(scriptList); - } - - @Override - public List generateCountScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - return Collections.singletonList(GREMLIN_SCRIPT_EDGE_ALL); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralGraph.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralGraph.java deleted file mode 100644 index 0ae92d2d..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralGraph.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import lombok.NoArgsConstructor; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; - -import java.util.*; -import java.util.function.Function; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; - -@NoArgsConstructor -public class GremlinScriptLiteralGraph implements GremlinScriptLiteral { - - private final GremlinScriptLiteralVertex scriptVertex = new GremlinScriptLiteralVertex(); - - private final GremlinScriptLiteralEdge scriptEdge = new GremlinScriptLiteralEdge(); - - @Override - public List generateInsertScript(@NonNull GremlinSource source) { - return generateInsertUpdateScript(source, - scriptVertex::generateInsertScript, - scriptEdge::generateInsertScript); - } - - @Override - public List generateDeleteAllScript() { - return Arrays.asList(GREMLIN_SCRIPT_EDGE_DROP_ALL, GREMLIN_QUERY_BARRIER, GREMLIN_SCRIPT_VERTEX_DROP_ALL); - } - - @Override - public List generateDeleteAllByClassScript(@NonNull GremlinSource source) { - return generateDeleteAllScript(); - } - - @Override - public List generateFindByIdScript(@Nullable GremlinSource source) { - throw new UnsupportedOperationException("Gremlin graph cannot findById by single query."); - } - - @Override - public List generateUpdateScript(@NonNull GremlinSource source) { - return generateInsertUpdateScript(source, - scriptVertex::generateUpdateScript, - scriptEdge::generateUpdateScript); - } - - @SuppressWarnings("unchecked") - private List generateInsertUpdateScript(@NonNull GremlinSource source, - @NonNull Function> vertexHandler, - @NonNull Function> edgeHandler) { - if (!(source instanceof GremlinSourceGraph)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceGraph"); - } - - final List scriptList = new ArrayList<>(); - final GremlinSourceGraph sourceGraph = (GremlinSourceGraph) source; - final List vertexes = (List) sourceGraph.getVertexSet(); - final List edges = (List) sourceGraph.getEdgeSet(); - - vertexes.forEach(vertex -> scriptList.addAll(vertexHandler.apply(vertex))); - scriptList.add(GREMLIN_QUERY_BARRIER); - edges.forEach(edge -> scriptList.addAll(edgeHandler.apply(edge))); - - return scriptList; - } - - @Override - public List generateDeleteByIdScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceGraph)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceGraph"); - } - - return this.generateDeleteAllScript(); - } - - @Override - public List generateFindAllScript(@NonNull GremlinSource source) { - throw new UnsupportedOperationException("Gremlin graph cannot be findAll."); - } - - public List generateIsEmptyScript() { - final List scriptList = Arrays.asList(GREMLIN_PRIMITIVE_GRAPH, GREMLIN_PRIMITIVE_VERTEX_ALL); - final String query = String.join(GREMLIN_PRIMITIVE_INVOKE, scriptList); - - return Collections.singletonList(query); - } - - @Override - public List generateCountScript(@NonNull GremlinSource source) { - throw new UnsupportedOperationException("Gremlin graph counting is not available."); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralVertex.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralVertex.java deleted file mode 100644 index b50695d0..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralVertex.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; -import static com.microsoft.spring.data.gremlin.common.GremlinEntityType.VERTEX; - -@NoArgsConstructor -public class GremlinScriptLiteralVertex extends AbstractGremlinScriptLiteral implements GremlinScriptLiteral { - - @Override - @SuppressWarnings("unchecked") - public List generateInsertScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - final List scriptList = new ArrayList<>(); - - scriptList.add(GREMLIN_PRIMITIVE_GRAPH); // g - scriptList.add(generateAddEntityWithLabel(source.getLabel(), VERTEX)); // addV('label') - - source.getId().ifPresent(id -> scriptList.add(generatePropertyWithRequiredId(id))); // property(id, xxx) - - scriptList.addAll(generateProperties(source.getProperties())); - - return completeScript(scriptList); - } - - @Override - public List generateDeleteAllScript() { - return Collections.singletonList(GREMLIN_SCRIPT_VERTEX_DROP_ALL); - } - - @Override - public List generateDeleteAllByClassScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_VERTEX_ALL, // V() - generateHasLabel(source.getLabel()), // has(label, 'label') - GREMLIN_PRIMITIVE_DROP // drop() - ); - - return completeScript(scriptList); - } - - @Override - public List generateFindByIdScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - Assert.isTrue(source.getId().isPresent(), "GremlinSource should contain id."); - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_VERTEX_ALL, // V() - generateHasId(source.getId().get(), source.getIdField()) // hasId(xxx) - ); - - return completeScript(scriptList); - } - - @Override - @SuppressWarnings("unchecked") - public List generateUpdateScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - final List scriptList = new ArrayList<>(); - - Assert.isTrue(source.getId().isPresent(), "GremlinSource should contain id."); - - scriptList.add(GREMLIN_PRIMITIVE_GRAPH); // g - scriptList.add(generateEntityWithRequiredId(source.getId().get(), VERTEX)); // V(id) - scriptList.addAll(generateProperties(source.getProperties())); - - return completeScript(scriptList); - } - - @Override - public List generateFindAllScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - final String classname = source.getProperties().get(GREMLIN_PROPERTY_CLASSNAME).toString(); - Assert.notNull(classname, "GremlinSource should contain predefined classname"); - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_VERTEX_ALL, // V() - generateHasLabel(source.getLabel()), // has(label, 'label') - generateHas(GREMLIN_PROPERTY_CLASSNAME, classname) // has(_classname, 'xxxxxx') - ); - - return completeScript(scriptList); - } - - @Override - public List generateDeleteByIdScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - Assert.isTrue(source.getId().isPresent(), "GremlinSource should contain id."); - - final List scriptList = Arrays.asList( - GREMLIN_PRIMITIVE_GRAPH, // g - GREMLIN_PRIMITIVE_VERTEX_ALL, // E() - generateHasId(source.getId().get(), source.getIdField()), // hasId(xxx) - GREMLIN_PRIMITIVE_DROP // drop() - ); - - return completeScript(scriptList); - } - - @Override - public List generateCountScript(@NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - return Collections.singletonList(GREMLIN_SCRIPT_VERTEX_ALL); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSource.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSource.java deleted file mode 100644 index 7c4ea7cb..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSource.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultsReader; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteral; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; -import org.apache.tinkerpop.gremlin.driver.Result; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static com.microsoft.spring.data.gremlin.common.Constants.GREMLIN_PROPERTY_CLASSNAME; - -public abstract class AbstractGremlinSource implements GremlinSource { - - @Setter - private Object id; - - @Getter - @Setter - private String label; - - @Getter - @Setter - private Field idField; - - @Getter - private Class domainClass; - - @Getter - @Setter - private Map properties; - - @Setter(AccessLevel.PRIVATE) - private GremlinScriptLiteral scriptLiteral; - - @Setter(AccessLevel.PRIVATE) - private GremlinSourceWriter sourceWriter; - - @Setter(AccessLevel.PRIVATE) - private GremlinSourceReader sourceReader; - - @Setter(AccessLevel.PRIVATE) - private GremlinResultsReader resultReader; - - protected AbstractGremlinSource() { - this.properties = new HashMap<>(); - } - - protected AbstractGremlinSource(Class domainClass) { - this.domainClass = domainClass; - this.properties = new HashMap<>(); - - setProperty(GREMLIN_PROPERTY_CLASSNAME, domainClass.getName()); - } - - @Override - public Optional getId() { - return Optional.ofNullable(this.id); - } - - /** - * The type of Id keep the consistency with the result from gremlin server, for generate query correctly. So if the - * id is ${@link GeneratedValue}, which may have different type against entity id field. - * - * @param id the given id from query. - */ - @Override - public void setId(Object id) { - final Field idField = getIdField(); - - if (idField == null) { - throw new GremlinInvalidEntityIdFieldException("Id Field of GremlinSource cannot be null"); - } - - if (idField.isAnnotationPresent(GeneratedValue.class) && id instanceof String) { - try { - this.id = Long.valueOf((String) id); // Gremlin server default id type is Long. - } catch (NumberFormatException ignore) { - this.id = id; - } - } else { - this.id = id; - } - } - - @Override - public void setGremlinScriptStrategy(@NonNull GremlinScriptLiteral script) { - this.setScriptLiteral(script); - } - - @Override - public void setGremlinSourceWriter(@NonNull GremlinSourceWriter writer) { - this.setSourceWriter(writer); - } - - @Override - public void setGremlinSourceReader(@NonNull GremlinSourceReader reader) { - this.setSourceReader(reader); - } - - @Override - public void setGremlinResultReader(@NonNull GremlinResultsReader reader) { - this.setResultReader(reader); - } - - @Override - public GremlinScriptLiteral getGremlinScriptLiteral() { - return this.scriptLiteral; - } - - @Override - public void doGremlinSourceWrite(@NonNull Object domain, @NonNull MappingGremlinConverter converter) { - Assert.notNull(this.sourceWriter, "the sourceWriter must be set before do writing"); - - this.sourceWriter.write(domain, converter, this); - } - - @Override - public T doGremlinSourceRead(@NonNull Class domainClass, @NonNull MappingGremlinConverter converter) { - Assert.notNull(this.sourceReader, "the sourceReader must be set before do reading"); - - return this.sourceReader.read(domainClass, converter, this); - } - - @Override - public void doGremlinResultRead(@NonNull List results) { - Assert.notNull(this.resultReader, "the resultReader must be set before do reading"); - - this.resultReader.read(results, this); - } - - private boolean hasProperty(String key) { - return this.properties.get(key) != null; - } - - @Override - public void setProperty(String key, Object value) { - if (this.hasProperty(key) && value == null) { - this.properties.remove(key); - } else { - this.properties.put(key, value); - } - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSourceReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSourceReader.java deleted file mode 100644 index c9e37d5b..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/AbstractGremlinSourceReader.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import lombok.NonNull; -import org.apache.tinkerpop.shaded.jackson.databind.JavaType; -import org.apache.tinkerpop.shaded.jackson.databind.type.TypeFactory; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.Date; - -public abstract class AbstractGremlinSourceReader { - - protected Object readProperty(@NonNull PersistentProperty property, @Nullable Object value) { - final Class type = property.getTypeInformation().getType(); - final JavaType javaType = TypeFactory.defaultInstance().constructType(property.getType()); - - if (value == null) { - return null; - } else if (type == int.class || type == Integer.class - || type == Boolean.class || type == boolean.class - || type == String.class) { - return value; - } else if (type == Date.class) { - Assert.isTrue(value instanceof Long, "Date store value must be instance of long"); - return new Date((Long) value); - } else { - final Object object; - - try { - object = GremlinUtils.getObjectMapper().readValue(value.toString(), javaType); - } catch (IOException e) { - throw new GremlinUnexpectedEntityTypeException("Failed to read String to Object", e); - } - - return object; - } - } - - protected Object getGremlinSourceId(@NonNull GremlinSource source) { - if (!source.getId().isPresent()) { - return null; - } - - final Object id = source.getId().get(); - final Field idField = source.getIdField(); - - if (idField.getType() == String.class) { - return id.toString(); - } else if (idField.getType() == Integer.class) { - Assert.isTrue(id instanceof Integer, "source Id should be Integer."); - return id; - } else if (idField.getType() == Long.class && id instanceof Integer) { - return Long.valueOf((Integer) id); - } else if (idField.getType() == Long.class && id instanceof Long) { - return id; - } - - throw new GremlinEntityInformationException("unsupported id field type: " + id.getClass().getSimpleName()); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSource.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSource.java deleted file mode 100644 index b8056e0b..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSource.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultsReader; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteral; -import lombok.NonNull; -import org.apache.tinkerpop.gremlin.driver.Result; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Provider interface to obtain and store information from domain class. - * For Vertex and Edge, they consist of id (String, Reserved), label (String, Reserved) and - * a set of properties. - * The property key should be String, and value can be one of String, number and boolean. - * - * @param The type of domain. - */ -public interface GremlinSource { - - /** - * Set the property map of domain - */ - void setProperty(String key, Object value); - - /** - * Get the id of domain - * - * @return the Optional of id - */ - Optional getId(); - - /** - * Set the id of domain - */ - void setId(Object id); - - /** - * Get the id Field of domain - * - * @return will never be null - */ - Field getIdField(); - - /** - * Set the id of domain - */ - void setIdField(Field id); - - /** - * Get the label of domain - * - * @return will never be null - */ - @NonNull - String getLabel(); - - /** - * Set the label of domain - */ - void setLabel(String label); - - /** - * Get the Class type of domain - * - * @return will never be null - */ - @NonNull - Class getDomainClass(); - - /** - * Get the properties of domain - * - * @return will never be null - */ - Map getProperties(); - - /** - * do the real write from domain to GremlinSource - */ - void doGremlinSourceWrite(Object domain, MappingGremlinConverter converter); - - /** - * do the real reading from Result to GremlinSource - */ - void doGremlinResultRead(List results); - - /** - * do the real reading from GremlinSource to domain - */ - T doGremlinSourceRead(Class domainClass, MappingGremlinConverter converter); - - /** - * return the GremlinScriptLiteral - */ - GremlinScriptLiteral getGremlinScriptLiteral(); - - /** - * Set the script Strategy of GremlinSource - */ - void setGremlinScriptStrategy(GremlinScriptLiteral script); - - /** - * Set the SourceWriter of GremlinSource - */ - void setGremlinSourceWriter(GremlinSourceWriter writer); - - /** - * Set the ResultReader for reading data from Gremlin Result to GremlinSource - */ - void setGremlinResultReader(GremlinResultsReader reader); - - /** - * Set the SourceReader for reading data from GremlinSource to domain - */ - void setGremlinSourceReader(GremlinSourceReader reader); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdge.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdge.java deleted file mode 100644 index 97db23d9..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdge.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultEdgeReader; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralEdge; -import lombok.Getter; -import lombok.Setter; - -public class GremlinSourceEdge extends AbstractGremlinSource { - - @Getter - @Setter - private Object vertexIdFrom; - - @Getter - @Setter - private Object vertexIdTo; - - public GremlinSourceEdge() { - super(); - initializeGremlinStrategy(); - } - - public GremlinSourceEdge(Class domainClass) { - super(domainClass); - initializeGremlinStrategy(); - } - - private void initializeGremlinStrategy() { - this.setGremlinScriptStrategy(new GremlinScriptLiteralEdge()); - this.setGremlinResultReader(new GremlinResultEdgeReader()); - this.setGremlinSourceReader(new GremlinSourceEdgeReader()); - this.setGremlinSourceWriter(new GremlinSourceEdgeWriter()); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeReader.java deleted file mode 100644 index cc58cfd5..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeReader.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; - -import static com.microsoft.spring.data.gremlin.common.Constants.PROPERTY_ID; - -@NoArgsConstructor -public class GremlinSourceEdgeReader extends AbstractGremlinSourceReader implements GremlinSourceReader { - - @Override - public T read(@NonNull Class domainClass, @NonNull MappingGremlinConverter converter, - @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be instance of GremlinSourceEdge"); - } - - final T domain = GremlinUtils.createInstance(domainClass); - final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); - final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domainClass); - - for (final Field field : FieldUtils.getAllFields(domainClass)) { - final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); - if (property == null) { - continue; - } - if (field.getName().equals(PROPERTY_ID) || field.getAnnotation(Id.class) != null) { - accessor.setProperty(property, super.getGremlinSourceId(source)); - continue; - } else if (field.getAnnotation(EdgeFrom.class) != null || field.getAnnotation(EdgeTo.class) != null) { - // We cannot do that here as the gremlin will not tell more information about vertex except Id. After - // the query of Edge end, we can get the Id of vertex from/to. And then we will do extra 2 query to - // obtain the 2 vertex and complete the edge. - // - // That work will be wrapped in GremlinTemplate insert, and skip the property here. - continue; - } - - final Object value = super.readProperty(property, source.getProperties().get(field.getName())); - accessor.setProperty(property, value); - } - - return domain; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeWriter.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeWriter.java deleted file mode 100644 index c207193a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceEdgeWriter.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import com.microsoft.spring.data.gremlin.common.Constants; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; - -import static com.microsoft.spring.data.gremlin.common.Constants.GREMLIN_PROPERTY_CLASSNAME; - -@NoArgsConstructor -public class GremlinSourceEdgeWriter implements GremlinSourceWriter { - - private Object getIdValue(@NonNull Object object, @NonNull MappingGremlinConverter converter) { - if (object instanceof String || object instanceof Long || object instanceof Integer) { - return object; - } else if (object.getClass().isPrimitive()) { - throw new GremlinUnexpectedEntityTypeException("only String type of primitive is allowed"); - } else { - return converter.getIdFieldValue(object); - } - } - - @Override - public void write(@NonNull Object domain, @NonNull MappingGremlinConverter converter, - @NonNull GremlinSource source) throws GremlinInvalidEntityIdFieldException { - if (!(source instanceof GremlinSourceEdge)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - source.setId(converter.getIdFieldValue(domain)); - - final GremlinSourceEdge sourceEdge = (GremlinSourceEdge) source; - final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domain.getClass()); - final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); - - for (final Field field : FieldUtils.getAllFields(domain.getClass())) { - final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); - if (property == null) { - continue; - } - - final Object object = accessor.getProperty(property); - - if (field.getName().equals(Constants.PROPERTY_ID) || field.getAnnotation(Id.class) != null) { - continue; - } else if (field.getName().equals(GREMLIN_PROPERTY_CLASSNAME)) { - throw new GremlinEntityInformationException("Domain Cannot use pre-defined field name: " - + GREMLIN_PROPERTY_CLASSNAME); - } else if (field.getAnnotation(EdgeFrom.class) != null) { - final Object vertexId = this.getIdValue(object, converter); - if (vertexId == null) { - throw new GremlinInvalidEntityIdFieldException("The vertex id for the from vertex cannot be null!"); - } - sourceEdge.setVertexIdFrom(vertexId); - } else if (field.getAnnotation(EdgeTo.class) != null) { - final Object vertexId = this.getIdValue(object, converter); - if (vertexId == null) { - throw new GremlinInvalidEntityIdFieldException("The vertex id for the to vertex cannot be null!"); - } - sourceEdge.setVertexIdTo(vertexId); - } - source.setProperty(field.getName(), accessor.getProperty(property)); - } - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraph.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraph.java deleted file mode 100644 index 3d2d8c5e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraph.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultsGraphReader; -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultsReader; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralGraph; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import lombok.Getter; - -import java.util.ArrayList; -import java.util.List; - -public class GremlinSourceGraph extends AbstractGremlinSource { - - @Getter - private List vertexSet = new ArrayList<>(); - - @Getter - private List edgeSet = new ArrayList<>(); - - @Getter - private GremlinResultsReader resultsReader; - - public GremlinSourceGraph() { - super(); - initializeGremlinStrategy(); - this.setGremlinSourceReader(new GremlinSourceGraphReader()); - this.resultsReader = new GremlinResultsGraphReader(); - } - - public GremlinSourceGraph(Class domainClass) { - super(domainClass); - initializeGremlinStrategy(); - this.setGremlinSourceReader(new GremlinSourceGraphReader()); - this.resultsReader = new GremlinResultsGraphReader(); - } - - public void addGremlinSource(GremlinSource source) { - if (source instanceof GremlinSourceVertex) { - this.vertexSet.add(source); - } else if (source instanceof GremlinSourceEdge) { - this.edgeSet.add(source); - } else { - throw new GremlinUnexpectedSourceTypeException("source type can only be Vertex or Edge"); - } - } - - private void initializeGremlinStrategy() { - this.setGremlinScriptStrategy(new GremlinScriptLiteralGraph()); - this.setGremlinSourceWriter(new GremlinSourceGraphWriter()); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraphReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraphReader.java deleted file mode 100644 index 0b326b40..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraphReader.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.annotation.EdgeSet; -import com.microsoft.spring.data.gremlin.annotation.VertexSet; -import com.microsoft.spring.data.gremlin.common.Constants; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import com.microsoft.spring.data.gremlin.repository.support.GremlinEntityInformation; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import static com.microsoft.spring.data.gremlin.common.Constants.PROPERTY_ID; - -@NoArgsConstructor -public class GremlinSourceGraphReader extends AbstractGremlinSourceReader implements GremlinSourceReader { - - @Override - public T read(@NonNull Class type, @NonNull MappingGremlinConverter converter, - @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceGraph)) { - throw new GremlinUnexpectedSourceTypeException("Should be instance of GremlinSourceGraph"); - } - - final GremlinSourceGraph graphSource = (GremlinSourceGraph) source; - final T entity = GremlinUtils.createInstance(type); - final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(entity); - final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(type); - - for (final Field field : FieldUtils.getAllFields(type)) { - final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); - if (property == null) { - continue; - } - - if ((field.getName().equals(PROPERTY_ID) || field.getAnnotation(Id.class) != null)) { - accessor.setProperty(property, super.getGremlinSourceId(graphSource)); - } else if (field.isAnnotationPresent(VertexSet.class)) { - accessor.setProperty(property, readEntitySet(graphSource.getVertexSet(), converter)); - } else if (field.isAnnotationPresent(EdgeSet.class)) { - accessor.setProperty(property, readEntitySet(graphSource.getEdgeSet(), converter)); - } - } - - return entity; - } - - private List readEntitySet(List sources, MappingGremlinConverter converter) { - Class domainClass; - final List domainObjects = new ArrayList<>(); - - for (final GremlinSource source : sources) { - try { - domainClass = Class.forName((String) source.getProperties().get(Constants.GREMLIN_PROPERTY_CLASSNAME)); - } catch (ClassNotFoundException e) { - throw new GremlinUnexpectedSourceTypeException("No Java class found for source property " - + Constants.GREMLIN_PROPERTY_CLASSNAME, e); - } - - // TODO: seems unnecessary here. - source.setIdField(new GremlinEntityInformation<>(domainClass).getIdField()); - domainObjects.add(source.doGremlinSourceRead(domainClass, converter)); - } - - return domainObjects; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraphWriter.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraphWriter.java deleted file mode 100644 index fbe51c0f..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceGraphWriter.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.annotation.EdgeSet; -import com.microsoft.spring.data.gremlin.annotation.VertexSet; -import com.microsoft.spring.data.gremlin.common.Constants; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; -import java.util.List; - -@NoArgsConstructor -public class GremlinSourceGraphWriter implements GremlinSourceWriter { - - private void writeGraphSet(@NonNull List objectList, @NonNull MappingGremlinConverter mappingConverter, - @NonNull GremlinSourceGraph sourceGraph) { - Assert.isInstanceOf(GremlinSourceGraph.class, sourceGraph, "should be instance of GremlinSourceGraph "); - - for (final Object object : objectList) { - final GremlinSource source = GremlinUtils.toGremlinSource(object.getClass()); - - source.doGremlinSourceWrite(object, mappingConverter); - sourceGraph.addGremlinSource(source); - } - } - - @Override - public void write(@NonNull Object domain, @NonNull MappingGremlinConverter converter, - @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceGraph)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceEdge"); - } - - final GremlinSourceGraph sourceGraph = (GremlinSourceGraph) source; - final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domain.getClass()); - final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); - - for (final Field field : FieldUtils.getAllFields(domain.getClass())) { - final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); - if (property == null) { - continue; - } - - if (field.getName().equals(Constants.PROPERTY_ID) || field.getAnnotation(Id.class) != null) { - continue; - } - - @SuppressWarnings("unchecked") final List objects = (List) accessor.getProperty(property); - - if (field.getAnnotation(VertexSet.class) != null || field.getAnnotation(EdgeSet.class) != null) { - this.writeGraphSet(objects, converter, sourceGraph); - } - } - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceReader.java deleted file mode 100644 index 08a41446..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceReader.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; - -/** - * Provider Entity type dependent read method. - */ -public interface GremlinSourceReader { - /** - * Read data from GremlinSource to domain - */ - T read(Class domainClass, MappingGremlinConverter converter, GremlinSource source); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertex.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertex.java deleted file mode 100644 index 0a5ab6c7..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertex.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultVertexReader; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralVertex; - -public class GremlinSourceVertex extends AbstractGremlinSource { - - public GremlinSourceVertex() { - super(); - initializeGremlinStrategy(); - } - - public GremlinSourceVertex(Class domainClass) { - super(domainClass); - initializeGremlinStrategy(); - } - - private void initializeGremlinStrategy() { - this.setGremlinScriptStrategy(new GremlinScriptLiteralVertex()); - this.setGremlinResultReader(new GremlinResultVertexReader()); - this.setGremlinSourceReader(new GremlinSourceVertexReader()); - this.setGremlinSourceWriter(new GremlinSourceVertexWriter()); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexReader.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexReader.java deleted file mode 100644 index 06ab8d6e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexReader.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.common.Constants; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; - -@NoArgsConstructor -public class GremlinSourceVertexReader extends AbstractGremlinSourceReader implements GremlinSourceReader { - - @Override - public T read(@NonNull Class domainClass, @NonNull MappingGremlinConverter converter, - @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be instance of GremlinSourceVertex"); - } - - final T domain = GremlinUtils.createInstance(domainClass); - final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); - final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domainClass); - - for (final Field field : FieldUtils.getAllFields(domainClass)) { - final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); - if (property == null) { - continue; - } - - if (field.getName().equals(Constants.PROPERTY_ID) || field.getAnnotation(Id.class) != null) { - accessor.setProperty(property, super.getGremlinSourceId(source)); - } else { - final Object value = super.readProperty(property, source.getProperties().get(field.getName())); - accessor.setProperty(property, value); - } - } - - return domain; - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexWriter.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexWriter.java deleted file mode 100644 index 3f799f2c..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceVertexWriter.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.springframework.data.annotation.Id; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.reflect.Field; - -import static com.microsoft.spring.data.gremlin.common.Constants.GREMLIN_PROPERTY_CLASSNAME; -import static com.microsoft.spring.data.gremlin.common.Constants.PROPERTY_ID; - -@NoArgsConstructor -public class GremlinSourceVertexWriter implements GremlinSourceWriter { - - @Override - public void write(@NonNull Object domain, @NonNull MappingGremlinConverter converter, - @NonNull GremlinSource source) { - if (!(source instanceof GremlinSourceVertex)) { - throw new GremlinUnexpectedSourceTypeException("should be the instance of GremlinSourceVertex"); - } - - source.setId(converter.getIdFieldValue(domain)); - - final GremlinPersistentEntity persistentEntity = converter.getPersistentEntity(domain.getClass()); - final ConvertingPropertyAccessor accessor = converter.getPropertyAccessor(domain); - - for (final Field field : FieldUtils.getAllFields(domain.getClass())) { - final PersistentProperty property = persistentEntity.getPersistentProperty(field.getName()); - if (property == null) { - continue; - } - - if (field.getName().equals(PROPERTY_ID) || field.getAnnotation(Id.class) != null) { - continue; - } else if (field.getName().equals(GREMLIN_PROPERTY_CLASSNAME)) { - throw new GremlinEntityInformationException("Domain Cannot use pre-defined field name: " - + GREMLIN_PROPERTY_CLASSNAME); - } - - source.setProperty(field.getName(), accessor.getProperty(property)); - } - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceWriter.java b/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceWriter.java deleted file mode 100644 index 6e4ba69a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceWriter.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; - -/** - * Provider Entity type dependent write method. - */ -public interface GremlinSourceWriter { - /** - * Write the domain class information to GremlinSource - */ - void write(Object domain, MappingGremlinConverter converter, GremlinSource source); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinEntityInformationException.java b/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinEntityInformationException.java deleted file mode 100644 index a5d4638a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinEntityInformationException.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.exception; - -import org.springframework.dao.TypeMismatchDataAccessException; - -public class GremlinEntityInformationException extends TypeMismatchDataAccessException { - - public GremlinEntityInformationException(String msg) { - super(msg); - } - - public GremlinEntityInformationException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinIllegalConfigurationException.java b/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinIllegalConfigurationException.java deleted file mode 100644 index f06fa2f3..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinIllegalConfigurationException.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.exception; - -import org.springframework.dao.InvalidDataAccessApiUsageException; - -public class GremlinIllegalConfigurationException extends InvalidDataAccessApiUsageException { - - public GremlinIllegalConfigurationException(String msg) { - super(msg); - } - - public GremlinIllegalConfigurationException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinInvalidEntityIdFieldException.java b/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinInvalidEntityIdFieldException.java deleted file mode 100644 index 0a95bda0..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinInvalidEntityIdFieldException.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.exception; - -public class GremlinInvalidEntityIdFieldException extends GremlinEntityInformationException { - - public GremlinInvalidEntityIdFieldException(String msg) { - super(msg); - } - - public GremlinInvalidEntityIdFieldException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinQueryException.java b/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinQueryException.java deleted file mode 100644 index e02f6d5c..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinQueryException.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.exception; - -import org.springframework.dao.DataAccessResourceFailureException; - -public class GremlinQueryException extends DataAccessResourceFailureException { - - public GremlinQueryException(String msg) { - super(msg); - } - - public GremlinQueryException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedEntityTypeException.java b/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedEntityTypeException.java deleted file mode 100644 index c9921c66..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedEntityTypeException.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.exception; - -public class GremlinUnexpectedEntityTypeException extends GremlinEntityInformationException { - - public GremlinUnexpectedEntityTypeException(String msg) { - super(msg); - } - - public GremlinUnexpectedEntityTypeException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedSourceTypeException.java b/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedSourceTypeException.java deleted file mode 100644 index 63c7813b..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/exception/GremlinUnexpectedSourceTypeException.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.exception; - -import org.springframework.dao.TypeMismatchDataAccessException; - -public class GremlinUnexpectedSourceTypeException extends TypeMismatchDataAccessException { - - public GremlinUnexpectedSourceTypeException(String msg) { - super(msg); - } - - public GremlinUnexpectedSourceTypeException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntity.java b/src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntity.java deleted file mode 100644 index f2a0b5e9..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.expression.BeanFactoryAccessor; -import org.springframework.context.expression.BeanFactoryResolver; -import org.springframework.data.mapping.model.BasicPersistentEntity; -import org.springframework.data.util.TypeInformation; -import org.springframework.expression.spel.support.StandardEvaluationContext; - -public class BasicGremlinPersistentEntity extends BasicPersistentEntity - implements GremlinPersistentEntity, ApplicationContextAware { - - private final StandardEvaluationContext context; - - public BasicGremlinPersistentEntity(TypeInformation information) { - super(information); - - this.context = new StandardEvaluationContext(); - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.context.addPropertyAccessor(new BeanFactoryAccessor()); - this.context.setBeanResolver(new BeanFactoryResolver(applicationContext)); - this.context.setRootObject(applicationContext); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentProperty.java b/src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentProperty.java deleted file mode 100644 index c0e29a69..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentProperty.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import com.microsoft.spring.data.gremlin.common.Constants; -import org.springframework.data.mapping.Association; -import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; -import org.springframework.data.mapping.model.Property; -import org.springframework.data.mapping.model.SimpleTypeHolder; - -public class BasicGremlinPersistentProperty extends AnnotationBasedPersistentProperty - implements GremlinPersistentProperty { - - public BasicGremlinPersistentProperty(Property property, GremlinPersistentEntity owner, - SimpleTypeHolder holder) { - super(property, owner, holder); - } - - @Override - protected Association createAssociation() { - return new Association<>(this, null); - } - - @Override - public boolean isIdProperty() { - return super.isIdProperty() || getName().equals(Constants.PROPERTY_ID); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContext.java b/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContext.java deleted file mode 100644 index b5b121aa..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContext.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import org.springframework.context.ApplicationContext; -import org.springframework.data.mapping.context.AbstractMappingContext; -import org.springframework.data.mapping.model.Property; -import org.springframework.data.mapping.model.SimpleTypeHolder; -import org.springframework.data.util.TypeInformation; - -public class GremlinMappingContext - extends AbstractMappingContext, GremlinPersistentProperty> { - private ApplicationContext context; - - @Override - public void setApplicationContext(ApplicationContext context) { - this.context = context; - } - - @Override - public GremlinPersistentProperty createPersistentProperty(Property property, - BasicGremlinPersistentEntity owner, - SimpleTypeHolder holder) { - return new BasicGremlinPersistentProperty(property, owner, holder); - } - - @Override - protected BasicGremlinPersistentEntity createPersistentEntity(TypeInformation typeInformation) { - final BasicGremlinPersistentEntity entity = new BasicGremlinPersistentEntity<>(typeInformation); - - if (this.context != null) { - entity.setApplicationContext(this.context); - } - - return entity; - } - -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentEntity.java b/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentEntity.java deleted file mode 100644 index 4b5b430d..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import org.springframework.data.mapping.PersistentEntity; - -public interface GremlinPersistentEntity extends PersistentEntity { - -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentProperty.java b/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentProperty.java deleted file mode 100644 index 7d7cde69..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/mapping/GremlinPersistentProperty.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import org.springframework.data.mapping.PersistentProperty; - -public interface GremlinPersistentProperty extends PersistentProperty { - -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinEntityMetadata.java b/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinEntityMetadata.java deleted file mode 100644 index 70cff11e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinEntityMetadata.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query; - -import org.springframework.data.repository.core.EntityMetadata; - -public interface GremlinEntityMetadata extends EntityMetadata { -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinOperations.java b/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinOperations.java deleted file mode 100644 index d92e0c5e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinOperations.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.query.query.GremlinQuery; - -import java.util.List; - -/** - * Provider interface for basic Operations with Gremlin - */ -public interface GremlinOperations { - - void deleteAll(); - - void deleteAll(GremlinEntityType type); - - void deleteAll(GremlinSource source); - - boolean isEmptyGraph(GremlinSource source); - - boolean existsById(Object id, GremlinSource source); - - void deleteById(Object id, GremlinSource source); - - T insert(T object, GremlinSource source); - - T findById(Object id, GremlinSource source); - - T findVertexById(Object id, GremlinSource source); - - T findEdgeById(Object id, GremlinSource source); - - T update(T object, GremlinSource source); - - T save(T object, GremlinSource source); - - List findAll(GremlinSource source); - - long vertexCount(); - - long edgeCount(); - - List find(GremlinQuery query, GremlinSource source); - - MappingGremlinConverter getMappingConverter(); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinTemplate.java b/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinTemplate.java deleted file mode 100644 index f84a554b..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/GremlinTemplate.java +++ /dev/null @@ -1,386 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query; - -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.GremlinFactory; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteral; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralEdge; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralGraph; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralVertex; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import com.microsoft.spring.data.gremlin.exception.GremlinQueryException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentEntity; -import com.microsoft.spring.data.gremlin.query.query.GremlinQuery; -import com.microsoft.spring.data.gremlin.query.query.QueryFindScriptGenerator; -import com.microsoft.spring.data.gremlin.query.query.QueryScriptGenerator; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.tinkerpop.gremlin.driver.Client; -import org.apache.tinkerpop.gremlin.driver.Result; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.model.ConvertingPropertyAccessor; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import static java.util.stream.Collectors.toList; - -public class GremlinTemplate implements GremlinOperations, ApplicationContextAware { - - private final GremlinFactory factory; - private final MappingGremlinConverter mappingConverter; - - private Client gremlinClient; - private ApplicationContext context; - - public GremlinTemplate(@NonNull GremlinFactory factory, @NonNull MappingGremlinConverter converter) { - this.factory = factory; - this.mappingConverter = converter; - } - - @Override - public MappingGremlinConverter getMappingConverter() { - return this.mappingConverter; - } - - public ApplicationContext getApplicationContext() { - return this.context; - } - - @Override - public void setApplicationContext(@NonNull ApplicationContext context) throws BeansException { - this.context = context; - } - - public Client getGremlinClient() { - if (this.gremlinClient == null) { - this.gremlinClient = this.factory.getGremlinClient(); - } - - return this.gremlinClient; - } - - @NonNull - private List executeQuery(@NonNull List queries) { - final List> parallelQueries = GremlinUtils.toParallelQueryList(queries); - - return parallelQueries.stream().flatMap(q -> executeQueryParallel(q).stream()).collect(toList()); - } - - @NonNull - private List executeQueryParallel(@NonNull List queries) { - return queries.parallelStream() - .map(q -> getGremlinClient().submit(q).all()) - .collect(toList()).parallelStream().flatMap(f -> { - try { - return f.get().stream(); - } catch (InterruptedException | ExecutionException e) { - throw new GremlinQueryException("unable to complete query from gremlin", e); - } - }) - .collect(toList()); - } - - @Override - public void deleteAll() { - final GremlinScriptLiteral script = new GremlinScriptLiteralGraph(); - final List queryList = script.generateDeleteAllScript(); - - executeQuery(queryList); - } - - @Override - public void deleteAll(GremlinEntityType type) { - final GremlinSource source = type.createGremlinSource(); - - executeQuery(source.getGremlinScriptLiteral().generateDeleteAllScript()); - } - - @Override - public void deleteAll(GremlinSource source) { - executeQuery(source.getGremlinScriptLiteral().generateDeleteAllByClassScript(source)); - } - - private List insertInternal(@NonNull T object, @NonNull GremlinSource source) { - this.mappingConverter.write(object, source); - - return executeQuery(source.getGremlinScriptLiteral().generateInsertScript(source)); - } - - @Override - public T insert(@NonNull T object, GremlinSource source) { - final boolean entityGraph = source instanceof GremlinSourceGraph; - - if (!entityGraph && source.getIdField().isAnnotationPresent(GeneratedValue.class) - && source.getId().isPresent()) { - throw new GremlinInvalidEntityIdFieldException("The entity meant to be created has a non-null id " - + "that is marked as @GeneratedValue"); - } - - // The current implementation doesn't support creating graphs that contain both edges - // and vertices that have null (generated) ids. In this case, vertex and edge creation - // need to be performed in two consecutive steps. - // TODO(SOON) Add this verification in the GremlinSourceGraphWriter - - final List results = insertInternal(object, source); - - if (!results.isEmpty()) { - if (entityGraph) { - return recoverGraphDomain((GremlinSourceGraph) source, results); - } else { - return recoverDomain(source, results); - } - } - - return null; - } - - @Override - public T findVertexById(@NonNull Object id, GremlinSource source) { - if (source instanceof GremlinSourceVertex) { - source.setId(id); - return this.findByIdInternal(source); - } - - throw new GremlinUnexpectedEntityTypeException("should be vertex domain for findVertexById"); - } - - private Object getEdgeAnnotatedFieldValue(@NonNull Field field, @NonNull Object vertexId) { - if (field.getType() == String.class || field.getType() == Long.class || field.getType() == Integer.class) { - return vertexId; - } else if (field.getType().isPrimitive()) { - throw new GremlinUnexpectedEntityTypeException("only String/Long/Integer type of Id Field is allowed"); - } else { - return this.findVertexById(vertexId, GremlinUtils.toGremlinSource(field.getType())); - } - } - - @NonNull - private Field getEdgeAnnotatedField(@NonNull Class domainClass, - @NonNull Class annotationClass) { - final List fields = FieldUtils.getFieldsListWithAnnotation(domainClass, annotationClass); - - if (fields.size() != 1) { - throw new GremlinEntityInformationException("should be only one Annotation"); - } - - return fields.get(0); - } - - /** - * Find Edge need another two query to obtain edgeFrom and edgeTo. - * This function will do that and make edge domain completion. - */ - private void completeEdge(@NonNull T domain, @NonNull GremlinSourceEdge source) { - final ConvertingPropertyAccessor accessor = this.mappingConverter.getPropertyAccessor(domain); - final GremlinPersistentEntity persistentEntity = this.mappingConverter.getPersistentEntity(domain.getClass()); - - final Field fromField = this.getEdgeAnnotatedField(domain.getClass(), EdgeFrom.class); - final Field toField = this.getEdgeAnnotatedField(domain.getClass(), EdgeTo.class); - - final PersistentProperty propertyFrom = persistentEntity.getPersistentProperty(fromField.getName()); - final PersistentProperty propertyTo = persistentEntity.getPersistentProperty(toField.getName()); - - Assert.notNull(propertyFrom, "persistence property should not be null"); - Assert.notNull(propertyTo, "persistence property should not be null"); - - accessor.setProperty(propertyFrom, this.getEdgeAnnotatedFieldValue(fromField, source.getVertexIdFrom())); - accessor.setProperty(propertyTo, this.getEdgeAnnotatedFieldValue(toField, source.getVertexIdTo())); - } - - @Override - public T findEdgeById(@NonNull Object id, @NonNull GremlinSource source) { - if (source instanceof GremlinSourceEdge) { - return this.findById(id, source); - } - - throw new GremlinUnexpectedEntityTypeException("should be edge domain for findEdge"); - } - - private T findByIdInternal(@NonNull GremlinSource source) { - final List queryList = source.getGremlinScriptLiteral().generateFindByIdScript(source); - final List results = this.executeQuery(queryList); - - if (results.isEmpty()) { - return null; - } - - return recoverDomain(source, results); - } - - @Override - public T findById(@NonNull Object id, @NonNull GremlinSource source) { - if (source instanceof GremlinSourceGraph) { - throw new UnsupportedOperationException("Gremlin graph cannot be findById."); - } - - source.setId(id); - - return findByIdInternal(source); - } - - private T updateInternal(@NonNull T object, @NonNull GremlinSource source) { - this.mappingConverter.write(object, source); - - final List queryList = source.getGremlinScriptLiteral().generateUpdateScript(source); - - executeQuery(queryList); - - return object; - } - - @Override - public T update(@NonNull T object, @NonNull GremlinSource source) { - final Optional optional = source.getId(); - - if (!(source instanceof GremlinSourceGraph) - && (!optional.isPresent() || notExistsById(optional.get(), source))) { - throw new GremlinQueryException("cannot update the object doesn't exist"); - } - - return this.updateInternal(object, source); - } - - @Override - public T save(@NonNull T object, @NonNull GremlinSource source) { - final Optional optional = source.getId(); - final boolean entityGraph = source instanceof GremlinSourceGraph; - - if (entityGraph && this.isEmptyGraph(source)) { - return insert(object, source); - } else if (!entityGraph && (!optional.isPresent() || notExistsById(optional.get(), source))) { - return insert(object, source); - } else { - return updateInternal(object, source); - } - } - - @Override - public List findAll(@NonNull GremlinSource source) { - if (source instanceof GremlinSourceGraph) { - throw new UnsupportedOperationException("Gremlin graph cannot be findAll."); - } - - final List queryList = source.getGremlinScriptLiteral().generateFindAllScript(source); - final List results = executeQuery(queryList); - - if (results.isEmpty()) { - return Collections.emptyList(); - } - - return recoverDomainList(source, results); - } - - @Override - public void deleteById(@NonNull Object id, @NonNull GremlinSource source) { - source.setId(id); - - final List queryList = source.getGremlinScriptLiteral().generateDeleteByIdScript(source); - - executeQuery(queryList); - } - - @Override - public boolean isEmptyGraph(@NonNull GremlinSource source) { - if (source instanceof GremlinSourceGraph) { - final GremlinScriptLiteralGraph literalGraph = (GremlinScriptLiteralGraph) source.getGremlinScriptLiteral(); - final List queryList = literalGraph.generateIsEmptyScript(); - final List results = this.executeQuery(queryList); - - return results.isEmpty(); - } - - throw new GremlinQueryException("only graph domain is allowed."); - } - - @Override - public long vertexCount() { - final GremlinScriptLiteral script = new GremlinScriptLiteralVertex(); - final List queryList = script.generateCountScript(new GremlinSourceVertex()); - final List results = this.executeQuery(queryList); - - return results.size(); - } - - @Override - public long edgeCount() { - final GremlinScriptLiteral script = new GremlinScriptLiteralEdge(); - final List queryList = script.generateCountScript(new GremlinSourceEdge()); - final List results = this.executeQuery(queryList); - - return results.size(); - } - - private T recoverDomain(@NonNull GremlinSource source, @NonNull List results) { - final T domain; - final Class domainClass = source.getDomainClass(); - - source.doGremlinResultRead(results); - domain = this.mappingConverter.read(domainClass, source); - - if (source instanceof GremlinSourceEdge) { - this.completeEdge(domain, (GremlinSourceEdge) source); - } - - return domain; - } - - private List recoverDomainList(@NonNull GremlinSource source, @NonNull List results) { - return results.stream().map(r -> recoverDomain(source, Collections.singletonList(r))).collect(toList()); - } - - private T recoverGraphDomain(@NonNull GremlinSourceGraph source, @NonNull List results) { - final T domain; - final Class domainClass = source.getDomainClass(); - - source.getResultsReader().read(results, source); - domain = source.doGremlinSourceRead(domainClass, mappingConverter); - return domain; - } - - private boolean notExistsById(@NonNull Object id, @NonNull GremlinSource source) { - return !existsById(id, source); - } - - @Override - public boolean existsById(@NonNull Object id, @NonNull GremlinSource source) { - return findById(id, source) != null; - } - - @Override - public List find(@NonNull GremlinQuery query, @NonNull GremlinSource source) { - final QueryScriptGenerator generator = new QueryFindScriptGenerator(source); - final List queryList = generator.generate(query); - final List results = this.executeQuery(queryList); - - if (results.isEmpty()) { - return Collections.emptyList(); - } - - return this.recoverDomainList(source, results); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadata.java b/src/main/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadata.java deleted file mode 100644 index 1f05dd7d..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadata.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query; - -public class SimpleGremlinEntityMetadata implements GremlinEntityMetadata { - - private final Class type; - - public SimpleGremlinEntityMetadata(Class type) { - this.type = type; - } - - public Class getJavaType() { - return this.type; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/criteria/Criteria.java b/src/main/java/com/microsoft/spring/data/gremlin/query/criteria/Criteria.java deleted file mode 100644 index 7282c6e0..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/criteria/Criteria.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.criteria; - -import lombok.Getter; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.List; - -@Getter -public class Criteria { - - private String subject; - private List subValues; - private final CriteriaType type; - private final List subCriteria; - - private Criteria(CriteriaType type) { - this.type = type; - this.subCriteria = new ArrayList<>(); - } - - private static boolean isBinaryOperation(CriteriaType type) { - switch (type) { - case AND: - case OR: - return true; - default: - return false; - } - } - - private static boolean isUnaryOperation(CriteriaType type) { - switch (type) { - case EXISTS: - case AFTER: - case BEFORE: - case BETWEEN: - case IS_EQUAL: - return true; - default: - return false; - } - } - - public static Criteria getUnaryInstance(CriteriaType type, @NonNull String subject, @NonNull List values) { - Assert.isTrue(isUnaryOperation(type), "type should be Unary operation"); - - final Criteria criteria = new Criteria(type); - - criteria.subject = subject; - criteria.subValues = values; - - return criteria; - } - - public static Criteria getBinaryInstance(CriteriaType type, @NonNull Criteria left, @NonNull Criteria right) { - Assert.isTrue(isBinaryOperation(type), "type should be Binary operation"); - - final Criteria criteria = new Criteria(type); - - criteria.subCriteria.add(left); - criteria.subCriteria.add(right); - - Assert.isTrue(criteria.getSubCriteria().size() == 2, "Binary should contain 2 subCriteria"); - - return criteria; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaType.java b/src/main/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaType.java deleted file mode 100644 index cd241b06..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaType.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.criteria; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; - -public enum CriteriaType { - IS_EQUAL, - OR, - AND, - EXISTS, - AFTER, - BEFORE, - BETWEEN; - - public static String criteriaTypeToGremlin(CriteriaType type) { - switch (type) { - case OR: - return GREMLIN_PRIMITIVE_OR; - case AND: - return GREMLIN_PRIMITIVE_AND; - case AFTER: - return GREMLIN_PRIMITIVE_IS_GT; - case BEFORE: - return GREMLIN_PRIMITIVE_IS_LT; - case BETWEEN: - return GREMLIN_PRIMITIVE_IS_BETWEEN; - default: - throw new UnsupportedOperationException("Unsupported criteria type."); - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameter.java b/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameter.java deleted file mode 100644 index 303c0047..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameter.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.paramerter; - -import org.springframework.core.MethodParameter; -import org.springframework.data.repository.query.Parameter; - -public class GremlinParameter extends Parameter { - - public GremlinParameter(MethodParameter parameter) { - super(parameter); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameterAccessor.java b/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameterAccessor.java deleted file mode 100644 index 970322c5..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameterAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.paramerter; - -import org.springframework.data.repository.query.ParameterAccessor; - -public interface GremlinParameterAccessor extends ParameterAccessor { -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameters.java b/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameters.java deleted file mode 100644 index 1ac83776..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParameters.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.paramerter; - -import org.springframework.core.MethodParameter; -import org.springframework.data.repository.query.Parameters; - -import java.lang.reflect.Method; -import java.util.List; - -public class GremlinParameters extends Parameters { - - public GremlinParameters(Method method) { - super(method); - } - - private GremlinParameters(List parameters) { - super(parameters); - } - - @Override - protected GremlinParameters createFrom(List parameters) { - return new GremlinParameters(parameters); - } - - @Override - protected GremlinParameter createParameter(MethodParameter parameter) { - return new GremlinParameter(parameter); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParametersParameterAccessor.java b/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParametersParameterAccessor.java deleted file mode 100644 index 47b5bb4a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/paramerter/GremlinParametersParameterAccessor.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.paramerter; - -import com.microsoft.spring.data.gremlin.query.query.GremlinQueryMethod; -import org.springframework.data.repository.query.ParametersParameterAccessor; - -public class GremlinParametersParameterAccessor extends ParametersParameterAccessor - implements GremlinParameterAccessor { - - public GremlinParametersParameterAccessor(GremlinQueryMethod method, Object[] values) { - super(method.getParameters(), values); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/AbstractGremlinQuery.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/AbstractGremlinQuery.java deleted file mode 100644 index 4cffcaea..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/AbstractGremlinQuery.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameterAccessor; -import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParametersParameterAccessor; -import org.springframework.data.repository.query.RepositoryQuery; -import org.springframework.data.repository.query.ResultProcessor; -import org.springframework.lang.NonNull; - -public abstract class AbstractGremlinQuery implements RepositoryQuery { - - private final GremlinQueryMethod method; - private final GremlinOperations operations; - - public AbstractGremlinQuery(@NonNull GremlinQueryMethod method, @NonNull GremlinOperations operations) { - this.method = method; - this.operations = operations; - } - - protected abstract GremlinQuery createQuery(GremlinParameterAccessor accessor); - - protected boolean isDeleteQuery() { - // panli: always return false as only take care find in one PR. - return false; - } - - @Override - public Object execute(@NonNull Object[] parameters) { - final GremlinParameterAccessor accessor = new GremlinParametersParameterAccessor(this.method, parameters); - - final GremlinQuery query = this.createQuery(accessor); - final ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor); - final GremlinQueryExecution execution = this.getExecution(); - - return execution.execute(query, processor.getReturnedType().getDomainType()); - } - - @Override - @NonNull - public GremlinQueryMethod getQueryMethod() { - return this.method; - } - - @NonNull - private GremlinQueryExecution getExecution() { - if (this.isDeleteQuery()) { - throw new UnsupportedOperationException("Not implemented yet"); - } else { - return new GremlinQueryExecution.FindExecution(this.operations); - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQuery.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQuery.java deleted file mode 100644 index 4b1c0de2..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQuery.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.query.criteria.Criteria; -import lombok.Getter; -import lombok.NonNull; - -public class GremlinQuery { - - @Getter - private final Criteria criteria; - - public GremlinQuery(@NonNull Criteria criteria) { - this.criteria = criteria; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryCreator.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryCreator.java deleted file mode 100644 index fdbb6dad..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryCreator.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentProperty; -import com.microsoft.spring.data.gremlin.query.criteria.Criteria; -import com.microsoft.spring.data.gremlin.query.criteria.CriteriaType; -import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameterAccessor; -import org.springframework.data.domain.Sort; -import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.repository.query.parser.AbstractQueryCreator; -import org.springframework.data.repository.query.parser.Part; -import org.springframework.data.repository.query.parser.PartTree; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.util.*; - -public class GremlinQueryCreator extends AbstractQueryCreator { - - private final MappingContext mappingContext; - private static final Map criteriaMap; - - static { - final Map map = new HashMap<>(); - - map.put(Part.Type.AFTER, CriteriaType.AFTER); - map.put(Part.Type.BEFORE, CriteriaType.BEFORE); - map.put(Part.Type.BETWEEN, CriteriaType.BETWEEN); - map.put(Part.Type.SIMPLE_PROPERTY, CriteriaType.IS_EQUAL); - map.put(Part.Type.EXISTS, CriteriaType.EXISTS); - - criteriaMap = Collections.unmodifiableMap(map); - } - - public GremlinQueryCreator(@NonNull PartTree partTree, @NonNull GremlinParameterAccessor accessor, - @NonNull MappingContext mappingContext) { - super(partTree, accessor); - - this.mappingContext = mappingContext; - } - - @Override // Note (panli): side effect here, this method will change the iterator status of parameters. - protected Criteria create(@NonNull Part part, @NonNull Iterator parameters) { - final Part.Type type = part.getType(); - final String subject = this.mappingContext.getPersistentPropertyPath(part.getProperty()).toDotPath(); - final List values = new ArrayList<>(); - - if (!criteriaMap.containsKey(type)) { - throw new UnsupportedOperationException("Unsupported keyword: " + type.toString()); - } - - for (int i = 0; i < part.getNumberOfArguments(); i++) { - Assert.isTrue(parameters.hasNext(), "should not reach the end of iterator"); - values.add(parameters.next()); - } - - return Criteria.getUnaryInstance(criteriaMap.get(type), subject, values); - } - - @Override - protected Criteria and(@NonNull Part part, @NonNull Criteria base, @NonNull Iterator parameters) { - final Criteria right = this.create(part, parameters); - - return Criteria.getBinaryInstance(CriteriaType.AND, base, right); - } - - @Override - protected Criteria or(@NonNull Criteria base, @NonNull Criteria criteria) { - return Criteria.getBinaryInstance(CriteriaType.OR, base, criteria); - } - - @Override - protected GremlinQuery complete(@NonNull Criteria criteria, @NonNull Sort sort) { - return new GremlinQuery(criteria); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryExecution.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryExecution.java deleted file mode 100644 index cae1241a..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryExecution.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import org.springframework.lang.NonNull; - -public interface GremlinQueryExecution { - Object execute(GremlinQuery query, Class type); - - final class FindExecution implements GremlinQueryExecution { - - private final GremlinOperations operations; - - public FindExecution(@NonNull GremlinOperations operations) { - this.operations = operations; - } - - @Override - public Object execute(@NonNull GremlinQuery query, @NonNull Class domainClass) { - final GremlinSource source = GremlinUtils.toGremlinSource(domainClass); - - return this.operations.find(query, source); - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryMethod.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryMethod.java deleted file mode 100644 index b38dc7b5..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/GremlinQueryMethod.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.query.GremlinEntityMetadata; -import com.microsoft.spring.data.gremlin.query.SimpleGremlinEntityMetadata; -import org.springframework.data.projection.ProjectionFactory; -import org.springframework.data.repository.core.EntityMetadata; -import org.springframework.data.repository.core.RepositoryMetadata; -import org.springframework.data.repository.query.QueryMethod; - -import java.lang.reflect.Method; - -public class GremlinQueryMethod extends QueryMethod { - - private GremlinEntityMetadata metadata; - - public GremlinQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { - super(method, metadata, factory); - } - - @Override - public EntityMetadata getEntityInformation() { - @SuppressWarnings("unchecked") final Class domainClass = (Class) super.getDomainClass(); - - this.metadata = new SimpleGremlinEntityMetadata<>(domainClass); - - return this.metadata; - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/PartTreeGremlinQuery.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/PartTreeGremlinQuery.java deleted file mode 100644 index 80e3c439..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/PartTreeGremlinQuery.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.mapping.GremlinPersistentProperty; -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameterAccessor; -import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.repository.query.ResultProcessor; -import org.springframework.data.repository.query.parser.PartTree; -import org.springframework.lang.NonNull; - -public class PartTreeGremlinQuery extends AbstractGremlinQuery { - - private final PartTree partTree; - private final ResultProcessor processor; - private final MappingContext mappingContext; - - public PartTreeGremlinQuery(@NonNull GremlinQueryMethod method, @NonNull GremlinOperations operations) { - super(method, operations); - - this.processor = method.getResultProcessor(); - this.partTree = new PartTree(method.getName(), processor.getReturnedType().getDomainType()); - this.mappingContext = operations.getMappingConverter().getMappingContext(); - } - - @Override - protected GremlinQuery createQuery(@NonNull GremlinParameterAccessor accessor) { - final GremlinQueryCreator creator = new GremlinQueryCreator(this.partTree, accessor, this.mappingContext); - - if (this.partTree.isLimiting()) { - throw new UnsupportedOperationException("Limitation is not supported yet"); - } - - return creator.createQuery(); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryFindScriptGenerator.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryFindScriptGenerator.java deleted file mode 100644 index 4baf87c7..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryFindScriptGenerator.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.query.criteria.Criteria; -import com.microsoft.spring.data.gremlin.query.criteria.CriteriaType; -import org.springframework.lang.NonNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static com.microsoft.spring.data.gremlin.common.Constants.*; -import static com.microsoft.spring.data.gremlin.conversion.script.AbstractGremlinScriptLiteral.*; - -public class QueryFindScriptGenerator implements QueryScriptGenerator { - - private final GremlinSource source; - - public QueryFindScriptGenerator(@NonNull GremlinSource source) { - this.source = source; - } - - private String getCriteriaSubject(@NonNull Criteria criteria) { - String subject = criteria.getSubject(); - - if (subject.equals(this.source.getIdField().getName())) { - subject = PROPERTY_ID; // If subject is @Id/id field, use id property in database. - } - - return subject; - } - - private String generateIsEqual(@NonNull Criteria criteria) { - final String subject = getCriteriaSubject(criteria); - - if (subject.equals(PROPERTY_ID)) { - return String.format(GREMLIN_PRIMITIVE_WHERE, generateHasId(criteria.getSubValues().get(0))); - } else { - return String.format(GREMLIN_PRIMITIVE_WHERE, generateHas(subject, criteria.getSubValues().get(0))); - } - } - - /** - * Generate script with only one subject and no subValue, like findByActiveExists(). - * - * @param criteria given query represent a query subject - * @return simple script with keyword from criteria type - */ - private String generateEmptyScript(@NonNull Criteria criteria) { - final String subject = this.getCriteriaSubject(criteria); - final String has = generateHas(subject, true); - - return String.format(GREMLIN_PRIMITIVE_WHERE, has); - } - - /** - * Generate script with only one subject and only one subValue, like findByCreateAtBefore(Date start). - * - * @param criteria given query represent a query subject - * @return simple script with keyword from criteria type - */ - private String generateSingleScript(@NonNull Criteria criteria) { - final CriteriaType type = criteria.getType(); - final String subject = this.getCriteriaSubject(criteria); - final long milliSeconds = GremlinUtils.timeToMilliSeconds(criteria.getSubValues().get(0)); - - final String values = String.format(GREMLIN_PRIMITIVE_VALUES, subject); - final String query = String.format(CriteriaType.criteriaTypeToGremlin(type), milliSeconds); - final String content = String.join(GREMLIN_PRIMITIVE_INVOKE, values, query); - - return String.format(GREMLIN_PRIMITIVE_WHERE, content); - } - - /** - * Generate script with only one subject and two subValue, like findByCreateAtBetween(Date start, Date end). - * - * @param criteria given query represent a query subject - * @return simple script with keyword from criteria type - */ - private String generateDoubleScript(Criteria criteria) { - final CriteriaType type = criteria.getType(); - final String subject = this.getCriteriaSubject(criteria); - final long start = GremlinUtils.toPrimitiveLong(criteria.getSubValues().get(0)); - final long end = GremlinUtils.toPrimitiveLong(criteria.getSubValues().get(1)); - - final String values = String.format(GREMLIN_PRIMITIVE_VALUES, subject); - final String query = String.format(CriteriaType.criteriaTypeToGremlin(type), start, end); - final String content = String.join(GREMLIN_PRIMITIVE_INVOKE, values, query); - - return String.format(GREMLIN_PRIMITIVE_WHERE, content); - } - - /** - * Generate script combined by AND/OR keyword. - * - * @param left sub script on left - * @param right sub script on right - * @param type should be AND/OR - * @return combined script with AND/OR - */ - private String generateCombinedScript(@NonNull String left, @NonNull String right, CriteriaType type) { - final String operation = CriteriaType.criteriaTypeToGremlin(type); - final String content = String.join(GREMLIN_PRIMITIVE_INVOKE, left, operation, right); - - return String.format(GREMLIN_PRIMITIVE_WHERE, content); - } - - - private String generateScriptTraversal(@NonNull Criteria criteria) { - final CriteriaType type = criteria.getType(); - - switch (type) { - case IS_EQUAL: - return this.generateIsEqual(criteria); - case AND: - case OR: - final String left = this.generateScriptTraversal(criteria.getSubCriteria().get(0)); - final String right = this.generateScriptTraversal(criteria.getSubCriteria().get(1)); - - return this.generateCombinedScript(left, right, type); - case AFTER: - case BEFORE: - return this.generateSingleScript(criteria); - case BETWEEN: - return this.generateDoubleScript(criteria); - case EXISTS: - return this.generateEmptyScript(criteria); - default: - throw new UnsupportedOperationException("unsupported Criteria type"); - } - } - - private List generateScript(@NonNull GremlinQuery query) { - final Criteria criteria = query.getCriteria(); - final List scriptList = new ArrayList<>(); - - scriptList.add(GREMLIN_PRIMITIVE_GRAPH); - - if (this.source instanceof GremlinSourceVertex) { - scriptList.add(GREMLIN_PRIMITIVE_VERTEX_ALL); - } else if (this.source instanceof GremlinSourceEdge) { - scriptList.add(GREMLIN_PRIMITIVE_EDGE_ALL); - } else { - throw new UnsupportedOperationException("Cannot generate script from graph entity"); - } - - scriptList.add(generateHasLabel(this.source.getLabel())); - scriptList.add(this.generateScriptTraversal(criteria)); - - return scriptList; - } - - @Override - @SuppressWarnings("unchecked") - public List generate(@NonNull GremlinQuery query) { - final List scriptList = new ArrayList<>(this.generateScript(query)); - - return Collections.singletonList(String.join(GREMLIN_PRIMITIVE_INVOKE, scriptList)); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryScriptGenerator.java b/src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryScriptGenerator.java deleted file mode 100644 index d36aa1cc..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/query/query/QueryScriptGenerator.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.query; - -import java.util.List; - -public interface QueryScriptGenerator { - - List generate(GremlinQuery query); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/GremlinRepository.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/GremlinRepository.java deleted file mode 100644 index a47ed614..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/GremlinRepository.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.NoRepositoryBean; - -import java.io.Serializable; - -@NoRepositoryBean -public interface GremlinRepository extends CrudRepository { - - Iterable findAll(Class domainClass); - - void deleteAll(GremlinEntityType type); - - void deleteAll(Class domainClass); - - long vertexCount(); - - long edgeCount(); -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/config/EnableGremlinRepositories.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/config/EnableGremlinRepositories.java deleted file mode 100644 index 4ccc3439..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/config/EnableGremlinRepositories.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.config; - -import com.microsoft.spring.data.gremlin.repository.support.GremlinRepositoryFactoryBean; -import org.springframework.context.annotation.ComponentScan.Filter; -import org.springframework.context.annotation.Import; -import org.springframework.data.repository.config.DefaultRepositoryBaseClass; - -import java.lang.annotation.*; - -import static com.microsoft.spring.data.gremlin.common.Constants.DEFAULT_REPOSITORY_IMPLEMENT_POSTFIX; - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@Import(GremlinRepositoryRegistrar.class) -public @interface EnableGremlinRepositories { - - /** - * Alias for basePackages. - */ - String[] value() default {}; - - /** - * Base packages to scan for components with annotations. - */ - String[] basePackages() default {}; - - /** - * Type-safe version of basePackages. - */ - Class[] basePackageClasses() default {}; - - /** - * Specifies types for component scan. - */ - Filter[] includeFilters() default {}; - - /** - * Specifies types for skipping component scan. - */ - Filter[] excludeFilters() default {}; - - /** - * Specifics the postfix to be used for custom repository implementation class name. - */ - String repositoryImplementationPostfix() default DEFAULT_REPOSITORY_IMPLEMENT_POSTFIX; - - /** - * Configures the repository base class to be used to create repository. - */ - Class repositoryBaseClass() default DefaultRepositoryBaseClass.class; - - /** - * Configures whether nested repository interface. - */ - boolean considerNestedRepositories() default false; - - /** - * Configure the class of repository factory bean. - */ - Class repositoryFactoryBeanClass() default GremlinRepositoryFactoryBean.class; - - /** - * Specific the namedQuery location. - */ - String namedQueriesLocation() default ""; -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtension.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtension.java deleted file mode 100644 index e588baa7..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtension.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.config; - -import com.microsoft.spring.data.gremlin.common.Constants; -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.apache.commons.lang3.NotImplementedException; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; -import org.springframework.data.repository.config.RepositoryConfigurationSource; - -import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.Collections; - -public class GremlinRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport { - - @Override - public String getModuleName() { - return Constants.GREMLIN_MODULE_NAME; - } - - @Override - public String getModulePrefix() { - return Constants.GREMLIN_MODULE_PREFIX; - } - - @Override - public String getRepositoryFactoryBeanClassName() { - throw new NotImplementedException("Gremlin RepositoryFactoryBean is not implemented"); - } - - @Override - public Collection> getIdentifyingTypes() { - return Collections.singleton(GremlinRepository.class); - } - - @Override - public Collection> getIdentifyingAnnotations() { - return Collections.emptyList(); - } - - @Override - public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource config) { - super.registerBeansForRoot(registry, config); - - if (!registry.containsBeanDefinition(Constants.GREMLIN_MAPPING_CONTEXT)) { - final RootBeanDefinition definition = new RootBeanDefinition(GremlinMappingContext.class); - - definition.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE); - definition.setSource(config.getSource()); - - registry.registerBeanDefinition(Constants.GREMLIN_MAPPING_CONTEXT, definition); - } - } - - @Override - public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) { - super.postProcess(builder, source); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrar.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrar.java deleted file mode 100644 index eaebf068..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrar.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.config; - -import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport; -import org.springframework.data.repository.config.RepositoryConfigurationExtension; - -import java.lang.annotation.Annotation; - -public class GremlinRepositoryRegistrar extends RepositoryBeanDefinitionRegistrarSupport { - - @Override - protected Class getAnnotation() { - return EnableGremlinRepositories.class; - } - - @Override - protected RepositoryConfigurationExtension getExtension() { - return new GremlinRepositoryConfigurationExtension(); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinEntityInformation.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinEntityInformation.java deleted file mode 100644 index 4f045ab0..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinEntityInformation.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import java.lang.reflect.Field; - -import org.springframework.data.repository.core.support.AbstractEntityInformation; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; -import org.springframework.util.ReflectionUtils; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import com.microsoft.spring.data.gremlin.annotation.Graph; -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; - -import lombok.Getter; - -public class GremlinEntityInformation extends AbstractEntityInformation { - - @Getter - private final Field idField; - - public GremlinEntityInformation(@NonNull Class domainClass) { - super(domainClass); - - this.idField = this.getIdField(domainClass); - } - - private GremlinSource createGremlinSource(@NonNull Class domainClass, @NonNull Field idField) { - final String label; - final String domainClassName = domainClass.getSimpleName(); - final Vertex vertex = domainClass.getAnnotation(Vertex.class); - final Edge edge = domainClass.getAnnotation(Edge.class); - final Graph graph = domainClass.getAnnotation(Graph.class); - final GremlinSource source; - - if (vertex != null && edge == null && graph == null) { - source = new GremlinSourceVertex<>(domainClass); - label = vertex.label().isEmpty() ? domainClassName : vertex.label(); - } else if (edge != null && vertex == null && graph == null) { - source = new GremlinSourceEdge<>(domainClass); - label = edge.label().isEmpty() ? domainClassName : edge.label(); - } else if (graph != null && vertex == null && edge == null) { - source = new GremlinSourceGraph<>(domainClass); - label = ""; - } else { - throw new GremlinUnexpectedEntityTypeException("Unexpected gremlin entity type"); - } - - source.setLabel(label); - source.setIdField(idField); - - return source; - } - - public GremlinSource createGremlinSource() { - return createGremlinSource(super.getJavaType(), idField); - } - - @Override - @Nullable - public ID getId(T entity) { - final Field idField = this.idField; - @SuppressWarnings("unchecked") final ID id = (ID) ReflectionUtils.getField(idField, entity); - - if (id == null && !(super.getJavaType().isAnnotationPresent(Graph.class)) - && !idField.isAnnotationPresent(GeneratedValue.class)) { - throw new GremlinInvalidEntityIdFieldException("A non-generated id field cannot be null!"); - } - return id; - } - - @Override - public Class getIdType() { - @SuppressWarnings("unchecked") final Class idClass = (Class) this.idField.getType(); - - return idClass; - } - - @NonNull - private Field getIdField(@NonNull Class domainClass) { - final Field idField = GremlinUtils.getIdField(domainClass); - - ReflectionUtils.makeAccessible(idField); - - return idField; - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactory.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactory.java deleted file mode 100644 index 67391a0d..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import com.microsoft.spring.data.gremlin.query.query.GremlinQueryMethod; -import com.microsoft.spring.data.gremlin.query.query.PartTreeGremlinQuery; -import org.springframework.context.ApplicationContext; -import org.springframework.data.projection.ProjectionFactory; -import org.springframework.data.repository.core.EntityInformation; -import org.springframework.data.repository.core.NamedQueries; -import org.springframework.data.repository.core.RepositoryInformation; -import org.springframework.data.repository.core.RepositoryMetadata; -import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import org.springframework.data.repository.query.QueryLookupStrategy; -import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider; -import org.springframework.data.repository.query.RepositoryQuery; -import org.springframework.lang.NonNull; -import org.springframework.util.Assert; - -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.Optional; - -public class GremlinRepositoryFactory extends RepositoryFactorySupport { - - private final ApplicationContext context; - private final GremlinOperations operations; - - public GremlinRepositoryFactory(@NonNull GremlinOperations operations, ApplicationContext context) { - this.operations = operations; - this.context = context; - } - - @Override - protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { - return SimpleGremlinRepository.class; - } - - @Override - protected Object getTargetRepository(RepositoryInformation information) { - final EntityInformation entityInfo = this.getEntityInformation(information.getDomainType()); - - return getTargetRepositoryViaReflection(information, entityInfo, this.context); - } - - @Override - public EntityInformation getEntityInformation(Class domainClass) { - return new GremlinEntityInformation<>(domainClass); - } - - @Override - protected Optional getQueryLookupStrategy( - QueryLookupStrategy.Key key, QueryMethodEvaluationContextProvider provider) { - return Optional.of(new GremlinQueryLookupStrategy(this.operations)); - } - - private static class GremlinQueryLookupStrategy implements QueryLookupStrategy { - - private final GremlinOperations operations; - - public GremlinQueryLookupStrategy(@NonNull GremlinOperations operations) { - this.operations = operations; - } - - @Override - public RepositoryQuery resolveQuery(@NonNull Method method, RepositoryMetadata metadata, - ProjectionFactory factory, NamedQueries namedQueries) { - final GremlinQueryMethod queryMethod = new GremlinQueryMethod(method, metadata, factory); - - Assert.notNull(queryMethod, "queryMethod should not be null"); - Assert.notNull(this.operations, "operations should not be null"); - - return new PartTreeGremlinQuery(queryMethod, this.operations); - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBean.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBean.java deleted file mode 100644 index 3791a10c..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBean.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.data.mapping.context.MappingContext; -import org.springframework.data.repository.Repository; -import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; -import org.springframework.data.repository.core.support.RepositoryFactorySupport; - -import java.io.Serializable; - -public class GremlinRepositoryFactoryBean, S, ID extends Serializable> - extends RepositoryFactoryBeanSupport implements ApplicationContextAware { - - private ApplicationContext context; - private GremlinOperations operations; - private boolean mappingContextConfigured = false; - - public GremlinRepositoryFactoryBean(Class repositoryInterface) { - super(repositoryInterface); - } - - @Autowired - public void setGremlinOperations(GremlinOperations operations) { - this.operations = operations; - } - - protected RepositoryFactorySupport getFactoryInstance(ApplicationContext context) { - return new GremlinRepositoryFactory(this.operations, context); - } - - @Override - protected final RepositoryFactorySupport createRepositoryFactory() { - return this.getFactoryInstance(this.context); - } - - @Override - public void setApplicationContext(ApplicationContext context) throws BeansException { - this.context = context; - } - - @Override - protected void setMappingContext(MappingContext mappingContext) { - super.setMappingContext(mappingContext); - - this.mappingContextConfigured = true; - } - - @Override - public void afterPropertiesSet() { - super.afterPropertiesSet(); - - if (!this.mappingContextConfigured) { - if (this.operations == null) { - this.setMappingContext(new GremlinMappingContext()); - } else { - this.setMappingContext(this.operations.getMappingConverter().getMappingContext()); - } - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/SimpleGremlinRepository.java b/src/main/java/com/microsoft/spring/data/gremlin/repository/support/SimpleGremlinRepository.java deleted file mode 100644 index d284cb3e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/repository/support/SimpleGremlinRepository.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.context.ApplicationContext; -import org.springframework.lang.NonNull; - -import java.io.Serializable; -import java.util.List; -import java.util.Optional; -import java.util.stream.StreamSupport; - -import static java.util.stream.Collectors.toList; - -public class SimpleGremlinRepository implements GremlinRepository { - - private final GremlinEntityInformation information; - - private final GremlinOperations operations; - - public SimpleGremlinRepository(GremlinEntityInformation information, @NonNull ApplicationContext context) { - this(information, context.getBean(GremlinOperations.class)); - } - - public SimpleGremlinRepository(GremlinEntityInformation information, @NonNull GremlinOperations operations) { - this.operations = operations; - this.information = information; - } - - @Override - @SuppressWarnings("unchecked") - public S save(@NonNull S domain) { - final GremlinSource source = this.information.createGremlinSource(); - - source.setId(this.information.getId(domain)); - - return (S) this.operations.save(domain, source); - } - - @Override - public Iterable saveAll(@NonNull Iterable domains) { - return StreamSupport.stream(domains.spliterator(), true).map(this::save).collect(toList()); - } - - @Override - public Iterable findAll() { - final GremlinSource source = this.information.createGremlinSource(); - - if (source instanceof GremlinSourceGraph) { - throw new UnsupportedOperationException("findAll of Graph is not supported"); - } - - return this.operations.findAll(source); - } - - @Override - public List findAllById(@NonNull Iterable ids) { - return StreamSupport.stream(ids.spliterator(), true).map(this::findById) - .filter(Optional::isPresent).map(Optional::get).collect(toList()); - } - - @Override - public Optional findById(@NonNull ID id) { - final T domain = this.operations.findById(id, this.information.createGremlinSource()); - - return domain == null ? Optional.empty() : Optional.of(domain); - } - - @Override - public Iterable findAll(@NonNull Class domainClass) { - return findAll(); - } - - @Override - public long vertexCount() { - return this.operations.vertexCount(); - } - - @Override - public long edgeCount() { - return this.operations.edgeCount(); - } - - /** - * The total number of vertex and edge, vertexCount and edgeCount is also available. - * - * @return the count of both vertex and edge. - */ - @Override - public long count() { - return this.vertexCount() + this.edgeCount(); - } - - @Override - public void delete(@NonNull T domain) { - this.operations.deleteById(this.information.getId(domain), this.information.createGremlinSource()); - } - - @Override - public void deleteById(@NonNull ID id) { - this.operations.deleteById(id, this.information.createGremlinSource()); - } - - @Override - public void deleteAll() { - this.operations.deleteAll(); - } - - @Override - public void deleteAll(GremlinEntityType type) { - this.operations.deleteAll(type); - } - - @Override - public void deleteAll(@NonNull Iterable domains) { - domains.forEach(this::delete); - } - - @Override - public void deleteAll(@NonNull Class domainClass) { - this.operations.deleteAll(this.information.createGremlinSource()); - } - - @Override - public boolean existsById(@NonNull ID id) { - return this.operations.existsById(id, this.information.createGremlinSource()); - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/MacAddress.java b/src/main/java/com/microsoft/spring/data/gremlin/telemetry/MacAddress.java deleted file mode 100644 index a76929e6..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/MacAddress.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -/* - * Disclaimer: - * This class is copied from https://github.com/Microsoft/azure-tools-for-java/ with minor modification (fixing - * static analysis error). - * Location in the repo: /Utils/azuretools-core/src/com/microsoft/azuretools/azurecommons/util/MacAddress.java - */ -package com.microsoft.spring.data.gremlin.telemetry; - -import lombok.AccessLevel; -import lombok.Cleanup; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MacAddress { - - private static final String UNKNOWN_MAC_ADDRESS = "Unknown-Mac-Address"; - private static final String MAC_REGEX = "([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}"; - private static final String MAC_REGEX_ZERO = "([0]{2}[:-]){5}[0]{2}"; - private static final String HASHED_MAC_REGEX = "[0-9a-f]{64}"; - - public static boolean isValidHashMacFormat(@NonNull String hashMac) { - if (hashMac.isEmpty()) { - return false; - } - - return Pattern.compile(HASHED_MAC_REGEX).matcher(hashMac).matches(); - } - - private static String getRawMac() { - final List commands; - final String os = System.getProperty("os.name"); - final StringBuilder macBuilder = new StringBuilder(); - - if (os != null && !os.isEmpty() && os.toLowerCase(Locale.US).startsWith("win")) { - commands = Collections.singletonList("getmac"); - } else { - commands = Arrays.asList("ifconfig", "-a"); - } - - try { - String tmp; - final ProcessBuilder builder = new ProcessBuilder(commands); - final Process process = builder.start(); - @Cleanup final InputStreamReader streamReader = new InputStreamReader(process.getInputStream(), "utf-8"); - @Cleanup final BufferedReader reader = new BufferedReader(streamReader); - - while ((tmp = reader.readLine()) != null) { - macBuilder.append(tmp); - } - } catch (IOException e) { - return ""; - } - - return macBuilder.toString(); - } - - private static String getHexDigest(byte digest) { - final String hex = Integer.toString((digest & 0xff) + 0x100, 16); - - return hex.substring(1); - } - - private static String hash(@NonNull String mac) { - if (mac.isEmpty()) { - return ""; - } - - final StringBuilder builder = new StringBuilder(); - - try { - final MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); - - messageDigest.update(mac.getBytes("UTF-8")); - - final byte[] digestBytes = messageDigest.digest(); - - for (final byte digest : digestBytes) { - builder.append(getHexDigest(digest)); - } - } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { - return ""; - } - - Assert.isTrue(isValidHashMacFormat(builder.toString()), "Invalid format for HashMac"); - - return builder.toString(); - } - - public static String getHashMac() { - final String rawMac = getRawMac(); - - if (rawMac.isEmpty()) { - return UNKNOWN_MAC_ADDRESS; - } - - final Pattern pattern = Pattern.compile(MAC_REGEX); - final Pattern patternZero = Pattern.compile(MAC_REGEX_ZERO); - final Matcher matcher = pattern.matcher(rawMac); - - String mac = ""; - - while (matcher.find()) { - mac = matcher.group(0); - - if (!patternZero.matcher(mac).matches()) { - break; - } - } - - final String hashMac = hash(mac); - - if (StringUtils.hasText(hashMac)) { - return hashMac; - } - - return UNKNOWN_MAC_ADDRESS; - } -} - diff --git a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/PropertyLoader.java b/src/main/java/com/microsoft/spring/data/gremlin/telemetry/PropertyLoader.java deleted file mode 100644 index 55822c8e..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/PropertyLoader.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.telemetry; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.lang.NonNull; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class PropertyLoader { - - private static final String PROJECT_PROPERTY_FILE = "/META-INF/project.properties"; - - private static final String TELEMETRY_CONFIG_FILE = "/telemetry.config"; - - public static String getProjectVersion() { - return getPropertyByName("project.version", PROJECT_PROPERTY_FILE); - } - - public static String getTelemetryInstrumentationKey() { - return getPropertyByName("telemetry.instrumentationKey", TELEMETRY_CONFIG_FILE); - } - - private static String getPropertyByName(@NonNull String name, @NonNull String filename) { - final Properties properties = new Properties(); - final InputStream inputStream = PropertyLoader.class.getResourceAsStream(filename); - - if (inputStream == null) { - return null; - } - - try { - properties.load(inputStream); - } catch (IOException e) { - // Omitted - } finally { - try { - inputStream.close(); - } catch (IOException e) { - // Omitted - } - } - - return properties.getProperty(name); - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetryEventData.java b/src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetryEventData.java deleted file mode 100644 index a6eb6478..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetryEventData.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.telemetry; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -import org.springframework.util.Assert; - -import java.time.Instant; -import java.util.Map; - -@Getter -public class TelemetryEventData { - - private final String name; - - @JsonProperty("iKey") - private final String instrumentationKey; - - private final Tags tags = new Tags("Spring-on-azure", "Java-maven-plugin"); - - private final EventData data = new EventData("EventData"); - - private final String time; - - public TelemetryEventData(String eventName, @NonNull Map properties) { - Assert.hasText(eventName, "Event name should contain text."); - - name = "Microsoft.ApplicationInsights.Event"; - instrumentationKey = PropertyLoader.getTelemetryInstrumentationKey(); - - data.getBaseData().setName(eventName); - data.getBaseData().setProperties(properties); - time = Instant.now().toString(); - } - - @Getter - private static class Tags { - - @JsonProperty("ai.cloud.roleInstance") - private final String aiCloudRoleInstance; - - @JsonProperty("ai.internal.sdkVersion") - private final String aiInternalSdkVersion; - - public Tags(String instance, String sdkVersion) { - aiCloudRoleInstance = instance; - aiInternalSdkVersion = sdkVersion; - } - } - - @Getter - private static class EventData { - - private final String baseType; - - private final CustomData baseData = new CustomData(); - - public EventData(String baseType) { - this.baseType = baseType; - } - - @Getter - @Setter(AccessLevel.PRIVATE) - private static class CustomData { - - private final Integer ver = 2; - - private String name; - - private Map properties; - } - } -} diff --git a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetrySender.java b/src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetrySender.java deleted file mode 100644 index 15294e25..00000000 --- a/src/main/java/com/microsoft/spring/data/gremlin/telemetry/TelemetrySender.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.telemetry; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.*; -import org.springframework.util.Assert; -import org.springframework.web.client.RestTemplate; - -import java.util.HashMap; -import java.util.Map; - -import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON; - -@Slf4j -public class TelemetrySender { - - private static final String PROPERTY_INSTALLATION_ID = "installationId"; - - private static final String PROPERTY_VERSION = "version"; - - private static final String PROPERTY_SERVICE_NAME = "serviceName"; - - private static final String PROJECT_INFO = "spring-data-gremlin/" + PropertyLoader.getProjectVersion(); - - private static final String TELEMETRY_TARGET_URL = "https://dc.services.visualstudio.com/v2/track"; - - private static final ObjectMapper MAPPER = new ObjectMapper(); - - private static final int RETRY_LIMIT = 3; // Align the retry times with sdk - - private static final RestTemplate REST_TEMPLATE = new RestTemplate(); - - private static final HttpHeaders HEADERS = new HttpHeaders(); - - static { - HEADERS.add(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON.toString()); - } - - private ResponseEntity executeRequest(final TelemetryEventData eventData) { - - try { - final HttpEntity body = new HttpEntity<>(MAPPER.writeValueAsString(eventData), HEADERS); - - return REST_TEMPLATE.exchange(TELEMETRY_TARGET_URL, HttpMethod.POST, body, String.class); - } catch (Exception ignore) { - log.trace("Failed to exchange telemetry request, {}.", ignore.getMessage()); - } - - return null; - } - - private void sendTelemetryData(@NonNull TelemetryEventData eventData) { - ResponseEntity response = null; - - for (int i = 0; i < RETRY_LIMIT; i++) { - response = executeRequest(eventData); - - if (response != null && response.getStatusCode() == HttpStatus.OK) { - return; - } - } - - if (response != null && response.getStatusCode() != HttpStatus.OK) { - log.trace("Failed to send telemetry data, response status code {}.", response.getStatusCode().toString()); - } - } - - public void send(String name) { - Assert.hasText(name, "Event name should contain text."); - - sendTelemetryData(new TelemetryEventData(name, getProperties())); - } - - private Map getProperties() { - final Map properties = new HashMap<>(); - - properties.put(PROPERTY_VERSION, PROJECT_INFO); - properties.put(PROPERTY_SERVICE_NAME, "gremlin"); - properties.put(PROPERTY_INSTALLATION_ID, MacAddress.getHashMac()); - - return properties; - } -} - diff --git a/src/main/resources/META-INF/project.properties b/src/main/resources/META-INF/project.properties deleted file mode 100644 index 90d42083..00000000 --- a/src/main/resources/META-INF/project.properties +++ /dev/null @@ -1 +0,0 @@ -project.version=@project.version@ diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories deleted file mode 100644 index d0072b45..00000000 --- a/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.data.repository.core.support.RepositoryFactorySupport=com.microsoft.spring.data.gremlin.repository.support.GremlinRepositoryFactory - diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 42947c47..00000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -gremlin.endpoint=endpoint.gremlin.cosmosdb.azure.com -gremlin.port=443 -gremlin.username=/dbs/database/colls/collection -gremlin.password=password diff --git a/src/main/resources/telemetry.config b/src/main/resources/telemetry.config deleted file mode 100644 index 61b615fa..00000000 --- a/src/main/resources/telemetry.config +++ /dev/null @@ -1 +0,0 @@ -telemetry.instrumentationKey=@telemetry.instrumentationKey@ \ No newline at end of file diff --git a/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationEdgeUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationEdgeUnitTest.java deleted file mode 100644 index 0004125e..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationEdgeUnitTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Dependency; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import org.junit.Assert; -import org.junit.Test; - -public class AnnotationEdgeUnitTest { - - @Test - public void testAnnotationEdgeDefaultLabel() { - final GremlinSource source = GremlinUtils.toGremlinSource(Dependency.class); - - Assert.assertTrue(source instanceof GremlinSourceEdge); - Assert.assertNotNull(source.getLabel()); - Assert.assertEquals(source.getLabel(), Dependency.class.getSimpleName()); - } - - @Test - public void testAnnotationEdgeSpecifiedLabel() { - final GremlinSource source = GremlinUtils.toGremlinSource(Relationship.class); - - Assert.assertTrue(source instanceof GremlinSourceEdge); - Assert.assertNotNull(source.getLabel()); - Assert.assertEquals(source.getLabel(), TestConstants.EDGE_RELATIONSHIP_LABEL); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationGraphUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationGraphUnitTest.java deleted file mode 100644 index a7844af6..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationGraphUnitTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.common.domain.Network; -import com.microsoft.spring.data.gremlin.common.domain.Roadmap; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import org.junit.Assert; -import org.junit.Test; - -public class AnnotationGraphUnitTest { - - @Test - public void testAnnotationGraphDefaultCollection() { - final GremlinSource source = GremlinUtils.toGremlinSource(Network.class); - - Assert.assertTrue(source instanceof GremlinSourceGraph); - Assert.assertTrue(source.getLabel().isEmpty()); - } - - @Test - public void testAnnotationGraphSpecifiedCollection() { - final GremlinSource source = GremlinUtils.toGremlinSource(Roadmap.class); - - Assert.assertTrue(source instanceof GremlinSourceGraph); - Assert.assertTrue(source.getLabel().isEmpty()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationVertexUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationVertexUnitTest.java deleted file mode 100644 index 010fb94a..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/annotation/AnnotationVertexUnitTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.annotation; - -import com.microsoft.spring.data.gremlin.common.GremlinUtils; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Library; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import org.junit.Assert; -import org.junit.Test; - -public class AnnotationVertexUnitTest { - - @Test - public void testAnnotationVertexDefaultLabel() { - final GremlinSource source = GremlinUtils.toGremlinSource(Library.class); - - Assert.assertTrue(source instanceof GremlinSourceVertex); - Assert.assertNotNull(source.getLabel()); - Assert.assertEquals(source.getLabel(), Library.class.getSimpleName()); - } - - @Test - public void testAnnotationVertexSpecifiedLabel() { - final GremlinSource source = GremlinUtils.toGremlinSource(Person.class); - - Assert.assertTrue(source instanceof GremlinSourceVertex); - Assert.assertNotNull(source.getLabel()); - Assert.assertEquals(source.getLabel(), TestConstants.VERTEX_PERSON_LABEL); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/GremlinFactoryUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/common/GremlinFactoryUnitTest.java deleted file mode 100644 index 1b628ee9..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/GremlinFactoryUnitTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.exception.GremlinIllegalConfigurationException; -import lombok.NoArgsConstructor; -import org.apache.tinkerpop.gremlin.driver.Client; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static com.microsoft.spring.data.gremlin.common.TestConstants.EMPTY_STRING; -import static com.microsoft.spring.data.gremlin.common.TestConstants.ILLEGAL_ENDPOINT_PORT; - -@ContextConfiguration(classes = {GremlinFactoryUnitTest.TestConfiguration.class}) -@RunWith(SpringJUnit4ClassRunner.class) -public class GremlinFactoryUnitTest { - - @Autowired - private GremlinFactory factory; - - @Test(expected = GremlinIllegalConfigurationException.class) - public void testGremlinFactoryException() { - final GremlinConfig config = GremlinConfig.builder(TestConstants.FAKE_ENDPOINT, TestConstants.FAKE_USERNAME, - TestConstants.FAKE_PASSWORD).build(); - - new GremlinFactory(config).getGremlinClient(); - } - - @Test - public void testGremlinFactoryNormal() { - final Client client = factory.getGremlinClient(); - - Assert.assertEquals(client.getCluster().getPort(), TestConstants.DEFAULT_ENDPOINT_PORT); - Assert.assertFalse(client.getSettings().getSession().isPresent()); - } - - @Configuration - @NoArgsConstructor - static class TestConfiguration { - - @Bean - public GremlinFactory getGremlinFactory() { - return new GremlinFactory(getGremlinConfig()); - } - - @Bean - public GremlinConfig getGremlinConfig() { - return GremlinConfig.builder(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING) - .port(ILLEGAL_ENDPOINT_PORT) - .build(); - } - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/GremlinUtilsUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/common/GremlinUtilsUnitTest.java deleted file mode 100644 index 5e845e75..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/GremlinUtilsUnitTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.common.domain.Service; -import com.microsoft.spring.data.gremlin.conversion.source.AbstractGremlinSource; -import org.junit.Assert; -import org.junit.Test; - -public class GremlinUtilsUnitTest { - - @Test(expected = IllegalArgumentException.class) - public void testCreateIntegerInstance() { - GremlinUtils.createInstance(Integer.class); - } - - @Test(expected = IllegalArgumentException.class) - public void testCreateTestConstantsInstance() { - GremlinUtils.createInstance(TestConstants.class); - } - - @Test(expected = IllegalArgumentException.class) - public void testCreateAbstractInstance() { - GremlinUtils.createInstance(AbstractGremlinSource.class); - } - - @Test(expected = UnsupportedOperationException.class) - public void testTimeToMilliSecondsException() { - GremlinUtils.timeToMilliSeconds(new Service()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testToPrimitiveLongException() { - GremlinUtils.toPrimitiveLong((short) 2); - } - - @Test - public void testToPrimitiveLong() { - Assert.assertEquals((long) 3, GremlinUtils.toPrimitiveLong(new Long(3))); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/MacAddressUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/common/MacAddressUnitTest.java deleted file mode 100644 index b4e5e329..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/MacAddressUnitTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.telemetry.MacAddress; -import org.junit.Assert; -import org.junit.Test; - -public class MacAddressUnitTest { - - @Test - public void testGetHashMacNormal() { - Assert.assertNotNull(MacAddress.getHashMac()); - Assert.assertFalse(MacAddress.getHashMac().isEmpty()); - Assert.assertFalse(MacAddress.isValidHashMacFormat("")); - Assert.assertTrue(MacAddress.isValidHashMacFormat(MacAddress.getHashMac())); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/TestConstants.java b/src/test/java/com/microsoft/spring/data/gremlin/common/TestConstants.java deleted file mode 100644 index faa1f8a9..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/TestConstants.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TestConstants { - - public static final int DEFAULT_ENDPOINT_PORT = 443; - public static final int ILLEGAL_ENDPOINT_PORT = -1; - public static final String FAKE_ENDPOINT = "XXX-xxx.XXX-xxx.cosmosdb.azure.com"; - public static final String FAKE_USERNAME = "XXX-xxx.username"; - public static final String FAKE_PASSWORD = "XXX-xxx.password"; - public static final String EMPTY_STRING = ""; - - public static final String PROPERTY_ID = "id"; - public static final String PROPERTY_NAME = "name"; - public static final String PROPERTY_LOCATION = "location"; - - public static final String VERTEX_PERSON_LABEL = "label-person"; - public static final String VERTEX_PROJECT_LABEL = "label-project"; - public static final String EDGE_RELATIONSHIP_LABEL = "label-relationship"; - public static final String GRAPH_ROADMAP_COLLECTION_NAME = "roadmap-collection"; - - public static final String VERTEX_PERSON_ID = "233333"; - public static final String VERTEX_PERSON_NAME = "incarnation-p-lee"; - - public static final String VERTEX_PERSON_0_ID = "000000"; - public static final String VERTEX_PERSON_0_NAME = "silencer"; - - public static final String VERTEX_PERSON_1_ID = "111111"; - public static final String VERTEX_PERSON_1_NAME = "templar-assassin"; - - public static final String VERTEX_PROJECT_ID = "666666"; - public static final String VERTEX_PROJECT_NAME = "spring-data-gremlin"; - public static final String VERTEX_PROJECT_URI = "https://github.com/Incarnation-p-lee/spring-data-gremlin.git"; - - public static final String VERTEX_PROJECT_0_ID = "222222"; - public static final String VERTEX_PROJECT_0_NAME = "spring-data-documentdb"; - public static final String VERTEX_PROJECT_0_URI = "https://github.com/Microsoft/spring-data-documentdb"; - - public static final String EDGE_RELATIONSHIP_ID = "999999"; - public static final String EDGE_RELATIONSHIP_NAME = "created"; - public static final String EDGE_RELATIONSHIP_LOCATION = "shanghai"; - - public static final String EDGE_RELATIONSHIP_0_ID = "333333"; - public static final String EDGE_RELATIONSHIP_0_NAME = "contributed"; - public static final String EDGE_RELATIONSHIP_0_LOCATION = "war3"; - - public static final String EDGE_RELATIONSHIP_1_ID = "444444"; - public static final String EDGE_RELATIONSHIP_1_NAME = "contributed"; - public static final String EDGE_RELATIONSHIP_1_LOCATION = "dota"; - - public static final String EDGE_RELATIONSHIP_2_ID = "555555"; - public static final String EDGE_RELATIONSHIP_2_NAME = "create"; - public static final String EDGE_RELATIONSHIP_2_LOCATION = "shanghai"; - - public static final String VERTEX_LABEL = "label-vertex"; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/TestGremlinProperties.java b/src/test/java/com/microsoft/spring/data/gremlin/common/TestGremlinProperties.java deleted file mode 100644 index 31f2fc47..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/TestGremlinProperties.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.apache.tinkerpop.gremlin.driver.ser.SerTokens; -import org.apache.tinkerpop.gremlin.driver.ser.Serializers; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -@ConfigurationProperties("gremlin") -public class TestGremlinProperties { - private String endpoint; - - private int port; - - private String username; - - private String password; - - private boolean sslEnabled = true; - - private boolean telemetryAllowed = true; - - private String serializer = Serializers.GRAPHSON.toString(); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/TestRepositoryConfiguration.java b/src/test/java/com/microsoft/spring/data/gremlin/common/TestRepositoryConfiguration.java deleted file mode 100644 index e4ed257c..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/TestRepositoryConfiguration.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import com.microsoft.spring.data.gremlin.config.AbstractGremlinConfiguration; -import com.microsoft.spring.data.gremlin.repository.config.EnableGremlinRepositories; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.PropertySource; - -@EnableGremlinRepositories -@PropertySource(value = {"classpath:application.properties"}) -@EnableConfigurationProperties(TestGremlinProperties.class) -public class TestRepositoryConfiguration extends AbstractGremlinConfiguration { - - @Autowired - private TestGremlinProperties testProps; - - @Override - public GremlinConfig getGremlinConfig() { - return GremlinConfig.builder(testProps.getEndpoint(), testProps.getUsername(), testProps.getPassword()) - .port(testProps.getPort()) - .telemetryAllowed(testProps.isTelemetryAllowed()) - .sslEnabled(testProps.isSslEnabled()) - .serializer(testProps.getSerializer()) - .build(); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/TestUtils.java b/src/test/java/com/microsoft/spring/data/gremlin/common/TestUtils.java deleted file mode 100644 index 20fccdb2..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/TestUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.junit.Assert; - -import java.util.Comparator; -import java.util.List; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TestUtils { - - public static void assertEntitiesEquals(List expect, List actual) { - Assert.assertEquals(actual.size(), expect.size()); - - actual.sort(Comparator.comparing(T::toString)); - expect.sort(Comparator.comparing(T::toString)); - - Assert.assertEquals(actual, expect); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/AdvancedUser.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/AdvancedUser.java deleted file mode 100644 index c49405f0..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/AdvancedUser.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Vertex -@Getter -@Setter -@NoArgsConstructor -public class AdvancedUser extends User { - - private int level; - - public AdvancedUser(String id, String name, int level) { - super(id, name); - - this.level = level; - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Book.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Book.java deleted file mode 100644 index 3abd3c4e..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Book.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -@Data -@Vertex -@AllArgsConstructor -@NoArgsConstructor -public class Book { - - @Id - private Integer serialNumber; - - private String name; - - private Double price; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/BookReference.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/BookReference.java deleted file mode 100644 index bea24e21..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/BookReference.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Edge -@Data -@AllArgsConstructor -@NoArgsConstructor -public class BookReference { - - private Integer id; - - @EdgeFrom - private Integer fromSerialNumber; - - @EdgeTo - private Integer toSerialNumber; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Dependency.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Dependency.java deleted file mode 100644 index 46bf8b54..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Dependency.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Edge -@Data -@AllArgsConstructor -public class Dependency { - - private String id; - - private String type; - - @EdgeFrom - private Library source; - - @EdgeTo - private Library target; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Group.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Group.java deleted file mode 100644 index e30b2cb2..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Group.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -@Edge -@Data -@NoArgsConstructor -public class Group { - - @Id - @GeneratedValue - private Long id; - - @EdgeFrom - private Student student; - - @EdgeTo - private GroupOwner groupOwner; - - public Group(Student student, GroupOwner groupOwner) { - this.student = student; - this.groupOwner = groupOwner; - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/GroupOwner.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/GroupOwner.java deleted file mode 100644 index eacef9de..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/GroupOwner.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -@Vertex -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GroupOwner { - - @Id - private String name; - - private Integer expireDays; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/InvalidDependency.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/InvalidDependency.java deleted file mode 100644 index 0f3b02ac..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/InvalidDependency.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Edge -@NoArgsConstructor -@AllArgsConstructor -public class InvalidDependency { - - private String id; - - @EdgeFrom - private String name; - - @EdgeFrom - private String fromId; - - @EdgeTo - private String toId; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Library.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Library.java deleted file mode 100644 index 6b331fa8..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Library.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Vertex -@Data -@AllArgsConstructor -public class Library { - - private String id; - - private String name; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Master.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Master.java deleted file mode 100644 index 9c0489d1..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Master.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Vertex(label = TestConstants.VERTEX_LABEL) -@AllArgsConstructor -@NoArgsConstructor -public class Master { - - private Long id; - - private String name; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Neighbor.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Neighbor.java deleted file mode 100644 index 17b26b5f..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Neighbor.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Edge -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Neighbor { - - private Long id; - - private Long distance; - - @EdgeFrom - private Student studentFrom; - - @EdgeTo - private Student studentTo; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Network.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Network.java deleted file mode 100644 index 942fde33..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Network.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.EdgeSet; -import com.microsoft.spring.data.gremlin.annotation.Graph; -import com.microsoft.spring.data.gremlin.annotation.VertexSet; -import lombok.Getter; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -@Graph -public class Network { - - @Getter - @Setter - private String id; - - @Getter - @VertexSet - private List vertexList; - - @Getter - @EdgeSet - private List edgeList; - - public Network() { - this.vertexList = new ArrayList<>(); - this.edgeList = new ArrayList<>(); - } - - public void vertexAdd(Object object) { - this.vertexList.add(object); - } - - public void edgeAdd(Object object) { - this.edgeList.add(object); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Orange.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Orange.java deleted file mode 100644 index 0af697b1..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Orange.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.GeneratedValue; -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -@Vertex -@Data -@NoArgsConstructor -public class Orange { - - @Id - @GeneratedValue - private String id; - - private String location; - - private Double price; - - public Orange(String location, Double price) { - this.location = location; - this.price = price; - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Person.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Person.java deleted file mode 100644 index d7ccff28..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Person.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Vertex(label = TestConstants.VERTEX_PERSON_LABEL) -public class Person { - - private String id; - - private String name; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Project.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Project.java deleted file mode 100644 index 99f97552..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Project.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Vertex(label = TestConstants.VERTEX_PROJECT_LABEL) -public class Project { - - private String id; - - private String name; - - private String uri; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Relationship.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Relationship.java deleted file mode 100644 index 45c1f722..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Relationship.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Edge(label = TestConstants.EDGE_RELATIONSHIP_LABEL) -public class Relationship { - - private String id; - - private String name; - - private String location; - - @EdgeFrom - private Person person; - - @EdgeTo - private Project project; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Roadmap.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Roadmap.java deleted file mode 100644 index 6ded31d2..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Roadmap.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.EdgeSet; -import com.microsoft.spring.data.gremlin.annotation.Graph; -import com.microsoft.spring.data.gremlin.annotation.VertexSet; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import lombok.Getter; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -@Graph(collection = TestConstants.GRAPH_ROADMAP_COLLECTION_NAME) -public class Roadmap { - - @Getter - @Setter - private String id; - - @VertexSet - private List vertexList; - - @EdgeSet - private List edgeList; - - public Roadmap() { - this.vertexList = new ArrayList<>(); - this.edgeList = new ArrayList<>(); - } - - public void vertexAdd(Object object) { - this.vertexList.add(object); - } - - public void edgeAdd(Object object) { - this.edgeList.add(object); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Service.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Service.java deleted file mode 100644 index dabfccde..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Service.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -import java.util.Date; -import java.util.Map; - -@AllArgsConstructor -@NoArgsConstructor -@Data -@Vertex -public class Service { - - @Id - private String id; - - private int instanceCount; - - private boolean active; - - private String name; - - private ServiceType type; - - private Date createAt; - - private Map properties; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/ServiceType.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/ServiceType.java deleted file mode 100644 index ec63f519..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/ServiceType.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -public enum ServiceType { - FRONT_END, - BACK_END, - BOTH -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/SimpleDependency.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/SimpleDependency.java deleted file mode 100644 index acbd104d..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/SimpleDependency.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Edge -@NoArgsConstructor -@AllArgsConstructor -public class SimpleDependency { - - private String id; - - private String name; - - @EdgeFrom - private String fromId; - - @EdgeTo - private String toId; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Student.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Student.java deleted file mode 100644 index def62893..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/Student.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Vertex(label = TestConstants.VERTEX_LABEL) -@AllArgsConstructor -@NoArgsConstructor -public class Student { - - private Long id; - - private String name; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/User.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/User.java deleted file mode 100644 index 90fd9b02..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/User.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class User { - - private String id; - - private String name; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/UserDomain.java b/src/test/java/com/microsoft/spring/data/gremlin/common/domain/UserDomain.java deleted file mode 100644 index a106ace3..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/domain/UserDomain.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.domain; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; - -@Vertex -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UserDomain { - - @Id - private String name; - - private int level; - - private boolean enabled; -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/AdvancedUserRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/AdvancedUserRepository.java deleted file mode 100644 index ab2821a5..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/AdvancedUserRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.AdvancedUser; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface AdvancedUserRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookReferenceRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookReferenceRepository.java deleted file mode 100644 index 87a3ad85..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookReferenceRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.BookReference; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface BookReferenceRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookRepository.java deleted file mode 100644 index f7dbc141..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/BookRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Book; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -import java.util.List; - -public interface BookRepository extends GremlinRepository { - - List findByNameOrPrice(String name, Double price); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupOwnerRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupOwnerRepository.java deleted file mode 100644 index 5d9f0c95..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupOwnerRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.GroupOwner; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface GroupOwnerRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupRepository.java deleted file mode 100644 index 2e34a5db..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/GroupRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Group; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface GroupRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/MasterRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/MasterRepository.java deleted file mode 100644 index c31790e7..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/MasterRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Master; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface MasterRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/NeighborRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/NeighborRepository.java deleted file mode 100644 index f6ccc934..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/NeighborRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Neighbor; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface NeighborRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/NetworkRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/NetworkRepository.java deleted file mode 100644 index 05caf153..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/NetworkRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Network; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface NetworkRepository extends GremlinRepository { - - List findByEdgeList(List edgeList); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/OrangeRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/OrangeRepository.java deleted file mode 100644 index 2cbbd207..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/OrangeRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Orange; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface OrangeRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/PersonRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/PersonRepository.java deleted file mode 100644 index c2e7e80b..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/PersonRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PersonRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/ProjectRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/ProjectRepository.java deleted file mode 100644 index cd9d10c3..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/ProjectRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Project; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ProjectRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/RelationshipRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/RelationshipRepository.java deleted file mode 100644 index d1d41a13..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/RelationshipRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface RelationshipRepository extends GremlinRepository { - - List findByLocation(String location); - - List findByNameAndLocation(String name, String location); - - List findByNameOrId(String name, String id); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/ServiceRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/ServiceRepository.java deleted file mode 100644 index c4efbf8c..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/ServiceRepository.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Service; -import com.microsoft.spring.data.gremlin.common.domain.ServiceType; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.springframework.stereotype.Repository; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -@Repository -public interface ServiceRepository extends GremlinRepository { - - List findByName(String name); - - List findByInstanceCount(int instanceCount); - - List findByActive(boolean isActive); - - List findByCreateAt(Date createAt); - - List findByProperties(Map properties); - - List findByNameAndInstanceCount(String name, int instanceCount); - - List findByNameOrInstanceCount(String name, int instanceCount); - - List findByNameAndInstanceCountAndType(String name, int instanceCount, ServiceType type); - - List findByNameAndActiveOrProperties(String name, boolean isActive, Map properties); - - List findByNameOrInstanceCountAndType(String name, int instanceCount, ServiceType type); - - List findByNameAndInstanceCountOrType(String name, int instanceCount, ServiceType type); - - List findByActiveExists(); - - List findByCreateAtAfter(Date expiryDate); - - List findByNameOrTypeAndInstanceCountAndCreateAtAfter(String name, ServiceType type, int instanceCount, - Date expiryDate); - - List findByCreateAtBefore(Date expiryDate); - - List findByCreateAtAfterAndCreateAtBefore(Date startDate, Date endDate); - - List findByCreateAtBetween(Date start, Date end); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/SimpleDependencyRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/SimpleDependencyRepository.java deleted file mode 100644 index aba5cdbe..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/SimpleDependencyRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.SimpleDependency; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -public interface SimpleDependencyRepository extends GremlinRepository { -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/StudentRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/StudentRepository.java deleted file mode 100644 index 90ea134f..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/StudentRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.Student; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -import java.util.List; - -public interface StudentRepository extends GremlinRepository { - - List findByName(String name); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/UserDomainRepository.java b/src/test/java/com/microsoft/spring/data/gremlin/common/repository/UserDomainRepository.java deleted file mode 100644 index 90894ea2..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/common/repository/UserDomainRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.common.repository; - -import com.microsoft.spring.data.gremlin.common.domain.UserDomain; -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; - -import java.util.List; - -public interface UserDomainRepository extends GremlinRepository { - - List findByName(String name); - - List findByEnabledExists(); - - List findByLevelBetween(int low, int high); -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfigurationIT.java b/src/test/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfigurationIT.java deleted file mode 100644 index a04a286d..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/config/AbstractGremlinConfigurationIT.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.config; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class AbstractGremlinConfigurationIT { - - @Autowired - private TestRepositoryConfiguration testConfig; - - @Test - public void testGremlinFactory() { - Assert.assertNotNull(this.testConfig.gremlinFactory()); - } - - @Test - @SneakyThrows - public void testMappingGremlinConverter() { - Assert.assertNotNull(this.testConfig.mappingGremlinConverter()); - } - - @Test - @SneakyThrows - public void testGremlinTemplate() { - Assert.assertNotNull(this.testConfig.gremlinTemplate(testConfig.gremlinFactory())); - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupportUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupportUnitTest.java deleted file mode 100644 index bc12b674..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/config/GremlinConfigurationSupportUnitTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.config; - -import com.microsoft.spring.data.gremlin.common.domain.*; -import lombok.NoArgsConstructor; -import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -public class GremlinConfigurationSupportUnitTest { - - private static final String TEST_CONFIG_PACKAGE_NAME = "com.microsoft.spring.data.gremlin.config"; - private static final String TEST_DOMAIN_PACKAGE_NAME = "com.microsoft.spring.data.gremlin.common.domain"; - private TestConfig config; - - @Before - public void setup() { - this.config = new TestConfig(); - } - - @Test - public void testGetMappingBasePackages() { - final Collection basePackages = this.config.getMappingBasePackages(); - - Assert.assertNotNull(basePackages); - Assert.assertEquals(basePackages.size(), 1); - Assert.assertEquals(basePackages.toArray()[0], TEST_CONFIG_PACKAGE_NAME); - } - - @Test - public void testGremlinMappingContext() throws ClassNotFoundException { - Assert.assertNotNull(this.config.gremlinMappingContext()); - } - - @Test - @SneakyThrows - public void testScanEntity() { - final Set> entities = this.config.scanEntities(TEST_DOMAIN_PACKAGE_NAME); - final Set> references = new HashSet<>(Arrays.asList( - Dependency.class, Library.class, Network.class, Person.class, Project.class, - Relationship.class, Roadmap.class, Service.class, SimpleDependency.class, InvalidDependency.class, - UserDomain.class, AdvancedUser.class, Student.class, Book.class, BookReference.class, - Neighbor.class, Master.class, Group.class, GroupOwner.class, Orange.class) - ); - - Assert.assertNotNull(entities); - Assert.assertEquals(entities.size(), references.size()); - - references.forEach(entity -> Assert.assertTrue(entities.contains(entity))); - } - - @Test - @SneakyThrows - public void testScanEntityEmpty() { - final Set> entities = this.config.scanEntities(""); - - Assert.assertTrue(entities.isEmpty()); - } - - @NoArgsConstructor - private class TestConfig extends GremlinConfigurationSupport { - - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/MappingGremlinConverterUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/MappingGremlinConverterUnitTest.java deleted file mode 100644 index 3dc4fb9c..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/MappingGremlinConverterUnitTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion; - -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Project; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import com.microsoft.spring.data.gremlin.repository.support.GremlinEntityInformation; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.context.ApplicationContext; - -import java.lang.reflect.Field; - -@RunWith(MockitoJUnitRunner.class) -public class MappingGremlinConverterUnitTest { - - private MappingGremlinConverter converter; - private GremlinMappingContext mappingContext; - - @Mock - private ApplicationContext applicationContext; - - @Before - public void setup() { - this.mappingContext = new GremlinMappingContext(); - - this.mappingContext.setApplicationContext(this.applicationContext); - this.mappingContext.afterPropertiesSet(); - this.mappingContext.getPersistentEntity(Person.class); - - this.converter = new MappingGremlinConverter(this.mappingContext); - } - - @Test - public void testMappingGremlinConverterGetter() { - Assert.assertEquals(this.converter.getMappingContext(), this.mappingContext); - Assert.assertNotNull(this.converter.getConversionService()); - - final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - final Field[] fields = FieldUtils.getAllFields(Person.class); - - Assert.assertNotNull(this.converter.getPropertyAccessor(person)); - Assert.assertEquals(converter.getIdFieldValue(person), TestConstants.VERTEX_PERSON_ID); - } - - @Test - public void testMappingGremlinConverterVertexRead() { - final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - final GremlinEntityInformation info = new GremlinEntityInformation<>(Person.class); - final GremlinSource source = info.createGremlinSource(); - - this.converter.write(person, source); - - Assert.assertTrue(source.getId().isPresent()); - Assert.assertEquals(source.getId().get(), person.getId()); - Assert.assertEquals(source.getProperties().get(TestConstants.PROPERTY_NAME), person.getName()); - } - - @Test - public void testMappingGremlinConverterEdgeRead() { - final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - final Project project = new Project(TestConstants.VERTEX_PROJECT_ID, TestConstants.VERTEX_PROJECT_NAME, - TestConstants.VERTEX_PROJECT_URI); - final Relationship relationship = new Relationship(TestConstants.EDGE_RELATIONSHIP_ID, - TestConstants.EDGE_RELATIONSHIP_NAME, TestConstants.EDGE_RELATIONSHIP_LOCATION, person, project); - final GremlinEntityInformation info = new GremlinEntityInformation<>(Relationship.class); - final GremlinSource source = info.createGremlinSource(); - - this.converter.write(relationship, source); - - Assert.assertTrue(source.getId().isPresent()); - Assert.assertEquals(source.getId().get(), relationship.getId()); - Assert.assertEquals(source.getProperties().get(TestConstants.PROPERTY_NAME), relationship.getName()); - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultUnitTest.java deleted file mode 100644 index 2d012e47..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/result/GremlinResultUnitTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.result; - -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralEdge; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralGraph; -import com.microsoft.spring.data.gremlin.conversion.script.GremlinScriptLiteralVertex; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import org.junit.Test; - -public class GremlinResultUnitTest { - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexInsertException() { - new GremlinScriptLiteralVertex().generateInsertScript(new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexUpdateException() { - new GremlinScriptLiteralVertex().generateUpdateScript(new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexFindByIdException() { - new GremlinScriptLiteralVertex().generateFindByIdScript(new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeInsertException() { - new GremlinScriptLiteralEdge().generateInsertScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeUpdateException() { - new GremlinScriptLiteralEdge().generateUpdateScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeFindByIdException() { - new GremlinScriptLiteralEdge().generateFindByIdScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testGraphInsertException() { - new GremlinScriptLiteralGraph().generateInsertScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testGraphUpdateException() { - new GremlinScriptLiteralGraph().generateUpdateScript(new GremlinSourceVertex()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testGraphFindByIdException() { - new GremlinScriptLiteralGraph().generateFindByIdScript(new GremlinSourceVertex()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteralUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteralUnitTest.java deleted file mode 100644 index ff5521db..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/AbstractGremlinScriptLiteralUnitTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import org.junit.Test; - -public class AbstractGremlinScriptLiteralUnitTest extends AbstractGremlinScriptLiteral { - - @Test(expected = GremlinInvalidEntityIdFieldException.class) - public void testEntityInvalidIdType() { - final Double id = 12.342; - AbstractGremlinScriptLiteral.generateEntityWithRequiredId(id, GremlinEntityType.EDGE); - } - - @Test(expected = GremlinInvalidEntityIdFieldException.class) - public void testPropertyInvalidIdType() { - final Double id = 12.342; - AbstractGremlinScriptLiteral.generatePropertyWithRequiredId(id); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralEdgeUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralEdgeUnitTest.java deleted file mode 100644 index 996eb55e..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralEdgeUnitTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Project; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import com.microsoft.spring.data.gremlin.repository.support.GremlinEntityInformation; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.context.ApplicationContext; - -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(MockitoJUnitRunner.class) -public class GremlinScriptLiteralEdgeUnitTest { - - private MappingGremlinConverter converter; - private GremlinMappingContext mappingContext; - private GremlinSource gremlinSource; - - @Mock - private ApplicationContext applicationContext; - - @Before - public void setup() { - this.mappingContext = new GremlinMappingContext(); - this.mappingContext.setApplicationContext(this.applicationContext); - this.mappingContext.afterPropertiesSet(); - this.mappingContext.getPersistentEntity(Person.class); - this.converter = new MappingGremlinConverter(this.mappingContext); - - final Relationship relationship = new Relationship("456", "rel-name", "china", - new Person("123", "bill"), // from - new Project("321", "ms-project", "http") // to - ); - @SuppressWarnings("unchecked") final GremlinEntityInformation info = - new GremlinEntityInformation(Relationship.class); - this.gremlinSource = info.createGremlinSource(); - this.converter.write(relationship, gremlinSource); - } - - @Test - public void testGenerateCountScript() { - final List queryList = new GremlinScriptLiteralEdge().generateCountScript(gremlinSource); - assertEquals(queryList.get(0), "g.E()"); - } - - @Test - public void testGenerateFindByIdScript() { - final List queryList = new GremlinScriptLiteralEdge().generateFindByIdScript(gremlinSource); - assertEquals(queryList.get(0), "g.E().hasId('456')"); - } - - @Test - public void testGenerateFindAllScript() { - final List queryList = new GremlinScriptLiteralEdge().generateFindAllScript(gremlinSource); - assertEquals(queryList.get(0), "g.E().has(label, 'label-relationship')" + - ".has('_classname', 'com.microsoft.spring.data.gremlin.common.domain.Relationship')"); - } - - @Test - public void testGenerateInsertScript() { - final List queryList = new GremlinScriptLiteralEdge().generateInsertScript(gremlinSource); - assertEquals(queryList.get(0), "g.V('123').as('from').V('321').as('to')" + - ".addE('label-relationship').from('from').to('to')" + - ".property(id, '456')" + - ".property('person', '{\"id\":\"123\",\"name\":\"bill\"}')" + - ".property('name', 'rel-name')" + - ".property('project', '{\"id\":\"321\",\"name\":\"ms-project\",\"uri\":\"http\"}')" + - ".property('location', 'china')" + - ".property('_classname', 'com.microsoft.spring.data.gremlin.common.domain.Relationship')"); - } - - @Test - public void testGenerateUpdateScript() { - final List queryList = new GremlinScriptLiteralEdge().generateUpdateScript(gremlinSource); - assertEquals(queryList.get(0), "g.E('456')" + - ".property('person', '{\"id\":\"123\",\"name\":\"bill\"}')" + - ".property('name', 'rel-name')" + - ".property('project', '{\"id\":\"321\",\"name\":\"ms-project\",\"uri\":\"http\"}')" + - ".property('location', 'china')" + - ".property('_classname', 'com.microsoft.spring.data.gremlin.common.domain.Relationship')"); - } - - @Test - public void testGenerateDeleteByIdScript() { - final List queryList = new GremlinScriptLiteralEdge().generateDeleteByIdScript(gremlinSource); - assertEquals(queryList.get(0), "g.E().hasId('456').drop()"); - } - - @Test - public void testGenerateDeleteAllScript() { - final List queryList = new GremlinScriptLiteralEdge().generateDeleteAllScript(); - assertEquals(queryList.get(0), "g.E().drop()"); - } - - @Test - public void testGenerateDeleteAllByClassScript() { - final List queryList = new GremlinScriptLiteralEdge().generateDeleteAllByClassScript(gremlinSource); - assertEquals(queryList.get(0), "g.E().has(label, 'label-relationship').drop()"); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testInvalidDeleteAllByClassScript() { - new GremlinScriptLiteralEdge().generateDeleteAllByClassScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testInvalidFindAllScript() { - new GremlinScriptLiteralEdge().generateFindAllScript(new GremlinSourceVertex()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralVertexUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralVertexUnitTest.java deleted file mode 100644 index 0967b2d3..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptLiteralVertexUnitTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import com.microsoft.spring.data.gremlin.repository.support.GremlinEntityInformation; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.context.ApplicationContext; - -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(MockitoJUnitRunner.class) -public class GremlinScriptLiteralVertexUnitTest { - - private MappingGremlinConverter converter; - private GremlinMappingContext mappingContext; - private GremlinSource gremlinSource; - - @Mock - private ApplicationContext applicationContext; - - @Before - public void setup() { - this.mappingContext = new GremlinMappingContext(); - this.mappingContext.setApplicationContext(this.applicationContext); - this.mappingContext.afterPropertiesSet(); - this.mappingContext.getPersistentEntity(Person.class); - this.converter = new MappingGremlinConverter(this.mappingContext); - - final Person person = new Person("123", "bill"); - @SuppressWarnings("unchecked") final GremlinEntityInformation info = new GremlinEntityInformation(Person.class); - this.gremlinSource = info.createGremlinSource(); - this.converter.write(person, gremlinSource); - } - - @Test - public void testGenerateCountScript() { - final List queryList = new GremlinScriptLiteralVertex().generateCountScript(gremlinSource); - assertEquals(queryList.get(0), "g.V()"); - } - - @Test - public void testGenerateFindByIdScript() { - final List queryList = new GremlinScriptLiteralVertex().generateFindByIdScript(gremlinSource); - assertEquals(queryList.get(0), "g.V().hasId('123')"); - } - - @Test - public void testGenerateFindAllScript() { - final List queryList = new GremlinScriptLiteralVertex().generateFindAllScript(gremlinSource); - assertEquals(queryList.get(0), "g.V().has(label, 'label-person')" + - ".has('_classname', 'com.microsoft.spring.data.gremlin.common.domain.Person')"); - } - - @Test - public void testGenerateInsertScript() { - final List queryList = new GremlinScriptLiteralVertex().generateInsertScript(gremlinSource); - assertEquals(queryList.get(0), "g.addV('label-person').property(id, '123').property('name', 'bill')" + - ".property('_classname', 'com.microsoft.spring.data.gremlin.common.domain.Person')"); - } - - @Test - public void testGenerateUpdateScript() { - final List queryList = new GremlinScriptLiteralVertex().generateUpdateScript(gremlinSource); - assertEquals(queryList.get(0), "g.V('123').property('name', 'bill')" + - ".property('_classname', 'com.microsoft.spring.data.gremlin.common.domain.Person')"); - } - - @Test - public void testGenerateDeleteByIdScript() { - final List queryList = new GremlinScriptLiteralVertex().generateDeleteByIdScript(gremlinSource); - assertEquals(queryList.get(0), "g.V().hasId('123').drop()"); - } - - @Test - public void testGenerateDeleteAllScript() { - final List queryList = new GremlinScriptLiteralVertex().generateDeleteAllScript(); - assertEquals(queryList.get(0), "g.V().drop()"); - } - - @Test - public void testGenerateDeleteAllByClassScript() { - final List queryList = new GremlinScriptLiteralVertex().generateDeleteAllByClassScript(gremlinSource); - assertEquals(queryList.get(0), "g.V().has(label, 'label-person').drop()"); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testInvalidDeleteAllByClassScript() { - new GremlinScriptLiteralVertex().generateDeleteAllByClassScript(new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testInvalidFindAllScript() { - new GremlinScriptLiteralVertex().generateFindAllScript(new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testInvalidDeleteById() { - new GremlinScriptLiteralVertex().generateDeleteByIdScript(new GremlinSourceEdge()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptUnitTest.java deleted file mode 100644 index 535a9472..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/script/GremlinScriptUnitTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.script; - -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultEdgeReader; -import com.microsoft.spring.data.gremlin.conversion.result.GremlinResultVertexReader; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import org.apache.tinkerpop.gremlin.driver.Result; -import org.junit.Assert; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - -import static java.util.Collections.singletonList; - -public class GremlinScriptUnitTest { - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexWriteException() { - new GremlinResultVertexReader().read(singletonList(new Result(new Object())), new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeReadException() { - new GremlinResultEdgeReader().read(singletonList(new Result(new Object())), new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedEntityTypeException.class) - public void testGeneratePropertyException() { - final Map properties = new HashMap<>(); - final GremlinSource source = new GremlinSourceVertex(); - - properties.put("person", source); - - GremlinScriptLiteralVertex.generateProperties(properties); - } - - @Test(expected = GremlinUnexpectedEntityTypeException.class) - public void testGenerateHasException() { - final GremlinSource source = new GremlinSourceVertex(); - - GremlinScriptLiteralVertex.generateHas("fake-name", source); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeDeleteByIdScriptException() { - new GremlinScriptLiteralEdge().generateDeleteByIdScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testGraphDeleteByIdScriptException() { - new GremlinScriptLiteralGraph().generateDeleteByIdScript(new GremlinSourceVertex()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testGraphFindAllScriptException() { - new GremlinScriptLiteralGraph().generateFindAllScript(new GremlinSourceVertex()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testGraphCountException() { - new GremlinScriptLiteralGraph().generateCountScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeCountScriptException() { - new GremlinScriptLiteralEdge().generateCountScript(new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexDeleteByIdScriptException() { - new GremlinScriptLiteralGraph().generateDeleteByIdScript(new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexCountScriptException() { - new GremlinScriptLiteralVertex().generateCountScript(new GremlinSourceEdge()); - } - - @Test - public void testVertexSourceSetProperty() { - final GremlinSource source = new GremlinSourceVertex<>(Person.class); - final Map properties = source.getProperties(); - final String fakeName = "fake-name"; - - properties.put(fakeName, "fake-value"); - properties.put("fake-name-0", "fake-value-0"); - properties.put("fake-name-1", "fake-value-1"); - - source.setProperty(fakeName, null); - - Assert.assertEquals(source.getProperties().size(), 3); // one predefined property _classname - Assert.assertNull(source.getProperties().get(fakeName)); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceUnitTest.java deleted file mode 100644 index 4bfbd16e..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/conversion/source/GremlinSourceUnitTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.conversion.source; - -import com.microsoft.spring.data.gremlin.annotation.EdgeFrom; -import com.microsoft.spring.data.gremlin.annotation.EdgeTo; -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.exception.GremlinEntityInformationException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedSourceTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.SneakyThrows; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.domain.EntityScanner; -import org.springframework.context.ApplicationContext; -import org.springframework.data.annotation.Persistent; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -public class GremlinSourceUnitTest { - - private MappingGremlinConverter converter; - - @Autowired - private ApplicationContext context; - - @Before - @SneakyThrows - public void setup() { - final GremlinMappingContext mappingContext = new GremlinMappingContext(); - - mappingContext.setInitialEntitySet(new EntityScanner(this.context).scan(Persistent.class)); - - this.converter = new MappingGremlinConverter(mappingContext); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexWriteException() { - new GremlinSourceVertexWriter().write(new Object(), this.converter, new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testVertexReadException() { - new GremlinSourceVertexReader().read(Object.class, this.converter, new GremlinSourceEdge()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeWriteException() { - new GremlinSourceEdgeWriter().write(new Object(), this.converter, new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testEdgeReadException() { - new GremlinSourceEdgeReader().read(Object.class, this.converter, new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testGraphWriteException() { - new GremlinSourceGraphWriter().write(new Object(), this.converter, new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testGraphReadException() { - new GremlinSourceEdgeReader().read(Object.class, this.converter, new GremlinSourceVertex()); - } - - @Test(expected = GremlinUnexpectedSourceTypeException.class) - public void testGraphAddSourceException() { - new GremlinSourceGraph().addGremlinSource(new GremlinSourceGraph()); - } - - @Test(expected = GremlinEntityInformationException.class) - public void testVertexWithPredefinedProperty() { - @SuppressWarnings("unchecked") final GremlinSource source = new GremlinSourceVertex(TestVertex.class); - - new GremlinSourceVertexWriter().write(new TestVertex("fake-id", "fake-name"), this.converter, source); - } - - @Test(expected = GremlinEntityInformationException.class) - public void testEdgeWithPredefinedProperty() { - @SuppressWarnings("unchecked") final GremlinSource source = new GremlinSourceEdge(TestEdge.class); - - new GremlinSourceEdgeWriter().write(new TestEdge("fake-id", "fake-name", "1", "2"), this.converter, source); - } - - @Vertex - @Data - @AllArgsConstructor - private static class TestVertex { - - private String id; - - private String _classname; - } - - @Vertex - @Data - @AllArgsConstructor - private static class TestEdge { - - private String id; - - private String _classname; - - @EdgeFrom - private String from; - - @EdgeTo - private String to; - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntityUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntityUnitTest.java deleted file mode 100644 index 745a4b2d..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentEntityUnitTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import com.microsoft.spring.data.gremlin.annotation.Edge; -import com.microsoft.spring.data.gremlin.annotation.Graph; -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Network; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.data.util.ClassTypeInformation; - -public class BasicGremlinPersistentEntityUnitTest { - - @Test - public void testVertexPersistentEntity() { - final BasicGremlinPersistentEntity entity = - new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Person.class)); - final Vertex annotation = entity.findAnnotation(Vertex.class); - - Assert.assertEquals(entity.getType(), Person.class); - Assert.assertEquals(annotation.annotationType(), Vertex.class); - Assert.assertEquals(annotation.label(), TestConstants.VERTEX_PERSON_LABEL); - } - - @Test - public void testEdgePersistentEntity() { - final BasicGremlinPersistentEntity entity = - new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Relationship.class)); - final Edge annotation = entity.findAnnotation(Edge.class); - - Assert.assertEquals(entity.getType(), Relationship.class); - Assert.assertEquals(annotation.annotationType(), Edge.class); - Assert.assertEquals(annotation.label(), TestConstants.EDGE_RELATIONSHIP_LABEL); - } - - @Test - public void testGraphPersistentEntity() { - final BasicGremlinPersistentEntity entity = - new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Network.class)); - final Graph annotation = entity.findAnnotation(Graph.class); - - Assert.assertEquals(entity.getType(), Network.class); - Assert.assertEquals(annotation.annotationType(), Graph.class); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentPropertyUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentPropertyUnitTest.java deleted file mode 100644 index ce0095c9..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/mapping/BasicGremlinPersistentPropertyUnitTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Network; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.data.mapping.model.Property; -import org.springframework.data.mapping.model.SimpleTypeHolder; -import org.springframework.data.util.ClassTypeInformation; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Field; - -public class BasicGremlinPersistentPropertyUnitTest { - - private BasicGremlinPersistentProperty createBasicGremlinPersistentProperty( - BasicGremlinPersistentEntity entity, Field field) { - return new BasicGremlinPersistentProperty(Property.of(entity.getTypeInformation(), field), entity, - SimpleTypeHolder.DEFAULT); - } - - @Test - public void testVertexPersistentProperty() { - final BasicGremlinPersistentEntity entity = - new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Person.class)); - Field field = ReflectionUtils.findField(Person.class, TestConstants.PROPERTY_ID); - BasicGremlinPersistentProperty property = this.createBasicGremlinPersistentProperty(entity, field); - - Assert.assertEquals(property.getName(), TestConstants.PROPERTY_ID); - Assert.assertTrue(property.isIdProperty()); - Assert.assertNotNull(property.createAssociation()); - - field = ReflectionUtils.findField(Person.class, TestConstants.PROPERTY_NAME); - property = this.createBasicGremlinPersistentProperty(entity, field); - - Assert.assertEquals(property.getName(), TestConstants.PROPERTY_NAME); - Assert.assertFalse(property.isIdProperty()); - Assert.assertNotNull(property.createAssociation()); - } - - @Test - public void testEdgePersistentProperty() { - final BasicGremlinPersistentEntity entity = - new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Relationship.class)); - Field field = ReflectionUtils.findField(Relationship.class, TestConstants.PROPERTY_ID); - BasicGremlinPersistentProperty property = this.createBasicGremlinPersistentProperty(entity, field); - - Assert.assertEquals(property.getName(), TestConstants.PROPERTY_ID); - Assert.assertTrue(property.isIdProperty()); - Assert.assertNotNull(property.createAssociation()); - - field = ReflectionUtils.findField(Relationship.class, TestConstants.PROPERTY_LOCATION); - property = this.createBasicGremlinPersistentProperty(entity, field); - - Assert.assertEquals(property.getName(), TestConstants.PROPERTY_LOCATION); - Assert.assertFalse(property.isIdProperty()); - Assert.assertNotNull(property.createAssociation()); - } - - @Test - public void testGraphPersistentProperty() { - final BasicGremlinPersistentEntity entity = - new BasicGremlinPersistentEntity<>(ClassTypeInformation.from(Network.class)); - final Field field = ReflectionUtils.findField(Network.class, TestConstants.PROPERTY_ID); - final BasicGremlinPersistentProperty property = this.createBasicGremlinPersistentProperty(entity, field); - - Assert.assertEquals(property.getName(), TestConstants.PROPERTY_ID); - Assert.assertTrue(property.isIdProperty()); - Assert.assertNotNull(property.createAssociation()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContextUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContextUnitTest.java deleted file mode 100644 index 747715e9..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/mapping/GremlinMappingContextUnitTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.mapping; - -import com.microsoft.spring.data.gremlin.annotation.Vertex; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Project; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.data.util.ClassTypeInformation; - -public class GremlinMappingContextUnitTest { - - @Test - public void testCreatePersistentProperty() { - final GremlinMappingContext context = new GremlinMappingContext(); - final BasicGremlinPersistentEntity entity = context.createPersistentEntity( - ClassTypeInformation.from(Project.class)); - - Assert.assertNotNull(entity); - Assert.assertNotNull(entity.findAnnotation(Vertex.class)); - Assert.assertEquals(entity.findAnnotation(Vertex.class).label(), TestConstants.VERTEX_PROJECT_LABEL); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/query/GremlinTemplateIT.java b/src/test/java/com/microsoft/spring/data/gremlin/query/GremlinTemplateIT.java deleted file mode 100644 index bcb4db88..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/query/GremlinTemplateIT.java +++ /dev/null @@ -1,576 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query; - -import com.microsoft.spring.data.gremlin.common.*; -import com.microsoft.spring.data.gremlin.common.domain.*; -import com.microsoft.spring.data.gremlin.conversion.MappingGremlinConverter; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSource; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.exception.GremlinQueryException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import com.microsoft.spring.data.gremlin.mapping.GremlinMappingContext; -import com.microsoft.spring.data.gremlin.repository.support.GremlinEntityInformation; -import lombok.NoArgsConstructor; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.domain.EntityScanner; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.data.annotation.Persistent; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.List; - -@RunWith(SpringJUnit4ClassRunner.class) -@PropertySource(value = {"classpath:application.properties"}) -@ContextConfiguration(classes = {GremlinTemplateIT.TestConfiguration.class}) -@EnableConfigurationProperties(TestGremlinProperties.class) -public class GremlinTemplateIT { - - private final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - private final Person person0 = new Person(TestConstants.VERTEX_PERSON_0_ID, TestConstants.VERTEX_PERSON_0_NAME); - private final Person person1 = new Person(TestConstants.VERTEX_PERSON_1_ID, TestConstants.VERTEX_PERSON_1_NAME); - - private final Project project = new Project(TestConstants.VERTEX_PROJECT_ID, TestConstants.VERTEX_PROJECT_NAME, - TestConstants.VERTEX_PROJECT_URI); - private final Project project0 = new Project(TestConstants.VERTEX_PROJECT_0_ID, TestConstants.VERTEX_PROJECT_0_NAME, - TestConstants.VERTEX_PROJECT_0_URI); - - private final Relationship relationship = new Relationship(TestConstants.EDGE_RELATIONSHIP_ID, - TestConstants.EDGE_RELATIONSHIP_NAME, TestConstants.EDGE_RELATIONSHIP_LOCATION, - this.person, this.project); - private final Relationship relationship0 = new Relationship(TestConstants.EDGE_RELATIONSHIP_0_ID, - TestConstants.EDGE_RELATIONSHIP_0_NAME, TestConstants.EDGE_RELATIONSHIP_0_LOCATION, - this.person0, this.project); - private final Relationship relationship1 = new Relationship(TestConstants.EDGE_RELATIONSHIP_1_ID, - TestConstants.EDGE_RELATIONSHIP_1_NAME, TestConstants.EDGE_RELATIONSHIP_1_LOCATION, - this.person1, this.project); - private final Relationship relationship2 = new Relationship(TestConstants.EDGE_RELATIONSHIP_2_ID, - TestConstants.EDGE_RELATIONSHIP_2_NAME, TestConstants.EDGE_RELATIONSHIP_2_LOCATION, - this.person, this.project0); - - private Network network; - - private final GremlinEntityInformation personInfo = new GremlinEntityInformation<>(Person.class); - private final GremlinEntityInformation projectInfo = new GremlinEntityInformation<>(Project.class); - private final GremlinEntityInformation relationshipInfo = - new GremlinEntityInformation<>(Relationship.class); - private final GremlinEntityInformation networkInfo = new GremlinEntityInformation<>(Network.class); - - private final GremlinSource personSource = personInfo.createGremlinSource(); - private final GremlinSource projectSource = projectInfo.createGremlinSource(); - private final GremlinSource relationshipSource = relationshipInfo.createGremlinSource(); - private final GremlinSource networkSource = networkInfo.createGremlinSource(); - - @Autowired - private ApplicationContext context; - - @Autowired - private GremlinFactory gremlinFactory; - - private GremlinTemplate template; - - @Before - public void setup() throws ClassNotFoundException { - final GremlinMappingContext mappingContext = new GremlinMappingContext(); - - mappingContext.setInitialEntitySet(new EntityScanner(this.context).scan(Persistent.class)); - - final MappingGremlinConverter converter = new MappingGremlinConverter(mappingContext); - - this.template = new GremlinTemplate(gremlinFactory, converter); - this.template.deleteAll(); - this.network = new Network(); - } - - private void buildTestGraph() { - this.network.vertexAdd(this.person); - this.network.vertexAdd(this.person0); - this.network.vertexAdd(this.person1); - this.network.vertexAdd(this.project); - this.network.vertexAdd(this.project0); - - this.network.edgeAdd(this.relationship); - this.network.edgeAdd(this.relationship0); - this.network.edgeAdd(this.relationship1); - this.network.edgeAdd(this.relationship2); - - this.template.insert(this.network, this.networkSource); - } - - @After - public void cleanup() { - this.template.deleteAll(); - } - - @Test - public void testVertexDeleteAll() { - this.buildTestGraph(); - - Person personVertex = this.template.findVertexById(this.person.getId(), this.personSource); - Project projectVertex = this.template.findVertexById(this.project.getId(), this.projectSource); - Relationship relationshipEdge = this.template.findEdgeById(this.relationship.getId(), this.relationshipSource); - - Assert.assertNotNull(personVertex); - Assert.assertNotNull(projectVertex); - Assert.assertNotNull(relationshipEdge); - - this.template.deleteAll(); - - personVertex = this.template.findVertexById(this.person.getId(), this.personSource); - projectVertex = this.template.findVertexById(this.project.getId(), this.projectSource); - relationshipEdge = this.template.findEdgeById(this.relationship.getId(), this.relationshipSource); - - Assert.assertNull(personVertex); - Assert.assertNull(projectVertex); - Assert.assertNull(relationshipEdge); - - Assert.assertTrue(this.template.findAll(this.personSource).isEmpty()); - Assert.assertTrue(this.template.findAll(this.projectSource).isEmpty()); - Assert.assertTrue(this.template.findAll(this.relationshipSource).isEmpty()); - } - - @Test - public void testVertexInsertNormal() { - this.template.insert(this.person0, this.personSource); - - final Person foundPerson = this.template.findVertexById(this.person0.getId(), this.personSource); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(foundPerson.getId(), this.person0.getId()); - Assert.assertEquals(foundPerson.getName(), this.person0.getName()); - } - - @Test(expected = GremlinQueryException.class) - public void testVertexInsertException() { - this.template.insert(this.person, this.personSource); - - final Person repeated = new Person(this.person.getId(), this.person.getName()); - - this.template.insert(repeated, this.personSource); - } - - @Test - public void testEdgeInsertNormal() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.project, this.projectSource); - this.template.insert(this.relationship, this.relationshipSource); - - final Relationship foundRelationship = this.template.findById(this.relationship.getId(), relationshipSource); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(foundRelationship.getId(), this.relationship.getId()); - Assert.assertEquals(foundRelationship.getName(), this.relationship.getName()); - Assert.assertEquals(foundRelationship.getLocation(), this.relationship.getLocation()); - } - - @Test(expected = GremlinQueryException.class) - public void testEdgeInsertException() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.project, this.projectSource); - this.template.insert(this.relationship, this.relationshipSource); - - final Relationship repeated = new Relationship(this.relationship.getId(), this.relationship.getName(), - this.relationship.getLocation(), this.person, this.project); - - this.template.insert(repeated, this.relationshipSource); - } - - @Test - public void testFindVertexById() { - Person foundPerson = this.template.findVertexById(this.person1.getId(), this.personSource); - Assert.assertNull(foundPerson); - - this.template.insert(this.person1, this.personSource); - - foundPerson = this.template.findVertexById(this.person1.getId(), this.personSource); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(foundPerson.getId(), this.person1.getId()); - Assert.assertEquals(foundPerson.getName(), this.person1.getName()); - } - - @Test(expected = GremlinUnexpectedEntityTypeException.class) - public void testFindVertexByIdException() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.project0, this.projectSource); - this.template.insert(this.relationship2, this.relationshipSource); - - this.template.findVertexById(this.project.getId(), this.relationshipSource); - } - - @Test - public void testFindEdgeById() { - Relationship foundRelationship = this.template.findEdgeById(this.relationship2.getId(), relationshipSource); - Assert.assertNull(foundRelationship); - - this.template.insert(this.person, this.personSource); - this.template.insert(this.project0, this.projectSource); - this.template.insert(this.relationship2, this.relationshipSource); - - foundRelationship = this.template.findEdgeById(this.relationship2.getId(), this.relationshipSource); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(foundRelationship.getId(), this.relationship2.getId()); - Assert.assertEquals(foundRelationship.getName(), this.relationship2.getName()); - Assert.assertEquals(foundRelationship.getLocation(), this.relationship2.getLocation()); - } - - @Test(expected = GremlinUnexpectedEntityTypeException.class) - public void testFindEdgeByIdException() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.project0, this.projectSource); - this.template.insert(this.relationship2, this.relationshipSource); - - this.template.findEdgeById(this.relationship2.getId(), this.projectSource); - } - - @Test - public void testFindById() { - this.buildTestGraph(); - final Person foundPerson = this.template.findById(this.person1.getId(), this.personSource); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(foundPerson.getId(), this.person1.getId()); - Assert.assertEquals(foundPerson.getName(), this.person1.getName()); - - final Relationship foundRelationship = this.template.findById(this.relationship.getId(), relationshipSource); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(foundRelationship.getId(), this.relationship.getId()); - Assert.assertEquals(foundRelationship.getName(), this.relationship.getName()); - Assert.assertEquals(foundRelationship.getLocation(), this.relationship.getLocation()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testFindByIdException() { - this.template.findById(this.network.getId(), this.networkSource); - } - - @Test(expected = GremlinQueryException.class) - public void testUpdateException() { - this.personSource.setId(this.person.getId()); - this.template.update(this.person, this.personSource); - } - - @Test - public void testUpdateVertex() { - this.template.insert(this.person, this.personSource); - - final String updatedName = "updated-person-name"; - final Person updatedPerson = new Person(this.person.getId(), updatedName); - - this.template.update(updatedPerson, this.personSource); - - final Person foundPerson = this.template.findById(updatedPerson.getId(), this.personSource); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(this.person.getId(), foundPerson.getId()); - Assert.assertEquals(updatedPerson.getId(), foundPerson.getId()); - Assert.assertEquals(updatedPerson.getName(), foundPerson.getName()); - } - - @Test - public void testUpdateEdge() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.project0, this.projectSource); - this.template.insert(this.relationship2, this.relationshipSource); - - final String updatedName = "updated-relation-name"; - final String updatedLocation = "updated-location"; - final Relationship updatedRelationship = new Relationship(TestConstants.EDGE_RELATIONSHIP_2_ID, - updatedName, updatedLocation, this.person, this.project0); - - this.template.update(updatedRelationship, this.relationshipSource); - - final Relationship foundRelationship = this.template.findById(updatedRelationship.getId(), relationshipSource); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(this.relationship2.getId(), foundRelationship.getId()); - Assert.assertEquals(updatedRelationship.getId(), foundRelationship.getId()); - Assert.assertEquals(updatedRelationship.getName(), foundRelationship.getName()); - Assert.assertEquals(updatedRelationship.getLocation(), foundRelationship.getLocation()); - } - - @Test - public void testUpdateGraph() { - this.buildTestGraph(); - - final String updatedName = "update-person-name"; - final String updatedLocation = "update-location"; - final String updatedUri = "http://localhost:2222"; - - final Person person = (Person) this.network.getVertexList().get(0); - final Project project = (Project) this.network.getVertexList().get(3); - final Relationship relationship = (Relationship) this.network.getEdgeList().get(0); - - person.setName(updatedName); - project.setUri(updatedUri); - relationship.setLocation(updatedLocation); - - this.template.update(network, this.networkInfo.createGremlinSource()); - - final Person foundPerson = this.template.findById(person.getId(), this.personSource); - final Project foundProject = this.template.findById(project.getId(), this.projectSource); - final Relationship foundRelationship = this.template.findById(relationship.getId(), this.relationshipSource); - - Assert.assertNotNull(foundPerson); - Assert.assertNotNull(foundProject); - Assert.assertNotNull(foundRelationship); - - Assert.assertEquals(foundPerson.getId(), person.getId()); - Assert.assertEquals(foundPerson.getName(), person.getName()); - - Assert.assertEquals(foundProject.getId(), project.getId()); - Assert.assertEquals(foundProject.getUri(), project.getUri()); - - Assert.assertEquals(foundRelationship.getId(), relationship.getId()); - Assert.assertEquals(foundRelationship.getLocation(), relationship.getLocation()); - } - - @Test - public void testSaveVertex() { - this.personSource.setId(this.person.getId()); - this.template.save(this.person, this.personSource); - - Person foundPerson = this.template.findById(this.person.getId(), this.personSource); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(foundPerson.getId(), this.person.getId()); - Assert.assertEquals(foundPerson.getName(), this.person.getName()); - - final String updatedName = "update-person-name"; - final Person updatedPerson = new Person(this.person.getId(), updatedName); - - this.personSource.setId(updatedPerson.getId()); - this.template.save(updatedPerson, this.personSource); - - foundPerson = this.template.findById(updatedPerson.getId(), this.personSource); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(foundPerson.getId(), updatedPerson.getId()); - Assert.assertEquals(foundPerson.getName(), updatedPerson.getName()); - } - - @Test - public void testSaveEdge() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.project, this.projectSource); - this.relationshipSource.setId(this.relationship.getId()); - this.template.save(this.relationship, this.relationshipSource); - - Relationship foundRelationship = this.template.findById(this.relationship.getId(), this.relationshipSource); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(foundRelationship.getId(), this.relationship.getId()); - Assert.assertEquals(foundRelationship.getName(), this.relationship.getName()); - Assert.assertEquals(foundRelationship.getLocation(), this.relationship.getLocation()); - - final String updatedName = "updated-relation-name"; - final String updatedLocation = "updated-location"; - final Relationship updatedRelationship = new Relationship(TestConstants.EDGE_RELATIONSHIP_2_ID, - updatedName, updatedLocation, this.person, this.project); - - this.relationshipSource.setId(updatedRelationship.getId()); - this.template.save(updatedRelationship, this.relationshipSource); - - foundRelationship = this.template.findById(updatedRelationship.getId(), this.relationshipSource); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(this.relationship2.getId(), foundRelationship.getId()); - Assert.assertEquals(updatedRelationship.getId(), foundRelationship.getId()); - Assert.assertEquals(updatedRelationship.getName(), foundRelationship.getName()); - Assert.assertEquals(updatedRelationship.getLocation(), foundRelationship.getLocation()); - } - - @Test - public void testSaveGraph() { - this.network.vertexAdd(this.person); - this.network.vertexAdd(this.project); - this.network.edgeAdd(this.relationship); - - this.template.save(network, this.networkSource); - - final Person personFound = this.template.findById(this.person.getId(), this.personSource); - - Assert.assertNotNull(personFound); - Assert.assertEquals(personFound.getId(), this.person.getId()); - - Relationship relationshipFound = this.template.findById(this.relationship.getId(), this.relationshipSource); - - Assert.assertNotNull(relationshipFound); - Assert.assertEquals(relationshipFound.getId(), this.relationship.getId()); - - final String updatedName = "updated-name"; - this.relationship.setName(updatedName); - - this.template.save(network, this.networkInfo.createGremlinSource()); - - relationshipFound = this.template.findById(this.relationship.getId(), this.relationshipSource); - - Assert.assertNotNull(relationshipFound); - Assert.assertEquals(relationshipFound.getId(), this.relationship.getId()); - Assert.assertEquals(relationshipFound.getName(), updatedName); - } - - @Test - public void testFindAllVertex() { - List personList = this.template.findAll(this.personSource); - - Assert.assertTrue(personList.isEmpty()); - - final List personCollection = Arrays.asList(this.person, this.person0, this.person1); - personCollection.forEach(person -> this.template.insert(person, this.personSource)); - - personList = this.template.findAll(this.personSource); - - Assert.assertFalse(personList.isEmpty()); - Assert.assertEquals(personList.size(), personCollection.size()); - - personList.sort((a, b) -> (a.getId().compareTo(b.getId()))); - personCollection.sort((a, b) -> (a.getId().compareTo(b.getId()))); - - Assert.assertArrayEquals(personList.toArray(), personCollection.toArray()); - } - - @Test - public void testFindAllEdge() { - this.template.insert(this.person, this.personSource); - this.template.insert(this.person0, this.personSource); - this.template.insert(this.person1, this.personSource); - this.template.insert(this.project, this.projectSource); - this.template.insert(this.project0, this.projectSource); - - List relationshipList = this.template.findAll(this.relationshipSource); - - Assert.assertTrue(relationshipList.isEmpty()); - - final List relationshipCollection = Arrays.asList(this.relationship, this.relationship0, - this.relationship1, this.relationship2); - relationshipCollection.forEach(relationship -> this.template.insert(relationship, this.relationshipSource)); - - relationshipList = this.template.findAll(this.relationshipSource); - - Assert.assertFalse(relationshipList.isEmpty()); - Assert.assertEquals(relationshipList.size(), relationshipCollection.size()); - - relationshipList.sort((a, b) -> (a.getId().compareTo(b.getId()))); - relationshipCollection.sort((a, b) -> (a.getId().compareTo(b.getId()))); - - Assert.assertArrayEquals(relationshipList.toArray(), relationshipCollection.toArray()); - } - - @Test - public void testVertexDeleteById() { - this.template.deleteById(this.person.getId(), this.personSource); - this.template.insert(this.person, this.personSource); - this.template.deleteById(this.person0.getId(), this.personSource); - - Person foundPerson = this.template.findById(this.person.getId(), this.personSource); - Assert.assertNotNull(foundPerson); - - this.template.deleteById(this.person.getId(), this.personSource); - - foundPerson = this.template.findById(this.person.getId(), this.personSource); - Assert.assertNull(foundPerson); - } - - @Test - public void testEdgeDeleteById() { - this.template.deleteById(this.relationship.getId(), this.relationshipSource); - - this.template.insert(this.person, this.personSource); - this.template.insert(this.project, this.projectSource); - this.template.insert(this.relationship, this.relationshipSource); - - this.template.deleteById(this.relationship0.getId(), this.relationshipSource); - - Relationship foundRelationship = this.template.findById(this.relationship.getId(), this.relationshipSource); - Assert.assertNotNull(foundRelationship); - - this.template.deleteById(this.relationship.getId(), this.relationshipSource); - - foundRelationship = this.template.findById(this.relationship.getId(), this.relationshipSource); - Assert.assertNull(foundRelationship); - } - - @Test - public void testGraphDeleteById() { - this.network.setId("fake-id"); - this.template.deleteById(this.network.getId(), this.relationshipSource); - - final Relationship foundRelationship = this.template.findById(this.relationship.getId(), relationshipSource); - Assert.assertNull(foundRelationship); - - final Person foundPerson = this.template.findById(this.person.getId(), this.personSource); - Assert.assertNull(foundPerson); - } - - @Test - public void testIsEmptyGraph() { - Assert.assertTrue(this.template.isEmptyGraph(this.networkSource)); - - this.network.vertexAdd(this.person); - this.network.vertexAdd(this.project); - this.network.edgeAdd(this.relationship); - this.template.insert(this.network, this.networkSource); - - Assert.assertFalse(this.template.isEmptyGraph(this.networkSource)); - } - - @Test(expected = GremlinQueryException.class) - public void testIsEmptyGraphException() { - this.template.isEmptyGraph(this.relationshipSource); - } - - @Test(expected = UnsupportedOperationException.class) - public void testInvalidDependencySaveException() { - final InvalidDependency dependency = new InvalidDependency(this.relationship.getId(), - this.relationship.getName(), this.person.getId(), this.project.getId()); - final GremlinSource source = new GremlinSourceGraph<>(InvalidDependency.class); - - this.personSource.setId(this.person.getId()); - this.template.save(this.person, this.personSource); - this.projectSource.setId(this.project.getId()); - this.template.save(this.project, this.projectSource); - this.relationshipSource.setId(this.relationship.getId()); - this.template.save(this.relationship, this.relationshipSource); - - this.template.findById(dependency.getId(), source); - } - - @Configuration - @NoArgsConstructor - static class TestConfiguration { - - @Autowired - private TestGremlinProperties properties; - - @Bean - public GremlinFactory getGremlinFactory() { - return new GremlinFactory(getGremlinConfig()); - } - - @Bean - public GremlinConfig getGremlinConfig() { - return GremlinConfig.builder(properties.getEndpoint(), properties.getUsername(), properties.getPassword()) - .sslEnabled(properties.isSslEnabled()) - .port(properties.getPort()) - .build(); - } - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadataUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadataUnitTest.java deleted file mode 100644 index 5d5f93af..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/query/SimpleGremlinEntityMetadataUnitTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query; - -import com.microsoft.spring.data.gremlin.common.domain.Person; -import org.junit.Assert; -import org.junit.Test; - -public class SimpleGremlinEntityMetadataUnitTest { - - @Test - public void testSimpleGremlinEntityMetadata() { - final SimpleGremlinEntityMetadata metadata = new SimpleGremlinEntityMetadata<>(Person.class); - - Assert.assertNotNull(metadata); - Assert.assertEquals(metadata.getJavaType(), Person.class); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaUnitTest.java deleted file mode 100644 index 8fe0914a..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/query/criteria/CriteriaUnitTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.criteria; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static com.microsoft.spring.data.gremlin.query.criteria.CriteriaType.IS_EQUAL; -import static com.microsoft.spring.data.gremlin.query.criteria.CriteriaType.OR; - -public class CriteriaUnitTest { - - @Test(expected = IllegalArgumentException.class) - public void testGetUnaryInstanceException() { - final List values = new ArrayList<>(); - - Criteria.getUnaryInstance(OR, "fake-name", values); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetBinaryInstanceException() { - final List values = new ArrayList<>(); - final Criteria left = Criteria.getUnaryInstance(IS_EQUAL, "fake-name", values); - final Criteria right = Criteria.getUnaryInstance(IS_EQUAL, "fake-name", values); - - Criteria.getBinaryInstance(IS_EQUAL, left, right); - } - - @Test(expected = UnsupportedOperationException.class) - public void testCriteriaTypeToGremlinException() { - CriteriaType.criteriaTypeToGremlin(IS_EQUAL); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/query/parameter/GremlinParameterUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/query/parameter/GremlinParameterUnitTest.java deleted file mode 100644 index 2d1fd951..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/query/parameter/GremlinParameterUnitTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.query.parameter; - -import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameter; -import com.microsoft.spring.data.gremlin.query.paramerter.GremlinParameters; -import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.core.MethodParameter; -import org.springframework.lang.NonNull; - -import java.lang.reflect.Method; - -public class GremlinParameterUnitTest { - - private Method method; - private MethodParameter methodParameter; - - public String handle(@NonNull String name) { - return "handle: " + name; - } - - @Before - @SneakyThrows - public void setup() { - method = this.getClass().getMethod("handle", String.class); - methodParameter = new MethodParameter(this.getClass().getMethod("handle", String.class), 0); - } - - @Test - public void testGremlinParameter() { - final GremlinParameter parameter = new GremlinParameter(this.methodParameter); - - Assert.assertNotNull(parameter); - Assert.assertEquals(parameter.getType(), String.class); - Assert.assertEquals(parameter.getIndex(), 0); - } - - @Test - public void testGremlinParameters() { - final GremlinParameters gremlinParameters = new GremlinParameters(this.method); - - Assert.assertNotNull(gremlinParameters); - Assert.assertEquals(gremlinParameters.getNumberOfParameters(), 1); - Assert.assertNotNull(gremlinParameters.getParameter(0)); - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/AdvancedUserRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/AdvancedUserRepositoryIT.java deleted file mode 100644 index 3d29f005..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/AdvancedUserRepositoryIT.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.AdvancedUser; -import com.microsoft.spring.data.gremlin.common.repository.AdvancedUserRepository; -import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class AdvancedUserRepositoryIT { - - private static final String ID_0 = "id-8000"; - private static final String ID_1 = "id-8001"; - - private static final String NAME_0 = "name-9000"; - private static final String NAME_1 = "name-9001"; - - private static final int LEVEL_0 = 4; - private static final int LEVEL_1 = 38; - - private static final AdvancedUser USER_0 = new AdvancedUser(ID_0, NAME_0, LEVEL_0); - private static final AdvancedUser USER_1 = new AdvancedUser(ID_1, NAME_1, LEVEL_1); - - @Autowired - private AdvancedUserRepository repository; - - @Before - public void setup() { - this.repository.deleteAll(); - } - - @Test - public void testCrudRepository() { - final List users = Arrays.asList(USER_0, USER_1); - this.repository.saveAll(users); - - final Optional optional = this.repository.findById(USER_0.getId()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(USER_0.getId(), optional.get().getId()); - Assert.assertEquals(USER_0.getName(), optional.get().getName()); - Assert.assertEquals(USER_0.getLevel(), optional.get().getLevel()); - - final List foundUsers = Lists.newArrayList(this.repository.findAll(AdvancedUser.class)); - Assert.assertEquals(foundUsers.size(), users.size()); - - this.repository.deleteById(USER_0.getId()); - - Assert.assertFalse(this.repository.findById(USER_0.getId()).isPresent()); - Assert.assertTrue(this.repository.findById(USER_1.getId()).isPresent()); - - this.repository.deleteAll(); - - Assert.assertFalse(this.repository.findById(USER_1.getId()).isPresent()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/BookReferenceRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/BookReferenceRepositoryIT.java deleted file mode 100644 index d1ed032a..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/BookReferenceRepositoryIT.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Book; -import com.microsoft.spring.data.gremlin.common.domain.BookReference; -import com.microsoft.spring.data.gremlin.common.repository.BookReferenceRepository; -import com.microsoft.spring.data.gremlin.common.repository.BookRepository; -import lombok.NonNull; -import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class BookReferenceRepositoryIT { - - private static final Integer BOOK_ID_0 = 0; - private static final Integer BOOK_ID_1 = 1; - private static final Integer BOOK_ID_2 = 2; - private static final Integer BOOK_REFERENCE_ID_0 = 3; - private static final Integer BOOK_REFERENCE_ID_1 = 4; - private static final Integer NO_EXIST_ID = -1; - - private static final String NAME_0 = "name-0"; - private static final String NAME_1 = "name-1"; - private static final String NAME_2 = "name-2"; - - private static final Double PRINCE_0 = 3.4; - private static final Double PRINCE_1 = 72.0; - private static final Double PRINCE_2 = 102.82; - - private static final Book BOOK_0 = new Book(BOOK_ID_0, NAME_0, PRINCE_0); - private static final Book BOOK_1 = new Book(BOOK_ID_1, NAME_1, PRINCE_1); - private static final Book BOOK_2 = new Book(BOOK_ID_2, NAME_2, PRINCE_2); - - private static final BookReference BOOK_REFERENCE_0 = new BookReference(BOOK_REFERENCE_ID_0, BOOK_ID_0, BOOK_ID_2); - private static final BookReference BOOK_REFERENCE_1 = new BookReference(BOOK_REFERENCE_ID_1, BOOK_ID_1, BOOK_ID_2); - - private static final List BOOKS = Arrays.asList(BOOK_0, BOOK_1, BOOK_2); - private static final List BOOK_REFERENCES = Arrays.asList(BOOK_REFERENCE_0, BOOK_REFERENCE_1); - - @Autowired - private BookReferenceRepository referenceRepository; - - @Autowired - private BookRepository bookRepository; - - @Before - public void setup() { - this.referenceRepository.deleteAll(); - this.bookRepository.deleteAll(); - } - - private void assertDomainListEquals(@NonNull List found, @NonNull List expected) { - found.sort(Comparator.comparing(BookReference::getId)); - expected.sort(Comparator.comparing(BookReference::getId)); - - Assert.assertEquals(found.size(), expected.size()); - Assert.assertEquals(found, expected); - } - - @Test - public void testDeleteAll() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertTrue(referenceRepository.findAll().iterator().hasNext()); - - referenceRepository.deleteAll(); - - Assert.assertFalse(referenceRepository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnType() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertTrue(referenceRepository.findAll().iterator().hasNext()); - - referenceRepository.deleteAll(GremlinEntityType.EDGE); - - Assert.assertFalse(referenceRepository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnDomain() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertTrue(referenceRepository.findAll().iterator().hasNext()); - - referenceRepository.deleteAll(BookReference.class); - - Assert.assertFalse(referenceRepository.findAll().iterator().hasNext()); - } - - @Test - public void testSave() { - bookRepository.saveAll(BOOKS); - referenceRepository.save(BOOK_REFERENCE_0); - - Assert.assertTrue(referenceRepository.findById(BOOK_REFERENCE_0.getId()).isPresent()); - Assert.assertFalse(referenceRepository.findById(BOOK_REFERENCE_1.getId()).isPresent()); - } - - @Test - public void testSaveAll() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - final List found = Lists.newArrayList(referenceRepository.findAll()); - - assertDomainListEquals(found, BOOK_REFERENCES); - } - - @Test - public void testFindById() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Optional optional = referenceRepository.findById(BOOK_REFERENCE_0.getId()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(optional.get(), BOOK_REFERENCE_0); - - optional = referenceRepository.findById(NO_EXIST_ID); - - Assert.assertFalse(optional.isPresent()); - } - - @Test - public void testExistsById() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertTrue(referenceRepository.existsById(BOOK_REFERENCE_0.getId())); - Assert.assertFalse(referenceRepository.existsById(NO_EXIST_ID)); - } - - @Test - public void testFindAllById() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - final List ids = Arrays.asList(BOOK_REFERENCE_0.getId(), BOOK_REFERENCE_1.getId()); - final List found = Lists.newArrayList(referenceRepository.findAllById(ids)); - - assertDomainListEquals(found, BOOK_REFERENCES); - - Assert.assertFalse(referenceRepository.findAllById(Collections.singleton(NO_EXIST_ID)).iterator().hasNext()); - } - - @Test - public void testCount() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertEquals(referenceRepository.count(), BOOK_REFERENCES.size() + BOOKS.size()); - - referenceRepository.deleteAll(); - - Assert.assertEquals(referenceRepository.count(), 0); - } - - @Test - public void testDeleteById() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertTrue(referenceRepository.findById(BOOK_REFERENCE_0.getId()).isPresent()); - - referenceRepository.deleteById(BOOK_REFERENCE_0.getId()); - - Assert.assertFalse(referenceRepository.findById(BOOK_REFERENCE_0.getId()).isPresent()); - } - - @Test - public void testEdgeCount() { - bookRepository.saveAll(BOOKS); - referenceRepository.saveAll(BOOK_REFERENCES); - - Assert.assertEquals(referenceRepository.edgeCount(), BOOK_REFERENCES.size()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/BookRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/BookRepositoryIT.java deleted file mode 100644 index 313128b2..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/BookRepositoryIT.java +++ /dev/null @@ -1,222 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Book; -import com.microsoft.spring.data.gremlin.common.repository.BookRepository; -import lombok.NonNull; -import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class BookRepositoryIT { - - private static final Integer ID_0 = 0; - private static final Integer ID_1 = 1; - private static final Integer ID_2 = 2; - private static final Integer NO_EXIST_ID = -1; - - private static final String NAME_0 = "name-0"; - private static final String NAME_1 = "name-1"; - private static final String NAME_2 = "name-2"; - private static final String NO_EXIST_NAME = "no-exist-name"; - - private static final Double PRINCE_0 = 3.4; - private static final Double PRINCE_1 = 72.0; - private static final Double PRINCE_2 = 102.82; - private static final Double NO_EXIST_PRICE = -144.23; - - private static final Book BOOK_0 = new Book(ID_0, NAME_0, PRINCE_0); - private static final Book BOOK_1 = new Book(ID_1, NAME_1, PRINCE_1); - private static final Book BOOK_2 = new Book(ID_2, NAME_2, PRINCE_2); - - private static final List BOOKS = Arrays.asList(BOOK_0, BOOK_1, BOOK_2); - - @Autowired - private BookRepository repository; - - @Before - public void setup() { - this.repository.deleteAll(); - } - - private void assertDomainListEquals(@NonNull List found, @NonNull List expected) { - found.sort(Comparator.comparing(Book::getSerialNumber)); - expected.sort(Comparator.comparing(Book::getSerialNumber)); - - Assert.assertEquals(found.size(), expected.size()); - Assert.assertEquals(found, expected); - } - - @Test - public void testDeleteAll() { - repository.saveAll(BOOKS); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(); - - Assert.assertFalse(repository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnType() { - repository.saveAll(BOOKS); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(GremlinEntityType.VERTEX); - - Assert.assertFalse(repository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnDomain() { - repository.saveAll(BOOKS); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(Book.class); - - Assert.assertFalse(repository.findAll().iterator().hasNext()); - } - - @Test - public void testSave() { - repository.save(BOOK_0); - - Assert.assertTrue(repository.findById(BOOK_0.getSerialNumber()).isPresent()); - Assert.assertFalse(repository.findById(BOOK_1.getSerialNumber()).isPresent()); - } - - @Test - public void testSaveAll() { - repository.saveAll(BOOKS); - - final List found = Lists.newArrayList(repository.findAll()); - - assertDomainListEquals(found, BOOKS); - } - - @Test - public void testFindById() { - repository.saveAll(BOOKS); - - Optional optional = repository.findById(BOOK_0.getSerialNumber()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(optional.get(), BOOK_0); - - optional = repository.findById(NO_EXIST_ID); - - Assert.assertFalse(optional.isPresent()); - } - - @Test - public void testExistsById() { - repository.saveAll(BOOKS); - - Assert.assertTrue(repository.existsById(BOOK_0.getSerialNumber())); - Assert.assertFalse(repository.existsById(NO_EXIST_ID)); - } - - @Test - public void testFindAllById() { - final List expected = Arrays.asList(BOOK_0, BOOK_1); - final List ids = Arrays.asList(BOOK_0.getSerialNumber(), BOOK_1.getSerialNumber(), NO_EXIST_ID); - - repository.saveAll(BOOKS); - - final List found = Lists.newArrayList(repository.findAllById(ids)); - - assertDomainListEquals(found, expected); - - Assert.assertFalse(repository.findAllById(Collections.singleton(NO_EXIST_ID)).iterator().hasNext()); - } - - @Test - public void testCount() { - repository.saveAll(BOOKS); - - Assert.assertEquals(repository.count(), BOOKS.size()); - - repository.deleteAll(); - - Assert.assertEquals(repository.count(), 0); - } - - @Test - public void testDeleteById() { - repository.saveAll(BOOKS); - - Assert.assertTrue(repository.findById(BOOK_0.getSerialNumber()).isPresent()); - - repository.deleteById(BOOK_0.getSerialNumber()); - - Assert.assertFalse(repository.findById(BOOK_0.getSerialNumber()).isPresent()); - } - - @Test - public void testVertexCount() { - repository.saveAll(BOOKS); - - Assert.assertEquals(repository.vertexCount(), BOOKS.size()); - } - - @Test - public void testEdgeCount() { - repository.saveAll(BOOKS); - - Assert.assertEquals(repository.edgeCount(), 0); - } - - @Test - public void testFindByNameOrPrince() { - repository.saveAll(BOOKS); - - List found = repository.findByNameOrPrice(BOOK_0.getName(), BOOK_1.getPrice()); - - assertDomainListEquals(found, Arrays.asList(BOOK_0, BOOK_1)); - - found = repository.findByNameOrPrice(NO_EXIST_NAME, NO_EXIST_PRICE); - - Assert.assertTrue(found.isEmpty()); - } - - @Test - public void testFindAllIncomplete() { - final Book book = new Book(ID_0, null, 2.34); - final Book bookNullName = new Book(ID_1, "null", 243.34); - - repository.save(book); - repository.save(bookNullName); - - final Optional optional = repository.findById(book.getSerialNumber()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(optional.get(), book); - - final Optional optionalNullName = repository.findById(bookNullName.getSerialNumber()); - - Assert.assertTrue(optionalNullName.isPresent()); - Assert.assertEquals(optionalNullName.get(), bookNullName); - - final List books = Lists.newArrayList(repository.findAll()); - - assertDomainListEquals(books, Arrays.asList(book, bookNullName)); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/GroupRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/GroupRepositoryIT.java deleted file mode 100644 index 218d4578..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/GroupRepositoryIT.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.TestUtils; -import com.microsoft.spring.data.gremlin.common.domain.Group; -import com.microsoft.spring.data.gremlin.common.domain.GroupOwner; -import com.microsoft.spring.data.gremlin.common.domain.Student; -import com.microsoft.spring.data.gremlin.common.repository.GroupOwnerRepository; -import com.microsoft.spring.data.gremlin.common.repository.GroupRepository; -import com.microsoft.spring.data.gremlin.common.repository.StudentRepository; -import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class GroupRepositoryIT { - - private static final Long STUDENT_ID_0 = 1111L; - private static final Long STUDENT_ID_1 = 1234L; - private static final Long STUDENT_ID_2 = 2345L; - private static final Long STUDENT_ID_3 = 4823L; - - private static final String STUDENT_NAME_0 = "student-0"; - private static final String STUDENT_NAME_1 = "student-1"; - private static final String STUDENT_NAME_2 = "student-2"; - private static final String STUDENT_NAME_3 = "student-3"; - - private static final String GROUP_OWNER_ID_0 = "owner-0"; - private static final String GROUP_OWNER_ID_1 = "owner-1"; - - private static final Integer GROUP_OWNER_EXPIRE_DAYS_0 = 90; - private static final Integer GROUP_OWNER_EXPIRE_DAYS_1 = 120; - - private static final Student STUDENT_0 = new Student(STUDENT_ID_0, STUDENT_NAME_0); - private static final Student STUDENT_1 = new Student(STUDENT_ID_1, STUDENT_NAME_1); - private static final Student STUDENT_2 = new Student(STUDENT_ID_2, STUDENT_NAME_2); - private static final Student STUDENT_3 = new Student(STUDENT_ID_3, STUDENT_NAME_3); - - private static final GroupOwner GROUP_OWNER_0 = new GroupOwner(GROUP_OWNER_ID_0, GROUP_OWNER_EXPIRE_DAYS_0); - private static final GroupOwner GROUP_OWNER_1 = new GroupOwner(GROUP_OWNER_ID_1, GROUP_OWNER_EXPIRE_DAYS_1); - - private static final Group GROUP_0 = new Group(STUDENT_0, GROUP_OWNER_0); - private static final Group GROUP_1 = new Group(STUDENT_1, GROUP_OWNER_0); - private static final Group GROUP_2 = new Group(STUDENT_2, GROUP_OWNER_0); - private static final Group GROUP_3 = new Group(STUDENT_3, GROUP_OWNER_0); - private static final Group GROUP_4 = new Group(STUDENT_0, GROUP_OWNER_1); - private static final Group GROUP_5 = new Group(STUDENT_1, GROUP_OWNER_1); - - private static final List STUDENTS = Arrays.asList(STUDENT_0, STUDENT_1, STUDENT_2, STUDENT_3); - private static final List GROUP_OWNERS = Arrays.asList(GROUP_OWNER_0, GROUP_OWNER_1); - private static final List GROUPS = Arrays.asList(GROUP_0, GROUP_1, GROUP_2, GROUP_3, GROUP_4, GROUP_5); - - @Autowired - private GroupRepository groupRepository; - - @Autowired - private GroupOwnerRepository groupOwnerRepository; - - @Autowired - private StudentRepository studentRepository; - - @Before - public void setup() { - this.groupOwnerRepository.deleteAll(); - this.studentRepository.deleteAll(); - this.groupRepository.deleteAll(); - - this.studentRepository.saveAll(STUDENTS); - this.groupOwnerRepository.saveAll(GROUP_OWNERS); - } - - @After - public void cleanup() { - this.groupOwnerRepository.deleteAll(); - this.studentRepository.deleteAll(); - this.groupRepository.deleteAll(); - } - - @Test - public void testGeneratedIdFindById() { - final Group expect = this.groupRepository.save(GROUP_0); - - Assert.assertNotNull(expect.getId()); - - final Optional optional = this.groupRepository.findById(expect.getId()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(expect, optional.get()); - } - - @Test - public void testGeneratedIdFindAll() { - final List expect = Lists.newArrayList(this.groupRepository.saveAll(GROUPS)); - final List actual = Lists.newArrayList(this.groupRepository.findAll()); - - TestUtils.assertEntitiesEquals(expect, actual); - } - - @Test - public void testGeneratedIdDeleteById() { - final Group group = this.groupRepository.save(GROUP_0); - - this.groupRepository.deleteById(group.getId()); - - Assert.assertFalse(this.groupRepository.findById(group.getId()).isPresent()); - Assert.assertFalse(this.groupRepository.existsById(group.getId())); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/MasterRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/MasterRepositoryIT.java deleted file mode 100644 index 15df11f6..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/MasterRepositoryIT.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Master; -import com.microsoft.spring.data.gremlin.common.domain.Student; -import com.microsoft.spring.data.gremlin.common.repository.MasterRepository; -import com.microsoft.spring.data.gremlin.common.repository.StudentRepository; -import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.List; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class MasterRepositoryIT { - - private static final Long ID_STUDENT = 1L; - private static final Long ID_MASTER = 2L; - - private static final String NAME = "name"; - - private static final Student STUDENT = new Student(ID_STUDENT, NAME); - - private static final Master MASTER = new Master(ID_MASTER, NAME); - - @Autowired - private MasterRepository masterRepository; - - @Autowired - private StudentRepository studentRepository; - - @Before - public void setup() { - this.masterRepository.deleteAll(); - this.studentRepository.deleteAll(); - } - - @After - public void cleanup() { - this.masterRepository.deleteAll(); - this.studentRepository.deleteAll(); - } - - @Test - public void testDuplicatedLabelFindAll() { - this.studentRepository.save(STUDENT); - this.masterRepository.save(MASTER); - - final List masters = Lists.newArrayList(this.masterRepository.findAll(Master.class)); - - Assert.assertEquals(masters.size(), 1); - Assert.assertEquals(masters.get(0), MASTER); - - final List students = Lists.newArrayList(this.studentRepository.findAll(Student.class)); - - Assert.assertEquals(students.size(), 1); - Assert.assertEquals(students.get(0), STUDENT); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/NeighborRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/NeighborRepositoryIT.java deleted file mode 100644 index aac4dcc6..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/NeighborRepositoryIT.java +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Neighbor; -import com.microsoft.spring.data.gremlin.common.domain.Student; -import com.microsoft.spring.data.gremlin.common.repository.NeighborRepository; -import com.microsoft.spring.data.gremlin.common.repository.StudentRepository; -import lombok.NonNull; -import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class NeighborRepositoryIT { - - private static final Long STUDENT_ID_0 = 12349274637234L; - private static final Long STUDENT_ID_1 = 1L; - private static final Long STUDENT_ID_2 = 2L; - private static final Long DISTANCE_0 = 1234L; - private static final Long DISTANCE_1 = 3422L; - private static final Long NEIGHBOR_ID_0 = 3L; - private static final Long NEIGHBOR_ID_1 = 4L; - private static final Long NO_EXIST_ID = -1L; - - private static final String NAME_0 = "name-0"; - private static final String NAME_1 = "name-1"; - private static final String NAME_2 = "name-2"; - - private static final Student STUDENT_0 = new Student(STUDENT_ID_0, NAME_0); - private static final Student STUDENT_1 = new Student(STUDENT_ID_1, NAME_1); - private static final Student STUDENT_2 = new Student(STUDENT_ID_2, NAME_2); - - private static final Neighbor NEIGHBOR_0 = new Neighbor(NEIGHBOR_ID_0, DISTANCE_0, STUDENT_0, STUDENT_1); - private static final Neighbor NEIGHBOR_1 = new Neighbor(NEIGHBOR_ID_1, DISTANCE_1, STUDENT_2, STUDENT_1); - - private static final List STUDENTS = Arrays.asList(STUDENT_0, STUDENT_1, STUDENT_2); - private static final List NEIGHBORS = Arrays.asList(NEIGHBOR_0, NEIGHBOR_1); - - @Autowired - private StudentRepository studentRepository; - - @Autowired - private NeighborRepository neighborRepository; - - @Before - public void setup() { - this.studentRepository.deleteAll(); - this.neighborRepository.deleteAll(); - } - - private void assertDomainListEquals(@NonNull List found, @NonNull List expected) { - found.sort(Comparator.comparing(Neighbor::getId)); - expected.sort(Comparator.comparing(Neighbor::getId)); - - Assert.assertEquals(found.size(), expected.size()); - Assert.assertEquals(found, expected); - } - - @Test - public void testDeleteAll() { - neighborRepository.deleteAll(); - - Assert.assertFalse(neighborRepository.findAll().iterator().hasNext()); - - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertTrue(neighborRepository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnType() { - neighborRepository.deleteAll(GremlinEntityType.EDGE); - - Assert.assertFalse(neighborRepository.findAll().iterator().hasNext()); - - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertTrue(neighborRepository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnDomain() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertTrue(neighborRepository.findAll().iterator().hasNext()); - - neighborRepository.deleteAll(Neighbor.class); - - Assert.assertFalse(neighborRepository.findAll().iterator().hasNext()); - } - - @Test - public void testSave() { - studentRepository.saveAll(STUDENTS); - neighborRepository.save(NEIGHBOR_0); - - Assert.assertTrue(neighborRepository.findById(NEIGHBOR_0.getId()).isPresent()); - Assert.assertFalse(neighborRepository.findById(NEIGHBOR_1.getId()).isPresent()); - } - - @Test - public void testSaveAll() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - final List found = Lists.newArrayList(neighborRepository.findAll()); - - assertDomainListEquals(found, NEIGHBORS); - } - - @Test - public void testFindById() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Optional optional = neighborRepository.findById(NEIGHBOR_0.getId()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(optional.get(), NEIGHBOR_0); - - optional = neighborRepository.findById(NO_EXIST_ID); - - Assert.assertFalse(optional.isPresent()); - } - - @Test - public void testExistsById() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertTrue(neighborRepository.existsById(NEIGHBOR_0.getId())); - Assert.assertFalse(neighborRepository.existsById(NO_EXIST_ID)); - } - - @Test - public void testFindAllById() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - final List ids = Arrays.asList(NEIGHBOR_0.getId(), NEIGHBOR_1.getId()); - final List found = Lists.newArrayList(neighborRepository.findAllById(ids)); - - assertDomainListEquals(found, NEIGHBORS); - - Assert.assertFalse(neighborRepository.findAllById(Collections.singleton(NO_EXIST_ID)).iterator().hasNext()); - } - - @Test - public void testCount() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertEquals(neighborRepository.count(), STUDENTS.size() + NEIGHBORS.size()); - - neighborRepository.deleteAll(); - - Assert.assertEquals(neighborRepository.count(), 0); - } - - @Test - public void testDeleteById() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertTrue(neighborRepository.findById(NEIGHBOR_0.getId()).isPresent()); - - neighborRepository.deleteById(NEIGHBOR_0.getId()); - - Assert.assertFalse(neighborRepository.findById(NEIGHBOR_0.getId()).isPresent()); - } - - @Test - public void testEdgeCount() { - studentRepository.saveAll(STUDENTS); - neighborRepository.saveAll(NEIGHBORS); - - Assert.assertEquals(neighborRepository.edgeCount(), NEIGHBORS.size()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/NetworkRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/NetworkRepositoryIT.java deleted file mode 100644 index c98f80c5..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/NetworkRepositoryIT.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Network; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Project; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.common.repository.NetworkRepository; -import com.microsoft.spring.data.gremlin.common.repository.PersonRepository; -import com.microsoft.spring.data.gremlin.common.repository.ProjectRepository; -import com.microsoft.spring.data.gremlin.common.repository.RelationshipRepository; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Collections; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class NetworkRepositoryIT { - - private final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - private final Project project = new Project(TestConstants.VERTEX_PROJECT_ID, TestConstants.VERTEX_PROJECT_NAME, - TestConstants.VERTEX_PROJECT_URI); - private final Relationship relationship = new Relationship(TestConstants.EDGE_RELATIONSHIP_ID, - TestConstants.EDGE_RELATIONSHIP_NAME, TestConstants.EDGE_RELATIONSHIP_LOCATION, - this.person, this.project); - - @Autowired - private NetworkRepository networkRepository; - - @Autowired - private PersonRepository personRepository; - - @Autowired - private ProjectRepository projectRepository; - - @Autowired - private RelationshipRepository relationshipRepository; - - @Before - public void setup() { - this.networkRepository.deleteAll(); - } - - @After - public void cleanup() { - this.networkRepository.deleteAll(); - } - - @Test - public void testDeleteById() { - final Network network = new Network(); - - network.setId("fake-id"); - network.vertexAdd(this.person); - network.vertexAdd(this.project); - network.edgeAdd(this.relationship); - - this.networkRepository.save(network); - - Assert.assertTrue(personRepository.findById(this.person.getId()).isPresent()); - Assert.assertTrue(projectRepository.findById(this.project.getId()).isPresent()); - Assert.assertTrue(relationshipRepository.findById(this.relationship.getId()).isPresent()); - - this.networkRepository.deleteById(network.getId()); - - Assert.assertFalse(personRepository.findById(this.person.getId()).isPresent()); - Assert.assertFalse(projectRepository.findById(this.project.getId()).isPresent()); - Assert.assertFalse(relationshipRepository.findById(this.relationship.getId()).isPresent()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testFindAllException() { - final Network network = new Network(); - - network.setId("fake-id"); - network.vertexAdd(this.person); - network.vertexAdd(this.project); - network.edgeAdd(this.relationship); - - this.networkRepository.save(network); - this.networkRepository.findAll(Network.class); - } - - @Test(expected = UnsupportedOperationException.class) - public void testFindScriptGeneratorException() { - final Network network = new Network(); - - network.setId("fake-id"); - network.vertexAdd(this.person); - network.vertexAdd(this.project); - network.edgeAdd(this.relationship); - - this.networkRepository.save(network); - this.networkRepository.findByEdgeList(Collections.singletonList(this.relationship)); - } - - @Test - public void testDeleteAllByType() { - final Network network = new Network(); - - network.setId("fake-id"); - network.vertexAdd(this.person); - network.vertexAdd(this.project); - network.edgeAdd(this.relationship); - - this.networkRepository.save(network); - this.networkRepository.deleteAll(GremlinEntityType.GRAPH); - - Assert.assertFalse(this.personRepository.findById(this.person.getId()).isPresent()); - Assert.assertFalse(this.projectRepository.findById(this.project.getId()).isPresent()); - Assert.assertFalse(this.relationshipRepository.findById(this.relationship.getId()).isPresent()); - } - - @Test - public void testDeleteAllByClass() { - final Network network = new Network(); - - network.setId("fake-id"); - network.vertexAdd(this.person); - network.vertexAdd(this.project); - network.edgeAdd(this.relationship); - - this.networkRepository.save(network); - this.networkRepository.deleteAll(Network.class); - - Assert.assertFalse(this.relationshipRepository.findById(this.relationship.getId()).isPresent()); - Assert.assertFalse(this.personRepository.findById(this.person.getId()).isPresent()); - Assert.assertFalse(this.projectRepository.findById(this.project.getId()).isPresent()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/OrangeRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/OrangeRepositoryIT.java deleted file mode 100644 index 20b5341c..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/OrangeRepositoryIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.TestUtils; -import com.microsoft.spring.data.gremlin.common.domain.Orange; -import com.microsoft.spring.data.gremlin.common.repository.OrangeRepository; -import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class OrangeRepositoryIT { - - private static final String LOCATION_0 = "location-0"; - private static final String LOCATION_1 = "location-1"; - private static final String LOCATION_2 = "location-2"; - private static final String LOCATION_3 = "location-3"; - - private static final Double PRINCE_0 = 1.79; - private static final Double PRINCE_1 = 2.09; - private static final Double PRINCE_2 = 3.29; - private static final Double PRINCE_3 = 3.99; - - private static final Orange ORANGE_0 = new Orange(LOCATION_0, PRINCE_0); - private static final Orange ORANGE_1 = new Orange(LOCATION_1, PRINCE_1); - private static final Orange ORANGE_2 = new Orange(LOCATION_2, PRINCE_2); - private static final Orange ORANGE_3 = new Orange(LOCATION_3, PRINCE_3); - - private static final List ORANGES = Arrays.asList(ORANGE_0, ORANGE_1, ORANGE_2, ORANGE_3); - - @Autowired - private OrangeRepository repository; - - @Before - public void setup() { - this.repository.deleteAll(); - } - - @After - public void cleanup() { - this.repository.deleteAll(); - } - - @Test - public void testGeneratedIdFindById() { - final Orange orange = this.repository.save(ORANGE_0); - - Assert.assertNotNull(orange.getId()); - - final Optional optional = this.repository.findById(orange.getId()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(optional.get(), orange); - } - - @Test - public void testGeneratedIdFindAll() { - final List expect = Lists.newArrayList(this.repository.saveAll(ORANGES)); - final List actual = Lists.newArrayList(this.repository.findAll()); - - TestUtils.assertEntitiesEquals(expect, actual); - } - - @Test - public void testGeneratedIdDeleteById() { - final Orange orange = this.repository.save(ORANGE_0); - - this.repository.deleteById(orange.getId()); - - Assert.assertFalse(this.repository.findById(orange.getId()).isPresent()); - Assert.assertFalse(this.repository.existsById(orange.getId())); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/PersonRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/PersonRepositoryIT.java deleted file mode 100644 index 4b00a9bd..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/PersonRepositoryIT.java +++ /dev/null @@ -1,235 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Project; -import com.microsoft.spring.data.gremlin.common.repository.PersonRepository; -import com.microsoft.spring.data.gremlin.common.repository.ProjectRepository; -import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class PersonRepositoryIT { - - private final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - private final Person person0 = new Person(TestConstants.VERTEX_PERSON_0_ID, TestConstants.VERTEX_PERSON_0_NAME); - private final Project project = new Project(TestConstants.VERTEX_PROJECT_ID, TestConstants.VERTEX_PROJECT_NAME, - TestConstants.VERTEX_PROJECT_URI); - - @Autowired - private PersonRepository repository; - - @Autowired - private ProjectRepository projectRepository; - - @Before - public void setup() { - this.repository.deleteAll(); - } - - @After - public void cleanup() { - this.repository.deleteAll(); - } - - @Test - public void testDeleteAll() { - this.repository.save(this.person); - - Assert.assertTrue(this.repository.existsById(this.person.getId())); - - this.repository.deleteAll(); - - Assert.assertFalse(this.repository.existsById(this.person.getId())); - } - - @Test - public void testDeleteById() { - this.repository.save(this.person); - this.repository.save(this.person0); - - Assert.assertTrue(this.repository.existsById(this.person.getId())); - Assert.assertTrue(this.repository.existsById(this.person0.getId())); - - this.repository.deleteById(this.person.getId()); - - Assert.assertFalse(this.repository.existsById(this.person.getId())); - Assert.assertTrue(this.repository.existsById(this.person0.getId())); - } - - @Test - public void testDelete() { - this.repository.save(this.person); - this.repository.save(this.person0); - - Assert.assertTrue(this.repository.existsById(this.person.getId())); - Assert.assertTrue(this.repository.existsById(this.person0.getId())); - - this.repository.delete(this.person); - - Assert.assertFalse(this.repository.existsById(this.person.getId())); - Assert.assertTrue(this.repository.existsById(this.person0.getId())); - } - - @Test - public void testDeleteAllIds() { - final List domains = Arrays.asList(this.person, this.person0); - - this.repository.save(this.person); - this.repository.save(this.person0); - - this.repository.deleteAll(domains); - - Assert.assertFalse(this.repository.existsById(this.person.getId())); - Assert.assertFalse(this.repository.existsById(this.person0.getId())); - } - - @Test - public void testSave() { - this.repository.save(this.person); - this.repository.save(this.person0); - - Assert.assertTrue(this.repository.existsById(this.person.getId())); - Assert.assertTrue(this.repository.existsById(this.person0.getId())); - } - - @Test - public void testSaveAll() { - final List domains = Arrays.asList(this.person, this.person0); - - this.repository.saveAll(domains); - - Assert.assertTrue(this.repository.existsById(this.person.getId())); - Assert.assertTrue(this.repository.existsById(this.person0.getId())); - } - - @Test - public void testFindById() { - this.repository.save(this.person); - - final Person foundPerson = this.repository.findById(this.person.getId()).get(); - - Assert.assertNotNull(foundPerson); - Assert.assertEquals(foundPerson.getId(), this.person.getId()); - Assert.assertEquals(foundPerson.getName(), this.person.getName()); - - Assert.assertFalse(this.repository.findById(this.person0.getId()).isPresent()); - } - - @Test - public void testExistById() { - Assert.assertFalse(this.repository.existsById(this.person.getId())); - - this.repository.save(this.person); - - Assert.assertTrue(this.repository.existsById(this.person.getId())); - } - - @Test - public void testFindAllById() { - final List domains = Arrays.asList(this.person, this.person0); - final List ids = Arrays.asList(this.person.getId(), this.person0.getId()); - - this.repository.saveAll(domains); - - final List foundDomains = (List) this.repository.findAllById(ids); - - domains.sort((a, b) -> (a.getId().compareTo(b.getId()))); - foundDomains.sort((a, b) -> (a.getId().compareTo(b.getId()))); - - Assert.assertArrayEquals(domains.toArray(), foundDomains.toArray()); - } - - @Test - public void testDomainClassFindAll() { - final List domains = Arrays.asList(this.person, this.person0); - List foundDomains = (List) this.repository.findAll(Person.class); - - Assert.assertTrue(foundDomains.isEmpty()); - - this.repository.saveAll(domains); - - foundDomains = (List) this.repository.findAll(Person.class); - - Assert.assertEquals(domains.size(), foundDomains.size()); - - domains.sort((a, b) -> (a.getId().compareTo(b.getId()))); - foundDomains.sort((a, b) -> (a.getId().compareTo(b.getId()))); - - Assert.assertArrayEquals(domains.toArray(), foundDomains.toArray()); - } - - @Test - public void testVertexCount() { - Assert.assertEquals(this.repository.count(), 0); - Assert.assertEquals(this.repository.edgeCount(), 0); - Assert.assertEquals(this.repository.vertexCount(), 0); - - this.repository.save(this.person); - this.repository.save(this.person0); - - Assert.assertEquals(this.repository.count(), 2); - Assert.assertEquals(this.repository.edgeCount(), 0); - Assert.assertEquals(this.repository.vertexCount(), this.repository.count()); - } - - @Test - public void testDeleteAllByType() { - this.repository.save(this.person); - this.repository.save(this.person0); - - this.repository.deleteAll(GremlinEntityType.VERTEX); - - Assert.assertFalse(this.repository.findById(this.person.getId()).isPresent()); - Assert.assertFalse(this.repository.findById(this.person0.getId()).isPresent()); - } - - @Test - public void testDeleteAllByClass() { - this.repository.save(this.person); - this.repository.save(this.person0); - this.projectRepository.save(this.project); - - this.repository.deleteAll(Person.class); - - Assert.assertFalse(this.repository.findById(this.person.getId()).isPresent()); - Assert.assertFalse(this.repository.findById(this.person0.getId()).isPresent()); - Assert.assertTrue(this.projectRepository.findById(this.project.getId()).isPresent()); - } - - @Test - public void testFindAll() { - final List persons = Arrays.asList(this.person, this.person0); - this.repository.saveAll(persons); - - final List foundPersons = Lists.newArrayList(this.repository.findAll()); - - foundPersons.sort(Comparator.comparing(Person::getId)); - persons.sort(Comparator.comparing(Person::getId)); - - Assert.assertEquals(persons, foundPersons); - - this.repository.deleteAll(); - Assert.assertFalse(this.repository.findAll().iterator().hasNext()); - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/RelationshipRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/RelationshipRepositoryIT.java deleted file mode 100644 index 5b5afa69..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/RelationshipRepositoryIT.java +++ /dev/null @@ -1,306 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Project; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.common.repository.PersonRepository; -import com.microsoft.spring.data.gremlin.common.repository.ProjectRepository; -import com.microsoft.spring.data.gremlin.common.repository.RelationshipRepository; -import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class RelationshipRepositoryIT { - - private final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - private final Person person0 = new Person(TestConstants.VERTEX_PERSON_0_ID, TestConstants.VERTEX_PERSON_0_NAME); - private final Project project = new Project(TestConstants.VERTEX_PROJECT_ID, TestConstants.VERTEX_PROJECT_NAME, - TestConstants.VERTEX_PROJECT_URI); - private final Relationship relationship = new Relationship(TestConstants.EDGE_RELATIONSHIP_ID, - TestConstants.EDGE_RELATIONSHIP_NAME, TestConstants.EDGE_RELATIONSHIP_LOCATION, - this.person, this.project); - private final Relationship relationship0 = new Relationship(TestConstants.EDGE_RELATIONSHIP_0_ID, - TestConstants.EDGE_RELATIONSHIP_0_NAME, TestConstants.EDGE_RELATIONSHIP_0_LOCATION, - this.person0, this.project); - - @Autowired - private RelationshipRepository relationshipRepo; - - @Autowired - private PersonRepository personRepo; - - @Autowired - private ProjectRepository projectRepo; - - @Before - public void setup() { - this.relationshipRepo.deleteAll(); - } - - @After - public void cleanup() { - this.relationshipRepo.deleteAll(); - } - - @Test - public void testDeleteAll() { - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - Assert.assertTrue(this.relationshipRepo.existsById(this.relationship.getId())); - - this.relationshipRepo.deleteAll(); - - Assert.assertFalse(this.relationshipRepo.existsById(this.person.getId())); - } - - @Test - public void testDeleteById() { - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - Assert.assertTrue(this.relationshipRepo.existsById(this.relationship.getId())); - - this.relationshipRepo.deleteById(this.relationship.getId()); - - Assert.assertFalse(this.relationshipRepo.existsById(this.relationship.getId())); - } - - @Test - public void testDelete() { - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - Assert.assertTrue(this.relationshipRepo.existsById(this.relationship.getId())); - - this.relationshipRepo.delete(this.relationship); - - Assert.assertFalse(this.relationshipRepo.existsById(this.relationship.getId())); - } - - @Test - public void testDeleteAllIds() { - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - final List domains = Arrays.asList(this.relationship); - - this.relationshipRepo.deleteAll(domains); - - Assert.assertFalse(this.relationshipRepo.existsById(this.relationship.getId())); - } - - @Test - public void testSave() { - Assert.assertFalse(this.relationshipRepo.existsById(this.relationship.getId())); - - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - Assert.assertTrue(this.relationshipRepo.existsById(this.relationship.getId())); - } - - @Test - public void testSaveAll() { - Assert.assertFalse(this.relationshipRepo.existsById(this.relationship.getId())); - - final List domains = Arrays.asList(this.relationship); - - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.saveAll(domains); - - Assert.assertTrue(this.relationshipRepo.existsById(this.relationship.getId())); - } - - @Test - public void testFindById() { - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - final Relationship foundRelationship = this.relationshipRepo.findById(this.relationship.getId()).get(); - - Assert.assertNotNull(foundRelationship); - Assert.assertEquals(foundRelationship.getId(), this.relationship.getId()); - Assert.assertEquals(foundRelationship.getName(), this.relationship.getName()); - - Assert.assertFalse(this.relationshipRepo.findById(this.person.getId()).isPresent()); - } - - @Test - public void testExistById() { - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - Assert.assertFalse(this.relationshipRepo.existsById(this.person.getId())); - Assert.assertTrue(this.relationshipRepo.existsById(this.relationship.getId())); - } - - - @Test - public void testFindAllById() { - final List domains = Arrays.asList(this.relationship); - final List ids = Arrays.asList(this.relationship.getId()); - - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.saveAll(domains); - - final List foundDomains = (List) this.relationshipRepo.findAllById(ids); - - domains.sort((a, b) -> (a.getId().compareTo(b.getId()))); - foundDomains.sort((a, b) -> (a.getId().compareTo(b.getId()))); - - Assert.assertArrayEquals(domains.toArray(), foundDomains.toArray()); - } - - @Test - public void testVertexCount() { - Assert.assertEquals(this.personRepo.count(), 0); - Assert.assertEquals(this.projectRepo.edgeCount(), 0); - Assert.assertEquals(this.relationshipRepo.vertexCount(), 0); - - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - Assert.assertEquals(this.personRepo.vertexCount(), 3); - Assert.assertEquals(this.projectRepo.vertexCount(), 3); - Assert.assertEquals(this.relationshipRepo.edgeCount(), 1); - Assert.assertEquals(this.relationshipRepo.count(), 4); - } - - @Test - public void testRelationshipFindByName() { - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - final List relationships = this.relationshipRepo.findByLocation(this.relationship.getLocation()); - - Assert.assertEquals(relationships.size(), 1); - Assert.assertEquals(relationships.get(0), this.relationship); - - this.relationshipRepo.deleteAll(); - - Assert.assertTrue(this.relationshipRepo.findByLocation(this.relationship.getLocation()).isEmpty()); - } - - @Test - public void testDeleteAllByType() { - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - this.relationshipRepo.deleteAll(GremlinEntityType.EDGE); - - Assert.assertFalse(this.relationshipRepo.findById(this.relationship.getId()).isPresent()); - Assert.assertTrue(this.personRepo.existsById(this.person.getId())); - Assert.assertTrue(this.personRepo.existsById(this.person0.getId())); - Assert.assertTrue(this.projectRepo.existsById(this.project.getId())); - } - - @Test - public void testDeleteAllByClass() { - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.deleteAll(Relationship.class); - - Assert.assertFalse(this.relationshipRepo.findById(this.relationship.getId()).isPresent()); - Assert.assertTrue(this.personRepo.findById(this.person0.getId()).isPresent()); - Assert.assertTrue(this.projectRepo.findById(this.project.getId()).isPresent()); - } - - @Test - public void testFindByNameAndLocation() { - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - - final List domains = this.relationshipRepo.findByNameAndLocation(relationship.getName(), - relationship.getLocation()); - - Assert.assertEquals(domains.size(), 1); - Assert.assertEquals(domains.get(0), this.relationship); - Assert.assertTrue(relationshipRepo.findByNameAndLocation(relationship.getName(), "faker").isEmpty()); - } - - @Test - public void testByNameOrId() { - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - this.relationshipRepo.save(this.relationship); - this.relationshipRepo.save(this.relationship0); - - final List domains = Arrays.asList(this.relationship, this.relationship0); - List foundDomains = relationshipRepo.findByNameOrId(relationship.getName(), - relationship0.getId()); - - domains.sort(Comparator.comparing(Relationship::getId)); - foundDomains.sort(Comparator.comparing(Relationship::getId)); - - Assert.assertEquals(foundDomains.size(), 2); - Assert.assertEquals(foundDomains, domains); - - foundDomains = this.relationshipRepo.findByNameOrId("fake-name", relationship0.getId()); - - Assert.assertEquals(foundDomains.size(), 1); - Assert.assertEquals(foundDomains.get(0), this.relationship0); - } - - @Test - public void testFindAll() { - this.personRepo.save(this.person0); - this.personRepo.save(this.person); - this.projectRepo.save(this.project); - - final List relationships = Arrays.asList(this.relationship, this.relationship0); - - this.relationshipRepo.saveAll(relationships); - - final List foundRelationships = Lists.newArrayList(this.relationshipRepo.findAll()); - - foundRelationships.sort(Comparator.comparing(Relationship::getId)); - relationships.sort(Comparator.comparing(Relationship::getId)); - - Assert.assertEquals(foundRelationships, relationships); - - this.relationshipRepo.deleteAll(); - - Assert.assertFalse(this.relationshipRepo.findAll().iterator().hasNext()); - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/ServiceRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/ServiceRepositoryIT.java deleted file mode 100644 index 4d82bb81..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/ServiceRepositoryIT.java +++ /dev/null @@ -1,460 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Service; -import com.microsoft.spring.data.gremlin.common.domain.ServiceType; -import com.microsoft.spring.data.gremlin.common.domain.SimpleDependency; -import com.microsoft.spring.data.gremlin.common.repository.ServiceRepository; -import com.microsoft.spring.data.gremlin.common.repository.SimpleDependencyRepository; -import lombok.SneakyThrows; -import org.junit.*; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.text.SimpleDateFormat; -import java.util.*; - -import static com.microsoft.spring.data.gremlin.common.domain.ServiceType.BACK_END; -import static com.microsoft.spring.data.gremlin.common.domain.ServiceType.FRONT_END; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class ServiceRepositoryIT { - - private static Service serviceA; - private static Service serviceB; - private static Service serviceC; - - private static Date createDateA; - private static Date createDateB; - private static Date createDateC; - - private static final Map PROPERTIES_A = new HashMap<>(); - private static final Map PROPERTIES_B = new HashMap<>(); - private static final Map PROPERTIES_C = new HashMap<>(); - - private static final String ID_A = "1234"; - private static final String ID_B = "8731"; - private static final String ID_C = "5781"; - - private static final int COUNT_A = 2; - private static final int COUNT_B = 8; - private static final int COUNT_C = 2; - - private static final String NAME_A = "name-A"; - private static final String NAME_B = "name-B"; - private static final String NAME_C = "name-A"; - - @Autowired - private ServiceRepository repository; - - @Autowired - private SimpleDependencyRepository dependencyRepo; - - @BeforeClass - @SneakyThrows - public static void initialize() { - PROPERTIES_B.put("serviceB-port", 8761); - PROPERTIES_B.put("priority", "high"); - PROPERTIES_B.put("enabled-hystrix", false); - - PROPERTIES_A.put("serviceA-port", 8888); - PROPERTIES_A.put("serviceB-port", 8761); - PROPERTIES_A.put("priority", "highest"); - - PROPERTIES_C.put("serviceC-port", 8090); - PROPERTIES_C.put("serviceB-port", 8761); - PROPERTIES_C.put("priority", "medium"); - - createDateA = new SimpleDateFormat("yyyyMMdd").parse("20180601"); - createDateB = new SimpleDateFormat("yyyyMMdd").parse("20180603"); - createDateC = new SimpleDateFormat("yyyyMMdd").parse("20180503"); - - serviceA = new Service(ID_A, COUNT_A, true, NAME_A, FRONT_END, createDateA, PROPERTIES_A); - serviceB = new Service(ID_B, COUNT_B, false, NAME_B, BACK_END, createDateB, PROPERTIES_B); - serviceC = new Service(ID_C, COUNT_C, false, NAME_C, BACK_END, createDateC, PROPERTIES_C); - } - - @Before - public void setup() { - this.repository.deleteAll(); - } - - @After - public void cleanup() { - this.repository.deleteAll(); - } - - @Test - public void testQueries() { - Assert.assertFalse(this.repository.findById(serviceA.getId()).isPresent()); - Assert.assertFalse(this.repository.findById(serviceB.getId()).isPresent()); - - this.repository.save(serviceA); - this.repository.save(serviceB); - - Optional foundOptional = this.repository.findById(serviceA.getId()); - Assert.assertTrue(foundOptional.isPresent()); - Assert.assertEquals(foundOptional.get(), serviceA); - - foundOptional = this.repository.findById(serviceB.getId()); - Assert.assertTrue(foundOptional.isPresent()); - Assert.assertEquals(foundOptional.get(), serviceB); - - this.repository.deleteById(serviceA.getId()); - this.repository.deleteById(serviceB.getId()); - - Assert.assertFalse(this.repository.findById(serviceA.getId()).isPresent()); - Assert.assertFalse(this.repository.findById(serviceB.getId()).isPresent()); - } - - @Test - public void testEdgeFromToStringId() { - final SimpleDependency depend = new SimpleDependency("fakeId", "faked", serviceA.getId(), serviceB.getId()); - - this.repository.save(serviceA); - this.repository.save(serviceB); - this.dependencyRepo.save(depend); - - final Optional foundOptional = this.dependencyRepo.findById(depend.getId()); - Assert.assertTrue(foundOptional.isPresent()); - Assert.assertEquals(foundOptional.get(), depend); - - this.dependencyRepo.delete(foundOptional.get()); - - Assert.assertTrue(this.repository.findById(serviceA.getId()).isPresent()); - Assert.assertTrue(this.repository.findById(serviceB.getId()).isPresent()); - } - - @Test - public void testFindByName() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = this.repository.findByName(serviceA.getName()); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceA); - - this.repository.deleteAll(); - - Assert.assertTrue(this.repository.findByName(serviceA.getName()).isEmpty()); - } - - @Test - public void testFindByInstanceCount() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = this.repository.findByInstanceCount(serviceB.getInstanceCount()); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceB); - - this.repository.deleteAll(); - - Assert.assertTrue(this.repository.findByInstanceCount(serviceB.getInstanceCount()).isEmpty()); - } - - @Test - public void testFindByIsActive() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = this.repository.findByActive(serviceB.isActive()); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceB); - - this.repository.deleteAll(); - - Assert.assertTrue(this.repository.findByActive(serviceB.isActive()).isEmpty()); - } - - @Test - public void testFindByCreateAt() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = this.repository.findByCreateAt(serviceA.getCreateAt()); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceA); - - this.repository.deleteAll(); - - Assert.assertTrue(this.repository.findByCreateAt(serviceB.getCreateAt()).isEmpty()); - } - - @Test - public void testFindByProperties() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = this.repository.findByProperties(serviceB.getProperties()); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceB); - - this.repository.deleteAll(); - - Assert.assertTrue(this.repository.findByProperties(serviceB.getProperties()).isEmpty()); - } - - @Test - public void testFindById() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final Optional foundConfig = this.repository.findById(serviceA.getId()); - final Optional foundEureka = this.repository.findById(serviceB.getId()); - - Assert.assertTrue(foundConfig.isPresent()); - Assert.assertTrue(foundEureka.isPresent()); - - Assert.assertEquals(foundConfig.get(), serviceA); - Assert.assertEquals(foundEureka.get(), serviceB); - } - - @Test - public void testFindByNameAndInstanceCount() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = repository.findByNameAndInstanceCount(NAME_B, COUNT_B); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceB); - Assert.assertTrue(repository.findByNameAndInstanceCount(NAME_B, COUNT_A).isEmpty()); - } - - @Test - public void testFindByNameAndInstanceCountAndType() { - this.repository.save(serviceA); - this.repository.save(serviceB); - - final List services = repository.findByNameAndInstanceCountAndType(NAME_B, COUNT_B, BACK_END); - - Assert.assertEquals(services.size(), 1); - Assert.assertEquals(services.get(0), serviceB); - Assert.assertTrue(repository.findByNameAndInstanceCountAndType(NAME_B, COUNT_A, ServiceType.BOTH).isEmpty()); - } - - @Test - public void testFindByNameOrInstanceCount() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - List foundServices = repository.findByNameOrInstanceCount(NAME_A, COUNT_B); - - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - foundServices = repository.findByNameOrInstanceCount("fake-name", COUNT_A); - - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceA); - } - - @Test - public void testFindByNameAndIsActiveOrProperties() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - List foundServices = repository.findByNameAndActiveOrProperties(NAME_A, true, PROPERTIES_B); - - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - foundServices = repository.findByNameAndActiveOrProperties(NAME_B, false, new HashMap<>()); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceB); - } - - @Test - public void testFindByNameOrInstanceCountAndType() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - List foundServices = repository.findByNameOrInstanceCountAndType(NAME_A, COUNT_B, BACK_END); - - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - foundServices = repository.findByNameOrInstanceCountAndType(NAME_B, COUNT_A, BACK_END); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceB); - } - - @Test - public void testFindByNameAndInstanceCountOrType() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - List foundServices = repository.findByNameAndInstanceCountOrType(NAME_A, COUNT_A, BACK_END); - - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - foundServices = repository.findByNameAndInstanceCountOrType(NAME_A, COUNT_B, BACK_END); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceB); - } - - @Test - public void testExistsByName() { - final List services = Arrays.asList(serviceA, serviceB, serviceC); - this.repository.saveAll(services); - - final List foundServices = repository.findByActiveExists(); - - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceA); - - this.repository.deleteAll(); - - Assert.assertTrue(repository.findByActiveExists().isEmpty()); - } - - @Test - @SneakyThrows - public void testFindByCreateAtAfter() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - Date testDate = new SimpleDateFormat("yyyyMMdd").parse("20180602"); - List foundServices = repository.findByCreateAtAfter(testDate); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceB); - - testDate = new SimpleDateFormat("yyyyMMdd").parse("20180502"); - foundServices = repository.findByCreateAtAfter(testDate); - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - testDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - foundServices = repository.findByCreateAtAfter(testDate); - Assert.assertTrue(foundServices.isEmpty()); - } - - @Test - @SneakyThrows - public void testFindByNameOrTypeAndInstanceCountAndCreateAtAfter() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - Date testDate = new SimpleDateFormat("yyyyMMdd").parse("20180601"); - List foundServices = repository.findByNameOrTypeAndInstanceCountAndCreateAtAfter(NAME_A, - serviceB.getType(), COUNT_B, testDate); - - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - testDate = new SimpleDateFormat("yyyyMMdd").parse("20180607"); - foundServices = repository.findByNameOrTypeAndInstanceCountAndCreateAtAfter(NAME_A, serviceB.getType(), COUNT_B, - testDate); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceA); - Assert.assertTrue(repository.findByNameOrTypeAndInstanceCountAndCreateAtAfter("fake-name", serviceB.getType(), - COUNT_B, testDate).isEmpty()); - } - - @Test - @SneakyThrows - public void testFindByCreateAtBefore() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - Date testDate = new SimpleDateFormat("yyyyMMdd").parse("20180602"); - List foundServices = repository.findByCreateAtBefore(testDate); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceA); - - testDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - foundServices = repository.findByCreateAtBefore(testDate); - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - testDate = new SimpleDateFormat("yyyyMMdd").parse("20180506"); - foundServices = repository.findByCreateAtBefore(testDate); - Assert.assertTrue(foundServices.isEmpty()); - } - - @Test - @SneakyThrows - public void testFindByCreateAtBeforeAndCreateAtAfter() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - Date startDate = new SimpleDateFormat("yyyyMMdd").parse("20180602"); - Date endDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - List foundServices = repository.findByCreateAtAfterAndCreateAtBefore(startDate, endDate); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceB); - - startDate = new SimpleDateFormat("yyyyMMdd").parse("20180506"); - endDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - foundServices = repository.findByCreateAtAfterAndCreateAtBefore(startDate, endDate); - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - startDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - endDate = new SimpleDateFormat("yyyyMMdd").parse("20180607"); - foundServices = repository.findByCreateAtAfterAndCreateAtBefore(startDate, endDate); - Assert.assertTrue(foundServices.isEmpty()); - } - - @Test - @SneakyThrows - public void testFindByCreateAtBetween() { - final List services = Arrays.asList(serviceA, serviceB); - this.repository.saveAll(services); - - Date startDate = new SimpleDateFormat("yyyyMMdd").parse("20180602"); - Date endDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - List foundServices = repository.findByCreateAtBetween(startDate, endDate); - Assert.assertEquals(foundServices.size(), 1); - Assert.assertEquals(foundServices.get(0), serviceB); - - startDate = new SimpleDateFormat("yyyyMMdd").parse("20180601"); - endDate = new SimpleDateFormat("yyyyMMdd").parse("20180604"); - foundServices = repository.findByCreateAtBetween(startDate, endDate); - services.sort(Comparator.comparing(Service::getId)); - foundServices.sort(Comparator.comparing(Service::getId)); - Assert.assertEquals(foundServices.size(), 2); - Assert.assertEquals(foundServices, services); - - startDate = new SimpleDateFormat("yyyyMMdd").parse("20180606"); - endDate = new SimpleDateFormat("yyyyMMdd").parse("20180607"); - foundServices = repository.findByCreateAtBetween(startDate, endDate); - Assert.assertTrue(foundServices.isEmpty()); - } -} - diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/StudentRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/StudentRepositoryIT.java deleted file mode 100644 index 3a3ed8c2..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/StudentRepositoryIT.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.GremlinEntityType; -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.Student; -import com.microsoft.spring.data.gremlin.common.repository.StudentRepository; -import lombok.NonNull; -import org.assertj.core.util.Lists; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class StudentRepositoryIT { - - private static final Long ID_0 = 12349274637234L; - private static final Long ID_1 = 1L; - private static final Long ID_2 = 2L; - private static final Long NO_EXIST_ID = -1L; - - private static final String NAME_0 = "name-0"; - private static final String NAME_1 = "name-1"; - private static final String NAME_2 = "name-2"; - private static final String NO_EXIST_NAME = "no-exist-name"; - - private static final Student STUDENT_0 = new Student(ID_0, NAME_0); - private static final Student STUDENT_1 = new Student(ID_1, NAME_1); - private static final Student STUDENT_2 = new Student(ID_2, NAME_2); - - private static final List STUDENTS = Arrays.asList(STUDENT_0, STUDENT_1, STUDENT_2); - - @Autowired - private StudentRepository repository; - - @Before - public void setup() { - this.repository.deleteAll(); - } - - private void assertDomainListEquals(@NonNull List found, @NonNull List expected) { - found.sort(Comparator.comparing(Student::getId)); - expected.sort(Comparator.comparing(Student::getId)); - - Assert.assertEquals(found.size(), expected.size()); - Assert.assertEquals(found, expected); - } - - @Test - public void testDeleteAll() { - repository.saveAll(STUDENTS); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(); - - Assert.assertFalse(repository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnType() { - repository.saveAll(STUDENTS); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(GremlinEntityType.EDGE); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(GremlinEntityType.VERTEX); - - Assert.assertFalse(repository.findAll().iterator().hasNext()); - } - - @Test - public void testDeleteAllOnDomain() { - repository.saveAll(STUDENTS); - - Assert.assertTrue(repository.findAll().iterator().hasNext()); - - repository.deleteAll(Student.class); - - Assert.assertFalse(repository.findAll().iterator().hasNext()); - } - - @Test - public void testSave() { - repository.save(STUDENT_0); - - Assert.assertTrue(repository.findById(STUDENT_0.getId()).isPresent()); - Assert.assertFalse(repository.findById(STUDENT_1.getId()).isPresent()); - } - - @Test - public void testSaveAll() { - repository.saveAll(STUDENTS); - - final List found = Lists.newArrayList(repository.findAll()); - - assertDomainListEquals(found, STUDENTS); - } - - @Test - public void testFindById() { - repository.saveAll(STUDENTS); - - Optional optional = repository.findById(STUDENT_0.getId()); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(optional.get(), STUDENT_0); - - optional = repository.findById(NO_EXIST_ID); - - Assert.assertFalse(optional.isPresent()); - } - - @Test - public void testExistsById() { - repository.saveAll(STUDENTS); - - Assert.assertTrue(repository.existsById(STUDENT_0.getId())); - Assert.assertFalse(repository.existsById(NO_EXIST_ID)); - } - - @Test - public void testFindAllById() { - final List expected = Arrays.asList(STUDENT_0, STUDENT_1); - final List ids = Arrays.asList(STUDENT_0.getId(), STUDENT_1.getId(), NO_EXIST_ID); - - repository.saveAll(STUDENTS); - - final List found = Lists.newArrayList(repository.findAllById(ids)); - - assertDomainListEquals(found, expected); - - Assert.assertFalse(repository.findAllById(Collections.singleton(NO_EXIST_ID)).iterator().hasNext()); - } - - @Test - public void testCount() { - repository.saveAll(STUDENTS); - - Assert.assertEquals(repository.count(), STUDENTS.size()); - - repository.deleteAll(); - - Assert.assertEquals(repository.count(), 0); - } - - @Test - public void testDeleteById() { - repository.saveAll(STUDENTS); - - Assert.assertTrue(repository.findById(STUDENT_0.getId()).isPresent()); - - repository.deleteById(STUDENT_0.getId()); - - Assert.assertFalse(repository.findById(STUDENT_0.getId()).isPresent()); - } - - @Test - public void testVertexCount() { - repository.saveAll(STUDENTS); - - Assert.assertEquals(repository.vertexCount(), STUDENTS.size()); - } - - @Test - public void testEdgeCount() { - repository.saveAll(STUDENTS); - - Assert.assertEquals(repository.edgeCount(), 0); - } - - @Test - public void testFindByName() { - repository.saveAll(STUDENTS); - - Assert.assertTrue(repository.findByName(NO_EXIST_NAME).isEmpty()); - Assert.assertEquals(repository.findByName(STUDENT_0.getName()).size(), 1); - Assert.assertEquals(repository.findByName(STUDENT_0.getName()).get(0), STUDENT_0); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/UserDomainRepositoryIT.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/UserDomainRepositoryIT.java deleted file mode 100644 index c043d4a3..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/UserDomainRepositoryIT.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository; - -import com.microsoft.spring.data.gremlin.common.TestRepositoryConfiguration; -import com.microsoft.spring.data.gremlin.common.domain.UserDomain; -import com.microsoft.spring.data.gremlin.common.repository.UserDomainRepository; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = TestRepositoryConfiguration.class) -public class UserDomainRepositoryIT { - - private static final String NAME_0 = "incarnation"; - private static final String NAME_1 = "absolute"; - private static final String NAME_2 = "test_name"; - private static final int LEVEL_0 = 4; - private static final int LEVEL_1 = 7; - private static final int LEVEL_2 = 7; - private static final UserDomain DOMAIN_0 = new UserDomain(NAME_0, LEVEL_0, true); - private static final UserDomain DOMAIN_1 = new UserDomain(NAME_1, LEVEL_1, true); - private static final UserDomain DOMAIN_2 = new UserDomain(NAME_2, LEVEL_2, false); - - @Autowired - private UserDomainRepository repository; - - @Before - public void setup() { - this.repository.deleteAll(); - } - - @Test - public void testWithNoIdName() { - Assert.assertEquals(0, this.repository.vertexCount()); - Assert.assertFalse(this.repository.findById(NAME_0).isPresent()); - - this.repository.save(DOMAIN_0); - final Optional optional = this.repository.findById(NAME_0); - - Assert.assertTrue(optional.isPresent()); - Assert.assertEquals(DOMAIN_0.getName(), optional.get().getName()); - Assert.assertEquals(DOMAIN_0.getLevel(), optional.get().getLevel()); - - this.repository.deleteById(NAME_0); - Assert.assertFalse(this.repository.findById(NAME_0).isPresent()); - } - - @Test - public void testFindByName() { - this.repository.save(DOMAIN_0); - - final List domains = this.repository.findByName(DOMAIN_0.getName()); - - Assert.assertEquals(domains.size(), 1); - Assert.assertEquals(domains.get(0), DOMAIN_0); - - this.repository.deleteAll(); - - Assert.assertTrue(this.repository.findByName(DOMAIN_0.getName()).isEmpty()); - } - - @Test - public void testFindByEnabledExists() { - final List domains = Arrays.asList(DOMAIN_0, DOMAIN_1); - - this.repository.saveAll(domains); - this.repository.save(DOMAIN_2); - - final List foundDomains = this.repository.findByEnabledExists(); - - domains.sort(Comparator.comparing(UserDomain::getName)); - foundDomains.sort(Comparator.comparing(UserDomain::getName)); - - Assert.assertEquals(foundDomains.size(), domains.size()); - Assert.assertEquals(foundDomains, domains); - - this.repository.deleteAll(domains); - - Assert.assertTrue(this.repository.findByEnabledExists().isEmpty()); - } - - @Test - public void testFindByLevelBetween() { - final List domains = Arrays.asList(DOMAIN_0, DOMAIN_1); - - this.repository.saveAll(domains); - - List foundDomains = this.repository.findByLevelBetween(8, 9); - Assert.assertTrue(foundDomains.isEmpty()); - - foundDomains = this.repository.findByLevelBetween(7, 8); - Assert.assertEquals(foundDomains.size(), 1); - Assert.assertEquals(foundDomains.get(0), DOMAIN_1); - - foundDomains = this.repository.findByLevelBetween(0, 8); - domains.sort(Comparator.comparing(UserDomain::getName)); - foundDomains.sort(Comparator.comparing(UserDomain::getName)); - - Assert.assertEquals(foundDomains.size(), domains.size()); - Assert.assertEquals(foundDomains, domains); - - this.repository.deleteAll(domains); - - Assert.assertTrue(this.repository.findByLevelBetween(0, 8).isEmpty()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtensionUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtensionUnitTest.java deleted file mode 100644 index 907b9097..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryConfigurationExtensionUnitTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.config; - -import com.microsoft.spring.data.gremlin.repository.GremlinRepository; -import org.apache.commons.lang3.NotImplementedException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.core.env.Environment; -import org.springframework.core.env.StandardEnvironment; -import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.type.StandardAnnotationMetadata; -import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; -import org.springframework.data.repository.config.RepositoryConfigurationSource; - -public class GremlinRepositoryConfigurationExtensionUnitTest { - - private static final String GREMLIN_MODULE_NAME = "Gremlin"; - private static final String GREMLIN_MODULE_PREFIX = "gremlin"; - private static final String GREMLIN_MAPPING_CONTEXT = "gremlinMappingContext"; - - private GremlinRepositoryConfigurationExtension extension; - - @Before - public void setup() { - this.extension = new GremlinRepositoryConfigurationExtension(); - } - - @Test - public void testGremlinRepositoryConfigurationExtensionGetters() { - Assert.assertEquals(this.extension.getModuleName(), GREMLIN_MODULE_NAME); - Assert.assertEquals(this.extension.getModulePrefix(), GREMLIN_MODULE_PREFIX); - Assert.assertEquals(this.extension.getIdentifyingTypes().size(), 1); - - Assert.assertSame(this.extension.getIdentifyingTypes().toArray()[0], GremlinRepository.class); - Assert.assertTrue(this.extension.getIdentifyingAnnotations().isEmpty()); - } - - @Test - public void testGremlinRepositoryConfigurationExtensionRegisterBeansForRoot() { - final ResourceLoader loader = new PathMatchingResourcePatternResolver(); - final Environment environment = new StandardEnvironment(); - final BeanDefinitionRegistry registry = new DefaultListableBeanFactory(); - final StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(GremlinConfig.class, true); - final RepositoryConfigurationSource config = new AnnotationRepositoryConfigurationSource(metadata, - EnableGremlinRepositories.class, loader, environment, registry); - - Assert.assertFalse(registry.containsBeanDefinition(GREMLIN_MAPPING_CONTEXT)); - - this.extension.registerBeansForRoot(registry, config); - - Assert.assertTrue(registry.containsBeanDefinition(GREMLIN_MAPPING_CONTEXT)); - } - - @Test(expected = NotImplementedException.class) - public void testGetRepositoryFactoryBeanClassNameException() { - this.extension.getRepositoryFactoryBeanClassName(); - } - - @EnableGremlinRepositories - private static class GremlinConfig { - - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrarUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrarUnitTest.java deleted file mode 100644 index fd0808fe..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/config/GremlinRepositoryRegistrarUnitTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.config; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class GremlinRepositoryRegistrarUnitTest { - - private GremlinRepositoryRegistrar registrar; - - @Before - public void setup() { - this.registrar = new GremlinRepositoryRegistrar(); - } - - @Test - public void testGremlinRepositoryRegistrarGetters() { - Assert.assertSame(this.registrar.getAnnotation(), EnableGremlinRepositories.class); - Assert.assertTrue(this.registrar.getExtension() instanceof GremlinRepositoryConfigurationExtension); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinEntityInformationUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinEntityInformationUnitTest.java deleted file mode 100644 index d6c2bf6f..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinEntityInformationUnitTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Network; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.domain.Relationship; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceEdge; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceGraph; -import com.microsoft.spring.data.gremlin.conversion.source.GremlinSourceVertex; -import com.microsoft.spring.data.gremlin.exception.GremlinInvalidEntityIdFieldException; -import com.microsoft.spring.data.gremlin.exception.GremlinUnexpectedEntityTypeException; -import lombok.Data; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.data.annotation.Id; - -import java.util.Date; - -public class GremlinEntityInformationUnitTest { - - @Test - public void testVertexEntityInformation() { - final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - final GremlinEntityInformation personInfo = new GremlinEntityInformation<>(Person.class); - - Assert.assertNotNull(personInfo.getIdField()); - Assert.assertEquals(personInfo.getId(person), TestConstants.VERTEX_PERSON_ID); - Assert.assertEquals(personInfo.getIdType(), String.class); - Assert.assertTrue(personInfo.createGremlinSource() instanceof GremlinSourceVertex); - } - - @Test - public void testEdgeEntityInformation() { - final GremlinEntityInformation relationshipInfo = - new GremlinEntityInformation(Relationship.class); - - Assert.assertNotNull(relationshipInfo.getIdField()); - Assert.assertTrue(relationshipInfo.createGremlinSource() instanceof GremlinSourceEdge); - } - - @Test - public void testGraphEntityInformation() { - final GremlinEntityInformation networkInfo = new GremlinEntityInformation(Network.class); - - Assert.assertNotNull(networkInfo.getIdField()); - Assert.assertTrue(networkInfo.createGremlinSource() instanceof GremlinSourceGraph); - } - - @Test(expected = GremlinUnexpectedEntityTypeException.class) - public void testEntityInformationException() { - new GremlinEntityInformation(TestDomain.class).createGremlinSource(); - } - - @Test(expected = GremlinInvalidEntityIdFieldException.class) - public void testEntityInformationNoIdException() { - new GremlinEntityInformation(TestNoIdDomain.class); - } - - @Test(expected = GremlinInvalidEntityIdFieldException.class) - public void testEntityInformationMultipleIdException() { - new GremlinEntityInformation(TestMultipleIdDomain.class); - } - - @Test(expected = GremlinInvalidEntityIdFieldException.class) - public void testEntityInformationNoStringIdException() { - new GremlinEntityInformation(TestNoStringIdDomain.class); - } - - @Test(expected = GremlinInvalidEntityIdFieldException.class) - public void testEntityInformationIdFieldAndIdAnnotation() { - new GremlinEntityInformation(TestIdFieldAndIdAnnotation.class); - } - - @Data - private class TestDomain { - private String id; - } - - @Data - private class TestNoIdDomain { - private String name; - } - - @Data - private class TestMultipleIdDomain { - @Id - private String name; - - @Id - private String location; - } - - @Data - private class TestIdFieldAndIdAnnotation { - @Id - private String name; - - @Id - private String where; - } - - @Data - private class TestNoStringIdDomain { - @Id - private Date date; - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBeanUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBeanUnitTest.java deleted file mode 100644 index f27f8caf..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryBeanUnitTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import com.microsoft.spring.data.gremlin.common.TestConstants; -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.common.repository.PersonRepository; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -public class GremlinRepositoryFactoryBeanUnitTest { - - @Autowired - private ApplicationContext context; - - private GremlinRepositoryFactoryBean factoryBean; - - @Before - @SuppressWarnings("unchecked") - public void setup() { - this.factoryBean = new GremlinRepositoryFactoryBean(PersonRepository.class); - } - - @Test - public void testGetFactoryInstance() { - final Person person = new Person(TestConstants.VERTEX_PERSON_ID, TestConstants.VERTEX_PERSON_NAME); - final RepositoryFactorySupport factorySupport = this.factoryBean.getFactoryInstance(this.context); - - Assert.assertNotNull(factorySupport); - Assert.assertEquals(factorySupport.getEntityInformation(Person.class).getIdType(), String.class); - Assert.assertEquals(factorySupport.getEntityInformation(Person.class).getId(person), person.getId()); - } -} diff --git a/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryUnitTest.java b/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryUnitTest.java deleted file mode 100644 index 1e9dfc74..00000000 --- a/src/test/java/com/microsoft/spring/data/gremlin/repository/support/GremlinRepositoryFactoryUnitTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for - * license information. - */ -package com.microsoft.spring.data.gremlin.repository.support; - -import com.microsoft.spring.data.gremlin.common.domain.Person; -import com.microsoft.spring.data.gremlin.query.GremlinOperations; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.repository.core.EntityInformation; -import org.springframework.data.repository.query.QueryLookupStrategy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.Optional; - -@RunWith(SpringJUnit4ClassRunner.class) -public class GremlinRepositoryFactoryUnitTest { - - @Mock - private GremlinOperations operations; - - @Autowired - private ApplicationContext context; - - private GremlinRepositoryFactory factory; - - @Before - public void setup() { - this.factory = new GremlinRepositoryFactory(this.operations, this.context); - } - - @Test - public void testGetRepositoryBaseClass() { - Assert.assertEquals(SimpleGremlinRepository.class, this.factory.getRepositoryBaseClass(null)); - } - - @Test - public void testGetEntityInformation() { - final EntityInformation information = this.factory.getEntityInformation(Person.class); - - Assert.assertNotNull(information); - Assert.assertEquals(information.getIdType(), String.class); - } - - @Test - public void testGetQueryLookupStrategy() { - final Optional strategyOptional = this.factory. - getQueryLookupStrategy(QueryLookupStrategy.Key.CREATE, null); - - Assert.assertTrue(strategyOptional.isPresent()); - } -} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties deleted file mode 100644 index 57bb8d4f..00000000 --- a/src/test/resources/application.properties +++ /dev/null @@ -1,8 +0,0 @@ -gremlin.endpoint=localhost -gremlin.port=8889 -gremlin.username=${your-username} -gremlin.password=${your-password} -gremlin.sslEnabled=false - -## Valid serializer(case sensitive): GRAPHSON(default), GRAPHSON_V1D0, GRAPHSON_V2D0, GRYO_V1D0, GRYO_LITE_V1D0 -# gremlin.serializer=GRAPHSON diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml deleted file mode 100644 index 8fbe6f97..00000000 --- a/src/test/resources/application.yml +++ /dev/null @@ -1,6 +0,0 @@ -gremlin: - endpoint: endpoint.gremlin.cosmosdb.azure.com - port: 443 - username: /dbs/database/colls/collection - password: password - telemetryAllowed: true diff --git a/src/test/resources/telemetry.config b/src/test/resources/telemetry.config deleted file mode 100644 index 61b615fa..00000000 --- a/src/test/resources/telemetry.config +++ /dev/null @@ -1 +0,0 @@ -telemetry.instrumentationKey=@telemetry.instrumentationKey@ \ No newline at end of file