From 11f06b9cbf4bdd10c8d9a1f2fb5681e266da7114 Mon Sep 17 00:00:00 2001 From: tillias Date: Mon, 5 Oct 2020 18:13:54 +0200 Subject: [PATCH] Added entities, services and resources for dependency tracking #2 --- .jhipster/Dependency.json | 46 +++ microcatalog.jdl | 7 + .../config/CacheConfiguration.java | 1 + .../microcatalog/domain/Dependency.java | 134 +++++++++ .../repository/DependencyRepository.java | 14 + .../web/rest/DependencyResource.java | 119 ++++++++ ...20201005051343_added_entity_Dependency.xml | 61 ++++ ...43_added_entity_constraints_Dependency.xml | 24 ++ .../config/liquibase/fake-data/dependency.csv | 11 + .../resources/config/liquibase/master.xml | 2 + src/main/webapp/app/app-routing.module.ts | 8 + .../app/core/icons/font-awesome-icons.ts | 2 + .../app/dashboard/dashboard-routing.module.ts | 14 + .../dependency-dashboard.component.html | 1 + .../dependency-dashboard.component.scss | 0 .../dependency-dashboard.component.ts | 12 + .../dependency-dashboard.module.ts | 11 + .../dependency-dashboard.route.ts | 9 + .../dependency-delete-dialog.component.html | 24 ++ .../dependency-delete-dialog.component.ts | 30 ++ .../dependency-detail.component.html | 46 +++ .../dependency/dependency-detail.component.ts | 31 +++ .../dependency-update.component.html | 72 +++++ .../dependency/dependency-update.component.ts | 118 ++++++++ .../dependency/dependency.component.html | 75 +++++ .../dependency/dependency.component.ts | 62 +++++ .../entities/dependency/dependency.module.ts | 16 ++ .../entities/dependency/dependency.route.ts | 83 ++++++ .../entities/dependency/dependency.service.ts | 38 +++ src/main/webapp/app/entities/entity.module.ts | 4 + .../app/layouts/navbar/navbar.component.html | 16 ++ .../app/shared/model/dependency.model.ts | 19 ++ src/main/webapp/i18n/de/dependency.json | 25 ++ src/main/webapp/i18n/de/global.json | 4 + src/main/webapp/i18n/en/dependency.json | 25 ++ src/main/webapp/i18n/en/global.json | 4 + .../microcatalog/domain/DependencyTest.java | 22 ++ .../web/rest/DependencyResourceIT.java | 261 ++++++++++++++++++ ...dependency-delete-dialog.component.spec.ts | 65 +++++ .../dependency-detail.component.spec.ts | 69 +++++ .../dependency-update.component.spec.ts | 61 ++++ .../dependency/dependency.component.spec.ts | 49 ++++ .../dependency/dependency.service.spec.ts | 104 +++++++ 43 files changed, 1799 insertions(+) create mode 100644 .jhipster/Dependency.json create mode 100644 src/main/java/com/github/microcatalog/domain/Dependency.java create mode 100644 src/main/java/com/github/microcatalog/repository/DependencyRepository.java create mode 100644 src/main/java/com/github/microcatalog/web/rest/DependencyResource.java create mode 100644 src/main/resources/config/liquibase/changelog/20201005051343_added_entity_Dependency.xml create mode 100644 src/main/resources/config/liquibase/changelog/20201005051343_added_entity_constraints_Dependency.xml create mode 100644 src/main/resources/config/liquibase/fake-data/dependency.csv create mode 100644 src/main/webapp/app/dashboard/dashboard-routing.module.ts create mode 100644 src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.html create mode 100644 src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.scss create mode 100644 src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts create mode 100644 src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.module.ts create mode 100644 src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.route.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.html create mode 100644 src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency-detail.component.html create mode 100644 src/main/webapp/app/entities/dependency/dependency-detail.component.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency-update.component.html create mode 100644 src/main/webapp/app/entities/dependency/dependency-update.component.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency.component.html create mode 100644 src/main/webapp/app/entities/dependency/dependency.component.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency.module.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency.route.ts create mode 100644 src/main/webapp/app/entities/dependency/dependency.service.ts create mode 100644 src/main/webapp/app/shared/model/dependency.model.ts create mode 100644 src/main/webapp/i18n/de/dependency.json create mode 100644 src/main/webapp/i18n/en/dependency.json create mode 100644 src/test/java/com/github/microcatalog/domain/DependencyTest.java create mode 100644 src/test/java/com/github/microcatalog/web/rest/DependencyResourceIT.java create mode 100644 src/test/javascript/spec/app/entities/dependency/dependency-delete-dialog.component.spec.ts create mode 100644 src/test/javascript/spec/app/entities/dependency/dependency-detail.component.spec.ts create mode 100644 src/test/javascript/spec/app/entities/dependency/dependency-update.component.spec.ts create mode 100644 src/test/javascript/spec/app/entities/dependency/dependency.component.spec.ts create mode 100644 src/test/javascript/spec/app/entities/dependency/dependency.service.spec.ts diff --git a/.jhipster/Dependency.json b/.jhipster/Dependency.json new file mode 100644 index 0000000..02a38a4 --- /dev/null +++ b/.jhipster/Dependency.json @@ -0,0 +1,46 @@ +{ + "name": "Dependency", + "fields": [ + { + "fieldName": "name", + "fieldType": "String", + "fieldValidateRules": [ + "required" + ] + }, + { + "fieldName": "description", + "fieldType": "byte[]", + "fieldTypeBlobContent": "text" + } + ], + "relationships": [ + { + "relationshipType": "many-to-one", + "otherEntityName": "microservice", + "otherEntityRelationshipName": "dependency", + "relationshipValidateRules": "required", + "relationshipName": "source", + "otherEntityField": "id" + }, + { + "relationshipType": "many-to-one", + "otherEntityName": "microservice", + "otherEntityRelationshipName": "dependency", + "relationshipValidateRules": "required", + "relationshipName": "target", + "otherEntityField": "id" + } + ], + "changelogDate": "20201005051343", + "entityTableName": "dependency", + "dto": "no", + "pagination": "no", + "service": "no", + "jpaMetamodelFiltering": false, + "fluentMethods": true, + "readOnly": false, + "embedded": false, + "clientRootFolder": "", + "applications": "*" +} diff --git a/microcatalog.jdl b/microcatalog.jdl index 7becdb2..0b861a8 100644 --- a/microcatalog.jdl +++ b/microcatalog.jdl @@ -17,8 +17,15 @@ entity Microservice { gitUrl String required } +entity Dependency { + name String required + description TextBlob +} + relationship ManyToOne { Microservice{team required} to Team Microservice{status required} to Status + Dependency{source required} to Microservice + Dependency{target required} to Microservice } diff --git a/src/main/java/com/github/microcatalog/config/CacheConfiguration.java b/src/main/java/com/github/microcatalog/config/CacheConfiguration.java index 8bf8d02..3dc3cad 100644 --- a/src/main/java/com/github/microcatalog/config/CacheConfiguration.java +++ b/src/main/java/com/github/microcatalog/config/CacheConfiguration.java @@ -51,6 +51,7 @@ public JCacheManagerCustomizer cacheManagerCustomizer() { createCache(cm, com.github.microcatalog.domain.Microservice.class.getName()); createCache(cm, com.github.microcatalog.domain.Team.class.getName()); createCache(cm, com.github.microcatalog.domain.Status.class.getName()); + createCache(cm, com.github.microcatalog.domain.Dependency.class.getName()); // jhipster-needle-ehcache-add-entry }; } diff --git a/src/main/java/com/github/microcatalog/domain/Dependency.java b/src/main/java/com/github/microcatalog/domain/Dependency.java new file mode 100644 index 0000000..1eb92a3 --- /dev/null +++ b/src/main/java/com/github/microcatalog/domain/Dependency.java @@ -0,0 +1,134 @@ +package com.github.microcatalog.domain; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; +import org.hibernate.annotations.Type; + +import javax.persistence.*; +import javax.validation.constraints.*; + +import java.io.Serializable; + +/** + * A Dependency. + */ +@Entity +@Table(name = "dependency") +@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) +public class Dependency implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") + @SequenceGenerator(name = "sequenceGenerator") + private Long id; + + @NotNull + @Column(name = "name", nullable = false) + private String name; + + @Lob + @Type(type = "org.hibernate.type.TextType") + @Column(name = "description") + private String description; + + @ManyToOne(optional = false) + @NotNull + @JsonIgnoreProperties(value = "dependencies", allowSetters = true) + private Microservice source; + + @ManyToOne(optional = false) + @NotNull + @JsonIgnoreProperties(value = "dependencies", allowSetters = true) + private Microservice target; + + // jhipster-needle-entity-add-field - JHipster will add fields here + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public Dependency name(String name) { + this.name = name; + return this; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public Dependency description(String description) { + this.description = description; + return this; + } + + public void setDescription(String description) { + this.description = description; + } + + public Microservice getSource() { + return source; + } + + public Dependency source(Microservice microservice) { + this.source = microservice; + return this; + } + + public void setSource(Microservice microservice) { + this.source = microservice; + } + + public Microservice getTarget() { + return target; + } + + public Dependency target(Microservice microservice) { + this.target = microservice; + return this; + } + + public void setTarget(Microservice microservice) { + this.target = microservice; + } + // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Dependency)) { + return false; + } + return id != null && id.equals(((Dependency) o).id); + } + + @Override + public int hashCode() { + return 31; + } + + // prettier-ignore + @Override + public String toString() { + return "Dependency{" + + "id=" + getId() + + ", name='" + getName() + "'" + + ", description='" + getDescription() + "'" + + "}"; + } +} diff --git a/src/main/java/com/github/microcatalog/repository/DependencyRepository.java b/src/main/java/com/github/microcatalog/repository/DependencyRepository.java new file mode 100644 index 0000000..9729198 --- /dev/null +++ b/src/main/java/com/github/microcatalog/repository/DependencyRepository.java @@ -0,0 +1,14 @@ +package com.github.microcatalog.repository; + +import com.github.microcatalog.domain.Dependency; + +import org.springframework.data.jpa.repository.*; +import org.springframework.stereotype.Repository; + +/** + * Spring Data repository for the Dependency entity. + */ +@SuppressWarnings("unused") +@Repository +public interface DependencyRepository extends JpaRepository { +} diff --git a/src/main/java/com/github/microcatalog/web/rest/DependencyResource.java b/src/main/java/com/github/microcatalog/web/rest/DependencyResource.java new file mode 100644 index 0000000..2aec08e --- /dev/null +++ b/src/main/java/com/github/microcatalog/web/rest/DependencyResource.java @@ -0,0 +1,119 @@ +package com.github.microcatalog.web.rest; + +import com.github.microcatalog.domain.Dependency; +import com.github.microcatalog.repository.DependencyRepository; +import com.github.microcatalog.web.rest.errors.BadRequestAlertException; + +import io.github.jhipster.web.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Optional; + +/** + * REST controller for managing {@link com.github.microcatalog.domain.Dependency}. + */ +@RestController +@RequestMapping("/api") +@Transactional +public class DependencyResource { + + private final Logger log = LoggerFactory.getLogger(DependencyResource.class); + + private static final String ENTITY_NAME = "dependency"; + + @Value("${jhipster.clientApp.name}") + private String applicationName; + + private final DependencyRepository dependencyRepository; + + public DependencyResource(DependencyRepository dependencyRepository) { + this.dependencyRepository = dependencyRepository; + } + + /** + * {@code POST /dependencies} : Create a new dependency. + * + * @param dependency the dependency to create. + * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new dependency, or with status {@code 400 (Bad Request)} if the dependency has already an ID. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PostMapping("/dependencies") + public ResponseEntity createDependency(@Valid @RequestBody Dependency dependency) throws URISyntaxException { + log.debug("REST request to save Dependency : {}", dependency); + if (dependency.getId() != null) { + throw new BadRequestAlertException("A new dependency cannot already have an ID", ENTITY_NAME, "idexists"); + } + Dependency result = dependencyRepository.save(dependency); + return ResponseEntity.created(new URI("/api/dependencies/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * {@code PUT /dependencies} : Updates an existing dependency. + * + * @param dependency the dependency to update. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated dependency, + * or with status {@code 400 (Bad Request)} if the dependency is not valid, + * or with status {@code 500 (Internal Server Error)} if the dependency couldn't be updated. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PutMapping("/dependencies") + public ResponseEntity updateDependency(@Valid @RequestBody Dependency dependency) throws URISyntaxException { + log.debug("REST request to update Dependency : {}", dependency); + if (dependency.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + Dependency result = dependencyRepository.save(dependency); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, dependency.getId().toString())) + .body(result); + } + + /** + * {@code GET /dependencies} : get all the dependencies. + * + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of dependencies in body. + */ + @GetMapping("/dependencies") + public List getAllDependencies() { + log.debug("REST request to get all Dependencies"); + return dependencyRepository.findAll(); + } + + /** + * {@code GET /dependencies/:id} : get the "id" dependency. + * + * @param id the id of the dependency to retrieve. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the dependency, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/dependencies/{id}") + public ResponseEntity getDependency(@PathVariable Long id) { + log.debug("REST request to get Dependency : {}", id); + Optional dependency = dependencyRepository.findById(id); + return ResponseUtil.wrapOrNotFound(dependency); + } + + /** + * {@code DELETE /dependencies/:id} : delete the "id" dependency. + * + * @param id the id of the dependency to delete. + * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. + */ + @DeleteMapping("/dependencies/{id}") + public ResponseEntity deleteDependency(@PathVariable Long id) { + log.debug("REST request to delete Dependency : {}", id); + dependencyRepository.deleteById(id); + return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/resources/config/liquibase/changelog/20201005051343_added_entity_Dependency.xml b/src/main/resources/config/liquibase/changelog/20201005051343_added_entity_Dependency.xml new file mode 100644 index 0000000..8299390 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20201005051343_added_entity_Dependency.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/changelog/20201005051343_added_entity_constraints_Dependency.xml b/src/main/resources/config/liquibase/changelog/20201005051343_added_entity_constraints_Dependency.xml new file mode 100644 index 0000000..fcad019 --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20201005051343_added_entity_constraints_Dependency.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/fake-data/dependency.csv b/src/main/resources/config/liquibase/fake-data/dependency.csv new file mode 100644 index 0000000..b15b98f --- /dev/null +++ b/src/main/resources/config/liquibase/fake-data/dependency.csv @@ -0,0 +1,11 @@ +id;name;description;source_id;target_id +1;Associate;../fake-data/blob/hipster.txt;1;1 +2;Consultant system Sleek Soft Bike;../fake-data/blob/hipster.txt;2;2 +3;Cambridgeshire;../fake-data/blob/hipster.txt;3;3 +4;South Dakota azure;../fake-data/blob/hipster.txt;4;4 +5;copy;../fake-data/blob/hipster.txt;5;5 +6;Chicken Rubber;../fake-data/blob/hipster.txt;6;6 +7;Frozen Suriname Gorgeous;../fake-data/blob/hipster.txt;7;7 +8;Lao People's Democratic Republic;../fake-data/blob/hipster.txt;8;8 +9;Qatar Wisconsin Product;../fake-data/blob/hipster.txt;9;9 +10;Cuba application;../fake-data/blob/hipster.txt;10;10 diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 8fc028c..45dc1c2 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -17,8 +17,10 @@ + + diff --git a/src/main/webapp/app/app-routing.module.ts b/src/main/webapp/app/app-routing.module.ts index a5dbceb..1014793 100644 --- a/src/main/webapp/app/app-routing.module.ts +++ b/src/main/webapp/app/app-routing.module.ts @@ -13,6 +13,14 @@ const LAYOUT_ROUTES = [navbarRoute, ...errorRoute]; imports: [ RouterModule.forRoot( [ + { + path: 'dashboard', + data: { + authorities: [Authority.USER], + }, + canActivate: [UserRouteAccessService], + loadChildren: () => import('./dashboard/dashboard-routing.module').then(m => m.DashboardRoutingModule), + }, { path: 'admin', data: { diff --git a/src/main/webapp/app/core/icons/font-awesome-icons.ts b/src/main/webapp/app/core/icons/font-awesome-icons.ts index 6c4872c..2707913 100644 --- a/src/main/webapp/app/core/icons/font-awesome-icons.ts +++ b/src/main/webapp/app/core/icons/font-awesome-icons.ts @@ -1,4 +1,5 @@ import { + faCubes, faUser, faSort, faSortUp, @@ -37,6 +38,7 @@ import { } from '@fortawesome/free-solid-svg-icons'; export const fontAwesomeIcons = [ + faCubes, faUser, faSort, faSortUp, diff --git a/src/main/webapp/app/dashboard/dashboard-routing.module.ts b/src/main/webapp/app/dashboard/dashboard-routing.module.ts new file mode 100644 index 0000000..e29f124 --- /dev/null +++ b/src/main/webapp/app/dashboard/dashboard-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { + path: 'dependencies', + loadChildren: () => import('./dependency-dashboard/dependency-dashboard.module').then(m => m.DependencyDashboardModule), + }, + ]), + ], +}) +export class DashboardRoutingModule {} diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.html b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.html new file mode 100644 index 0000000..9cbad68 --- /dev/null +++ b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.html @@ -0,0 +1 @@ +

