gcube-cms-suite/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ProfiledDocumentsTests.java

128 lines
4.0 KiB
Java
Raw Normal View History

2021-09-20 16:47:35 +02:00
package org.gcube.application.geoportal.service;
import org.bson.Document;
2022-01-17 13:30:21 +01:00
import org.gcube.application.cms.Serialization;
2021-12-07 11:16:26 +01:00
import org.gcube.application.cms.tests.TokenSetter;
2022-01-17 13:30:21 +01:00
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
2021-09-20 16:47:35 +02:00
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
2022-01-17 13:30:21 +01:00
import org.junit.Assert;
2021-12-07 11:16:26 +01:00
import org.junit.Before;
2021-09-20 16:47:35 +02:00
import org.junit.Test;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
2021-12-07 11:16:26 +01:00
import javax.ws.rs.core.Response;
2021-09-20 16:47:35 +02:00
import java.util.Collections;
import java.util.List;
2021-12-07 11:16:26 +01:00
import static org.junit.Assert.assertEquals;
2022-01-17 18:19:40 +01:00
public class ProfiledDocumentsTests extends BasicServiceTestUnit{
2021-09-20 16:47:35 +02:00
2022-01-12 18:42:22 +01:00
String testProfileId="profiledConcessioni";
2021-12-07 11:16:26 +01:00
@Before
public void setContext(){
TokenSetter.set(scope);
2021-09-20 16:47:35 +02:00
}
2021-12-07 11:16:26 +01:00
2021-09-20 16:47:35 +02:00
@Test
2021-12-07 11:16:26 +01:00
public void testMissingProfile(){
Response resp = target(InterfaceConstants.Methods.PROJECTS)
.path("non-existent-profile").request().get();
assertEquals(resp.getStatus(),404);
2021-09-20 16:47:35 +02:00
}
2021-12-07 11:16:26 +01:00
2021-09-20 16:47:35 +02:00
@Test
2021-12-07 11:16:26 +01:00
public void getAll() {
System.out.println(target(InterfaceConstants.Methods.PROJECTS).path(testProfileId).request(MediaType.APPLICATION_JSON).get(List.class));
2021-09-20 16:47:35 +02:00
}
2022-01-12 18:42:22 +01:00
2022-01-17 13:30:21 +01:00
@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());
}
});
}
2022-01-12 18:42:22 +01:00
@Test
2022-01-17 18:19:40 +01:00
public void registerNew() throws Exception {
2022-01-12 18:42:22 +01:00
WebTarget target=target(InterfaceConstants.Methods.PROJECTS);
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
2022-01-17 18:19:40 +01:00
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
2022-01-12 18:42:22 +01:00
}
2021-12-07 11:16:26 +01:00
// @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)));
// }
2021-09-20 16:47:35 +02:00
}