Skip to content

Commit

Permalink
Refactoring to create exception handler. Also creating adr domain pac…
Browse files Browse the repository at this point in the history
…kage, (finos#716)
  • Loading branch information
grahampacker-ms committed Jan 17, 2025
1 parent 78ff101 commit 4fc0f4c
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import io.quarkus.test.junit.TestProfile;
import org.bson.Document;
import org.eclipse.microprofile.config.ConfigProvider;
import org.finos.calm.domain.Adr;
import org.finos.calm.domain.AdrBuilder;
import org.finos.calm.domain.AdrContent;
import org.finos.calm.domain.AdrDecision;
import org.finos.calm.domain.AdrDecisionBuilder;
import org.finos.calm.domain.AdrLinkBuilder;
import org.finos.calm.domain.AdrOption;
import org.finos.calm.domain.AdrOptionBuilder;
import org.finos.calm.domain.AdrStatus;
import org.finos.calm.domain.NewAdr;
import org.finos.calm.domain.NewAdrBuilder;
import org.finos.calm.domain.adr.Adr;
import org.finos.calm.domain.adr.AdrBuilder;
import org.finos.calm.domain.adr.AdrContent;
import org.finos.calm.domain.adr.AdrDecision;
import org.finos.calm.domain.adr.AdrDecisionBuilder;
import org.finos.calm.domain.adr.AdrLinkBuilder;
import org.finos.calm.domain.adr.AdrOption;
import org.finos.calm.domain.adr.AdrOptionBuilder;
import org.finos.calm.domain.adr.AdrStatus;
import org.finos.calm.domain.adr.NewAdr;
import org.finos.calm.domain.adr.NewAdrBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
Expand All @@ -43,7 +43,7 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MongoAdrIntegration {

ObjectMapper objectMapper;
private ObjectMapper objectMapper;

private static final Logger logger = LoggerFactory.getLogger(MongoAdrIntegration.class);

Expand All @@ -70,7 +70,7 @@ public class MongoAdrIntegration {
.links(List.of(AdrLinkBuilder.builder().rel("abc").href("http://abc.com").build()))
.build();

private final AdrContent adrContent = AdrContent.builderFromNewAdr(newAdr).status(AdrStatus.DRAFT).build();
private final AdrContent adrContent = AdrContent.builderFromNewAdr(newAdr).status(AdrStatus.draft).build();

@BeforeEach
public void setupAdrs() {
Expand Down Expand Up @@ -190,7 +190,7 @@ void end_to_end_verify_get_revisions() {
@Order(7)
void end_to_end_verify_update_an_adr_status() throws JsonProcessingException {
given()
.when().post("/calm/namespaces/finos/adrs/1/status/PROPOSED")
.when().post("/calm/namespaces/finos/adrs/1/status/proposed")
.then()
.statusCode(201)
.header("Location", containsString("calm/namespaces/finos/adrs/1"));
Expand All @@ -204,7 +204,7 @@ void end_to_end_verify_status_changed() throws JsonProcessingException {
.when().get("/calm/namespaces/finos/adrs/1/revisions/3")
.then()
.statusCode(200)
.body("adrContent.status", equalTo("PROPOSED"));
.body("adrContent.status", equalTo("proposed"));
}

}
10 changes: 0 additions & 10 deletions calm-hub/src/main/java/org/finos/calm/domain/AdrStatus.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.finos.calm.domain;
package org.finos.calm.domain.adr;

import io.soabase.recordbuilder.core.RecordBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.finos.calm.domain;
package org.finos.calm.domain.adr;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
Expand Down Expand Up @@ -40,12 +39,19 @@ public static AdrContentBuilder builderFromNewAdr(NewAdr newAdr) {
.links(newAdr.links());
}

// does not include datetimes in equals
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
AdrContent that = (AdrContent) o;
return Objects.equals(title, that.title) && status == that.status && Objects.equals(contextAndProblemStatement, that.contextAndProblemStatement) && Objects.equals(decisionDrivers, that.decisionDrivers) && Objects.equals(consideredOptions, that.consideredOptions) && Objects.equals(decisionOutcome, that.decisionOutcome) && Objects.equals(links, that.links);
return Objects.equals(title, that.title) &&
status == that.status &&
Objects.equals(contextAndProblemStatement, that.contextAndProblemStatement) &&
Objects.equals(decisionDrivers, that.decisionDrivers) &&
Objects.equals(consideredOptions, that.consideredOptions) &&
Objects.equals(decisionOutcome, that.decisionOutcome) &&
Objects.equals(links, that.links);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.finos.calm.domain;
package org.finos.calm.domain.adr;

import io.soabase.recordbuilder.core.RecordBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.finos.calm.domain;
package org.finos.calm.domain.adr;

import io.soabase.recordbuilder.core.RecordBuilder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.finos.calm.domain;
package org.finos.calm.domain.adr;

import io.soabase.recordbuilder.core.RecordBuilder;

Expand Down
10 changes: 10 additions & 0 deletions calm-hub/src/main/java/org/finos/calm/domain/adr/AdrStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.finos.calm.domain.adr;

public enum AdrStatus {
draft,
proposed,
accepted,
superseded,
rejected,
deprecated;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.finos.calm.domain;
package org.finos.calm.domain.adr;

import io.soabase.recordbuilder.core.RecordBuilder;

import java.time.LocalDateTime;
import java.util.List;

@RecordBuilder.Options(enableWither = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.finos.calm.domain.exception;

public class AdrParseException extends Exception {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.finos.calm.domain.exception;

public class AdrPersistenceException extends Exception {
}
Loading

0 comments on commit 4fc0f4c

Please sign in to comment.