Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Oct 14, 2023
1 parent 6f0c33e commit bc93f30
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import java.util.Map;
import java.util.UUID;

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION, defaultImpl = GeneralQueryRequest.class)
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM)
@JsonSubTypes({ @JsonSubTypes.Type(GeneralQueryRequest.class), @JsonSubTypes.Type(GICQueryRequest.class) })
@JsonIgnoreProperties(ignoreUnknown = true)
public interface QueryRequest {
public Map<String, String> getResourceCredentials();
public QueryRequest setResourceCredentials(Map<String, String> resourceCredentials);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package edu.harvard.dbmi.avillach.domain;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DatabindContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;

import java.io.IOException;

public class QueryRequestTypeResolver implements TypeIdResolver {
private JavaType javaType;

@Override
public void init(JavaType javaType) {
this.javaType = javaType;
}

@Override
public String idFromValue(Object o) {
return null;
}

@Override
public String idFromValueAndType(Object o, Class<?> aClass) {
return null;
}

@Override
public String idFromBaseType() {
return null;
}

@Override
public JavaType typeFromId(DatabindContext databindContext, String s) throws IOException {
return null;
}

@Override
public String getDescForKnownTypeIds() {
return null;
}

@Override
public JsonTypeInfo.Id getMechanism() {
return JsonTypeInfo.Id.DEDUCTION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,41 @@
public class QueryRequestTest {
private static final ObjectMapper mapper = new ObjectMapper();

@Test
public void shouldSerializeGeneralQueryRequest() throws JsonProcessingException {
GeneralQueryRequest expected = new GeneralQueryRequest();
expected.setQuery(null);
expected.setResourceCredentials(new HashMap<>());
expected.setResourceUUID(UUID.randomUUID());
String json = mapper.writeValueAsString(expected);

QueryRequest actual = mapper.readValue(json, QueryRequest.class);

Assert.assertEquals(GeneralQueryRequest.class, actual.getClass());
Assert.assertEquals(expected.getResourceUUID(), actual.getResourceUUID());
}

@Test
public void shouldSerializeGICRequest() throws JsonProcessingException {
GICQueryRequest expected = new GICQueryRequest();
expected.setQuery(null);
expected.setResourceCredentials(new HashMap<>());
expected.setResourceUUID(UUID.randomUUID());
expected.setCommonAreaUUID(UUID.randomUUID());
expected.setInstitutionOfOrigin("Top secret institution (shh!)");
String json = mapper.writeValueAsString(expected);

QueryRequest actual = mapper.readValue(json, QueryRequest.class);

Assert.assertEquals(GICQueryRequest.class, actual.getClass());
Assert.assertEquals(expected.getResourceUUID(), actual.getResourceUUID());
}
// @Test
// public void shouldSerializeGeneralQueryRequest() throws JsonProcessingException {
// GeneralQueryRequest expected = new GeneralQueryRequest();
// expected.setQuery(null);
// expected.setResourceCredentials(new HashMap<>());
// expected.setResourceUUID(UUID.randomUUID());
// String json = mapper.writeValueAsString(expected);
//
// QueryRequest actual = mapper.readValue(json, QueryRequest.class);
//
// Assert.assertEquals(GeneralQueryRequest.class, actual.getClass());
// Assert.assertEquals(expected.getResourceUUID(), actual.getResourceUUID());
// }
//
// @Test
// public void shouldSerializeGICRequest() throws JsonProcessingException {
// GICQueryRequest expected = new GICQueryRequest();
// expected.setQuery(null);
// expected.setResourceCredentials(new HashMap<>());
// expected.setResourceUUID(UUID.randomUUID());
// expected.setCommonAreaUUID(UUID.randomUUID());
// expected.setInstitutionOfOrigin("Top secret institution (shh!)");
// String json = mapper.writeValueAsString(expected);
//
// QueryRequest actual = mapper.readValue(json, QueryRequest.class);
//
// Assert.assertEquals(GICQueryRequest.class, actual.getClass());
// Assert.assertEquals(expected.getResourceUUID(), actual.getResourceUUID());
// }
//
// @Test
// public void shouldWorkWithRealRequests() throws JsonProcessingException {
// String json = "{\"resourceUUID\":\"de273216-3b46-4dec-a330-1aa0634624ae\",\"query\":{\"categoryFilters\":{},\"numericFilters\":{},\"requiredFields\":[],\"anyRecordOf\":[],\"variantInfoFilters\":[{\"categoryVariantInfoFilters\":{},\"numericVariantInfoFilters\":{}}],\"expectedResultType\":\"COUNT\"}}";
// QueryRequest actual = mapper.readValue(json, QueryRequest.class);
//
// Assert.assertNotNull(actual);
// }
}

0 comments on commit bc93f30

Please sign in to comment.