Skip to content

Commit

Permalink
test: create integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed May 19, 2023
1 parent 04a0bef commit 68c1099
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum OrientDBDocumentConfigurations implements Supplier<String> {
/**
* The user's credential.
*/
USER("jnosql.orientdb.-user"),
USER("jnosql.orientdb.user"),
/**
* The password's credential
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public enum DocumentDatabase implements Supplier<OrientDBDocumentManagerFactory>
public OrientDBDocumentManagerFactory get() {
return configuration.apply(Settings.builder().build());
}

public OrientDBDocumentManager get(String database){
OrientDBDocumentManagerFactory managerFactory = get();
return managerFactory.apply(database);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.databases.orientdb.integration;

import jakarta.nosql.Column;
import jakarta.nosql.Entity;
import jakarta.nosql.Id;

@Entity
public record Book(@Id String id, @Column("title") String title, @Column("edition") int edition) {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.databases.orientdb.integration;


import jakarta.inject.Inject;
import org.eclipse.jnosql.databases.orientdb.communication.DocumentDatabase;
import org.eclipse.jnosql.databases.orientdb.mapping.OrientDBTemplate;
import org.eclipse.jnosql.mapping.Convert;
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension;
import org.jboss.weld.junit5.auto.AddExtensions;
import org.jboss.weld.junit5.auto.AddPackages;
import org.jboss.weld.junit5.auto.EnableAutoWeld;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;

import java.util.Optional;

import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;

@EnableAutoWeld
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
@AddPackages(Book.class)
@AddPackages(OrientDBTemplate.class)
@AddExtensions({EntityMetadataExtension.class,
DocumentExtension.class})
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
class OrientDBTemplateIntegrationTest {

@Inject
private OrientDBTemplate template;

static {
DocumentDatabase.INSTANCE.get("library");
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
}
@Test
public void shouldInsert() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
template.insert(book);
Optional<Book> optional = template.find(Book.class, book.id());
assertThat(optional).isNotNull().isNotEmpty()
.get().isEqualTo(book);
}

@Test
public void shouldUpdate() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
assertThat(template.insert(book))
.isNotNull()
.isEqualTo(book);

Book updated = new Book(book.id(), book.title() + " updated", 2);

assertThat(template.update(updated))
.isNotNull()
.isNotEqualTo(book);

assertThat(template.find(Book.class, book.id()))
.isNotNull().get().isEqualTo(updated);

}

@Test
public void shouldFindById() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
assertThat(template.insert(book))
.isNotNull()
.isEqualTo(book);

assertThat(template.find(Book.class, book.id()))
.isNotNull().get().isEqualTo(book);
}

@Test
public void shouldDelete() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
assertThat(template.insert(book))
.isNotNull()
.isEqualTo(book);

template.delete(Book.class, book.id());
assertThat(template.find(Book.class, book.id()))
.isNotNull().isEmpty();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.databases.orientdb.integration;


import com.orientechnologies.orient.core.db.ODatabaseType;
import jakarta.inject.Inject;
import jakarta.nosql.document.DocumentTemplate;
import org.eclipse.jnosql.databases.orientdb.communication.DocumentDatabase;
import org.eclipse.jnosql.databases.orientdb.communication.OrientDBDocumentConfigurations;
import org.eclipse.jnosql.mapping.Convert;
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension;
import org.jboss.weld.junit5.auto.AddExtensions;
import org.jboss.weld.junit5.auto.AddPackages;
import org.jboss.weld.junit5.auto.EnableAutoWeld;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;

import java.util.Optional;

import static com.orientechnologies.orient.core.db.ODatabaseType.PLOCAL;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;

@EnableAutoWeld
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
@AddPackages(Book.class)
@AddExtensions({EntityMetadataExtension.class,
DocumentExtension.class})
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
class TemplateIntegrationTest {

@Inject
private DocumentTemplate template;

static {
DocumentDatabase.INSTANCE.get("library");
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "jnosql");
System.setProperty(OrientDBDocumentConfigurations.HOST.get(), "/tmp/db/");
System.setProperty(OrientDBDocumentConfigurations.USER.get(), "root");
System.setProperty(OrientDBDocumentConfigurations.PASSWORD.get(), "rootpwd");
System.setProperty(OrientDBDocumentConfigurations.STORAGE_TYPE.get(), PLOCAL.toString());
}

@Test
public void shouldInsert() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
template.insert(book);
Optional<Book> optional = template.find(Book.class, book.id());
assertThat(optional).isNotNull().isNotEmpty()
.get().isEqualTo(book);
}

@Test
public void shouldUpdate() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
assertThat(template.insert(book))
.isNotNull()
.isEqualTo(book);

Book updated = new Book(book.id(), book.title() + " updated", 2);

assertThat(template.update(updated))
.isNotNull()
.isNotEqualTo(book);

assertThat(template.find(Book.class, book.id()))
.isNotNull().get().isEqualTo(updated);

}

@Test
public void shouldFindById() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
assertThat(template.insert(book))
.isNotNull()
.isEqualTo(book);

assertThat(template.find(Book.class, book.id()))
.isNotNull().get().isEqualTo(book);
}

@Test
public void shouldDelete() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
assertThat(template.insert(book))
.isNotNull()
.isEqualTo(book);

template.delete(Book.class, book.id());
assertThat(template.find(Book.class, book.id()))
.isNotNull().isEmpty();
}


}

0 comments on commit 68c1099

Please sign in to comment.