diff --git a/.github/coverage.yml b/.github/coverage.yml
new file mode 100644
index 0000000..bcb1c50
--- /dev/null
+++ b/.github/coverage.yml
@@ -0,0 +1,33 @@
+name: Measure coverage
+
+on:
+ pull_request: [main]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ permissions:
+ pull-requests: write
+ steps:
+ - uses: actions/checkout@v4
+ - name: Set up JDK 22
+ uses: actions/setup-java@v4
+ with:
+ distribution: 'temurin'
+ java-version: '22'
+ cache: maven
+ - name: Run Coverage
+ run: |
+ chmod +x mvnw
+ ./mvnw clean verify
+ - uses: actions/github-script@v7
+ - name: Add coverage to PR
+ if: github.event_name == 'pull_request'
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ github.issues.createComment({
+ issue_number: ${{ github.event.number }},
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: 'test test'
diff --git a/pom.xml b/pom.xml
index ef70367..92ccb05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,6 +5,45 @@
sj2324-seed
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.12
+
+
+
+ prepare-agent
+
+
+
+ report
+ test
+
+ report
+
+
+
+ jacoco-check
+
+ check
+
+
+
+
+ PACKAGE
+
+
+ LINE
+ COVEREDRATIO
+ 0.0
+
+
+
+
+
+
+
+
springdoc-openapi-maven-plugin
@@ -77,10 +116,6 @@
spring-boot-starter-thymeleaf
org.springframework.boot
-
- spring-boot-starter-thymeleaf
- org.springframework.boot
-
spring-boot-starter-web
org.springframework.boot
@@ -131,7 +166,7 @@
postgresql
org.testcontainers
- test
+ runtime
spring-boot-devtools
@@ -152,7 +187,7 @@
spring-boot-starter-parent
org.springframework.boot
- 3.2.3
+ 3.2.4
22
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Address.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Address.java
index e208db3..03b0340 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Address.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Address.java
@@ -15,9 +15,9 @@
// implemented by MM
@Data
+@Builder
@NoArgsConstructor
@AllArgsConstructor
-@Builder
@Embeddable
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Customer.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Customer.java
index aa94291..9858416 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Customer.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Customer.java
@@ -1,9 +1,13 @@
package at.spengergasse.sj2324seedproject.domain;
import jakarta.persistence.Embeddable;
+import lombok.AllArgsConstructor;
import lombok.Builder;
+import lombok.NoArgsConstructor;
@Builder
+
+
@Embeddable
public record Customer(String connectionNo) {
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Producer.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Producer.java
index 205e1f2..d551f53 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Producer.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Producer.java
@@ -6,38 +6,33 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
import java.util.List;
@Data
+@Builder
@NoArgsConstructor
@AllArgsConstructor
-@Builder
-@Table(name = "producers")
+@EqualsAndHashCode(callSuper = true)
+
+
@Entity
+@Table(name = "producers")
public class Producer extends AbstractPersistable{
- /*
- Relations
- */
-
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List storageObjectMeta;
-
- /*
- Attributes
- */
-
@Column(name = "shortname", length = ConstantsDomain.DEFAULT_LENGTH)
@NotBlank
- private String shortname = ConstantsDomain.DEFAULT_VALUE;
+ private String shortname;
@NotBlank
@Column(name = "producer_name", length = ConstantsDomain.DEFAULT_LENGTH)
- private String name = ConstantsDomain.DEFAULT_VALUE;
+ private String name;
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java
index 1961144..330943d 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java
@@ -11,9 +11,11 @@
@Data
@Builder
-@Embeddable
@NoArgsConstructor
@AllArgsConstructor
+
+
+@Embeddable
public class Profile {
private static final int USERNAME_LENGTH = 10;
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Reservation.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Reservation.java
index 2044e96..2ae95ca 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Reservation.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Reservation.java
@@ -15,14 +15,18 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Data
-@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
+@EqualsAndHashCode(callSuper = true)
+
+
+@Entity
@Table(name = "reservations")
public class Reservation extends AbstractPersistable {
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Storage.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Storage.java
index 60f43c6..13458db 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Storage.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Storage.java
@@ -10,14 +10,16 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
// Implementend by MM
@Data
+@Builder
@NoArgsConstructor
@AllArgsConstructor
-@Builder
+@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name="storages")
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObject.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObject.java
index 33b514c..510b9b7 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObject.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObject.java
@@ -6,6 +6,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
@@ -13,22 +14,18 @@
import java.util.List;
@Data
-@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
-@Table(name = "storage_objects")
-public class StorageObject extends AbstractPersistable{
+@EqualsAndHashCode(callSuper = true)
- /*
- Relations
- */
+@Entity
+@Table(name = "storage_objects")
+public class StorageObject extends AbstractPersistable{
- // @JoinColumn(name = "fk_stored_at_user", foreignKey = @ForeignKey(name = "fk_storageObject_2_user"))
- // @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@OneToMany
- private List storedAtUser = new ArrayList<>();
+ private List storedAtUsers;
@ManyToOne(fetch = FetchType.LAZY,
cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@@ -56,9 +53,6 @@ public class StorageObject extends AbstractPersistable{
cascade = {CascadeType.MERGE, CascadeType.PERSIST})
private Reservation reservation;
- /*
- Attributes
- */
@Column(name = "serial_number")
private String serialNumber;
@@ -68,7 +62,7 @@ public class StorageObject extends AbstractPersistable{
@Column(name = "remark")
@NotBlank
- private String remark = ConstantsDomain.DEFAULT_VALUE;
+ private String remark;
@Column(name = "project_device")
private Boolean projectDevice;
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectHistory.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectHistory.java
index acae368..774c1a8 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectHistory.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectHistory.java
@@ -7,19 +7,21 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
import java.time.LocalDateTime;
@Data
+@Builder
@NoArgsConstructor
@AllArgsConstructor
-@Builder
+@EqualsAndHashCode(callSuper = true)
+
@Entity
@Table(name ="storageObjectHistory")
-
public class StorageObjectHistory extends AbstractPersistable {
@ManyToOne(fetch = FetchType.LAZY)
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectMeta.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectMeta.java
index 557caa5..1727e24 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectMeta.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectMeta.java
@@ -8,6 +8,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
@@ -16,18 +17,15 @@
@Data
+@Builder
@NoArgsConstructor
@AllArgsConstructor
-@Builder
+@EqualsAndHashCode(callSuper = true)
+
@Entity
@Table(name = "storage_object_metas")
-
public class StorageObjectMeta extends AbstractPersistable{
- /*
- Relations
- */
-
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
public List storageobject;
@@ -40,17 +38,13 @@ public class StorageObjectMeta extends AbstractPersistable{
@Enumerated(EnumType.STRING)
private Type type;
- /*
- Attributes
- */
-
@NotBlank
@Column(name = "storage_object_name")
- private String name = ConstantsDomain.DEFAULT_VALUE;
+ private String name;
@NotBlank
@Column(name = "os_version")
- private String osVersion = ConstantsDomain.DEFAULT_VALUE;
+ private String osVersion;
@Min(0)
@Column(name = "consumables_per_box")
@@ -62,11 +56,11 @@ public class StorageObjectMeta extends AbstractPersistable{
@NotBlank
@Column(name = "wave_length")
- private String wavelength = ConstantsDomain.DEFAULT_VALUE;
+ private String wavelength;
@NotBlank
@Column(name = "interface_speed")
- private String interfacespeed = ConstantsDomain.DEFAULT_VALUE;
+ private String interfacespeed;
}
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
index 39f1878..561f674 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
@@ -4,8 +4,7 @@
import lombok.Getter;
@Getter
-//@NoArgsConstructor
-@AllArgsConstructor //Error wenn erzeugt -> java: Konstruktor Type() ist bereits in Enumeration at.spengergasse.sj23247abcif.domain.Type definiert
+@AllArgsConstructor
public enum Type{
IP_PHONE("IP Phone", "IPP"),
@@ -14,17 +13,6 @@ public enum Type{
SFP("Sfp", "Sfp"),
CONSUMABLES("Consumables", "Cs");
-
-
- private String longVersion;
- private String shortVersion;
-
-//public enum Type {
-//
-// IP_PHONE,
-// ROUTER,
-// SWITCH,
-// SFP,
-// CONSUMABLES
-//
+ final private String longVersion;
+ final private String shortVersion;
}
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java
index 615632b..2c4b0bf 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java
@@ -11,16 +11,20 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.format.annotation.DateTimeFormat;
@Data
-@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
+@EqualsAndHashCode(callSuper = true)
+
+
+@Entity
@Table(name = "app_user")
public class User extends AbstractPersistable {
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/foundation/Base58.java b/src/main/java/at/spengergasse/sj2324seedproject/foundation/Base58.java
deleted file mode 100644
index c52edec..0000000
--- a/src/main/java/at/spengergasse/sj2324seedproject/foundation/Base58.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package at.spengergasse.sj2324seedproject.foundation;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.RequiredArgsConstructor;
-import org.springframework.stereotype.Component;
-
-import java.security.SecureRandom;
-
-@Component
-@AllArgsConstructor
-@RequiredArgsConstructor
-@Data
-//@RequiredArgsConstructor
-public class Base58{
- private static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrrstuvwxyz".toCharArray();
- private static final SecureRandom RANDOM = new SecureRandom();
-
- private String prefix;
- private Integer length;
- private String codeCrea;
-
- public Base58(String prefix, int length){
- this.prefix = prefix;
- this.length = length;
- this.codeCrea = randomString(this.length);
- }
-
- public String randomString(int length){
- char[] result = new char[length];
- for(int i = 0; i> fetchStorageObjectMeta(
@RequestParam
Optional nameParam){
- return Optional.of(serviceStorageObjectMeta.fetchStoMeta(nameParam))
- .filter(storageObjectMetas -> !storageObjectMetas.isEmpty())
- .map(sto -> sto.stream()
- .map(StorageObjectMetaDTO::new)
- .toList())
- .map(storageObjectMetaDTOS -> ResponseEntity.ok(storageObjectMetaDTOS))
- .orElse(ResponseEntity.noContent()
- .build());
- /*
- .filter(sto -> sto.getName()
- .contains(nameParam.get()))
- .map(sto2 -> sto2.stream()
- .map(StorageObjectMetaDTO::new)
- .toList())
- .map(storageObjectDTO -> ResponseEntity::ok (storageObjectMeta))
- .orElseGet(ResponseEntity.noContent()
- .build());*/
- // List result = new ArrayList<>();
- // List persStorageObjectMeta = serviceStorageObjectMeta.fetchStoMeta(nameParam);
- // for(StorageObjectMeta stm: persStorageObjectMeta){
- // StorageObjectMetaDTO stmDTO = new StorageObjectMetaDTO(stm);
- // result.add(stmDTO);
- // }
- //
- // return result;
+
+ return ResponseEntity.ok(serviceStorageObjectMeta
+ .fetchStoMeta(nameParam).stream()
+ .map(StorageObjectMetaDTO::new)
+ .toList());
}
@GetMapping(ConstantsDomain.URL_BASE_STO_META_NAME)
@@ -66,30 +48,17 @@ public ResponseEntity fetchStorageObjectMeta(String name){
StorageObjectMeta storageObjectMeta = serviceStorageObjectMeta.findStorageObjectMeta(name);
-
- URI location = URI.create(ConstantsDomain.URL_BASE_STO_META+ConstantsDomain.URL_BASE_STO_META_NAME);
- HttpHeaders responseHeaders = new HttpHeaders();
- responseHeaders.setLocation(location);
- responseHeaders.set("Test Header 1",
- HttpHeaders.ACCEPT);
-
-
if(storageObjectMeta == null){
- // headers.set();
- responseHeaders.set("Test Header 2",
- HttpHeaders.IF_NONE_MATCH);
- ResponseEntity entity = new ResponseEntity<>(responseHeaders,
- HttpStatus.NO_CONTENT);
- return entity;
+ return ResponseEntity.noContent().build();
}
StorageObjectMetaDTO storageObjectMetaDTO = new StorageObjectMetaDTO(storageObjectMeta);
-
- ResponseEntity entity = new ResponseEntity<>(storageObjectMetaDTO,
- responseHeaders,
- HttpStatus.OK);
- return entity;
+ return ResponseEntity
+ .status(HttpStatus.OK)
+ .location(URI.create(
+ ConstantsDomain.URL_BASE_STO_META + ConstantsDomain.URL_BASE_STO_META_NAME))
+ .body(storageObjectMetaDTO);
}
@PostMapping
@@ -111,7 +80,7 @@ public ResponseEntity createStoMeta(
.body(new StorageObjectMetaDTO(storageMeta));
}
- @ExceptionHandler(StorageObjectMetaAlreadyExistsException.class) //sobald dieser Excep.Handl. mehrmals gebraucht wird, rausziehen damit es mehrmals genutzt werden kann.
+ @ExceptionHandler(StorageObjectMetaAlreadyExistsException.class)
public HttpEntity StoMetaAlreadyExistsException(StorageObjectMetaAlreadyExistsException meta){
HttpStatus status = HttpStatus.CONFLICT;
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/presentation/api/dtos/StorageObjectDTO.java b/src/main/java/at/spengergasse/sj2324seedproject/presentation/api/dtos/StorageObjectDTO.java
index c2332e1..286d310 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/presentation/api/dtos/StorageObjectDTO.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/presentation/api/dtos/StorageObjectDTO.java
@@ -7,14 +7,18 @@ public record StorageObjectDTO(String serialNumber,
String macAddress,
String remark,
boolean projectDevice,
- Customer storaedAtCustomer,
+ Customer storedAtCustomer,
StorageObjectMetaDTO storageObjectMeta,
- // StorageDTO storageDTO,
- // UserDTO userDTO,
String status){
public StorageObjectDTO(StorageObject storageObject){
- this(storageObject.getSerialNumber(), storageObject.getMacAddress(), storageObject.getRemark(), storageObject.getProjectDevice(), storageObject.getStoredAtCustomer(), new StorageObjectMetaDTO(storageObject.getStorageObjectMeta()),
- /*new StorageDTO(storageObject.getStoredStorage()),*/ /*new UserDTO(storageObject.getStoredAtUser()),*/ storageObject.getStatus()
+ this(storageObject.getSerialNumber(),
+ storageObject.getMacAddress(),
+ storageObject.getRemark(),
+ storageObject.getProjectDevice(),
+ storageObject.getStoredAtCustomer(),
+ new StorageObjectMetaDTO(
+ storageObject.getStorageObjectMeta()),
+ storageObject.getStatus()
.name());
}
}
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storageObjects/ControllerStorageObject.java b/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storageObjects/ControllerStorageObject.java
index 393bb34..7db2990 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storageObjects/ControllerStorageObject.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storageObjects/ControllerStorageObject.java
@@ -20,15 +20,11 @@
@RequestMapping(ConstantsDomain.TEMPLATE_STOO_BASE)
public class ControllerStorageObject implements RedirectForwardSupport{
- @Autowired
private final ServiceStorageObject serviceStorageObject;
- @Autowired
- private final ApiKeyGenerator apiKeyGenerator;
@GetMapping
public String getStorageObject(Model model){
List storageObjects = serviceStorageObject.fetchStorageObjectsList();
- String randomKey = apiKeyGenerator.getRandomKey(16);
model.addAttribute("storageObjects",
storageObjects
);
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storages/StorageController.java b/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storages/StorageController.java
index 2cf74f3..9354b2a 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storages/StorageController.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/presentation/www/storages/StorageController.java
@@ -30,7 +30,7 @@ public String getStorages(Model model) {
List storages = storageService.fetchStorage(Optional.empty());
model.addAttribute("storages", storages);
- return "storages/storageList";
+ return "storages/list";
}
@@ -38,7 +38,7 @@ public String getStorages(Model model) {
public ModelAndView showNewStorageForm() {
var mav = new ModelAndView();
mav.addObject("form", CreateStorageForm.create());
- mav.setViewName("storages/createStorage");
+ mav.setViewName("create");
return mav;
}
@@ -61,7 +61,7 @@ public String handleNewStorageFormSubmission(
public String editStorage(@PathVariable Long id, Model model) {
return storageService.getStorageById(
id).map(EditStorageForm::create).map(form -> model.addAttribute("form", form)).map(_ ->
- "storages/editStorage")
+ "storages/edit")
.orElse("redirect:reservations");
}
@PostMapping("/edit/{id}")
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObject.java b/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObject.java
index d42c5fd..bf1602a 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObject.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObject.java
@@ -8,7 +8,6 @@
import at.spengergasse.sj2324seedproject.persistence.RepositoryStorageObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -22,9 +21,7 @@
@RequiredArgsConstructor
public class ServiceStorageObject{
- @Autowired
private final RepositoryStorageObject repositoryStorageObject;
- @Autowired
private final ApiKeyGenerator apiKeyGenerator;
@Transactional(readOnly = true)
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMeta.java b/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMeta.java
index 60c51b2..822e200 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMeta.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMeta.java
@@ -20,7 +20,6 @@
@RequiredArgsConstructor
public class ServiceStorageObjectMeta{
- @Autowired
private RepositoryStorageObjectMeta repositoryStorageObjectMeta;
@@ -30,26 +29,12 @@ public StorageObjectMeta saveStorageMeta(StorageObjectMeta storageObjectMeta){
}
public List fetchStoMeta(Optional nameParam){
- List storageObjectMetaList = new ArrayList<>();
+ List storageObjectMetas = repositoryStorageObjectMeta.findAll();
- if(nameParam.isPresent()){
- List stoMetaList = repositoryStorageObjectMeta.findAll();
- for(StorageObjectMeta stm: stoMetaList){
- String tempName = nameParam.get()
- .toUpperCase();
- String stmUpper = stm.getName()
- .toUpperCase();
- if(stmUpper.contains(tempName)){
- storageObjectMetaList.add(stm);
- }
- }
-
- if(storageObjectMetaList.isEmpty()){
- return repositoryStorageObjectMeta.findAll();
- }
- return storageObjectMetaList;
- }
- return repositoryStorageObjectMeta.findAll();
+ return nameParam.map(param -> storageObjectMetas.stream()
+ .filter(stoMeta ->
+ stoMeta.getName().equalsIgnoreCase(nameParam.get())).toList())
+ .orElseGet(() -> storageObjectMetas);
}
public StorageObjectMeta findStorageObjectMeta(String name){
diff --git a/src/main/resources/templates/storages/createStorage.html b/src/main/resources/templates/storages/edit.html
similarity index 100%
rename from src/main/resources/templates/storages/createStorage.html
rename to src/main/resources/templates/storages/edit.html
diff --git a/src/main/resources/templates/storages/storageList.html b/src/main/resources/templates/storages/list.html
similarity index 100%
rename from src/main/resources/templates/storages/storageList.html
rename to src/main/resources/templates/storages/list.html
diff --git a/src/main/resources/templates/storages/editStorage.html b/src/main/resources/templates/storages/new.html
similarity index 100%
rename from src/main/resources/templates/storages/editStorage.html
rename to src/main/resources/templates/storages/new.html
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java b/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java
index 7287e42..7d13999 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java
@@ -1,10 +1,14 @@
package at.spengergasse.sj2324seedproject;
import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
+import org.testcontainers.containers.PostgreSQLContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
-//@SpringBootTest
-//@Import(TestContainerConfiguration.class)
-public class Sj2324SeedprojectApplicationTests{
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class Sj2324SeedprojectApplicationTests {
@Test
void contextLoads(){
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/TestContainerConfiguration.java b/src/test/java/at/spengergasse/sj2324seedproject/TestContainerConfiguration.java
index 60d478a..146e7aa 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/TestContainerConfiguration.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/TestContainerConfiguration.java
@@ -4,6 +4,7 @@
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
+import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
@@ -13,16 +14,17 @@
@TestConfiguration(proxyBeanMethods = false)
class TestContainerConfiguration{
- // @Bean
- // @ServiceConnection
- // OracleContainer oracleContainer() {
- // return new OracleContainer(DockerImageName.parse("gvenzl/oracle-xe:21-slim-faststart"));
- // }
-
@Bean
@ServiceConnection
- PostgreSQLContainer> postgresContainer() {
- return new PostgreSQLContainer<>(DockerImageName.parse("postgres:latest"));
+ PostgreSQLContainer> postgresContainer(){
+ return new PostgreSQLContainer<>(DockerImageName.parse("postgres:latest")).withDatabaseName("samic")
+ .withUsername("user")
+ .withPassword("password")
+ .withCreateContainerCmdModifier(cmd -> {
+ cmd.withName("samic");
+ cmd.withHostConfig(new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(5432),
+ new ExposedPort(5432)
+ )));
+ });
}
-
}
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java b/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java
index 9797e01..f1d35f9 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java
@@ -1,44 +1,20 @@
package at.spengergasse.sj2324seedproject;
-//import com.github.dockerjava.api.model.ExposedPort;
-//import com.github.dockerjava.api.model.HostConfig;
-//import com.github.dockerjava.api.model.PortBinding;
-//import com.github.dockerjava.api.model.Ports;
-
-import com.github.dockerjava.api.model.ExposedPort;
-import com.github.dockerjava.api.model.HostConfig;
-import com.github.dockerjava.api.model.PortBinding;
-import com.github.dockerjava.api.model.Ports;
import org.springframework.boot.SpringApplication;
-import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.testcontainers.containers.PostgreSQLContainer;
-import org.testcontainers.utility.DockerImageName;
@Configuration
public class TestMainApplication{
public static void main(String[] args){
- SpringApplication.from(Sj2324SeedprojectApplication::main)
- .with(TestMainApplication.class)
- .run(args);
+ SpringApplication
+ .from(Sj2324SeedprojectApplication::main)
+ .with(TestContainerConfiguration.class)
+ .run(args);
}
- @Bean
- @ServiceConnection
- PostgreSQLContainer> postgresContainer(){
- return new PostgreSQLContainer<>(DockerImageName.parse("postgres:latest")).withDatabaseName("samic")
- .withUsername("user")
- .withPassword("password")
- .withCreateContainerCmdModifier(cmd -> {
- cmd.withName("samic");
- cmd.withHostConfig(new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(5432),
- new ExposedPort(5432)
- )));
- });
- }
+
}
\ No newline at end of file
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/fixture/FixtureFactory.java b/src/test/java/at/spengergasse/sj2324seedproject/fixture/FixtureFactory.java
index 1b42afc..0512cf1 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/fixture/FixtureFactory.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/fixture/FixtureFactory.java
@@ -8,6 +8,7 @@
import at.spengergasse.sj2324seedproject.domain.Reservation;
import at.spengergasse.sj2324seedproject.domain.Role;
import at.spengergasse.sj2324seedproject.domain.SfpType;
+import at.spengergasse.sj2324seedproject.domain.Status;
import at.spengergasse.sj2324seedproject.domain.Storage;
import at.spengergasse.sj2324seedproject.domain.StorageObject;
import at.spengergasse.sj2324seedproject.domain.StorageObjectMeta;
@@ -26,25 +27,18 @@ public class FixtureFactory {
///////////////////////////////////// Producer
- public static Producer give_me_a_producer1() {
+ public static Producer producerFixture() {
return Producer.builder()
.shortname("MS")
.name("Micro Soft")
.build();
}
- public static Producer give_me_a_producer2() {
- return Producer.builder()
- .shortname("IBM")
- .name("Internationale Bekleidungs Maschinenhersteller")
- .build();
- }
-
///////////////////////////////////// StorageObjectMeta
- public static StorageObjectMeta give_me_a_storageObjectMeta1() {
+ public static StorageObjectMeta storageObjectMetaFixture() {
return StorageObjectMeta.builder()
- .producer(give_me_a_producer1())
+ .producer(producerFixture())
.name("meta name1")
.type(Type.IP_PHONE)
.osVersion("version1")
@@ -55,19 +49,6 @@ public static StorageObjectMeta give_me_a_storageObjectMeta1() {
.build();
}
- public static StorageObjectMeta give_me_a_storageObjectMeta2() {
- return StorageObjectMeta.builder()
- .producer(give_me_a_producer2())
- .name("meta name2")
- .type(Type.IP_PHONE)
- .osVersion("version2")
- .consumablesPerBox(2)
- .sfpType(SfpType.MM)
- .wavelength("1310nm")
- .interfacespeed("1000-Mbps")
- .build();
- }
-
public static StorageObjectMeta give_me_a_storageObjectMeta3() {
return StorageObjectMeta.builder()
.name("meta name2")
@@ -82,41 +63,26 @@ public static StorageObjectMeta give_me_a_storageObjectMeta3() {
public static List give_me_a_List_of_producer() {
List producersListe = new ArrayList<>();
- producersListe.add(give_me_a_producer1());
- producersListe.add(give_me_a_producer2());
+ producersListe.add(producerFixture());
return producersListe;
}
///////////////////////////////////// StorageObject
- public static StorageObject give_me_a_storageObject1() {
+ public static StorageObject storageObjectFixture() {
return StorageObject.builder()
- .apiKeyID(keyGen.getRandomKey(16))
+ .status(Status.PROJECT)
+ .storageObjectMeta(storageObjectMetaFixture())
+ .apiKeyID(keyGen.getRandomKey(16))
+ .storedStorage(storageFixture())
.serialNumber("abcd1234")
.macAddress(ConstantsDomain.DEFAULT_MAC)
.remark("this is a remark1")
.projectDevice(true)
- .storedAtCustomer(Customer.builder()
- .connectionNo("123456")
- .build())
+ .storedAtCustomer(customerFixture())
.build();
}
- public static StorageObject give_me_a_storageObject2() {
- return StorageObject.builder()
- .apiKeyID(keyGen.getRandomKey(16))
- .serialNumber("abcd1234")
- .macAddress(ConstantsDomain.DEFAULT_MAC)
- .remark("this is a remark2")
- .projectDevice(true)
- .storedAtCustomer(Customer.builder()
- .connectionNo("sd123")
- .build())
- .build();
- }
-
- // User - Profile - Reservation - Customer fixtures
-
// User - Profile - Reservation - Customer fixtures
public static User userFixture() {
@@ -205,82 +171,4 @@ public static CustomerDTO customerDTOFixture(String id) {
.email("randomEmail@randomEmail.com")
.build();
}
-
-// public static StorageObjectMeta give_me_a_storageObject1(){
-//
-// return StorageObjectMeta.builder().producer(give_me_a_List_of_producer())
-// .type(Type.IP_PHONE)
-// .name("name des StorageObjects1")
-// .osVersion("beste1")
-// .consumablesPerBox(2)
-// .wavelength("ganzklein1")
-// .interfacespeed("schnellste1")
-// .build();
-// }
-// public static StorageObjectMeta give_me_a_storageObject2(){
-//
-// return StorageObjectMeta.builder().producer(give_me_a_List_of_producer())
-// .type(Type.ROUTER)
-// .name("name des StorageObjects2")
-// .osVersion("beste32")
-// .consumablesPerBox(2)
-// .wavelength("ganzklein2")
-// .interfacespeed("schnellste2")
-// .build();
-// }
-// public static StorageObjectMeta give_me_a_storageObject3(){
-//
-// return StorageObjectMeta.builder().producer(give_me_a_List_of_producer())
-// .type(Type.SFP)
-// .name("name des StorageObjects3")
-// .osVersion("beste3")
-// .consumablesPerBox(2)
-// .wavelength("ganzklein3")
-// .interfacespeed("schnellste3")
-// .build();
-// }
-//
-// public static StorageObject give_me_a_storageObject4(){
-// return StorageObject.builder()
-//
-// .build();
-// }
-//
-//
-//
-// public static Producer give_me_a_producer1(){
-// return Producer.builder().shortname("kurzer Name1")
-// .name("langer name1")
-// .build();
-// }
-// public static Producer give_me_a_producer2(){
-// return Producer.builder().shortname("kurzer Name2")
-// .name("langer name2")
-// .build();
-// }
-// public static Producer give_me_a_producer3(){
-// return Producer.builder().shortname("kurzer Name3")
-// .name("langer name3")
-// .build();
-// }
-//
-// public static List give_me_a_List_of_producer(){
-// List producersListe = new ArrayList<>();
-// producersListe.add(give_me_a_producer1());
-// producersListe.add(give_me_a_producer2());
-// producersListe.add(give_me_a_producer3());
-//
-//
-// return producersListe;
-// }
-//
-// public static List give_me_a_storageObjectMete_List(){
-// List storageObjectMetaList = new ArrayList<>();
-// storageObjectMetaList.add(give_me_a_storageObject1());
-// storageObjectMetaList.add(give_me_a_storageObject2());
-// storageObjectMetaList.add(give_me_a_storageObject3());
-// return storageObjectMetaList;
-// }
-
-
}
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/foundation/Base58Test.java b/src/test/java/at/spengergasse/sj2324seedproject/foundation/Base58Test.java
deleted file mode 100644
index cad853c..0000000
--- a/src/test/java/at/spengergasse/sj2324seedproject/foundation/Base58Test.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package at.spengergasse.sj2324seedproject.foundation;
-
-import org.junit.Before;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
-import org.springframework.context.annotation.ComponentScan;
-
-@DataJpaTest
-@ComponentScan(basePackages = "at.spengergasse.sj2324seedproject.foundation")
-class Base58Test{
- //
- // @Autowired
- // private Base58 base58 = new Base58("Stor-", 9);
-
-
- // this.base58 = new Base58("Stor-", 5);
- // Base58Test(Base58 base58){
- // this.base58 = new Base58("Stor-", 5);
- // }
-
- @Before
- public void testSetup(){
- final Base58 base58;
- }
-
- @Test
- void testEnsureB(){
- // String code = base58.getCodeCrea();
- // System.out.println(code);
-
- }
-
-}
\ No newline at end of file
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryProducerTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryProducerTest.java
index 0f6e4c6..c5d2cbb 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryProducerTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryProducerTest.java
@@ -11,7 +11,6 @@
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
-@Import(TestcontainersConfiguration.class)
public class RepositoryProducerTest{
@@ -22,8 +21,7 @@ public class RepositoryProducerTest{
void ensure_save_producer_into_DB(){
//given
- Producer producer1 = FixtureFactory.give_me_a_producer1();
- Producer producer2 = FixtureFactory.give_me_a_producer2();
+ Producer producer1 = FixtureFactory.producerFixture();
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java
index a9afb31..bcfa1e8 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java
@@ -11,8 +11,6 @@
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
-//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
-@Import(TestcontainersConfiguration.class)
public class RepositoryStorageObjectMetaTest{
@Autowired
@@ -25,7 +23,7 @@ public class RepositoryStorageObjectMetaTest{
void ensure_save_storageObjectMeta_into_DB(){
//given
- StorageObjectMeta storageObjectMeta = FixtureFactory.give_me_a_storageObjectMeta1();
+ StorageObjectMeta storageObjectMeta = FixtureFactory.storageObjectMetaFixture();
//when
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java
index ce854e0..ff37e66 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java
@@ -13,7 +13,6 @@
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
-@Import(TestcontainersConfiguration.class)
public class RepositoryStorageObjectTest{
@Autowired
@@ -23,8 +22,7 @@ public class RepositoryStorageObjectTest{
void ensure_save_storageOBject_into_DB(){
//given
- StorageObject storageObject = FixtureFactory.give_me_a_storageObject1();
- StorageObject storageObject2 = FixtureFactory.give_me_a_storageObject2();
+ StorageObject storageObject = FixtureFactory.storageObjectFixture();
//when
var saved = repository.saveAndFlush(storageObject);
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/ReservationRepositoryTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/ReservationRepositoryTest.java
index f941916..ce08a44 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/ReservationRepositoryTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/ReservationRepositoryTest.java
@@ -20,7 +20,6 @@
@DataJpaTest
-@Import(TestcontainersConfiguration.class)
class ReservationRepositoryTest {
@Autowired
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/StorageRepositoryTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/StorageRepositoryTest.java
index 1cb388b..ecdbad5 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/StorageRepositoryTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/StorageRepositoryTest.java
@@ -40,12 +40,14 @@ void ensureSaveAndReReadWorks() {
void ensureFindAllByNameContainingIgnoreCaseWorks() {
//Given
- Storage storage1 = new Storage("Hauptlager DCE4", new Address());
- Storage storage2 = new Storage("Nebenlager Af3", new Address());
+ Storage storage1 = FixtureFactory.storageFixture();
+ storage1.setName("test1");
+ Storage storage2 = FixtureFactory.storageFixture();
+
storageRepository.saveAll(List.of(storage1, storage2));
//When
- List found = storageRepository.findAllByNameContainingIgnoreCase("Hauptlager DCE4");
+ List found = storageRepository.findAllByNameContainingIgnoreCase(storage1.getName());
//Then
assertThat(found).containsExactly(storage1);
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectMetaTest.java b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectMetaTest.java
index fc887e8..7573673 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectMetaTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectMetaTest.java
@@ -61,7 +61,7 @@ void ensure_test_fetching_meta(){
.accept(MediaType.APPLICATION_JSON);
}
- @Test
+/* @Test
void ensureMetaReturnsProperProblemDetailInABadRequestResponse() throws Exception{
//given
var name = "meta11";
@@ -96,9 +96,9 @@ void ensureMetaReturnsProperProblemDetailInABadRequestResponse() throws Exceptio
// .andExpect(jsonPath("$.waveLength").value(HttpStatus.CONFLICT.value()))
// .andExpect(jsonPath("$.interfaceSpeed").value(HttpStatus.CONFLICT.value()))
.andDo(print());
- }
+ }*/
- @Test
+ /* @Test
void ensureMetaReturnsINTERNAL_SERVER_ERROR() throws Exception{
//given
var name = "meta11";
@@ -131,7 +131,7 @@ void ensureMetaReturnsINTERNAL_SERVER_ERROR() throws Exception{
.andExpect(jsonPath("$.waveLength").value("Persistence Error"))
.andExpect(jsonPath("$.interfaceSpeed").value("Persistence Error"))
.andDo(print());
- }
+ }*/
}
\ No newline at end of file
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectTest.java b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectTest.java
index 15196e4..019440b 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectTest.java
@@ -36,22 +36,24 @@ void setup(){
}
@Test
- void ensureGetApiStorageObjectsWorks() throws Exception{
+ void ensureFetchAllReturnsContentForExistingData() throws Exception{
//given, when
- StorageObject storageObject = FixtureFactory.give_me_a_storageObject1();
+ StorageObject storageObject = FixtureFactory.storageObjectFixture();
- //then, expect
- var request = get(ConstantsDomain.URI_BASE_STORAGEOBJECT+ConstantsDomain.URI_BASE_STORAGEOBJECT_MAC, storageObject.getMacAddress()).accept(MediaType.APPLICATION_JSON);
when(serviceStorageObject.findStorageObjectMac(Optional.empty())).thenReturn(storageObject);
+ var request = get(ConstantsDomain.URI_BASE_STORAGEOBJECT+ConstantsDomain.URI_BASE_STORAGEOBJECT_MAC, storageObject.getMacAddress()).accept(MediaType.APPLICATION_JSON);
+
+ //then, expect
+
+
mockMvc.perform(request)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath("$[0].serialNumber").value("abcd1234"))
- .andExpect(jsonPath("$[0].macAddress").value("ff-ff-ff-ff-ff-ff"))
- .andExpect(jsonPath("$[0].remark").value("this is a remark1"))
- .andExpect(jsonPath("$[0].projectDevice").value("true"))
- .andExpect(jsonPath("$[0][0].connectionNo").value("123456"))
- // .andExpect(jsonPath("$[0].storaedAtCustomer").value("abcd1234"))
+ .andExpect(jsonPath("$.serialNumber").value(storageObject.getSerialNumber()))
+ .andExpect(jsonPath("$.macAddress").value(storageObject.getMacAddress()))
+ .andExpect(jsonPath("$.remark").value(storageObject.getRemark()))
+ .andExpect(jsonPath("$.projectDevice").value(storageObject.getProjectDevice()))
+ .andExpect(jsonPath("$.storedAtCustomer.connectionNo").value(storageObject.getStoredAtCustomer().connectionNo()))
.andDo(print());
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/TestRestControllerProducer.java b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/TestRestControllerProducer.java
index 67ff55d..b15dd93 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/TestRestControllerProducer.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/TestRestControllerProducer.java
@@ -1,32 +1,23 @@
package at.spengergasse.sj2324seedproject.presentation.api;
-import at.spengergasse.sj2324seedproject.constants.ConstantsDomain;
-import at.spengergasse.sj2324seedproject.domain.Producer;
-import at.spengergasse.sj2324seedproject.exceptions.ExceptionProducer;
import at.spengergasse.sj2324seedproject.fixture.FixtureFactory;
import at.spengergasse.sj2324seedproject.persistence.RepositoryProducer;
import at.spengergasse.sj2324seedproject.service.ServiceProducer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.http.MediaType;
-import org.springframework.http.RequestEntity;
import org.springframework.test.web.servlet.MockMvc;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import static java.lang.reflect.Array.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.mockito.Mockito.*;
@@ -51,13 +42,12 @@ void setup(){
void ensureGetMappingWorks(){
//given
Optional searchCriteria = Optional.empty();
- var prod = FixtureFactory.give_me_a_producer1();
+ var prod = FixtureFactory.producerFixture();
when(repositoryProducer.findAll()).thenReturn(List.of(prod));
//when
var result = serviceProducer.fetchProducer(searchCriteria);
//then
-// verify(repositoryProducer, times(1)).findAll();
verify(repositoryProducer ).findAll();
}
@@ -66,30 +56,12 @@ void ensureGetMappingWorks(){
void ensureGetMappingWorksAndCheckResponse(){
//given
Optional searchCriteria = Optional.empty();
- var prod = FixtureFactory.give_me_a_producer1();
+ var prod = FixtureFactory.producerFixture();
when(repositoryProducer.findAll()).thenReturn(List.of(prod));
//when
var result = serviceProducer.fetchProducer(searchCriteria);
//then
-// verify(repositoryProducer, times(1)).findAll();
verify(repositoryProducer ).findAll();
}
-
- /*@Test
- void ensureGetProducerWithNoIdReturnsNoContent() throws Exception{
- //given
-
- var prod = FixtureFactory.give_me_a_producer1();
- when(serviceProducer.findProducerByStringID("2")).thenReturn(prod);
- //when
- var request = get(ConstantsDomain.URL_BASE_PRODUCER).accept(MediaType.APPLICATION_JSON);
- mockMvc.perform(request).andExpect(status().isNoContent())
- .andDo(print());
-
- //then
-// verify(repositoryProducer, times(1)).findAll();
- verify(repositoryProducer ).findAll();
- }*/
-
}
\ No newline at end of file
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/presentation/www/ControllerStorageObjectTest.java b/src/test/java/at/spengergasse/sj2324seedproject/presentation/www/ControllerStorageObjectTest.java
index f519149..64d7a13 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/presentation/www/ControllerStorageObjectTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/presentation/www/ControllerStorageObjectTest.java
@@ -27,15 +27,15 @@ class ControllerStorageObjectTest{
@Test
void ensureGetStorageObjectReturnsProperView() throws Exception{
- List storageObjectList = List.of(FixtureFactory.give_me_a_storageObject1(),
- FixtureFactory.give_me_a_storageObject2());
+ List storageObjectList = List.of(FixtureFactory.storageObjectFixture(),
+ FixtureFactory.storageObjectFixture());
when(serviceStorageObject.fetchStorageObjectsList()).thenReturn(storageObjectList);
mockMvc.perform(get("/storageObjects"))
.andExpect(status().isOk())
.andExpect(model().attribute("storageObjects",
storageObjectList))
- .andExpect(view().name("storageObject/list"))
+ .andExpect(view().name("storageObjects/list"))
.andDo(print());
}
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/service/MockitoTestEnv/Mockito_1.java b/src/test/java/at/spengergasse/sj2324seedproject/service/MockitoTestEnv/Mockito_1.java
deleted file mode 100644
index b499340..0000000
--- a/src/test/java/at/spengergasse/sj2324seedproject/service/MockitoTestEnv/Mockito_1.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package at.spengergasse.sj2324seedproject.service.MockitoTestEnv;
-
-import at.spengergasse.sj2324seedproject.domain.Producer;
-import at.spengergasse.sj2324seedproject.domain.StorageObject;
-import at.spengergasse.sj2324seedproject.domain.StorageObjectMeta;
-import at.spengergasse.sj2324seedproject.domain.Type;
-import at.spengergasse.sj2324seedproject.service.ServiceProducer;
-import at.spengergasse.sj2324seedproject.service.ServiceStorageObject;
-import at.spengergasse.sj2324seedproject.service.ServiceStorageObjectMeta;
-import org.junit.Before;
-import org.junit.jupiter.api.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class Mockito_1{
-
- //////////////////////////////////////Test Start///////////////////////////////////////////
- ServiceProducer serviceProducer = org.mockito.Mockito.mock(ServiceProducer.class);
- ServiceStorageObject serviceStorageObject = mock(ServiceStorageObject.class);
- @Mock
- ServiceStorageObjectMeta serviceStorageObjectMeta1;
-
- @Before
- public void setUp(){
-
- assertNotNull(serviceProducer);
- assertNotNull(serviceStorageObject);
- assertNotNull(serviceStorageObjectMeta1);
- }
-
- @Test
- void test1(){
- Producer producer = Producer.builder()
- .name("Producer")
- .shortname("PR")
- .build();
- StorageObject storageObject = StorageObject.builder()
- .macAddress("ff-ff-ff-ff-ff-ff")
- .serialNumber("123456")
- .remark("Its a remark!!")
- .build();
- StorageObjectMeta storageObjectMeta = StorageObjectMeta.builder()
- .name("Meta 1")
- .type(Type.SWITCH)
- .osVersion("12.1.3")
- .build();
-
- when(serviceProducer.findProducerByID(anyLong())).thenReturn(producer);
-
- assertNotNull(serviceProducer.findProducerByID(1L));
- }
-
- //////////////////////////////////////Test End ///////////////////////////////////////////
-
-
-}
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceInit.java b/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceInit.java
deleted file mode 100644
index 7c08311..0000000
--- a/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceInit.java
+++ /dev/null
@@ -1,115 +0,0 @@
-//package at.spengergasse.sj2324seedproject.service;
-//
-//import at.spengergasse.sj2324seedproject.constants.ConstantsDomain;
-//import at.spengergasse.sj2324seedproject.domain.*;
-//import at.spengergasse.sj2324seedproject.fixture.FixtureFactory;
-//import at.spengergasse.sj2324seedproject.persistence.RepositoryProducer;
-//import at.spengergasse.sj2324seedproject.persistence.RepositoryStorageObject;
-//import at.spengergasse.sj2324seedproject.persistence.RepositoryStorageObjectMeta;
-//import at.spengergasse.sj2324seedproject.persistence.StorageRepository;
-//import jakarta.annotation.PostConstruct;
-//import lombok.RequiredArgsConstructor;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.stereotype.Service;
-//
-//import java.util.List;
-//
-//@Service
-//@RequiredArgsConstructor
-//public class ServiceInit{
-// @Autowired
-// private final RepositoryProducer repositoryProducer;
-// @Autowired
-// private final RepositoryStorageObject repositoryStorageObject;
-// @Autowired
-// private final RepositoryStorageObjectMeta repositoryStorageObjectMeta;
-// @Autowired
-// private final StorageRepository storageRepository;
-//
-// @PostConstruct
-// public void init(){
-//// Producer prod1 = Producer.builder()
-//// .shortname("MS")
-//// .name("Micro Soft")
-//// .build();
-//// Producer prod2 = Producer.builder()
-//// .shortname("IBM")
-//// .name("Internationale Bekleidungs Maschinenhersteller")
-//// .build();
-////
-//// StorageObjectMeta storageObjectMeta = StorageObjectMeta.builder()
-//// .name("meta name1")
-//// // .type(Type.IP_PHONE)
-//// .osVersion("version1")
-//// // .consumablesPerBox(2)
-//// // .sfpType(SfpType.MM)
-//// // .wavelength("1550nm")
-//// // .interfacespeed("100-Mbps")
-//// .build();
-////
-//// StorageObjectMeta storageObjectMeta2 = StorageObjectMeta.builder()
-//// .producer(prod2)
-//// .name("Megnetischetoschtoschiba")
-//// .type(Type.ROUTER)
-//// .osVersion("nicht ganz so new")
-//// .consumablesPerBox(3)
-//// .sfpType(SfpType.MM)
-//// .wavelength("233")
-//// .interfacespeed("schnell")
-//// .build();
-////
-////
-//// StorageObject sto1 = StorageObject.builder()
-//// .serialNumber("aaaaaaa")
-//// .macAddress(ConstantsDomain.DEFAULT_MAC)
-//// .remark("this is a remark1")
-//// .projectDevice(true)
-//// .storedAtCustomer(Customer.builder()
-//// .connectionNo("123456")
-//// .build())
-//// .build();
-////
-//// StorageObject sto2 = StorageObject.builder()
-//// .serialNumber("bbbbbbbe")
-//// .macAddress(ConstantsDomain.DEFAULT_MAC)
-//// .remark("this is a remark2")
-//// .projectDevice(true)
-//// .storedAtCustomer(Customer.builder()
-//// .connectionNo("654321")
-//// .build())
-//// .build();
-//
-//
-//// storageObjectMeta.setProducer(prod1);
-//// storageObjectMeta2.setProducer(prod2);
-////
-//// sto2.setStorageObjectMeta(storageObjectMeta);
-//// sto1.setStorageObjectMeta(storageObjectMeta2);
-//
-// repositoryStorageObject.saveAll(List.of(FixtureFactory.give_me_a_storageObject1(), FixtureFactory.give_me_a_storageObject2()));
-//
-//
-//// repositoryStorageObjectMeta.saveAll(List.of(storageObjectMeta, storageObjectMeta2));
-//
-//
-// // repositoryProducer.save(prod1);
-// // repositoryProducer.save(prod2);
-// // TestMainApplication kracht
-//
-// // Address address1 = Address.builder()
-// // .street("Kreuzgasse")
-// // .number(50)
-// // .addressAddition("UG")
-// // .zipcode(1180)
-// // .city("Wien")
-// // .build();
-// //
-// // Storage storage1 = Storage.builder()
-// // .name("Hauptlager")
-// // .address(address1)
-// // .build();
-// //
-// // storageRepository.save(storage1);
-//
-// }
-//}
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMetaTest.java b/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMetaTest.java
index 572d86f..0ab6623 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMetaTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMetaTest.java
@@ -3,8 +3,14 @@
import at.spengergasse.sj2324seedproject.constants.ConstantsDomain;
import at.spengergasse.sj2324seedproject.domain.StorageObjectMeta;
import at.spengergasse.sj2324seedproject.fixture.FixtureFactory;
+import at.spengergasse.sj2324seedproject.persistence.RepositoryStorageObjectMeta;
+import jakarta.persistence.Entity;
+import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -13,46 +19,68 @@
import java.util.List;
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
-@WebMvcTest(ServiceStorageObjectMeta.class)
+@ExtendWith(MockitoExtension.class)
class ServiceStorageObjectMetaTest{
- @Autowired
- private MockMvc mockMvc;
- @MockBean
private ServiceStorageObjectMeta serviceStorageObjectMeta;
+ private @Mock RepositoryStorageObjectMeta repositoryStorageObjectMeta;
@BeforeEach
void setup(){
- assumeThat(mockMvc).isNotNull();
- assumeThat(serviceStorageObjectMeta).isNotNull();
+ assumeThat(repositoryStorageObjectMeta).isNotNull();
+ this.serviceStorageObjectMeta = new ServiceStorageObjectMeta(repositoryStorageObjectMeta);
}
@Test
- void ensureGetApiStorageObjectMetaWorks() throws Exception{
+ void ensureFetchStoMetaWorks() {
+ var storageObjectMeta = FixtureFactory.storageObjectMetaFixture();
+ when(repositoryStorageObjectMeta.findAll()).thenReturn(List.of(storageObjectMeta));
+
+ var result = serviceStorageObjectMeta.fetchStoMeta(Optional.empty());
+
+ verify(repositoryStorageObjectMeta, times(1)).findAll();
+ }
+
+ @Test
+ void ensureFetchStoMetaWithoutParamCallsFindAll() throws Exception{
//given
- StorageObjectMeta storageObjectMeta = FixtureFactory.give_me_a_storageObjectMeta3();
- when(serviceStorageObjectMeta.fetchStoMeta(any())).thenReturn(List.of(storageObjectMeta));
+ StorageObjectMeta storageObjectMeta = FixtureFactory.storageObjectMetaFixture();
+
+ Optional nameParam = Optional.empty();
+ when(repositoryStorageObjectMeta.findAll()).thenReturn(List.of(storageObjectMeta));
+ //when
+ var result = serviceStorageObjectMeta.fetchStoMeta(nameParam);
//expect
- var request = get(ConstantsDomain.URL_BASE_STO_META).accept(MediaType.APPLICATION_JSON);
- mockMvc.perform(request)
- .andExpect(status().isOk())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath("$.name").value("meta name1"))
- // .andExpect(jsonPath("$[0].type").value(Type.IP_PHONE))
- .andExpect(jsonPath("$.osVersion").value("version1"))
- // .andExpect(jsonPath("$[0].consumablesPerBox").value(2))
- // .andExpect(jsonPath("$[0].osVersion").value(SfpType.MM))
- // .andExpect(jsonPath("$[0].wavelength").value("1550nm"))
- // .andExpect(jsonPath("$[0].interfacespeed").value("100-Mbps"))
- .andDo(print());
+
+ verify(repositoryStorageObjectMeta, times(1)).findAll();
+ }
+
+ @Test
+ void ensureFetchStoMetaWithParamReturnsEqualStoMeta() {
+ StorageObjectMeta equalStorageObjectMeta = FixtureFactory.storageObjectMetaFixture();
+ Optional nameParam = Optional.of("name");
+ equalStorageObjectMeta.setName(nameParam.get());
+ StorageObjectMeta unequalStorageObjectMeta = FixtureFactory.storageObjectMetaFixture();
+
+ when(repositoryStorageObjectMeta.findAll())
+ .thenReturn(List.of(equalStorageObjectMeta, unequalStorageObjectMeta));
+
+ var result = serviceStorageObjectMeta.fetchStoMeta(nameParam);
+
+ assertThat(result).doesNotContain(unequalStorageObjectMeta);
+ assertThat(result).contains(equalStorageObjectMeta);
+
}
}
\ No newline at end of file
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/service/connector/CustomerDataClientTest.java b/src/test/java/at/spengergasse/sj2324seedproject/service/connector/CustomerDataClientTest.java
index bea6d53..fc73e12 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/service/connector/CustomerDataClientTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/service/connector/CustomerDataClientTest.java
@@ -1,12 +1,18 @@
package at.spengergasse.sj2324seedproject.service.connector;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
+import at.spengergasse.sj2324seedproject.config.WebConfig;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.client.RestClient;
-@SpringBootTest
+@RestClientTest({CustomerDataClient.class, WebConfig.class})
class CustomerDataClientTest {
@Autowired