114 lines
3.2 KiB
Java
114 lines
3.2 KiB
Java
package org.gcube.application.geoportal.service;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import org.bson.Document;
|
|
import org.gcube.application.cms.Serialization;
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
|
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
|
import org.gcube.application.geoportal.common.model.rest.Configuration;
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
|
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import javax.ws.rs.client.Entity;
|
|
import javax.ws.rs.client.WebTarget;
|
|
import javax.ws.rs.core.MediaType;
|
|
import javax.ws.rs.core.Response;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
public class ProfiledDocumentsTests extends BasicServiceTestUnit{
|
|
|
|
String testProfileId="profiledConcessioni";
|
|
|
|
@Before
|
|
public void setContext(){
|
|
TokenSetter.set(scope);
|
|
}
|
|
|
|
|
|
protected WebTarget baseTarget(){
|
|
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
|
}
|
|
// GET
|
|
@Test
|
|
public void testMissingProfile(){
|
|
Response resp = baseTarget()
|
|
.path("non-existent-profile").request().get();
|
|
assertEquals(resp.getStatus(),404);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void getAll() {
|
|
System.out.println(baseTarget().request(MediaType.APPLICATION_JSON).get(List.class));
|
|
}
|
|
|
|
@Test
|
|
public void getByID(){
|
|
baseTarget().request(MediaType.APPLICATION_JSON).get(List.class).forEach(d ->{
|
|
|
|
try {
|
|
check(baseTarget().path((Serialization.convert(d,ProfiledDocument.class)).get_id())
|
|
.request(MediaType.APPLICATION_JSON).get(),ProfiledDocument.class);
|
|
} catch (Exception e) {
|
|
e.printStackTrace(System.err);
|
|
Assert.fail(e.getMessage());
|
|
}
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void getConfiguration() {
|
|
System.out.println(baseTarget().request(MediaType.APPLICATION_JSON).get(Configuration.class));
|
|
}
|
|
|
|
// Queries
|
|
@Test
|
|
public void query() throws JsonProcessingException {
|
|
System.out.println(baseTarget().path(InterfaceConstants.Methods.QUERY_PATH).
|
|
request(MediaType.APPLICATION_JSON).
|
|
post(Entity.entity(Serialization.write(new QueryRequest()),MediaType.APPLICATION_JSON)));
|
|
}
|
|
|
|
// CREATE / edit / delete
|
|
|
|
@Test
|
|
public void registerNew() throws Exception {
|
|
createNew();
|
|
}
|
|
|
|
private ProfiledDocument createNew() throws Exception {
|
|
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
|
return check(baseTarget().request(MediaType.APPLICATION_JSON).
|
|
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
|
}
|
|
|
|
@Test
|
|
public void edit() throws Exception {
|
|
ProfiledDocument doc=createNew();
|
|
String beforeJson=doc.getTheDocument().toJson();
|
|
doc.getTheDocument().put("someStrangeField","someOtherRandomValue");
|
|
String edited=doc.getTheDocument().toJson();
|
|
Assert.assertNotEquals(beforeJson,doc.getTheDocument().toJson());
|
|
doc=check(baseTarget().path(doc.get_id()).request(MediaType.APPLICATION_JSON).
|
|
put(Entity.entity(doc.getTheDocument(), MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
|
Assert.assertEquals(edited,doc.getTheDocument().toJson());
|
|
}
|
|
|
|
@Test
|
|
public void addFileSet() throws Exception {
|
|
|
|
ProfiledDocument doc = createNew();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|