Skip to content

Commit

Permalink
craetes test in test
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Sep 1, 2019
1 parent 970750d commit 12135fb
Showing 1 changed file with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static java.util.stream.Collectors.toList;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -59,7 +62,6 @@ public void after() {
getGraph().traversal().E().toList().forEach(Edge::remove);
}


@Test
public void shouldReturnErrorWhenThereIsNotId() {
assertThrows(IdNotFoundException.class, () -> {
Expand All @@ -73,18 +75,33 @@ public void shouldReturnErrorWhenEntityIsNull() {
assertThrows(NullPointerException.class, () -> getGraphTemplate().insert(null));
}


@Test
public void shouldInsertAnEntity() {
Person person = builder().withAge()
.withName("Otavio").build();
Person updated = getGraphTemplate().insert(person);

assertNotNull(updated.getId());

getGraphTemplate().delete(updated.getId());
}

@Test
public void shouldInsertEntities() {
Person otavio = builder().withAge()
.withName("Otavio").build();

Person poliana = builder().withAge()
.withName("Poliana").build();

final Iterable<Person> people = getGraphTemplate()
.insert(Arrays.asList(otavio, poliana));

final boolean allHasId = StreamSupport.stream(people.spliterator(), false)
.map(Person::getId)
.allMatch(Objects::nonNull);
assertTrue(allHasId);
}

@Test
public void shouldMergeOnInsert() {
Person person = builder().withAge()
Expand All @@ -93,7 +110,6 @@ public void shouldMergeOnInsert() {
assertTrue(person == updated);
}


@Test
public void shouldGetErrorWhenIdIsNullWhenUpdate() {
assertThrows(IllegalStateException.class, () -> {
Expand Down Expand Up @@ -131,6 +147,29 @@ public void shouldUpdate() {
getGraphTemplate().delete(update.getId());
}

@Test
public void shouldUpdateEntities() {
Person otavio = builder().withAge()
.withName("Otavio").build();

Person poliana = builder().withAge()
.withName("Poliana").build();

final Iterable<Person> insertPeople = getGraphTemplate().insert(Arrays.asList(otavio, poliana));

final List<Person> newPeople = StreamSupport.stream(insertPeople.spliterator(), false)
.map(p -> builder().withAge().withId(p.getId()).withName(p.getName() + " updated").build())
.collect(toList());

final Iterable<Person> update = getGraphTemplate().update(newPeople);

final boolean allUpdated = StreamSupport.stream(update.spliterator(), false)
.map(Person::getName).allMatch(name -> name.contains(" updated"));

assertTrue(allUpdated);
}


@Test
public void shouldMergeOnUpdate() {
Person person = builder().withAge()
Expand Down Expand Up @@ -181,6 +220,21 @@ public void shouldDeleteAnEntity() {
assertFalse(getGraphTemplate().find(person.getId()).isPresent());
}

@Test
public void shouldDeleteEntities() {

Person otavio = getGraphTemplate().insert(builder().withAge()
.withName("Otavio").build());

Person poliana = getGraphTemplate().insert(builder().withAge()
.withName("Poliana").build());

assertTrue(getGraphTemplate().find(otavio.getId()).isPresent());
getGraphTemplate().delete(Arrays.asList(otavio.getId(), poliana.getId()));
assertFalse(getGraphTemplate().find(otavio.getId()).isPresent());
assertFalse(getGraphTemplate().find(poliana.getId()).isPresent());
}

@Test
public void shouldReturnErrorWhenGetEdgesIdHasNullId() {
assertThrows(NullPointerException.class, () -> getGraphTemplate().getEdgesById(null, Direction.BOTH));
Expand Down

0 comments on commit 12135fb

Please sign in to comment.