added debug code and tests

This commit is contained in:
2019-03-14 17:37:56 +01:00
parent 827b110e7c
commit 0d0984bb53
3 changed files with 102 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package de.muehlencord.shared.account.dao;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.gson.annotations.Expose;
import java.util.Date;
import java.util.Objects;
/**
*
@ -28,10 +29,10 @@ public class ApiKeyObject {
@Expose
private String userName;
@Expose
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm'Z'")
@JsonFormat(shape = JsonFormat.Shape.STRING, locale="en_US", timezone = "UTC", pattern="yyyy-MM-dd'T'HH:mm:ss:SSS'Z[UTC]'")
private Date issuedOn;
@Expose
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm'Z'")
@JsonFormat(shape = JsonFormat.Shape.STRING, locale="en_US", timezone = "UTC", pattern="yyyy-MM-dd'T'HH:mm:ss:SSS'Z[UTC]'")
private Date expiresOn;
@Expose
private String authToken;
@ -68,4 +69,37 @@ public class ApiKeyObject {
this.authToken = authToken;
}
@Override
public int hashCode() {
int hash = 3;
hash = 53 * hash + Objects.hashCode(this.userName);
hash = 53 * hash + Objects.hashCode(this.issuedOn);
hash = 53 * hash + Objects.hashCode(this.expiresOn);
hash = 53 * hash + Objects.hashCode(this.authToken);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ApiKeyObject other = (ApiKeyObject) obj;
if (!Objects.equals(this.userName, other.userName)) {
return false;
}
if (!Objects.equals(this.authToken, other.authToken)) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,41 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.account.dao;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
public class ApiKeyObjectTest {
@Test
public void testJackson() throws JsonProcessingException, IOException {
ApiKeyObject apiKeyObject = new ApiKeyObject();
apiKeyObject.setUserName("web");
apiKeyObject.setIssuedOn(new Date());
apiKeyObject.setExpiresOn(new Date());
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(apiKeyObject);
System.out.println(json);
ApiKeyObject apiKeyObject2 = mapper.readValue (json, ApiKeyObject.class);
assertTrue (apiKeyObject.equals(apiKeyObject2));
}
}