Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.12.x] fix #1486 and add Util unit tests #1510

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public static Instant toInstant(Object time) {
try {
return ZonedDateTime.parse(str, DateTimeFormatter.ISO_DATE_TIME).toInstant();
} catch (DateTimeParseException e) {
e.printStackTrace();
log.warn("failed to convert "+time+" to timestamp using "+str,e);
}
}
return null;//nothing matched
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.hyperfoil.tools.horreum.svc;


import com.fasterxml.jackson.databind.node.LongNode;
import com.fasterxml.jackson.databind.node.TextNode;
import io.hyperfoil.tools.horreum.test.HorreumTestProfile;
import io.hyperfoil.tools.horreum.test.PostgresResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.oidc.server.OidcWiremockTestResource;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.time.Instant;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@QuarkusTest
@QuarkusTestResource(PostgresResource.class)
@QuarkusTestResource(OidcWiremockTestResource.class)
@TestProfile(HorreumTestProfile.class)
public class UtilTest {


@Test
public void toInstant_valid() throws IOException {
//already an instant
assertNotNull(Util.toInstant(Instant.now()),"failed to handle instant input");
//number
assertNotNull(Util.toInstant(System.currentTimeMillis()),"failed to parse current millis");
//strings
assertNotNull(Util.toInstant(""+System.currentTimeMillis()),"failed to parse millis as string");
assertNotNull(Util.toInstant("2020-01-01"),"failed to parse yyyy-mm-dd");
assertNotNull(Util.toInstant("2020-01-01T01:01:01"),"failed to parse YYYY-MM-DDTHH:mm:ss");
assertNotNull(Util.toInstant("2020-01-01T01:01:01Z"),"failed to parse YYYY-MM-DDThh:mm:ssZ");
assertNotNull(Util.toInstant("2020-01-01T01:01:01+00:00"),"failed to parse YYYY-MM-DDThh:mm:ss[+-]zz:zz");
assertNotNull(Util.toInstant("2024-03-11T22:16:24.302655-04:00"),"failed to parse ISO with microseconds and zzzz");
//json
assertNotNull(Util.toInstant(new TextNode("2020-01-01")),"failed to parse json text YYYY-MM-DD");
assertNotNull(Util.toInstant(new LongNode(System.currentTimeMillis())),"failed to parse current millis as json node");

}

}
Loading