dependency-dashboard works!

diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.scss b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts new file mode 100644 index 0000000..80682a4 --- /dev/null +++ b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.component.ts @@ -0,0 +1,12 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'jhi-dependency-dashboard', + templateUrl: './dependency-dashboard.component.html', + styleUrls: ['./dependency-dashboard.component.scss'], +}) +export class DependencyDashboardComponent implements OnInit { + constructor() {} + + ngOnInit(): void {} +} diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.module.ts b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.module.ts new file mode 100644 index 0000000..fdda86c --- /dev/null +++ b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.module.ts @@ -0,0 +1,11 @@ +import { NgModule } from '@angular/core'; +import { DependencyDashboardComponent } from './dependency-dashboard.component'; +import { RouterModule } from '@angular/router'; +import { dependencyDashboardRoute } from './dependency-dashboard.route'; +import { MicrocatalogSharedModule } from '../../shared/shared.module'; + +@NgModule({ + imports: [MicrocatalogSharedModule, RouterModule.forChild(dependencyDashboardRoute)], + declarations: [DependencyDashboardComponent], +}) +export class DependencyDashboardModule {} diff --git a/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.route.ts b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.route.ts new file mode 100644 index 0000000..a7e5f8e --- /dev/null +++ b/src/main/webapp/app/dashboard/dependency-dashboard/dependency-dashboard.route.ts @@ -0,0 +1,9 @@ +import { Routes } from '@angular/router'; +import { DependencyDashboardComponent } from './dependency-dashboard.component'; + +export const dependencyDashboardRoute: Routes = [ + { + path: '', + component: DependencyDashboardComponent, + }, +]; diff --git a/src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.html b/src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.html new file mode 100644 index 0000000..58de9e3 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.html @@ -0,0 +1,24 @@ +
+ + + + + +
diff --git a/src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.ts b/src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.ts new file mode 100644 index 0000000..765bc26 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency-delete-dialog.component.ts @@ -0,0 +1,30 @@ +import { Component } from '@angular/core'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { JhiEventManager } from 'ng-jhipster'; + +import { IDependency } from 'app/shared/model/dependency.model'; +import { DependencyService } from './dependency.service'; + +@Component({ + templateUrl: './dependency-delete-dialog.component.html', +}) +export class DependencyDeleteDialogComponent { + dependency?: IDependency; + + constructor( + protected dependencyService: DependencyService, + public activeModal: NgbActiveModal, + protected eventManager: JhiEventManager + ) {} + + cancel(): void { + this.activeModal.dismiss(); + } + + confirmDelete(id: number): void { + this.dependencyService.delete(id).subscribe(() => { + this.eventManager.broadcast('dependencyListModification'); + this.activeModal.close(); + }); + } +} diff --git a/src/main/webapp/app/entities/dependency/dependency-detail.component.html b/src/main/webapp/app/entities/dependency/dependency-detail.component.html new file mode 100644 index 0000000..4f4bc04 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency-detail.component.html @@ -0,0 +1,46 @@ +
+
+
+

