Skip to content

Commit

Permalink
test: create ingration test to hazelcast and key-value template
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 4f10789 commit a0b9600
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@


import jakarta.inject.Inject;
import org.assertj.core.api.Assertions;
import org.eclipse.jnosql.communication.Value;
import org.eclipse.jnosql.databases.hazelcast.communication.HazelcastConfigurations;
import org.eclipse.jnosql.databases.hazelcast.communication.model.User;
import org.eclipse.jnosql.databases.hazelcast.mapping.HazelcastTemplate;
import org.eclipse.jnosql.mapping.Convert;
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
Expand All @@ -30,24 +26,18 @@
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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@EnableAutoWeld
@AddPackages(value = {Convert.class, KeyValueEntityConverter.class})
@AddPackages(Book.class)
@AddPackages(HazelcastTemplate.class)
@AddExtensions({EntityMetadataExtension.class,
KeyValueExtension.class})
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
class HazelcastTemplateIntegrationTest {

@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.hazelcast.integration;


import jakarta.inject.Inject;
import jakarta.nosql.keyvalue.KeyValueTemplate;
import org.eclipse.jnosql.databases.hazelcast.mapping.HazelcastTemplate;
import org.eclipse.jnosql.mapping.Convert;
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
import org.eclipse.jnosql.mapping.keyvalue.KeyValueEntityConverter;
import org.eclipse.jnosql.mapping.keyvalue.spi.KeyValueExtension;
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 java.util.Optional;

import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;

@EnableAutoWeld
@AddPackages(value = {Convert.class, KeyValueEntityConverter.class})
@AddPackages(Book.class)
@AddPackages(HazelcastTemplate.class)
@AddExtensions({EntityMetadataExtension.class,
KeyValueExtension.class})
class KeyValueTemplateIntegrationTest {

@Inject
private KeyValueTemplate template;

static {
System.setProperty(MappingConfigurations.KEY_VALUE_DATABASE.get(), "library");
}

@Test
public void shouldPutValue() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
template.put(book);
Optional<Book> effective = template.get(book.id(), Book.class);
assertThat(effective)
.isNotNull()
.isPresent()
.get().isEqualTo(book);
}

@Test
public void shouldGet() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
template.put(book);
Optional<Book> effective = template.get(book.id(), Book.class);
assertThat(effective)
.isNotNull()
.isPresent()
.get().isEqualTo(book);
}

@Test
public void shouldDelete() {
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
template.put(book);
Optional<Book> effective = template.get(book.id(), Book.class);
assertThat(effective)
.isNotNull()
.isPresent()
.get().isEqualTo(book);
template.delete(Book.class, book.id());

assertThat(template.get(book.id(), Book.class))
.isEmpty();
}
}

0 comments on commit a0b9600

Please sign in to comment.