@Override protected void setUp() throws Exception { syncano = new Syncano(mContext, Constants.INSTANCE_NAME, Constants.API_KEY); assertTrue( "Device should be connected to internet before test", DownloadTool.connectionAvailable(mContext)); // Create test project ParamsProjectNew paramsProjectNew = new ParamsProjectNew("CI Test Project"); ResponseProjectNew responseProjectNew = syncano.projectNew(paramsProjectNew); assertEquals( "Failed to create test project", Response.CODE_SUCCESS, (int) responseProjectNew.getResultCode()); projectId = responseProjectNew.getProject().getId(); // Create test collection ParamsCollectionNew paramsCollectionNew = new ParamsCollectionNew(projectId, "CI Test Collection"); ResponseCollectionNew responseCollectionNew = syncano.collectionNew(paramsCollectionNew); assertEquals( "Failed to create test collection", Response.CODE_SUCCESS, (int) responseCollectionNew.getResultCode()); collectionId = responseCollectionNew.getCollection().getId(); lock = new CountDownLatch(1); conn = new SyncServerConnection( mContext, Constants.INSTANCE_NAME, Constants.API_KEY, new SyncServerListener() { @Override public void onMessage(String object, JsonObject message) { Log.d(TAG, "message " + object + " " + message); } @Override public void onError(String why) { Log.d(TAG, "error: " + why); } @Override public void onDisconnected() { Log.d(TAG, "disconnected"); lock.countDown(); } @Override public void onConnected() { Log.d(TAG, "connected"); lock.countDown(); } }); conn.start(); lock.await(WAITING_MILLIS, TimeUnit.MILLISECONDS); assertTrue(conn.isConnected()); }
@Override protected void tearDown() throws Exception { conn.stop(); // Clean test collection (called before project is deleted) ParamsCollectionDelete paramsCollectionDelete = new ParamsCollectionDelete(projectId, collectionId); Response responseCollectionDelete = syncano.collectionDelete(paramsCollectionDelete); assertEquals( "Failed to clean test collection", Response.CODE_SUCCESS, (int) responseCollectionDelete.getResultCode()); // Clean test project ParamsProjectDelete paramsProjectDelete = new ParamsProjectDelete(projectId); Response responseProjectDelete = syncano.projectDelete(paramsProjectDelete); assertEquals( "Failed to clean test project", Response.CODE_SUCCESS, (int) responseProjectDelete.getResultCode()); }