Dependency {{ dependency.id }}

+ +
+ + + +
+
Name
+
+ {{ dependency.name }} +
+
Description
+
+ {{ dependency.description }} +
+
Source
+
+ +
+
Target
+
+ +
+
+ + + + +
+
+
diff --git a/src/main/webapp/app/entities/dependency/dependency-detail.component.ts b/src/main/webapp/app/entities/dependency/dependency-detail.component.ts new file mode 100644 index 0000000..f2b89dc --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency-detail.component.ts @@ -0,0 +1,31 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { JhiDataUtils } from 'ng-jhipster'; + +import { IDependency } from 'app/shared/model/dependency.model'; + +@Component({ + selector: 'jhi-dependency-detail', + templateUrl: './dependency-detail.component.html', +}) +export class DependencyDetailComponent implements OnInit { + dependency: IDependency | null = null; + + constructor(protected dataUtils: JhiDataUtils, protected activatedRoute: ActivatedRoute) {} + + ngOnInit(): void { + this.activatedRoute.data.subscribe(({ dependency }) => (this.dependency = dependency)); + } + + byteSize(base64String: string): string { + return this.dataUtils.byteSize(base64String); + } + + openFile(contentType = '', base64String: string): void { + this.dataUtils.openFile(contentType, base64String); + } + + previousState(): void { + window.history.back(); + } +} diff --git a/src/main/webapp/app/entities/dependency/dependency-update.component.html b/src/main/webapp/app/entities/dependency/dependency-update.component.html new file mode 100644 index 0000000..cd19549 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency-update.component.html @@ -0,0 +1,72 @@ +
+
+
+

