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()));
}
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();
}
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);
}
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());
}
Aggregations