Skip to content

Commit

Permalink
fixed the godforsaken serialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
mkimberlin committed Aug 21, 2024
1 parent ddf55e4 commit bfcac1a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle-native-build-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
env:
PROJECT_ID: ${{ secrets.RUN_PROJECT }}
RUN_REGION: us-central1
SERVICE_NAME: checkins-develop
SERVICE_NAME: checkins-develop-native
jobs:
build:
runs-on: ubuntu-latest
environment:
name: Development
url: https://checkins-develop-tuvcfzotpq-uc.a.run.app/
url: https://checkins-develop-native-tuvcfzotpq-uc.a.run.app/
steps:
- uses: actions/checkout@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.objectcomputing.checkins.util.serialize.LocalDateTimeSerializer;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.data.annotation.AutoPopulated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.objectcomputing.checkins.util.serialize.LocalDateTimeSerializer;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.Nullable;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.objectcomputing.checkins.util.serialize;

import io.micronaut.core.annotation.Introspected;

import java.time.format.DateTimeFormatter;

@Introspected
public class LocalDateTimeSerializer extends com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer {

protected LocalDateTimeSerializer() {
super();
}

public LocalDateTimeSerializer(DateTimeFormatter t) {
super(t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"allDeclaredConstructors" : true,
"allPublicConstructors" : true
},
{
"name": "com.objectcomputing.checkins.util.serialize.LocalDateTimeSerializer",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true
},
{
"name": "com.objectcomputing.checkins.services.permissions.PermissionSerializer",
"allDeclaredConstructors" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -51,6 +54,8 @@ class ReviewPeriodControllerTest
extends TestContainersSuite
implements ReviewAssignmentFixture, ReviewPeriodFixture, MemberProfileFixture, RoleFixture, FeedbackRequestFixture {

public static final Logger LOG = LoggerFactory.getLogger(ReviewPeriodControllerTest.class);

@Inject
@Client("/services/review-periods")
private HttpClient client;
Expand Down Expand Up @@ -189,6 +194,11 @@ void testReviewPeriodCreateDTOSerialization() throws JsonProcessingException {
reviewPeriodCreateDTO.setSelfReviewCloseDate(LocalDateTime.now());
reviewPeriodCreateDTO.setCloseDate(LocalDateTime.now());

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String expectedLaunchDateFormat = formatter.format(reviewPeriodCreateDTO.getLaunchDate());
String expectedSelfReviewCloseDateFormat = formatter.format(reviewPeriodCreateDTO.getSelfReviewCloseDate());
String expectedCloseDateFormat = formatter.format(reviewPeriodCreateDTO.getCloseDate());

final HttpRequest<ReviewPeriodCreateDTO> request = HttpRequest.
POST("/", reviewPeriodCreateDTO).basicAuth(ADMIN_ROLE, ADMIN_ROLE);
final HttpResponse<String> response = client.toBlocking().exchange(request, String.class);
Expand All @@ -199,17 +209,12 @@ void testReviewPeriodCreateDTOSerialization() throws JsonProcessingException {
assertEquals(HttpStatus.CREATED, response.getStatus());

ObjectMapper objectMapper = new ObjectMapper();
String expectedJson = objectMapper.writeValueAsString(reviewPeriodCreateDTO);

String expectedLaunchDateFormat = objectMapper.readTree(expectedJson).get("launchDate").asText();
String actualLaunchDateFormat = objectMapper.readTree(actualJson).get("launchDate").asText();
assertEquals(expectedLaunchDateFormat, actualLaunchDateFormat);

String expectedSelfReviewCloseDateFormat = objectMapper.readTree(expectedJson).get("selfReviewCloseDate").asText();
String actualSelfReviewCloseDateFormat = objectMapper.readTree(actualJson).get("selfReviewCloseDate").asText();
assertEquals(expectedSelfReviewCloseDateFormat, actualSelfReviewCloseDateFormat);

String expectedCloseDateFormat = objectMapper.readTree(expectedJson).get("closeDate").asText();
String actualCloseDateFormat = objectMapper.readTree(actualJson).get("closeDate").asText();
assertEquals(expectedCloseDateFormat, actualCloseDateFormat);
}
Expand Down

0 comments on commit bfcac1a

Please sign in to comment.