Create or edit a Dependency

+ +
+ + +
+ + +
+ +
+ + +
+ + This field is required. + +
+
+ +
+ + +
+ +
+ + +
+
+ + This field is required. + +
+ +
+ + +
+
+ + This field is required. + +
+
+ +
+ + + +
+
+
+
diff --git a/src/main/webapp/app/entities/dependency/dependency-update.component.ts b/src/main/webapp/app/entities/dependency/dependency-update.component.ts new file mode 100644 index 0000000..7baf5ff --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency-update.component.ts @@ -0,0 +1,118 @@ +import { Component, OnInit } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import { FormBuilder, Validators } from '@angular/forms'; +import { ActivatedRoute } from '@angular/router'; +import { Observable } from 'rxjs'; +import { JhiDataUtils, JhiFileLoadError, JhiEventManager, JhiEventWithContent } from 'ng-jhipster'; + +import { IDependency, Dependency } from 'app/shared/model/dependency.model'; +import { DependencyService } from './dependency.service'; +import { AlertError } from 'app/shared/alert/alert-error.model'; +import { IMicroservice } from 'app/shared/model/microservice.model'; +import { MicroserviceService } from 'app/entities/microservice/microservice.service'; + +@Component({ + selector: 'jhi-dependency-update', + templateUrl: './dependency-update.component.html', +}) +export class DependencyUpdateComponent implements OnInit { + isSaving = false; + microservices: IMicroservice[] = []; + + editForm = this.fb.group({ + id: [], + name: [null, [Validators.required]], + description: [], + source: [null, Validators.required], + target: [null, Validators.required], + }); + + constructor( + protected dataUtils: JhiDataUtils, + protected eventManager: JhiEventManager, + protected dependencyService: DependencyService, + protected microserviceService: MicroserviceService, + protected activatedRoute: ActivatedRoute, + private fb: FormBuilder + ) {} + + ngOnInit(): void { + this.activatedRoute.data.subscribe(({ dependency }) => { + this.updateForm(dependency); + + this.microserviceService.query().subscribe((res: HttpResponse) => (this.microservices = res.body || [])); + }); + } + + updateForm(dependency: IDependency): void { + this.editForm.patchValue({ + id: dependency.id, + name: dependency.name, + description: dependency.description, + source: dependency.source, + target: dependency.target, + }); + } + + byteSize(base64String: string): string { + return this.dataUtils.byteSize(base64String); + } + + openFile(contentType: string, base64String: string): void { + this.dataUtils.openFile(contentType, base64String); + } + + setFileData(event: any, field: string, isImage: boolean): void { + this.dataUtils.loadFileToForm(event, this.editForm, field, isImage).subscribe(null, (err: JhiFileLoadError) => { + this.eventManager.broadcast( + new JhiEventWithContent('microcatalogApp.error', { ...err, key: 'error.file.' + err.key }) + ); + }); + } + + previousState(): void { + window.history.back(); + } + + save(): void { + this.isSaving = true; + const dependency = this.createFromForm(); + if (dependency.id !== undefined) { + this.subscribeToSaveResponse(this.dependencyService.update(dependency)); + } else { + this.subscribeToSaveResponse(this.dependencyService.create(dependency)); + } + } + + private createFromForm(): IDependency { + return { + ...new Dependency(), + id: this.editForm.get(['id'])!.value, + name: this.editForm.get(['name'])!.value, + description: this.editForm.get(['description'])!.value, + source: this.editForm.get(['source'])!.value, + target: this.editForm.get(['target'])!.value, + }; + } + + protected subscribeToSaveResponse(result: Observable>): void { + result.subscribe( + () => this.onSaveSuccess(), + () => this.onSaveError() + ); + } + + protected onSaveSuccess(): void { + this.isSaving = false; + this.previousState(); + } + + protected onSaveError(): void { + this.isSaving = false; + } + + trackById(index: number, item: IMicroservice): any { + return item.id; + } +} diff --git a/src/main/webapp/app/entities/dependency/dependency.component.html b/src/main/webapp/app/entities/dependency/dependency.component.html new file mode 100644 index 0000000..b521985 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency.component.html @@ -0,0 +1,75 @@ +
+

+ Dependencies + + +

