Skip to content

Commit

Permalink
fix compile errors and contextLoads failing
Browse files Browse the repository at this point in the history
- reorder annotations in entity. New Order block of lombok annotations -> Block of jpa.persistence annotations above class
- add @EqualsAndHashCode(callSuper = true) for all entities
fixes compile errors and possible feature issues because super is not called
- remove some comments in entities
- remove direct assignments to private variables
fixes compile error, probably not needed as well and @builder would ignore them that way as well
- remove @import(TestcontainersConfiguration.class) in all integration tests, since redundant
- make @SpringBootTest to use random Port in Sj2324SeedprojectApplicationTests
- move postgresContainer bean from TestMainApplication to TestContainerConfiguration
- make main in TestMainApplication use TestContainerConfiguration
- remove on spring-boot-starter-thymeleaf as dependency, since it was listed twice in pom.xml
- bump spring-boot-starter-parent to version 3.2.3 from 3.2.4
solving a compile error related to repackage not supporting class file major version 66
- make postgresql from testcontainers be in runtime scope
fixes not being able to verify package with maven, since driver could not be found

fixes #12

Signed-off-by: Aleksandar Zivkovic <[email protected]>
  • Loading branch information
alekszivko committed Dec 25, 2024
1 parent b789c84 commit 9f3f46a
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

// implemented by MM
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Builder


@Embeddable
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long>{

/*
Relations
*/

@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<StorageObjectMeta> 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;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

@Data
@Builder
@Embeddable
@NoArgsConstructor
@AllArgsConstructor


@Embeddable
public class Profile {

private static final int USERNAME_LENGTH = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
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.ArrayList;
import java.util.List;

@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "storage_objects")
public class StorageObject extends AbstractPersistable<Long>{
@EqualsAndHashCode(callSuper = true)

/*
Relations
*/

@Entity
@Table(name = "storage_objects")
public class StorageObject extends AbstractPersistable<Long>{

// @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<User> storedAtUser = new ArrayList<>();
private List<User> storedAtUsers;

@ManyToOne(fetch = FetchType.LAZY,
cascade = {CascadeType.MERGE, CascadeType.PERSIST})
Expand Down Expand Up @@ -56,9 +53,6 @@ public class StorageObject extends AbstractPersistable<Long>{
cascade = {CascadeType.MERGE, CascadeType.PERSIST})
private Reservation reservation;

/*
Attributes
*/
@Column(name = "serial_number")
private String serialNumber;

Expand All @@ -68,7 +62,7 @@ public class StorageObject extends AbstractPersistable<Long>{

@Column(name = "remark")
@NotBlank
private String remark = ConstantsDomain.DEFAULT_VALUE;
private String remark;

@Column(name = "project_device")
private Boolean projectDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> {

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,18 +17,15 @@


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)

@Entity
@Table(name = "storage_object_metas")

public class StorageObjectMeta extends AbstractPersistable<Long>{

/*
Relations
*/

@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
public List<StorageObject> storageobject;

Expand All @@ -40,17 +38,13 @@ public class StorageObjectMeta extends AbstractPersistable<Long>{
@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")
Expand All @@ -62,11 +56,11 @@ public class StorageObjectMeta extends AbstractPersistable<Long>{

@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;


}
18 changes: 3 additions & 15 deletions src/main/java/at/spengergasse/sj2324seedproject/domain/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> {

Expand Down
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
)));
});
}

}
Loading

0 comments on commit 9f3f46a

Please sign in to comment.