2017-10-30 14:31:46 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry;
|
|
|
|
|
2019-02-05 15:25:45 +01:00
|
|
|
import java.io.IOException;
|
2019-01-17 15:37:25 +01:00
|
|
|
|
2019-10-25 17:45:16 +02:00
|
|
|
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
|
|
|
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
2019-02-05 15:25:45 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2020-07-03 15:17:35 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextCreator;
|
2020-01-27 17:56:46 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
2019-10-18 11:57:14 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
2020-02-03 10:52:57 +01:00
|
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
2017-10-30 14:31:46 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2019-10-18 11:57:14 +02:00
|
|
|
public class DataBaseCreator extends ContextTest {
|
2017-12-18 12:25:19 +01:00
|
|
|
|
2020-03-20 11:19:10 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(DataBaseCreator.class);
|
2017-10-30 14:31:46 +01:00
|
|
|
|
|
|
|
@Test
|
2017-12-18 12:25:19 +01:00
|
|
|
public void createDatabase() throws Exception {
|
2020-07-03 15:17:35 +02:00
|
|
|
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
|
|
|
|
2020-03-20 11:19:10 +01:00
|
|
|
logger.debug("Going to create DB");
|
2019-10-18 11:57:14 +02:00
|
|
|
String db = DatabaseEnvironment.DB_URI;
|
2019-10-30 09:58:18 +01:00
|
|
|
logger.debug("{} created", db);
|
2020-07-03 15:17:35 +02:00
|
|
|
|
2020-09-23 10:55:51 +02:00
|
|
|
}
|
|
|
|
|
2020-11-05 15:59:37 +01:00
|
|
|
@Test
|
2020-09-23 10:55:51 +02:00
|
|
|
public void createAllContext() throws Exception {
|
|
|
|
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
|
|
|
|
|
|
|
ContextCreator contextCreator = new ContextCreator();
|
2020-07-03 15:17:35 +02:00
|
|
|
contextCreator.all();
|
|
|
|
|
2017-10-30 14:31:46 +01:00
|
|
|
}
|
|
|
|
|
2019-02-05 15:25:45 +01:00
|
|
|
protected Context create(Context context) throws ResourceRegistryException, IOException {
|
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
2020-02-03 10:52:57 +01:00
|
|
|
contextManagement.setJson(ElementMapper.marshal(context));
|
2019-02-05 15:25:45 +01:00
|
|
|
String contextString = contextManagement.create();
|
|
|
|
logger.info("Created {}", contextString);
|
2020-02-03 10:52:57 +01:00
|
|
|
Context c = ElementMapper.unmarshal(Context.class, contextString);
|
2019-02-05 15:25:45 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
public void createDevContext() throws Exception {
|
|
|
|
Context gcube = new ContextImpl("gcube");
|
|
|
|
gcube = create(gcube);
|
|
|
|
|
|
|
|
Context devsec = new ContextImpl("devsec");
|
|
|
|
devsec.setParent(gcube);
|
|
|
|
devsec = create(devsec);
|
|
|
|
|
|
|
|
Context devVRE = new ContextImpl("devVRE");
|
|
|
|
devVRE.setParent(devsec);
|
|
|
|
devVRE = create(devVRE);
|
|
|
|
|
|
|
|
Context devNext = new ContextImpl("devNext");
|
|
|
|
devNext.setParent(gcube);
|
|
|
|
devNext = create(devNext);
|
|
|
|
|
|
|
|
Context nextNext = new ContextImpl("NextNext");
|
|
|
|
nextNext.setParent(devNext);
|
|
|
|
nextNext = create(nextNext);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-30 14:31:46 +01:00
|
|
|
}
|