Search in sources :

Example 11 with DatabaseConnector

use of org.eclipse.sw360.datahandler.couchdb.DatabaseConnector in project sw360portal by sw360.

the class DatabaseTestSetup method main.

public static void main(String[] args) throws MalformedURLException {
    DatabaseConnector db = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), DatabaseSettings.COUCH_DB_DATABASE);
    Project project = new Project().setName("Test Project");
    project.addToModerators("user1");
    db.add(project);
    ModerationRequest moderationRequest = new ModerationRequest();
    moderationRequest.setDocumentId(project.id).setDocumentType(DocumentType.PROJECT);
    moderationRequest.setRequestingUser("cedric.bodet@tngtech.com");
    moderationRequest.addToModerators("cedric.bodet@tngtech.com");
    db.add(moderationRequest);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 12 with DatabaseConnector

use of org.eclipse.sw360.datahandler.couchdb.DatabaseConnector in project sw360portal by sw360.

the class ProjectHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    List<Project> projects = new ArrayList<>();
    projects.add(new Project().setId("P1").setName("Project1").setBusinessUnit("AB CD EF").setCreatedBy("user1"));
    projects.add(new Project().setId("P2").setName("Project2").setBusinessUnit("AB CD FE").setCreatedBy("user2"));
    projects.get(1).addToContributors("user1");
    projects.add(new Project().setId("P3").setName("Project3").setBusinessUnit("AB CD EF").setCreatedBy("user3"));
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Project project : projects) {
        databaseConnector.add(project);
    }
    // Create the connector
    handler = new ProjectHandler();
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 13 with DatabaseConnector

use of org.eclipse.sw360.datahandler.couchdb.DatabaseConnector in project sw360portal by sw360.

the class DatabaseConnectorTest method setUp.

@Before
public void setUp() throws Exception {
    // Create the test object
    object = new TestObject();
    object.setName("Test");
    object.setText("This is some nice test text.");
    // Initialize the mapper factory
    factory = new MapperFactory(ImmutableList.<Class<?>>of(TestObject.class), Collections.<Class<?>>emptyList(), Maps.newHashMap());
    // Default connector for testing
    HttpClient httpClient = new StdHttpClient.Builder().url(COUCH_DB_URL).build();
    CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
    // Create database if it does not exists
    if (!dbInstance.checkIfDbExists(COUCH_DB_DATABASE)) {
        dbInstance.createDatabase(COUCH_DB_DATABASE);
    }
    CouchDbConnector db = new StdCouchDbConnector(COUCH_DB_DATABASE, dbInstance, factory);
    // Add the object
    db.create(object);
    // Save id and rev for teardown
    id = object.getId();
    rev = object.getRevision();
    // Now create the actual database connector
    connector = new DatabaseConnector(DatabaseTestProperties.getConfiguredHttpClient(), COUCH_DB_DATABASE, factory);
}
Also used : StdHttpClient(org.ektorp.http.StdHttpClient) HttpClient(org.ektorp.http.HttpClient) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) TestObject(org.eclipse.sw360.testthrift.TestObject) CouchDbInstance(org.ektorp.CouchDbInstance) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) CouchDbConnector(org.ektorp.CouchDbConnector) Before(org.junit.Before)

Aggregations

DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)12 Before (org.junit.Before)7 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)4 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 AttachmentConnector (org.eclipse.sw360.datahandler.couchdb.AttachmentConnector)2 ComponentDatabaseHandler (org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler)2 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)1 ComponentSearchHandler (org.eclipse.sw360.datahandler.db.ComponentSearchHandler)1 ProjectDatabaseHandler (org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler)1 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)1 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)1 TestObject (org.eclipse.sw360.testthrift.TestObject)1 CouchDbConnector (org.ektorp.CouchDbConnector)1 CouchDbInstance (org.ektorp.CouchDbInstance)1