Search in sources :

Example 6 with TestObject

use of org.eclipse.sw360.testthrift.TestObject in project sw360portal by sw360.

the class DatabaseConnectorTest method testAddDocument.

@Test
public void testAddDocument() throws Exception {
    // Make new object
    TestObject object1 = new TestObject();
    object1.setName("SecondObject");
    object1.setText("This is also some nice text...");
    // Add it
    assertTrue(connector.add(object1));
    // Check that it is there then delete it;
    assertTrue(connector.contains(object1.getId()));
    assertTrue(connector.deleteById(object1.getId()));
}
Also used : TestObject(org.eclipse.sw360.testthrift.TestObject) Test(org.junit.Test)

Example 7 with TestObject

use of org.eclipse.sw360.testthrift.TestObject in project sw360portal by sw360.

the class DatabaseConnectorTest method testUpdateDocument.

@Test
public void testUpdateDocument() throws Exception {
    // Change something in the object
    object.setText("Some new text");
    // Update the document
    connector.update(object);
    // Checkt that the object's revision was updated
    assertNotEquals(rev, object.getRevision());
    // Fetch it again to check it was updated in the database
    TestObject object1 = connector.get(TestObject.class, id);
    assertEquals("Test", object1.getName());
    assertEquals("Some new text", object1.getText());
    // Check that both revision match
    assertEquals(object.getRevision(), object1.getRevision());
    // Check that revision has changed
    assertNotEquals(rev, object1.getRevision());
    rev = object1.getRevision();
}
Also used : TestObject(org.eclipse.sw360.testthrift.TestObject) Test(org.junit.Test)

Example 8 with TestObject

use of org.eclipse.sw360.testthrift.TestObject 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)

Example 9 with TestObject

use of org.eclipse.sw360.testthrift.TestObject in project sw360portal by sw360.

the class MapperFactoryTest method testLicenseDeserialization.

@Test
public void testLicenseDeserialization() throws Exception {
    // Serialize the object (as string)
    String string = mapper.writeValueAsString(object);
    // Deserialize the object
    TestObject parsedObject = mapper.readValue(string, TestObject.class);
    // Check field values
    assertEquals(TEST_ID, parsedObject.getId());
    assertEquals(TEST_REV, parsedObject.getRevision());
    assertEquals(TEST_NAME, parsedObject.getName());
    assertNull("test not present", parsedObject.getText());
}
Also used : TestObject(org.eclipse.sw360.testthrift.TestObject) Test(org.junit.Test)

Aggregations

TestObject (org.eclipse.sw360.testthrift.TestObject)9 Test (org.junit.Test)5 Before (org.junit.Before)3 CouchDbConnector (org.ektorp.CouchDbConnector)1 CouchDbInstance (org.ektorp.CouchDbInstance)1 HttpClient (org.ektorp.http.HttpClient)1 StdHttpClient (org.ektorp.http.StdHttpClient)1 StdCouchDbConnector (org.ektorp.impl.StdCouchDbConnector)1 StdCouchDbInstance (org.ektorp.impl.StdCouchDbInstance)1