added debug code and tests
This commit is contained in:
@ -27,5 +27,30 @@
|
|||||||
<groupId>de.muehlencord.shared</groupId>
|
<groupId>de.muehlencord.shared</groupId>
|
||||||
<artifactId>shared-util</artifactId>
|
<artifactId>shared-util</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.3.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
|
<version>5.3.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.3.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.9.8</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -18,6 +18,7 @@ package de.muehlencord.shared.account.dao;
|
|||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -28,10 +29,10 @@ public class ApiKeyObject {
|
|||||||
@Expose
|
@Expose
|
||||||
private String userName;
|
private String userName;
|
||||||
@Expose
|
@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;
|
private Date issuedOn;
|
||||||
@Expose
|
@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;
|
private Date expiresOn;
|
||||||
@Expose
|
@Expose
|
||||||
private String authToken;
|
private String authToken;
|
||||||
@ -68,4 +69,37 @@ public class ApiKeyObject {
|
|||||||
this.authToken = authToken;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user