@@ -11,3 +16,5 @@
+
+
diff --git a/src/main/webapp/app/shared/alert/alert-error.component.ts b/src/main/webapp/app/shared/alert/alert-error.component.ts
index a540625..d82eae0 100644
--- a/src/main/webapp/app/shared/alert/alert-error.component.ts
+++ b/src/main/webapp/app/shared/alert/alert-error.component.ts
@@ -72,6 +72,10 @@ export class AlertErrorComponent implements OnDestroy {
this.addErrorAlert('Not found', 'error.url.not.found');
break;
+ case 422:
+ this.addErrorAlert(httpErrorResponse.error.BusinessMessage);
+ break;
+
default:
if (httpErrorResponse.error !== '' && httpErrorResponse.error.message) {
this.addErrorAlert(httpErrorResponse.error.message);
diff --git a/src/test/java/com/github/microcatalog/service/custom/DependencyServiceTest.java b/src/test/java/com/github/microcatalog/service/custom/DependencyServiceTest.java
index 7b4e4a7..aa9f91b 100644
--- a/src/test/java/com/github/microcatalog/service/custom/DependencyServiceTest.java
+++ b/src/test/java/com/github/microcatalog/service/custom/DependencyServiceTest.java
@@ -6,7 +6,7 @@
import com.github.microcatalog.service.custom.exceptions.CircularDependenciesException;
import com.github.microcatalog.service.custom.exceptions.SelfCircularException;
import com.github.microcatalog.utils.DependencyBuilder;
-import com.github.microcatalog.web.rest.errors.BadRequestAlertException;
+import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -43,9 +43,9 @@ void findAll() {
@Test
void findById() {
- final long id = 3L;
+ final Long id = 3L;
- given(repository.findById(id)).willReturn(Optional.of(new DependencyBuilder().withId(id).build()));
+ given(repository.findById(id)).willReturn(Optional.of(dependency(id.intValue(), null, null)));
Optional
maybeDependency = service.findById(id);
assertThat(maybeDependency).isPresent();
@@ -66,20 +66,17 @@ void deleteById() {
@Test
void create_WithId_ExceptionIsThrown() {
assertThatIllegalArgumentException()
- .isThrownBy(() ->service.create(new DependencyBuilder().withId(1L).build()))
+ .isThrownBy(() -> service.create(dependency(1, null, null)))
.withMessageStartingWith("A new dependency can not already have an id");
}
@Test
void create_SelfCycle_ExceptionIsThrown() {
- assertThatThrownBy(() -> service.create(
- new DependencyBuilder()
- .withSource(2L)
- .withTarget(2L)
- .build()
- ))
+ final Dependency dependency = dependency(null, 2, 2);
+
+ assertThatThrownBy(() -> service.create(dependency))
.isInstanceOf(SelfCircularException.class)
- .hasMessageStartingWith("Source id is the same as target id");
+ .hasMessageStartingWith("Source of dependency can't be the same as target");
}
@Test
@@ -96,14 +93,14 @@ void create_WillIntroduceCircularDependencies_ExceptionIsThrown() {
)
);
- assertThatThrownBy(() -> service.create(
- new DependencyBuilder()
- .withSource(4L)
- .withTarget(1L)
- .build()
- ))
+ final Dependency dependency = dependency(null, 4, 1);
+
+ assertThatThrownBy(() -> service.create(dependency))
.isInstanceOf(CircularDependenciesException.class)
- .hasMessageStartingWith("Circular dependency will be introduced.");
+ .hasMessageStartingWith("Circular dependency will be introduced")
+ .extracting("cycles", InstanceOfAssertFactories.ITERABLE)
+ .extracting("id")
+ .containsExactlyInAnyOrder(1L, 2L, 3L, 4L);
}
@Test
@@ -119,19 +116,11 @@ void create_Success() {
)
);
- final Dependency expected = new DependencyBuilder()
- .withId(1L)
- .withSource(3L)
- .withTarget(4L)
- .build();
+ final Dependency expected = dependency(1, 3, 4);
given(repository.save(any(Dependency.class))).willReturn(expected);
- Dependency persistent = service.create(
- new DependencyBuilder()
- .withSource(3L)
- .withTarget(4L)
- .build());
+ Dependency persistent = service.create(dependency(null, 3, 4));
assertThat(persistent).isEqualTo(expected);
@@ -142,21 +131,17 @@ void create_Success() {
void update_NoId_ExceptionIsThrown() {
assertThatIllegalArgumentException()
.isThrownBy(() ->
- service.update(new DependencyBuilder().withSource(1L).withTarget(2L).build()))
+ service.update(dependency(null, 1, 2)))
.withMessageStartingWith("Updating non-persistent entity without id");
}
@Test
void update_SelfCycle_ExceptionIsThrown() {
- assertThatThrownBy(() -> service.update(
- new DependencyBuilder()
- .withId(1L)
- .withSource(2L)
- .withTarget(2L)
- .build()
- ))
+ final Dependency dependency = dependency(1, 2, 2);
+
+ assertThatThrownBy(() -> service.update(dependency))
.isInstanceOf(SelfCircularException.class)
- .hasMessageStartingWith("Source id is the same as target id");
+ .hasMessageStartingWith("Source of dependency can't be the same as target");
}
@Test
@@ -174,17 +159,16 @@ void update_WillIntroduceCircularDependencies_ExceptionIsThrown() {
);
given(repository.findById(3L))
- .willReturn(Optional.of(new DependencyBuilder().withId(3L).withSource(3L).withTarget(4L).build()));
-
- assertThatThrownBy(() -> service.update(
- new DependencyBuilder()
- .withId(3L)
- .withSource(3L)
- .withTarget(1L)
- .build()
- ))
+ .willReturn(Optional.of(dependency(3, 3, 4)));
+
+ final Dependency dependency = dependency(3, 3, 1);
+
+ assertThatThrownBy(() -> service.update(dependency))
.isInstanceOf(CircularDependenciesException.class)
- .hasMessageStartingWith("Circular dependency will be introduced.");
+ .hasMessageStartingWith("Circular dependency will be introduced")
+ .extracting("cycles", InstanceOfAssertFactories.ITERABLE)
+ .extracting("id")
+ .containsExactlyInAnyOrder(1L, 2L, 3L);
}
@Test
@@ -202,25 +186,32 @@ void update_Success() {
);
given(repository.findById(2L))
- .willReturn(Optional.of(new DependencyBuilder().withId(2L).withSource(2L).withTarget(3L).build()));
+ .willReturn(Optional.of(dependency(2, 2, 3)));
- final Dependency expected = new DependencyBuilder()
- .withId(2L)
- .withSource(2L)
- .withTarget(4L)
- .build();
+ final Dependency expected = dependency(2, 2, 4);
given(repository.save(any(Dependency.class))).willReturn(expected);
- Dependency persistent = service.update(
- new DependencyBuilder()
- .withId(2L)
- .withSource(2L)
- .withTarget(4L)
- .build());
+ Dependency persistent = service.update(dependency(2, 2, 4));
assertThat(persistent).isEqualTo(expected);
then(repository).should().save(any(Dependency.class));
}
+
+ private Dependency dependency(final Integer id, final Integer sourceId, final Integer targetId) {
+ DependencyBuilder builder = new DependencyBuilder();
+
+ if (sourceId != null) {
+ builder.withSource(Long.valueOf(sourceId));
+ }
+ if (targetId != null) {
+ builder.withTarget(Long.valueOf(targetId));
+ }
+ if (id != null) {
+ builder.withId(Long.valueOf(id));
+ }
+
+ return builder.build();
+ }
}
diff --git a/src/test/java/com/github/microcatalog/service/custom/GraphLoaderServiceTest.java b/src/test/java/com/github/microcatalog/service/custom/GraphLoaderServiceTest.java
index ea75043..6493d4f 100644
--- a/src/test/java/com/github/microcatalog/service/custom/GraphLoaderServiceTest.java
+++ b/src/test/java/com/github/microcatalog/service/custom/GraphLoaderServiceTest.java
@@ -8,14 +8,11 @@
import com.github.microcatalog.utils.MicroserviceBuilder;
import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultEdge;
-import org.jgrapht.nio.dot.DOTExporter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
-import java.io.StringWriter;
-import java.io.Writer;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
@@ -25,7 +22,7 @@
import static org.mockito.BDDMockito.then;
@SpringBootTest(classes = GraphLoaderService.class)
-public class GraphLoaderServiceTest {
+class GraphLoaderServiceTest {
@MockBean
private MicroserviceRepository microserviceRepository;
@@ -43,8 +40,8 @@ void loadEmptyGraph() {
Graph graph = sut.loadGraph();
assertThat(graph).isNotNull();
- assertThat(graph.vertexSet()).hasSize(0);
- assertThat(graph.edgeSet()).hasSize(0);
+ assertThat(graph.vertexSet()).isEmpty();
+ assertThat(graph.edgeSet()).isEmpty();
then(microserviceRepository).should().findAll();
then(dependencyRepository).should().findAll();