128 lines
4.0 KiB
Java
128 lines
4.0 KiB
Java
package org.gcube.application.geoportal.service;
|
|
|
|
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.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);
|
|
}
|
|
|
|
@Test
|
|
public void testMissingProfile(){
|
|
Response resp = target(InterfaceConstants.Methods.PROJECTS)
|
|
.path("non-existent-profile").request().get();
|
|
assertEquals(resp.getStatus(),404);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void getAll() {
|
|
System.out.println(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class));
|
|
}
|
|
|
|
@Test
|
|
public void getByID(){
|
|
target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class).forEach(d ->{
|
|
|
|
try {
|
|
check(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).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 registerNew() throws Exception {
|
|
WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
|
|
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
|
check(target.path(testProfileId).request(MediaType.APPLICATION_JSON).
|
|
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
|
|
|
}
|
|
|
|
private ProfiledDocument createNew() throws Exception {
|
|
WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
|
|
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
|
|
return check(target.path(testProfileId).request(MediaType.APPLICATION_JSON).
|
|
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
|
|
}
|
|
|
|
@Test
|
|
public void addFileSet() throws Exception {
|
|
// TODO Test register fileset
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
// public void getFilteredAll() {
|
|
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
// Document document =new Document(Collections.singletonMap("key", "value"));
|
|
//
|
|
// System.out.println(target.path("search").request(MediaType.APPLICATION_JSON).
|
|
// post(Entity.entity(document, MediaType.APPLICATION_JSON)));
|
|
//
|
|
// }
|
|
//
|
|
// @Test
|
|
// public void getAllByProfile() {
|
|
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
// System.out.println(target.path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class));
|
|
// }
|
|
//
|
|
// @Test
|
|
// public void getFilteredByProfile() {
|
|
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
// Document document =new Document(Collections.singletonMap("key", "value"));
|
|
//
|
|
// System.out.println(target.path("search").path(testProfileId).request(MediaType.APPLICATION_JSON).
|
|
// post(Entity.entity(document, MediaType.APPLICATION_JSON)));
|
|
//
|
|
// }
|
|
//
|
|
//
|
|
// @Test
|
|
// public void getById() {
|
|
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
// System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON).get().readEntity(String.class));
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
// @Test
|
|
// public void updateDocument() {
|
|
// WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
|
|
// Document document =new Document(Collections.singletonMap("key", "value"));
|
|
//
|
|
// System.out.println(target.path(testProfileId).path(projectId).request(MediaType.APPLICATION_JSON).
|
|
// put(Entity.entity(document, MediaType.APPLICATION_JSON)));
|
|
// }
|
|
}
|