From df79729370391a65a424182dac96411b319afee2 Mon Sep 17 00:00:00 2001
From: Aleks <141594826+alekszivko@users.noreply.github.com>
Date: Mon, 23 Dec 2024 04:54:27 +0100
Subject: [PATCH] Revert "Cicd/13 add to GitHub actions coverage tests on pull
request"
---
pom.xml | 47 +-----
.../sj2324seedproject/domain/Address.java | 2 +-
.../sj2324seedproject/domain/Customer.java | 4 -
.../sj2324seedproject/domain/Producer.java | 21 +--
.../sj2324seedproject/domain/Profile.java | 4 +-
.../sj2324seedproject/domain/Reservation.java | 6 +-
.../sj2324seedproject/domain/Storage.java | 4 +-
.../domain/StorageObject.java | 20 ++-
.../domain/StorageObjectHistory.java | 6 +-
.../domain/StorageObjectMeta.java | 22 +--
.../sj2324seedproject/domain/Type.java | 18 ++-
.../sj2324seedproject/domain/User.java | 6 +-
.../sj2324seedproject/foundation/Base58.java | 37 +++++
.../api/RestControllerStorageObjectMeta.java | 61 ++++++--
.../api/dtos/StorageObjectDTO.java | 14 +-
.../ControllerStorageObject.java | 4 +
.../www/storages/StorageController.java | 6 +-
.../service/ServiceStorageObject.java | 3 +
.../service/ServiceStorageObjectMeta.java | 25 +++-
.../{edit.html => createStorage.html} | 0
.../storages/{new.html => editStorage.html} | 0
.../storages/{list.html => storageList.html} | 0
.../Sj2324SeedprojectApplicationTests.java | 10 +-
.../TestContainerConfiguration.java | 20 ++-
.../TestMainApplication.java | 34 ++++-
.../fixture/FixtureFactory.java | 134 ++++++++++++++++--
.../foundation/Base58Test.java | 33 +++++
.../persistence/RepositoryProducerTest.java | 4 +-
.../RepositoryStorageObjectMetaTest.java | 4 +-
.../RepositoryStorageObjectTest.java | 4 +-
.../ReservationRepositoryTest.java | 1 +
.../persistence/StorageRepositoryTest.java | 8 +-
.../RestControllerStorageObjectMetaTest.java | 8 +-
.../api/RestControllerStorageObjectTest.java | 22 ++-
.../api/TestRestControllerProducer.java | 32 ++++-
.../www/ControllerStorageObjectTest.java | 6 +-
.../service/MockitoTestEnv/Mockito_1.java | 64 +++++++++
.../service/ServiceInit.java | 115 +++++++++++++++
.../service/ServiceStorageObjectMetaTest.java | 70 +++------
.../connector/CustomerDataClientTest.java | 8 +-
40 files changed, 644 insertions(+), 243 deletions(-)
create mode 100644 src/main/java/at/spengergasse/sj2324seedproject/foundation/Base58.java
rename src/main/resources/templates/storages/{edit.html => createStorage.html} (100%)
rename src/main/resources/templates/storages/{new.html => editStorage.html} (100%)
rename src/main/resources/templates/storages/{list.html => storageList.html} (100%)
create mode 100644 src/test/java/at/spengergasse/sj2324seedproject/foundation/Base58Test.java
create mode 100644 src/test/java/at/spengergasse/sj2324seedproject/service/MockitoTestEnv/Mockito_1.java
create mode 100644 src/test/java/at/spengergasse/sj2324seedproject/service/ServiceInit.java
diff --git a/pom.xml b/pom.xml
index 92ccb05..ef70367 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,45 +5,6 @@
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
@@ -116,6 +77,10 @@
spring-boot-starter-thymeleaf
org.springframework.boot
+
+ spring-boot-starter-thymeleaf
+ org.springframework.boot
+
spring-boot-starter-web
org.springframework.boot
@@ -166,7 +131,7 @@
postgresql
org.testcontainers
- runtime
+ test
spring-boot-devtools
@@ -187,7 +152,7 @@
spring-boot-starter-parent
org.springframework.boot
- 3.2.4
+ 3.2.3
22
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Address.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Address.java
index 03b0340..e208db3 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 9858416..aa94291 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Customer.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Customer.java
@@ -1,13 +1,9 @@
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 d551f53..205e1f2 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Producer.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Producer.java
@@ -6,33 +6,38 @@
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
-@EqualsAndHashCode(callSuper = true)
-
-
-@Entity
+@Builder
@Table(name = "producers")
+@Entity
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;
+ private String shortname = ConstantsDomain.DEFAULT_VALUE;
@NotBlank
@Column(name = "producer_name", length = ConstantsDomain.DEFAULT_LENGTH)
- private String name;
+ private String name = ConstantsDomain.DEFAULT_VALUE;
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java
index 330943d..1961144 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Profile.java
@@ -11,11 +11,9 @@
@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 2ae95ca..2044e96 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Reservation.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Reservation.java
@@ -15,18 +15,14 @@
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 13458db..60f43c6 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Storage.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Storage.java
@@ -10,16 +10,14 @@
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
-@EqualsAndHashCode(callSuper = true)
+@Builder
@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 510b9b7..33b514c 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObject.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObject.java
@@ -6,7 +6,6 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
-import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
@@ -14,18 +13,22 @@
import java.util.List;
@Data
+@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
-@EqualsAndHashCode(callSuper = true)
-
-
-@Entity
@Table(name = "storage_objects")
public class StorageObject extends AbstractPersistable{
+ /*
+ Relations
+ */
+
+
+ // @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 storedAtUsers;
+ private List storedAtUser = new ArrayList<>();
@ManyToOne(fetch = FetchType.LAZY,
cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@@ -53,6 +56,9 @@ public class StorageObject extends AbstractPersistable{
cascade = {CascadeType.MERGE, CascadeType.PERSIST})
private Reservation reservation;
+ /*
+ Attributes
+ */
@Column(name = "serial_number")
private String serialNumber;
@@ -62,7 +68,7 @@ public class StorageObject extends AbstractPersistable{
@Column(name = "remark")
@NotBlank
- private String remark;
+ private String remark = ConstantsDomain.DEFAULT_VALUE;
@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 774c1a8..acae368 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectHistory.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectHistory.java
@@ -7,21 +7,19 @@
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
-@EqualsAndHashCode(callSuper = true)
-
+@Builder
@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 1727e24..557caa5 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectMeta.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/StorageObjectMeta.java
@@ -8,7 +8,6 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
-import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.AbstractPersistable;
@@ -17,15 +16,18 @@
@Data
-@Builder
@NoArgsConstructor
@AllArgsConstructor
-@EqualsAndHashCode(callSuper = true)
-
+@Builder
@Entity
@Table(name = "storage_object_metas")
+
public class StorageObjectMeta extends AbstractPersistable{
+ /*
+ Relations
+ */
+
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
public List storageobject;
@@ -38,13 +40,17 @@ public class StorageObjectMeta extends AbstractPersistable{
@Enumerated(EnumType.STRING)
private Type type;
+ /*
+ Attributes
+ */
+
@NotBlank
@Column(name = "storage_object_name")
- private String name;
+ private String name = ConstantsDomain.DEFAULT_VALUE;
@NotBlank
@Column(name = "os_version")
- private String osVersion;
+ private String osVersion = ConstantsDomain.DEFAULT_VALUE;
@Min(0)
@Column(name = "consumables_per_box")
@@ -56,11 +62,11 @@ public class StorageObjectMeta extends AbstractPersistable{
@NotBlank
@Column(name = "wave_length")
- private String wavelength;
+ private String wavelength = ConstantsDomain.DEFAULT_VALUE;
@NotBlank
@Column(name = "interface_speed")
- private String interfacespeed;
+ private String interfacespeed = ConstantsDomain.DEFAULT_VALUE;
}
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
index 561f674..39f1878 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
@@ -4,7 +4,8 @@
import lombok.Getter;
@Getter
-@AllArgsConstructor
+//@NoArgsConstructor
+@AllArgsConstructor //Error wenn erzeugt -> java: Konstruktor Type() ist bereits in Enumeration at.spengergasse.sj23247abcif.domain.Type definiert
public enum Type{
IP_PHONE("IP Phone", "IPP"),
@@ -13,6 +14,17 @@ public enum Type{
SFP("Sfp", "Sfp"),
CONSUMABLES("Consumables", "Cs");
- final private String longVersion;
- final private String shortVersion;
+
+
+ private String longVersion;
+ private String shortVersion;
+
+//public enum Type {
+//
+// IP_PHONE,
+// ROUTER,
+// SWITCH,
+// SFP,
+// CONSUMABLES
+//
}
diff --git a/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java b/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java
index 2c4b0bf..615632b 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/domain/User.java
@@ -11,20 +11,16 @@
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
new file mode 100644
index 0000000..c52edec
--- /dev/null
+++ b/src/main/java/at/spengergasse/sj2324seedproject/foundation/Base58.java
@@ -0,0 +1,37 @@
+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 ResponseEntity.ok(serviceStorageObjectMeta
- .fetchStoMeta(nameParam).stream()
- .map(StorageObjectMetaDTO::new)
- .toList());
+ 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;
}
@GetMapping(ConstantsDomain.URL_BASE_STO_META_NAME)
@@ -48,17 +66,30 @@ 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){
- return ResponseEntity.noContent().build();
+ // headers.set();
+ responseHeaders.set("Test Header 2",
+ HttpHeaders.IF_NONE_MATCH);
+ ResponseEntity entity = new ResponseEntity<>(responseHeaders,
+ HttpStatus.NO_CONTENT);
+ return entity;
}
StorageObjectMetaDTO storageObjectMetaDTO = new StorageObjectMetaDTO(storageObjectMeta);
- return ResponseEntity
- .status(HttpStatus.OK)
- .location(URI.create(
- ConstantsDomain.URL_BASE_STO_META + ConstantsDomain.URL_BASE_STO_META_NAME))
- .body(storageObjectMetaDTO);
+
+ ResponseEntity entity = new ResponseEntity<>(storageObjectMetaDTO,
+ responseHeaders,
+ HttpStatus.OK);
+ return entity;
}
@PostMapping
@@ -80,7 +111,7 @@ public ResponseEntity createStoMeta(
.body(new StorageObjectMetaDTO(storageMeta));
}
- @ExceptionHandler(StorageObjectMetaAlreadyExistsException.class)
+ @ExceptionHandler(StorageObjectMetaAlreadyExistsException.class) //sobald dieser Excep.Handl. mehrmals gebraucht wird, rausziehen damit es mehrmals genutzt werden kann.
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 286d310..c2332e1 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,18 +7,14 @@ public record StorageObjectDTO(String serialNumber,
String macAddress,
String remark,
boolean projectDevice,
- Customer storedAtCustomer,
+ Customer storaedAtCustomer,
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()),
- storageObject.getStatus()
+ 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()
.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 7db2990..393bb34 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,11 +20,15 @@
@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 9354b2a..2cf74f3 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/list";
+ return "storages/storageList";
}
@@ -38,7 +38,7 @@ public String getStorages(Model model) {
public ModelAndView showNewStorageForm() {
var mav = new ModelAndView();
mav.addObject("form", CreateStorageForm.create());
- mav.setViewName("create");
+ mav.setViewName("storages/createStorage");
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/edit")
+ "storages/editStorage")
.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 bf1602a..d42c5fd 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObject.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObject.java
@@ -8,6 +8,7 @@
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;
@@ -21,7 +22,9 @@
@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 822e200..60c51b2 100644
--- a/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMeta.java
+++ b/src/main/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMeta.java
@@ -20,6 +20,7 @@
@RequiredArgsConstructor
public class ServiceStorageObjectMeta{
+ @Autowired
private RepositoryStorageObjectMeta repositoryStorageObjectMeta;
@@ -29,12 +30,26 @@ public StorageObjectMeta saveStorageMeta(StorageObjectMeta storageObjectMeta){
}
public List fetchStoMeta(Optional nameParam){
- List storageObjectMetas = repositoryStorageObjectMeta.findAll();
+ List storageObjectMetaList = new ArrayList<>();
- return nameParam.map(param -> storageObjectMetas.stream()
- .filter(stoMeta ->
- stoMeta.getName().equalsIgnoreCase(nameParam.get())).toList())
- .orElseGet(() -> storageObjectMetas);
+ 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();
}
public StorageObjectMeta findStorageObjectMeta(String name){
diff --git a/src/main/resources/templates/storages/edit.html b/src/main/resources/templates/storages/createStorage.html
similarity index 100%
rename from src/main/resources/templates/storages/edit.html
rename to src/main/resources/templates/storages/createStorage.html
diff --git a/src/main/resources/templates/storages/new.html b/src/main/resources/templates/storages/editStorage.html
similarity index 100%
rename from src/main/resources/templates/storages/new.html
rename to src/main/resources/templates/storages/editStorage.html
diff --git a/src/main/resources/templates/storages/list.html b/src/main/resources/templates/storages/storageList.html
similarity index 100%
rename from src/main/resources/templates/storages/list.html
rename to src/main/resources/templates/storages/storageList.html
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java b/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java
index 7d13999..7287e42 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/Sj2324SeedprojectApplicationTests.java
@@ -1,14 +1,10 @@
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(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-public class Sj2324SeedprojectApplicationTests {
+//@SpringBootTest
+//@Import(TestContainerConfiguration.class)
+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 146e7aa..60d478a 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/TestContainerConfiguration.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/TestContainerConfiguration.java
@@ -4,7 +4,6 @@
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;
@@ -14,17 +13,16 @@
@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")).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)
- )));
- });
+ PostgreSQLContainer> postgresContainer() {
+ return new PostgreSQLContainer<>(DockerImageName.parse("postgres:latest"));
}
+
}
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java b/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java
index f1d35f9..9797e01 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/TestMainApplication.java
@@ -1,20 +1,44 @@
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(TestContainerConfiguration.class)
- .run(args);
+ SpringApplication.from(Sj2324SeedprojectApplication::main)
+ .with(TestMainApplication.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 0512cf1..1b42afc 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/fixture/FixtureFactory.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/fixture/FixtureFactory.java
@@ -8,7 +8,6 @@
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;
@@ -27,18 +26,25 @@ public class FixtureFactory {
///////////////////////////////////// Producer
- public static Producer producerFixture() {
+ public static Producer give_me_a_producer1() {
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 storageObjectMetaFixture() {
+ public static StorageObjectMeta give_me_a_storageObjectMeta1() {
return StorageObjectMeta.builder()
- .producer(producerFixture())
+ .producer(give_me_a_producer1())
.name("meta name1")
.type(Type.IP_PHONE)
.osVersion("version1")
@@ -49,6 +55,19 @@ public static StorageObjectMeta storageObjectMetaFixture() {
.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")
@@ -63,26 +82,41 @@ public static StorageObjectMeta give_me_a_storageObjectMeta3() {
public static List give_me_a_List_of_producer() {
List producersListe = new ArrayList<>();
- producersListe.add(producerFixture());
+ producersListe.add(give_me_a_producer1());
+ producersListe.add(give_me_a_producer2());
return producersListe;
}
///////////////////////////////////// StorageObject
- public static StorageObject storageObjectFixture() {
+ public static StorageObject give_me_a_storageObject1() {
return StorageObject.builder()
- .status(Status.PROJECT)
- .storageObjectMeta(storageObjectMetaFixture())
- .apiKeyID(keyGen.getRandomKey(16))
- .storedStorage(storageFixture())
+ .apiKeyID(keyGen.getRandomKey(16))
.serialNumber("abcd1234")
.macAddress(ConstantsDomain.DEFAULT_MAC)
.remark("this is a remark1")
.projectDevice(true)
- .storedAtCustomer(customerFixture())
+ .storedAtCustomer(Customer.builder()
+ .connectionNo("123456")
+ .build())
.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() {
@@ -171,4 +205,82 @@ 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
new file mode 100644
index 0000000..cad853c
--- /dev/null
+++ b/src/test/java/at/spengergasse/sj2324seedproject/foundation/Base58Test.java
@@ -0,0 +1,33 @@
+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 c5d2cbb..0f6e4c6 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryProducerTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryProducerTest.java
@@ -11,6 +11,7 @@
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
+@Import(TestcontainersConfiguration.class)
public class RepositoryProducerTest{
@@ -21,7 +22,8 @@ public class RepositoryProducerTest{
void ensure_save_producer_into_DB(){
//given
- Producer producer1 = FixtureFactory.producerFixture();
+ Producer producer1 = FixtureFactory.give_me_a_producer1();
+ Producer producer2 = FixtureFactory.give_me_a_producer2();
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java
index bcfa1e8..a9afb31 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectMetaTest.java
@@ -11,6 +11,8 @@
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
+//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
+@Import(TestcontainersConfiguration.class)
public class RepositoryStorageObjectMetaTest{
@Autowired
@@ -23,7 +25,7 @@ public class RepositoryStorageObjectMetaTest{
void ensure_save_storageObjectMeta_into_DB(){
//given
- StorageObjectMeta storageObjectMeta = FixtureFactory.storageObjectMetaFixture();
+ StorageObjectMeta storageObjectMeta = FixtureFactory.give_me_a_storageObjectMeta1();
//when
diff --git a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java
index ff37e66..ce854e0 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/RepositoryStorageObjectTest.java
@@ -13,6 +13,7 @@
import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
+@Import(TestcontainersConfiguration.class)
public class RepositoryStorageObjectTest{
@Autowired
@@ -22,7 +23,8 @@ public class RepositoryStorageObjectTest{
void ensure_save_storageOBject_into_DB(){
//given
- StorageObject storageObject = FixtureFactory.storageObjectFixture();
+ StorageObject storageObject = FixtureFactory.give_me_a_storageObject1();
+ StorageObject storageObject2 = FixtureFactory.give_me_a_storageObject2();
//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 ce08a44..f941916 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/ReservationRepositoryTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/ReservationRepositoryTest.java
@@ -20,6 +20,7 @@
@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 ecdbad5..1cb388b 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/persistence/StorageRepositoryTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/persistence/StorageRepositoryTest.java
@@ -40,14 +40,12 @@ void ensureSaveAndReReadWorks() {
void ensureFindAllByNameContainingIgnoreCaseWorks() {
//Given
- Storage storage1 = FixtureFactory.storageFixture();
- storage1.setName("test1");
- Storage storage2 = FixtureFactory.storageFixture();
-
+ Storage storage1 = new Storage("Hauptlager DCE4", new Address());
+ Storage storage2 = new Storage("Nebenlager Af3", new Address());
storageRepository.saveAll(List.of(storage1, storage2));
//When
- List found = storageRepository.findAllByNameContainingIgnoreCase(storage1.getName());
+ List found = storageRepository.findAllByNameContainingIgnoreCase("Hauptlager DCE4");
//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 7573673..fc887e8 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 019440b..15196e4 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/RestControllerStorageObjectTest.java
@@ -36,24 +36,22 @@ void setup(){
}
@Test
- void ensureFetchAllReturnsContentForExistingData() throws Exception{
+ void ensureGetApiStorageObjectsWorks() throws Exception{
//given, when
- StorageObject storageObject = FixtureFactory.storageObjectFixture();
-
- 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);
+ StorageObject storageObject = FixtureFactory.give_me_a_storageObject1();
//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);
mockMvc.perform(request)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
- .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()))
+ .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"))
.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 b15dd93..67ff55d 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/TestRestControllerProducer.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/presentation/api/TestRestControllerProducer.java
@@ -1,23 +1,32 @@
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.*;
@@ -42,12 +51,13 @@ void setup(){
void ensureGetMappingWorks(){
//given
Optional searchCriteria = Optional.empty();
- var prod = FixtureFactory.producerFixture();
+ var prod = FixtureFactory.give_me_a_producer1();
when(repositoryProducer.findAll()).thenReturn(List.of(prod));
//when
var result = serviceProducer.fetchProducer(searchCriteria);
//then
+// verify(repositoryProducer, times(1)).findAll();
verify(repositoryProducer ).findAll();
}
@@ -56,12 +66,30 @@ void ensureGetMappingWorks(){
void ensureGetMappingWorksAndCheckResponse(){
//given
Optional searchCriteria = Optional.empty();
- var prod = FixtureFactory.producerFixture();
+ var prod = FixtureFactory.give_me_a_producer1();
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 64d7a13..f519149 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.storageObjectFixture(),
- FixtureFactory.storageObjectFixture());
+ List storageObjectList = List.of(FixtureFactory.give_me_a_storageObject1(),
+ FixtureFactory.give_me_a_storageObject2());
when(serviceStorageObject.fetchStorageObjectsList()).thenReturn(storageObjectList);
mockMvc.perform(get("/storageObjects"))
.andExpect(status().isOk())
.andExpect(model().attribute("storageObjects",
storageObjectList))
- .andExpect(view().name("storageObjects/list"))
+ .andExpect(view().name("storageObject/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
new file mode 100644
index 0000000..b499340
--- /dev/null
+++ b/src/test/java/at/spengergasse/sj2324seedproject/service/MockitoTestEnv/Mockito_1.java
@@ -0,0 +1,64 @@
+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
new file mode 100644
index 0000000..7c08311
--- /dev/null
+++ b/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceInit.java
@@ -0,0 +1,115 @@
+//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 0ab6623..572d86f 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMetaTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/service/ServiceStorageObjectMetaTest.java
@@ -3,14 +3,8 @@
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;
@@ -19,68 +13,46 @@
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.*;
-@ExtendWith(MockitoExtension.class)
+@WebMvcTest(ServiceStorageObjectMeta.class)
class ServiceStorageObjectMetaTest{
+ @Autowired
+ private MockMvc mockMvc;
+ @MockBean
private ServiceStorageObjectMeta serviceStorageObjectMeta;
- private @Mock RepositoryStorageObjectMeta repositoryStorageObjectMeta;
@BeforeEach
void setup(){
- assumeThat(repositoryStorageObjectMeta).isNotNull();
- this.serviceStorageObjectMeta = new ServiceStorageObjectMeta(repositoryStorageObjectMeta);
+ assumeThat(mockMvc).isNotNull();
+ assumeThat(serviceStorageObjectMeta).isNotNull();
}
@Test
- 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{
+ void ensureGetApiStorageObjectMetaWorks() throws Exception{
//given
- StorageObjectMeta storageObjectMeta = FixtureFactory.storageObjectMetaFixture();
-
- Optional nameParam = Optional.empty();
+ StorageObjectMeta storageObjectMeta = FixtureFactory.give_me_a_storageObjectMeta3();
+ when(serviceStorageObjectMeta.fetchStoMeta(any())).thenReturn(List.of(storageObjectMeta));
- when(repositoryStorageObjectMeta.findAll()).thenReturn(List.of(storageObjectMeta));
- //when
- var result = serviceStorageObjectMeta.fetchStoMeta(nameParam);
//expect
-
- 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);
-
+ 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());
}
}
\ 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 fc73e12..bea6d53 100644
--- a/src/test/java/at/spengergasse/sj2324seedproject/service/connector/CustomerDataClientTest.java
+++ b/src/test/java/at/spengergasse/sj2324seedproject/service/connector/CustomerDataClientTest.java
@@ -1,18 +1,12 @@
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;
-@RestClientTest({CustomerDataClient.class, WebConfig.class})
+@SpringBootTest
class CustomerDataClientTest {
@Autowired