+ + + + + +
+ No dependencies found +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
IDNameDescriptionSourceTarget
{{ dependency.id }}{{ dependency.name }}{{ dependency.description }} + + + + +
+ + + + + +
+
+
+
diff --git a/src/main/webapp/app/entities/dependency/dependency.component.ts b/src/main/webapp/app/entities/dependency/dependency.component.ts new file mode 100644 index 0000000..3ab4588 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency.component.ts @@ -0,0 +1,62 @@ +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +import { Subscription } from 'rxjs'; +import { JhiEventManager, JhiDataUtils } from 'ng-jhipster'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; + +import { IDependency } from 'app/shared/model/dependency.model'; +import { DependencyService } from './dependency.service'; +import { DependencyDeleteDialogComponent } from './dependency-delete-dialog.component'; + +@Component({ + selector: 'jhi-dependency', + templateUrl: './dependency.component.html', +}) +export class DependencyComponent implements OnInit, OnDestroy { + dependencies?: IDependency[]; + eventSubscriber?: Subscription; + + constructor( + protected dependencyService: DependencyService, + protected dataUtils: JhiDataUtils, + protected eventManager: JhiEventManager, + protected modalService: NgbModal + ) {} + + loadAll(): void { + this.dependencyService.query().subscribe((res: HttpResponse) => (this.dependencies = res.body || [])); + } + + ngOnInit(): void { + this.loadAll(); + this.registerChangeInDependencies(); + } + + ngOnDestroy(): void { + if (this.eventSubscriber) { + this.eventManager.destroy(this.eventSubscriber); + } + } + + trackId(index: number, item: IDependency): number { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + return item.id!; + } + + byteSize(base64String: string): string { + return this.dataUtils.byteSize(base64String); + } + + openFile(contentType = '', base64String: string): void { + return this.dataUtils.openFile(contentType, base64String); + } + + registerChangeInDependencies(): void { + this.eventSubscriber = this.eventManager.subscribe('dependencyListModification', () => this.loadAll()); + } + + delete(dependency: IDependency): void { + const modalRef = this.modalService.open(DependencyDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); + modalRef.componentInstance.dependency = dependency; + } +} diff --git a/src/main/webapp/app/entities/dependency/dependency.module.ts b/src/main/webapp/app/entities/dependency/dependency.module.ts new file mode 100644 index 0000000..007b0f1 --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency.module.ts @@ -0,0 +1,16 @@ +import { NgModule } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +import { MicrocatalogSharedModule } from 'app/shared/shared.module'; +import { DependencyComponent } from './dependency.component'; +import { DependencyDetailComponent } from './dependency-detail.component'; +import { DependencyUpdateComponent } from './dependency-update.component'; +import { DependencyDeleteDialogComponent } from './dependency-delete-dialog.component'; +import { dependencyRoute } from './dependency.route'; + +@NgModule({ + imports: [MicrocatalogSharedModule, RouterModule.forChild(dependencyRoute)], + declarations: [DependencyComponent, DependencyDetailComponent, DependencyUpdateComponent, DependencyDeleteDialogComponent], + entryComponents: [DependencyDeleteDialogComponent], +}) +export class MicrocatalogDependencyModule {} diff --git a/src/main/webapp/app/entities/dependency/dependency.route.ts b/src/main/webapp/app/entities/dependency/dependency.route.ts new file mode 100644 index 0000000..5352e3c --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency.route.ts @@ -0,0 +1,83 @@ +import { Injectable } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +import { Resolve, ActivatedRouteSnapshot, Routes, Router } from '@angular/router'; +import { Observable, of, EMPTY } from 'rxjs'; +import { flatMap } from 'rxjs/operators'; + +import { Authority } from 'app/shared/constants/authority.constants'; +import { UserRouteAccessService } from 'app/core/auth/user-route-access-service'; +import { IDependency, Dependency } from 'app/shared/model/dependency.model'; +import { DependencyService } from './dependency.service'; +import { DependencyComponent } from './dependency.component'; +import { DependencyDetailComponent } from './dependency-detail.component'; +import { DependencyUpdateComponent } from './dependency-update.component'; + +@Injectable({ providedIn: 'root' }) +export class DependencyResolve implements Resolve { + constructor(private service: DependencyService, private router: Router) {} + + resolve(route: ActivatedRouteSnapshot): Observable | Observable { + const id = route.params['id']; + if (id) { + return this.service.find(id).pipe( + flatMap((dependency: HttpResponse) => { + if (dependency.body) { + return of(dependency.body); + } else { + this.router.navigate(['404']); + return EMPTY; + } + }) + ); + } + return of(new Dependency()); + } +} + +export const dependencyRoute: Routes = [ + { + path: '', + component: DependencyComponent, + data: { + authorities: [Authority.USER], + pageTitle: 'microcatalogApp.dependency.home.title', + }, + canActivate: [UserRouteAccessService], + }, + { + path: ':id/view', + component: DependencyDetailComponent, + resolve: { + dependency: DependencyResolve, + }, + data: { + authorities: [Authority.USER], + pageTitle: 'microcatalogApp.dependency.home.title', + }, + canActivate: [UserRouteAccessService], + }, + { + path: 'new', + component: DependencyUpdateComponent, + resolve: { + dependency: DependencyResolve, + }, + data: { + authorities: [Authority.USER], + pageTitle: 'microcatalogApp.dependency.home.title', + }, + canActivate: [UserRouteAccessService], + }, + { + path: ':id/edit', + component: DependencyUpdateComponent, + resolve: { + dependency: DependencyResolve, + }, + data: { + authorities: [Authority.USER], + pageTitle: 'microcatalogApp.dependency.home.title', + }, + canActivate: [UserRouteAccessService], + }, +]; diff --git a/src/main/webapp/app/entities/dependency/dependency.service.ts b/src/main/webapp/app/entities/dependency/dependency.service.ts new file mode 100644 index 0000000..7eb893f --- /dev/null +++ b/src/main/webapp/app/entities/dependency/dependency.service.ts @@ -0,0 +1,38 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +import { SERVER_API_URL } from 'app/app.constants'; +import { createRequestOption } from 'app/shared/util/request-util'; +import { IDependency } from 'app/shared/model/dependency.model'; + +type EntityResponseType = HttpResponse; +type EntityArrayResponseType = HttpResponse; + +@Injectable({ providedIn: 'root' }) +export class DependencyService { + public resourceUrl = SERVER_API_URL + 'api/dependencies'; + + constructor(protected http: HttpClient) {} + + create(dependency: IDependency): Observable { + return this.http.post(this.resourceUrl, dependency, { observe: 'response' }); + } + + update(dependency: IDependency): Observable { + return this.http.put(this.resourceUrl, dependency, { observe: 'response' }); + } + + find(id: number): Observable { + return this.http.get(`${this.resourceUrl}/${id}`, { observe: 'response' }); + } + + query(req?: any): Observable { + const options = createRequestOption(req); + return this.http.get(this.resourceUrl, { params: options, observe: 'response' }); + } + + delete(id: number): Observable> { + return this.http.delete(`${this.resourceUrl}/${id}`, { observe: 'response' }); + } +} diff --git a/src/main/webapp/app/entities/entity.module.ts b/src/main/webapp/app/entities/entity.module.ts index f9fac28..c212877 100644 --- a/src/main/webapp/app/entities/entity.module.ts +++ b/src/main/webapp/app/entities/entity.module.ts @@ -16,6 +16,10 @@ import { RouterModule } from '@angular/router'; path: 'status', loadChildren: () => import('./status/status.module').then(m => m.MicrocatalogStatusModule), }, + { + path: 'dependency', + loadChildren: () => import('./dependency/dependency.module').then(m => m.MicrocatalogDependencyModule), + }, /* jhipster-needle-add-entity-route - JHipster will add entity modules routes here */ ]), ], diff --git a/src/main/webapp/app/layouts/navbar/navbar.component.html b/src/main/webapp/app/layouts/navbar/navbar.component.html index c785223..30f7d69 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.component.html +++ b/src/main/webapp/app/layouts/navbar/navbar.component.html @@ -16,6 +16,16 @@ + +
  • + + + Dependency + +
  • diff --git a/src/main/webapp/app/shared/model/dependency.model.ts b/src/main/webapp/app/shared/model/dependency.model.ts new file mode 100644 index 0000000..40f3126 --- /dev/null +++ b/src/main/webapp/app/shared/model/dependency.model.ts @@ -0,0 +1,19 @@ +import { IMicroservice } from 'app/shared/model/microservice.model'; + +export interface IDependency { + id?: number; + name?: string; + description?: any; + source?: IMicroservice; + target?: IMicroservice; +} + +export class Dependency implements IDependency { + constructor( + public id?: number, + public name?: string, + public description?: any, + public source?: IMicroservice, + public target?: IMicroservice + ) {} +} diff --git a/src/main/webapp/i18n/de/dependency.json b/src/main/webapp/i18n/de/dependency.json new file mode 100644 index 0000000..dc6303e --- /dev/null +++ b/src/main/webapp/i18n/de/dependency.json @@ -0,0 +1,25 @@ +{ + "microcatalogApp": { + "dependency": { + "home": { + "title": "Dependencies", + "createLabel": "Dependency erstellen", + "createOrEditLabel": "Dependency erstellen oder bearbeiten", + "notFound": "No Dependencies found" + }, + "created": "Dependency erstellt mit ID {{ param }}", + "updated": "Dependency aktualisiert mit ID {{ param }}", + "deleted": "Dependency gelöscht mit ID {{ param }}", + "delete": { + "question": "Soll Dependency {{ id }} wirklich dauerhaft gelöscht werden?" + }, + "detail": { + "title": "Dependency" + }, + "name": "Name", + "description": "Description", + "source": "Source", + "target": "Target" + } + } +} diff --git a/src/main/webapp/i18n/de/global.json b/src/main/webapp/i18n/de/global.json index a80626c..8d4b26d 100644 --- a/src/main/webapp/i18n/de/global.json +++ b/src/main/webapp/i18n/de/global.json @@ -4,12 +4,16 @@ "browsehappy": "Sie benutzen einen veralteten Browser. Bitte aktualisieren Sie Ihren Browser, um die Benutzerfreundlichkeit zu erhöhen.", "menu": { "home": "Startseite", + "dashboard": { + "dependencies": "Abhängigkeiten" + }, "jhipster-needle-menu-add-element": "JHipster will add additional menu entries here (do not translate!)", "entities": { "main": "Entitäten", "microservice": "Microservice", "team": "Team", "status": "Status", + "dependency": "Dependency", "jhipster-needle-menu-add-entry": "JHipster will add additional entities here (do not translate!)" }, "account": { diff --git a/src/main/webapp/i18n/en/dependency.json b/src/main/webapp/i18n/en/dependency.json new file mode 100644 index 0000000..09d3432 --- /dev/null +++ b/src/main/webapp/i18n/en/dependency.json @@ -0,0 +1,25 @@ +{ + "microcatalogApp": { + "dependency": { + "home": { + "title": "Dependencies", + "createLabel": "Create a new Dependency", + "createOrEditLabel": "Create or edit a Dependency", + "notFound": "No Dependencies found" + }, + "created": "A new Dependency is created with identifier {{ param }}", + "updated": "A Dependency is updated with identifier {{ param }}", + "deleted": "A Dependency is deleted with identifier {{ param }}", + "delete": { + "question": "Are you sure you want to delete Dependency {{ id }}?" + }, + "detail": { + "title": "Dependency" + }, + "name": "Name", + "description": "Description", + "source": "Source", + "target": "Target" + } + } +} diff --git a/src/main/webapp/i18n/en/global.json b/src/main/webapp/i18n/en/global.json index 5a839d6..7801eed 100644 --- a/src/main/webapp/i18n/en/global.json +++ b/src/main/webapp/i18n/en/global.json @@ -4,12 +4,16 @@ "browsehappy": "You are using an outdated browser. Please upgrade your browser to improve your experience.", "menu": { "home": "Home", + "dashboard": { + "dependencies": "Dependencies" + }, "jhipster-needle-menu-add-element": "JHipster will add additional menu entries here (do not translate!)", "entities": { "main": "Entities", "microservice": "Microservice", "team": "Team", "status": "Status", + "dependency": "Dependency", "jhipster-needle-menu-add-entry": "JHipster will add additional entities here (do not translate!)" }, "account": { diff --git a/src/test/java/com/github/microcatalog/domain/DependencyTest.java b/src/test/java/com/github/microcatalog/domain/DependencyTest.java new file mode 100644 index 0000000..6dc41d2 --- /dev/null +++ b/src/test/java/com/github/microcatalog/domain/DependencyTest.java @@ -0,0 +1,22 @@ +package com.github.microcatalog.domain; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import com.github.microcatalog.web.rest.TestUtil; + +public class DependencyTest { + + @Test + public void equalsVerifier() throws Exception { + TestUtil.equalsVerifier(Dependency.class); + Dependency dependency1 = new Dependency(); + dependency1.setId(1L); + Dependency dependency2 = new Dependency(); + dependency2.setId(dependency1.getId()); + assertThat(dependency1).isEqualTo(dependency2); + dependency2.setId(2L); + assertThat(dependency1).isNotEqualTo(dependency2); + dependency1.setId(null); + assertThat(dependency1).isNotEqualTo(dependency2); + } +} diff --git a/src/test/java/com/github/microcatalog/web/rest/DependencyResourceIT.java b/src/test/java/com/github/microcatalog/web/rest/DependencyResourceIT.java new file mode 100644 index 0000000..503994d --- /dev/null +++ b/src/test/java/com/github/microcatalog/web/rest/DependencyResourceIT.java @@ -0,0 +1,261 @@ +package com.github.microcatalog.web.rest; + +import com.github.microcatalog.MicrocatalogApp; +import com.github.microcatalog.domain.Dependency; +import com.github.microcatalog.domain.Microservice; +import com.github.microcatalog.repository.DependencyRepository; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Base64Utils; +import javax.persistence.EntityManager; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +/** + * Integration tests for the {@link DependencyResource} REST controller. + */ +@SpringBootTest(classes = MicrocatalogApp.class) +@AutoConfigureMockMvc +@WithMockUser +public class DependencyResourceIT { + + private static final String DEFAULT_NAME = "AAAAAAAAAA"; + private static final String UPDATED_NAME = "BBBBBBBBBB"; + + private static final String DEFAULT_DESCRIPTION = "AAAAAAAAAA"; + private static final String UPDATED_DESCRIPTION = "BBBBBBBBBB"; + + @Autowired + private DependencyRepository dependencyRepository; + + @Autowired + private EntityManager em; + + @Autowired + private MockMvc restDependencyMockMvc; + + private Dependency dependency; + + /** + * Create an entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Dependency createEntity(EntityManager em) { + Dependency dependency = new Dependency() + .name(DEFAULT_NAME) + .description(DEFAULT_DESCRIPTION); + // Add required entity + Microservice microservice; + if (TestUtil.findAll(em, Microservice.class).isEmpty()) { + microservice = MicroserviceResourceIT.createEntity(em); + em.persist(microservice); + em.flush(); + } else { + microservice = TestUtil.findAll(em, Microservice.class).get(0); + } + dependency.setSource(microservice); + // Add required entity + dependency.setTarget(microservice); + return dependency; + } + /** + * Create an updated entity for this test. + * + * This is a static method, as tests for other entities might also need it, + * if they test an entity which requires the current entity. + */ + public static Dependency createUpdatedEntity(EntityManager em) { + Dependency dependency = new Dependency() + .name(UPDATED_NAME) + .description(UPDATED_DESCRIPTION); + // Add required entity + Microservice microservice; + if (TestUtil.findAll(em, Microservice.class).isEmpty()) { + microservice = MicroserviceResourceIT.createUpdatedEntity(em); + em.persist(microservice); + em.flush(); + } else { + microservice = TestUtil.findAll(em, Microservice.class).get(0); + } + dependency.setSource(microservice); + // Add required entity + dependency.setTarget(microservice); + return dependency; + } + + @BeforeEach + public void initTest() { + dependency = createEntity(em); + } + + @Test + @Transactional + public void createDependency() throws Exception { + int databaseSizeBeforeCreate = dependencyRepository.findAll().size(); + // Create the Dependency + restDependencyMockMvc.perform(post("/api/dependencies") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(dependency))) + .andExpect(status().isCreated()); + + // Validate the Dependency in the database + List dependencyList = dependencyRepository.findAll(); + assertThat(dependencyList).hasSize(databaseSizeBeforeCreate + 1); + Dependency testDependency = dependencyList.get(dependencyList.size() - 1); + assertThat(testDependency.getName()).isEqualTo(DEFAULT_NAME); + assertThat(testDependency.getDescription()).isEqualTo(DEFAULT_DESCRIPTION); + } + + @Test + @Transactional + public void createDependencyWithExistingId() throws Exception { + int databaseSizeBeforeCreate = dependencyRepository.findAll().size(); + + // Create the Dependency with an existing ID + dependency.setId(1L); + + // An entity with an existing ID cannot be created, so this API call must fail + restDependencyMockMvc.perform(post("/api/dependencies") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(dependency))) + .andExpect(status().isBadRequest()); + + // Validate the Dependency in the database + List dependencyList = dependencyRepository.findAll(); + assertThat(dependencyList).hasSize(databaseSizeBeforeCreate); + } + + + @Test + @Transactional + public void checkNameIsRequired() throws Exception { + int databaseSizeBeforeTest = dependencyRepository.findAll().size(); + // set the field null + dependency.setName(null); + + // Create the Dependency, which fails. + + + restDependencyMockMvc.perform(post("/api/dependencies") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(dependency))) + .andExpect(status().isBadRequest()); + + List dependencyList = dependencyRepository.findAll(); + assertThat(dependencyList).hasSize(databaseSizeBeforeTest); + } + + @Test + @Transactional + public void getAllDependencies() throws Exception { + // Initialize the database + dependencyRepository.saveAndFlush(dependency); + + // Get all the dependencyList + restDependencyMockMvc.perform(get("/api/dependencies?sort=id,desc")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.[*].id").value(hasItem(dependency.getId().intValue()))) + .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME))) + .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString()))); + } + + @Test + @Transactional + public void getDependency() throws Exception { + // Initialize the database + dependencyRepository.saveAndFlush(dependency); + + // Get the dependency + restDependencyMockMvc.perform(get("/api/dependencies/{id}", dependency.getId())) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.id").value(dependency.getId().intValue())) + .andExpect(jsonPath("$.name").value(DEFAULT_NAME)) + .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString())); + } + @Test + @Transactional + public void getNonExistingDependency() throws Exception { + // Get the dependency + restDependencyMockMvc.perform(get("/api/dependencies/{id}", Long.MAX_VALUE)) + .andExpect(status().isNotFound()); + } + + @Test + @Transactional + public void updateDependency() throws Exception { + // Initialize the database + dependencyRepository.saveAndFlush(dependency); + + int databaseSizeBeforeUpdate = dependencyRepository.findAll().size(); + + // Update the dependency + Dependency updatedDependency = dependencyRepository.findById(dependency.getId()).get(); + // Disconnect from session so that the updates on updatedDependency are not directly saved in db + em.detach(updatedDependency); + updatedDependency + .name(UPDATED_NAME) + .description(UPDATED_DESCRIPTION); + + restDependencyMockMvc.perform(put("/api/dependencies") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(updatedDependency))) + .andExpect(status().isOk()); + + // Validate the Dependency in the database + List dependencyList = dependencyRepository.findAll(); + assertThat(dependencyList).hasSize(databaseSizeBeforeUpdate); + Dependency testDependency = dependencyList.get(dependencyList.size() - 1); + assertThat(testDependency.getName()).isEqualTo(UPDATED_NAME); + assertThat(testDependency.getDescription()).isEqualTo(UPDATED_DESCRIPTION); + } + + @Test + @Transactional + public void updateNonExistingDependency() throws Exception { + int databaseSizeBeforeUpdate = dependencyRepository.findAll().size(); + + // If the entity doesn't have an ID, it will throw BadRequestAlertException + restDependencyMockMvc.perform(put("/api/dependencies") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtil.convertObjectToJsonBytes(dependency))) + .andExpect(status().isBadRequest()); + + // Validate the Dependency in the database + List dependencyList = dependencyRepository.findAll(); + assertThat(dependencyList).hasSize(databaseSizeBeforeUpdate); + } + + @Test + @Transactional + public void deleteDependency() throws Exception { + // Initialize the database + dependencyRepository.saveAndFlush(dependency); + + int databaseSizeBeforeDelete = dependencyRepository.findAll().size(); + + // Delete the dependency + restDependencyMockMvc.perform(delete("/api/dependencies/{id}", dependency.getId()) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isNoContent()); + + // Validate the database contains one less item + List dependencyList = dependencyRepository.findAll(); + assertThat(dependencyList).hasSize(databaseSizeBeforeDelete - 1); + } +} diff --git a/src/test/javascript/spec/app/entities/dependency/dependency-delete-dialog.component.spec.ts b/src/test/javascript/spec/app/entities/dependency/dependency-delete-dialog.component.spec.ts new file mode 100644 index 0000000..e0e0a4c --- /dev/null +++ b/src/test/javascript/spec/app/entities/dependency/dependency-delete-dialog.component.spec.ts @@ -0,0 +1,65 @@ +import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { of } from 'rxjs'; +import { JhiEventManager } from 'ng-jhipster'; + +import { MicrocatalogTestModule } from '../../../test.module'; +import { MockEventManager } from '../../../helpers/mock-event-manager.service'; +import { MockActiveModal } from '../../../helpers/mock-active-modal.service'; +import { DependencyDeleteDialogComponent } from 'app/entities/dependency/dependency-delete-dialog.component'; +import { DependencyService } from 'app/entities/dependency/dependency.service'; + +describe('Component Tests', () => { + describe('Dependency Management Delete Component', () => { + let comp: DependencyDeleteDialogComponent; + let fixture: ComponentFixture; + let service: DependencyService; + let mockEventManager: MockEventManager; + let mockActiveModal: MockActiveModal; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [MicrocatalogTestModule], + declarations: [DependencyDeleteDialogComponent], + }) + .overrideTemplate(DependencyDeleteDialogComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(DependencyDeleteDialogComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(DependencyService); + mockEventManager = TestBed.get(JhiEventManager); + mockActiveModal = TestBed.get(NgbActiveModal); + }); + + describe('confirmDelete', () => { + it('Should call delete service on confirmDelete', inject( + [], + fakeAsync(() => { + // GIVEN + spyOn(service, 'delete').and.returnValue(of({})); + + // WHEN + comp.confirmDelete(123); + tick(); + + // THEN + expect(service.delete).toHaveBeenCalledWith(123); + expect(mockActiveModal.closeSpy).toHaveBeenCalled(); + expect(mockEventManager.broadcastSpy).toHaveBeenCalled(); + }) + )); + + it('Should not call delete service on clear', () => { + // GIVEN + spyOn(service, 'delete'); + + // WHEN + comp.cancel(); + + // THEN + expect(service.delete).not.toHaveBeenCalled(); + expect(mockActiveModal.dismissSpy).toHaveBeenCalled(); + }); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/dependency/dependency-detail.component.spec.ts b/src/test/javascript/spec/app/entities/dependency/dependency-detail.component.spec.ts new file mode 100644 index 0000000..4f0c697 --- /dev/null +++ b/src/test/javascript/spec/app/entities/dependency/dependency-detail.component.spec.ts @@ -0,0 +1,69 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; +import { of } from 'rxjs'; +import { JhiDataUtils } from 'ng-jhipster'; + +import { MicrocatalogTestModule } from '../../../test.module'; +import { DependencyDetailComponent } from 'app/entities/dependency/dependency-detail.component'; +import { Dependency } from 'app/shared/model/dependency.model'; + +describe('Component Tests', () => { + describe('Dependency Management Detail Component', () => { + let comp: DependencyDetailComponent; + let fixture: ComponentFixture; + let dataUtils: JhiDataUtils; + const route = ({ data: of({ dependency: new Dependency(123) }) } as any) as ActivatedRoute; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [MicrocatalogTestModule], + declarations: [DependencyDetailComponent], + providers: [{ provide: ActivatedRoute, useValue: route }], + }) + .overrideTemplate(DependencyDetailComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(DependencyDetailComponent); + comp = fixture.componentInstance; + dataUtils = fixture.debugElement.injector.get(JhiDataUtils); + }); + + describe('OnInit', () => { + it('Should load dependency on init', () => { + // WHEN + comp.ngOnInit(); + + // THEN + expect(comp.dependency).toEqual(jasmine.objectContaining({ id: 123 })); + }); + }); + + describe('byteSize', () => { + it('Should call byteSize from JhiDataUtils', () => { + // GIVEN + spyOn(dataUtils, 'byteSize'); + const fakeBase64 = 'fake base64'; + + // WHEN + comp.byteSize(fakeBase64); + + // THEN + expect(dataUtils.byteSize).toBeCalledWith(fakeBase64); + }); + }); + + describe('openFile', () => { + it('Should call openFile from JhiDataUtils', () => { + // GIVEN + spyOn(dataUtils, 'openFile'); + const fakeContentType = 'fake content type'; + const fakeBase64 = 'fake base64'; + + // WHEN + comp.openFile(fakeContentType, fakeBase64); + + // THEN + expect(dataUtils.openFile).toBeCalledWith(fakeContentType, fakeBase64); + }); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/dependency/dependency-update.component.spec.ts b/src/test/javascript/spec/app/entities/dependency/dependency-update.component.spec.ts new file mode 100644 index 0000000..b229357 --- /dev/null +++ b/src/test/javascript/spec/app/entities/dependency/dependency-update.component.spec.ts @@ -0,0 +1,61 @@ +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; +import { HttpResponse } from '@angular/common/http'; +import { FormBuilder } from '@angular/forms'; +import { of } from 'rxjs'; + +import { MicrocatalogTestModule } from '../../../test.module'; +import { DependencyUpdateComponent } from 'app/entities/dependency/dependency-update.component'; +import { DependencyService } from 'app/entities/dependency/dependency.service'; +import { Dependency } from 'app/shared/model/dependency.model'; + +describe('Component Tests', () => { + describe('Dependency Management Update Component', () => { + let comp: DependencyUpdateComponent; + let fixture: ComponentFixture; + let service: DependencyService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [MicrocatalogTestModule], + declarations: [DependencyUpdateComponent], + providers: [FormBuilder], + }) + .overrideTemplate(DependencyUpdateComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(DependencyUpdateComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(DependencyService); + }); + + describe('save', () => { + it('Should call update service on save for existing entity', fakeAsync(() => { + // GIVEN + const entity = new Dependency(123); + spyOn(service, 'update').and.returnValue(of(new HttpResponse({ body: entity }))); + comp.updateForm(entity); + // WHEN + comp.save(); + tick(); // simulate async + + // THEN + expect(service.update).toHaveBeenCalledWith(entity); + expect(comp.isSaving).toEqual(false); + })); + + it('Should call create service on save for new entity', fakeAsync(() => { + // GIVEN + const entity = new Dependency(); + spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity }))); + comp.updateForm(entity); + // WHEN + comp.save(); + tick(); // simulate async + + // THEN + expect(service.create).toHaveBeenCalledWith(entity); + expect(comp.isSaving).toEqual(false); + })); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/dependency/dependency.component.spec.ts b/src/test/javascript/spec/app/entities/dependency/dependency.component.spec.ts new file mode 100644 index 0000000..0f591cb --- /dev/null +++ b/src/test/javascript/spec/app/entities/dependency/dependency.component.spec.ts @@ -0,0 +1,49 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { HttpHeaders, HttpResponse } from '@angular/common/http'; + +import { MicrocatalogTestModule } from '../../../test.module'; +import { DependencyComponent } from 'app/entities/dependency/dependency.component'; +import { DependencyService } from 'app/entities/dependency/dependency.service'; +import { Dependency } from 'app/shared/model/dependency.model'; + +describe('Component Tests', () => { + describe('Dependency Management Component', () => { + let comp: DependencyComponent; + let fixture: ComponentFixture; + let service: DependencyService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [MicrocatalogTestModule], + declarations: [DependencyComponent], + }) + .overrideTemplate(DependencyComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(DependencyComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(DependencyService); + }); + + it('Should call load all on init', () => { + // GIVEN + const headers = new HttpHeaders().append('link', 'link;link'); + spyOn(service, 'query').and.returnValue( + of( + new HttpResponse({ + body: [new Dependency(123)], + headers, + }) + ) + ); + + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenCalled(); + expect(comp.dependencies && comp.dependencies[0]).toEqual(jasmine.objectContaining({ id: 123 })); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/dependency/dependency.service.spec.ts b/src/test/javascript/spec/app/entities/dependency/dependency.service.spec.ts new file mode 100644 index 0000000..3c75ac7 --- /dev/null +++ b/src/test/javascript/spec/app/entities/dependency/dependency.service.spec.ts @@ -0,0 +1,104 @@ +import { TestBed, getTestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { DependencyService } from 'app/entities/dependency/dependency.service'; +import { IDependency, Dependency } from 'app/shared/model/dependency.model'; + +describe('Service Tests', () => { + describe('Dependency Service', () => { + let injector: TestBed; + let service: DependencyService; + let httpMock: HttpTestingController; + let elemDefault: IDependency; + let expectedResult: IDependency | IDependency[] | boolean | null; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + }); + expectedResult = null; + injector = getTestBed(); + service = injector.get(DependencyService); + httpMock = injector.get(HttpTestingController); + + elemDefault = new Dependency(0, 'AAAAAAA', 'AAAAAAA'); + }); + + describe('Service methods', () => { + it('should find an element', () => { + const returnedFromService = Object.assign({}, elemDefault); + + service.find(123).subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'GET' }); + req.flush(returnedFromService); + expect(expectedResult).toMatchObject(elemDefault); + }); + + it('should create a Dependency', () => { + const returnedFromService = Object.assign( + { + id: 0, + }, + elemDefault + ); + + const expected = Object.assign({}, returnedFromService); + + service.create(new Dependency()).subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'POST' }); + req.flush(returnedFromService); + expect(expectedResult).toMatchObject(expected); + }); + + it('should update a Dependency', () => { + const returnedFromService = Object.assign( + { + name: 'BBBBBB', + description: 'BBBBBB', + }, + elemDefault + ); + + const expected = Object.assign({}, returnedFromService); + + service.update(expected).subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'PUT' }); + req.flush(returnedFromService); + expect(expectedResult).toMatchObject(expected); + }); + + it('should return a list of Dependency', () => { + const returnedFromService = Object.assign( + { + name: 'BBBBBB', + description: 'BBBBBB', + }, + elemDefault + ); + + const expected = Object.assign({}, returnedFromService); + + service.query().subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'GET' }); + req.flush([returnedFromService]); + httpMock.verify(); + expect(expectedResult).toContainEqual(expected); + }); + + it('should delete a Dependency', () => { + service.delete(123).subscribe(resp => (expectedResult = resp.ok)); + + const req = httpMock.expectOne({ method: 'DELETE' }); + req.flush({ status: 200 }); + expect(expectedResult); + }); + }); + + afterEach(() => { + httpMock.verify(); + }); + }); +});